-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
104 lines (67 loc) · 2.16 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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);
boxPosition=width/2-100
boxY=610;
boxleftSprite=createSprite(boxPosition, boxY, 20,100);
boxleftSprite.shapeColor=color(255,0,0);
boxLeftBody = Bodies.rectangle(boxPosition+20, boxY, 20,100 , {isStatic:true} );
World.add(world, boxLeftBody);
boxBase=createSprite(boxPosition+100, boxY+40, 200,20);
boxBase.shapeColor=color(255,0,0);
boxBottomBody = Bodies.rectangle(boxPosition+100, boxY+45-20, 200,20 , {isStatic:true} );
World.add(world, boxBottomBody);
boxleftSprite=createSprite(boxPosition+200 , boxY, 20,100);
boxleftSprite.shapeColor=color(255,0,0);
boxRightBody = Bodies.rectangle(boxPosition+200-20 , boxY, 20,100 , {isStatic:true} );
World.add(world, boxRightBody);
Engine.run(engine);
}
function draw() {
rectMode(CENTER);
background(0);
packageSprite.x= packageBody.position.x
packageSprite.y= packageBody.position.y
packageSprite.x=helicopterSprite.x
move();
drawSprites();
}
function move (){
if(keyDown(LEFT_ARROW))
{
helicopterSprite.x=helicopterSprite.x-5;
}
if(keyDown(RIGHT_ARROW))
{
helicopterSprite.x=helicopterSprite.x+5;
}
if(keyCode === DOWN_ARROW) {
Matter.Body.setStatic(packageBody,false)
}
}