-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayer.js
More file actions
73 lines (60 loc) · 1.57 KB
/
player.js
File metadata and controls
73 lines (60 loc) · 1.57 KB
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
67
68
class Player {
constructor(ctx, canvas) {
this.ctx = ctx;
this.canvas = canvas;
this.parameters = {
x: 400,
y: 400,
radius: 40,
hittable: true
}
this.score = 0;
}
drawPlayer() {
let { x, y, radius } = this.parameters;
this.ctx.beginPath();
this.ctx.arc(x, y, radius, 0, Math.PI*2);
this.ctx.strokeStyle = "red";
this.ctx.stroke();
this.ctx.closePath();
if (!this.parameters.hittable) {
ctx.fillStyle = 'red';
ctx.fill();
}
// this.image = new Image();
// this.image.src = './app/assets/1200px-SNice.svg.png'
}
updatePosition(direction, num) {
switch (direction) {
case "right":
this.parameters.x += num;
break;
case "left":
this.parameters.x -= num;
break;
case "up":
this.parameters.y -= num;
break;
case "down":
this.parameters.y += num;
break;
default:
break;
}
}
collision() {
this.score += 1;
}
circleCollision() {
if (this.parameters.hittable) { this.score -= 1 };
if (this.score < 0) {
this.score = 0;
}
}
drawScore() {
this.ctx.font = "24px Arial";
this.ctx.fillStyle = "#0095DD";
this.ctx.fillText("Score: "+this.score, 500, 80);
}
}
export default Player;