-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayer.js
More file actions
39 lines (33 loc) · 767 Bytes
/
player.js
File metadata and controls
39 lines (33 loc) · 767 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
class Player {
x;
y;
height;
width;
speed;
color;
constructor(x, y, height, width, speed, color) {
this.x = x;
this.y = y;
this.height = height;
this.width = width;
this.speed = speed;
this.color = color;
}
draw(context) {
context.beginPath();
context.rect(this.x, this.y, this.width, this.height)
context.fillStyle = this.color;
context.fill();
context.closePath();
}
moveLeft(canvasWidth) {
this.x -= this.speed;
if (this.x < 0)
this.x += canvasWidth;
}
moveRight(canvasWidth) {
this.x += this.speed;
if (this.x >= canvasWidth)
this.x -= canvasWidth;
}
}