-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
65 lines (44 loc) · 1.28 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 helicopterIMG, helicopterSprite, packageSprite,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);
packageSprite=createSprite(width/2, 80, 10,10);
packageSprite.addImage(packageIMG)
packageSprite.scale=0.2
helicopterSprite=createSprite(width/2, 200, 10,10);
helicopterSprite.addImage(helicopterIMG)
helicopterSprite.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.4, 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);
packageSprite.x= packageBody.position.x
packageSprite.y= packageBody.position.y
keyPressed();
drawSprites();
}
function keyPressed() {
if (keyCode === DOWN_ARROW) {
{ Matter.Body.setStatic(packageBody,false); }
}
}