-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
62 lines (45 loc) · 1.1 KB
/
sketch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
var starImg, fairyImg, bgImg;
var fairy , fairyVoice;
var star, starBody;
const Engine = Matter.Engine;
const World = Matter.World;
const Bodies = Matter.Bodies;
const Body = Matter.Body;
function preload()
{
starImg = loadImage("images/star.png");
fairyImg = loadAnimation("images/fairyImage1.png","images/fairyImage2.png");
bgImg = loadImage("images/starNight.png");
fairyVoice = loadSound("sound/JoyMusic.mp3");
}
function setup() {
createCanvas(800, 750);
// fairyVoice.play();
fairy = createSprite(130, 520);
fairy.addAnimation("fairyflying",fairyImg);
fairy.scale =0.25;
star = createSprite(650,30);
star.addImage(starImg);
star.scale = 0.2;
engine = Engine.create();
world = engine.world;
starBody = Bodies.circle(650 , 30 , 5 , {restitution:0.5, isStatic:true});
World.add(world, starBody);
Engine.run(engine);
}
function draw() {
background(bgImg);
drawSprites();
if(fairy.x>650){
Matter.Body.setStatic(starBody.body,false);
}
}
function keyPressed() {
//write code here
if(keyCode===LEFT_ARROW) {
fairy.x=fairy.x-15
}
if(keyCode===RIGHT_ARROW){
fairy.x=fairy.x+15
}
}