-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
74 lines (59 loc) · 1.62 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
const Engine = Matter.Engine;
const World= Matter.World;
const Bodies = Matter.Bodies;
const Constraint = Matter.Constraint;
var engine, world;
var box1, pig1;
var backgroundImg,platform;
var bird, slingShot;
function preload() {
backgroundImg = loadImage("sprites/bg.png");
}
function setup(){
var canvas = createCanvas(1200,400);
engine = Engine.create();
world = engine.world;
ground = new Ground(600,height,1200,20);
platform = new Ground(150, 305, 300, 170);
box1 = new Box(700,320,70,70);
box2 = new Box(920,320,70,70);
pig1 = new Pig(810, 350);
log1 = new Log(810,260,300, PI/2);
box3 = new Box(700,240,70,70);
box4 = new Box(920,240,70,70);
pig3 = new Pig(810, 220);
log3 = new Log(810,180,300, PI/2);
box5 = new Box(810,160,70,70);
log4 = new Log(760,120,150, PI/7);
log5 = new Log(870,120,150, -PI/7);
bird = new Bird(100,100);
log6 = new Log(230,180,80, PI/2);
slingShot = new slingshot(bird.body,{x:200,y:100});
}
function draw(){
background(backgroundImg);
Engine.update(engine);
strokeWeight(4);
box1.display();
box2.display();
ground.display();
pig1.display();
log1.display();
box3.display();
box4.display();
pig3.display();
log3.display();
box5.display();
log4.display();
log5.display();
bird.display();
platform.display();
log6.display();
slingShot.display();
}
function mouseReleased(){
slingShot.fly();
}
function mouseDragged(){
Matter.Body.setPosition(bird.body,{x:mouseX,y:mouseY})
}