-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaddle.js
52 lines (44 loc) · 1.12 KB
/
paddle.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
import { ctx, purple } from "./game.js";
import { gridsafe, grid_size } from "./grid.js";
import { mouseX, mouseY } from "./ui.js";
import { canvas } from "./game.js";
export class Paddle {
constructor() {
this.colour = purple;
this.x = canvas.width / 2;
this.y = canvas.height / 2;
this.direction = 0;
}
get x() {
return this._x;
}
set x(new_val) {
this._x = gridsafe(new_val);
}
get y() {
return this._y;
}
set y(new_val) {
this._y = gridsafe(new_val);
}
get direction() {
// 0 is vertical, 1 is horizontal
return this._dir;
}
set direction(new_value) {
if (new_value == 0) {
this.height = grid_size * 2;
this.width = grid_size;
} else {
this.height = grid_size;
this.width = grid_size * 2;
}
this.x = mouseX - this.width / 2;
this.y = mouseY - this.height / 2;
this._dir = new_value;
}
draw() {
ctx.fillStyle = this.colour;
ctx.fillRect(this.x, this.y, this.width, this.height);
}
}