-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathitem.js
More file actions
66 lines (54 loc) · 977 Bytes
/
item.js
File metadata and controls
66 lines (54 loc) · 977 Bytes
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
export default class Item {
#x;
#y;
#width;
#height;
#color;
#speed;
#colorArr;
constructor(x = 0, speed = 4) {
this.#x = x;
this.#y = 0;
this.#width = 15;
this.#height = 15;
this.#colorArr = ['#9933FF', '#FFCCFF', '#CC99FF'];
this.#speed = speed;
}
move() {
this.#y += this.#speed;
}
draw(ctx) {
let x = this.#x;
let y = this.#y;
let width = this.#width;
let height = this.#height;
let colorIndex = Math.floor(Math.random() * 3);
let color = this.#colorArr[colorIndex];
ctx.fillStyle = color;
ctx.fillRect(x, y, width, height);
}
update() {
this.#y += this.#speed;
}
endCheck(size) {
if (this.#y >= size) {
return true;
}
return false;
}
get x() {
return this.#x;
}
get y() {
return this.#y;
}
get width() {
return this.#width;
}
get height() {
return this.#height;
}
speedUp() {
this.#speed += 0.5;
}
}