-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
73 lines (61 loc) · 1.26 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
var ship;
var circles = [];
var beams = [];
function setup() {
createCanvas(600, 400);
ship = new Ship();
// beams = new Beam(width/2, height/2);
for (var i = 0; i < 6; i++) {
circles[i] = new Circle(i*80+80, 60);
}
}
function draw() {
background(51);
ship.show();
ship.move();
for (var i = 0; i < beams.length; i++) {
beams[i].show();
beams[i].move();
for (var j = 0; j < circles.length; j++) {
if (beams[i].hits(circles[j])) {
circles[j].shrink();
beams[i].delete();
console.log("hit");
}
}
}
var edge = false;
for (var i = 0; i < circles.length; i++) {
circles[i].show();
circles[i].move();
if (circles[i].x > width || circles[i].x < 0) {
edge = true;
}
}
if (edge) {
for (var i = 0; i < circles.length; i++) {
circles[i].shiftDown();
}
}
for (var i = beams.length-1; i >= 0; i--) {
if (beams[i].toDelete) {
beams.splice(i, 1);
}
}
}
function keyReleased() {
if (key != ' ') {
ship.setDir(0);
}
}
function keyPressed() {
if (key === ' ') {
var beam = new Beam(ship.x, height);
beams.push(beam);
}
if (keyCode === RIGHT_ARROW) {
ship.setDir(1);
} else if (keyCode === LEFT_ARROW) {
ship.setDir(-1);
}
}