-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShip.js
53 lines (41 loc) · 787 Bytes
/
Ship.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
class Ship {
constructor(x, spaceshipImage) {
this.x = x;
this.score = 0;
this.r = 15;
this.respawn();
this.spaceshipImage = spaceshipImage;
}
update() {
if (this.isUp && this.y > 0) {
this.up();
} else if (this.isDown && this.y < height - 20) {
this.down();
}
if (this.hasPlayerScoredAPoint()) {
this.score ++;
this.respawn();
}
}
display() {
imageMode(CENTER);
image(this.spaceshipImage, this.x, this.y, this.r*2, this.r*2);
}
up() {
this.y--;
}
down() {
this.y++;
}
hasPlayerScoredAPoint() {
if (this.y <= 0) {
return true;
}
return false;
}
respawn() {
this.y = height - 20;
this.isUp = false
this.isDown = false;
}
}