-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
69 lines (45 loc) · 1.31 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
63
64
65
66
var helicopterIMG, helicopter, package,packageIMG;
var packageBody,ground;
const Engine = Matter.Engine;
const World = Matter.World;
const Bodies = Matter.Bodies;
const Body = Matter.Body;
function preload()
{
helicopterIMG=loadImage("helicopter.png")
packageIMG=loadImage("package.png")
}
function setup() {
createCanvas(800, 700);
rectMode(CENTER);
package=createSprite(width/2, 80, 10,10);
package.addImage(packageIMG)
package.scale=0.2
helicopter=createSprite(width/2, 200, 10,10);
helicopter.addImage(helicopterIMG)
helicopter.scale=0.6
groundSprite=createSprite(width/2, height-35, width,10);
groundSprite.shapeColor=color(255)
engine = Engine.create();
world = engine.world;
packageBody = Bodies.circle(width/2 , 200 , 5 , {restitution:0.5, isStatic:true});
World.add(world, packageBody);
//Create a Ground
ground = Bodies.rectangle(width/2, 650, width, 10 , {isStatic:true} );
World.add(world, ground);
Engine.run(engine);
}
function draw() {
rectMode(CENTER);
background(0);
package.x= packageBody.position.x
package.y= packageBody.position.y
keyPressed();
drawSprites();
}
function keyPressed() {
if (keyCode == DOWN_ARROW) {
// Look at the hints in the document and understand how to make the package body fall only on
Body.setStatic(packageBody, false);
}
}