-
Notifications
You must be signed in to change notification settings - Fork 0
/
obstacle.js
47 lines (42 loc) · 904 Bytes
/
obstacle.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
// obstacles.js
const obstacleTypes = {
redBox: {
color: [255, 0, 0],
size: 40,
image: null,
},
blueBox: {
color: [0, 0, 255],
size: 30,
image: null,
},
};
class Obstacle {
constructor(type, xPosition) {
this.type = obstacleTypes[type];
this.x = xPosition;
this.y = 300 - this.type.size * 0.5;
this.image = this.type.image;
}
show() {
rectMode(CENTER);
if (this.image) {
image(this.image, this.x, this.y, this.type.size, this.type.size);
} else {
fill(this.type.color);
noStroke();
rect(this.x, this.y, this.type.size, this.type.size);
}
}
update(speed) {
this.x -= speed;
}
hits(character) {
let distance = dist(this.x, this.y, character.x, character.y);
return distance < 25;
}
offscreen() {
// 화면 밖으로 나갔는지 판별
return this.x < -this.type.size;
}
}