-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
49 lines (35 loc) · 991 Bytes
/
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
const Engine = Matter.Engine;
const World = Matter.World;
const Bodies = Matter.Bodies;
const Constraint = Matter.Constraint;
var engine, world;
var canvas, angle, tower, ground, cannon;
var cannonball
function preload() {
backgroundImg = loadImage("./assets/background.gif");
towerImage = loadImage("./assets/tower.png");
}
function setup() {
canvas = createCanvas(1200,600);
engine = Engine.create();
world = engine.world;
angle = -PI / 4;
ground = new Ground(0, height - 1, width * 2, 1);
tower = new Tower(150, 350, 160, 310);
cannon = new Cannon(180, 110, 110, 50, angle);
cannonball = new Cannonball(cannon.x, cannon.y)
}
function draw() {
background(189);
image(backgroundImg, 0, 0, width, height);
Engine.update(engine);
ground.display();
cannon.display();
tower.display();
cannonball.display();
}
function keyReleased(){
if (keyCode===DOWN_ARROW){
cannonball.shoot();
}
}