-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoins.js
46 lines (38 loc) · 1.23 KB
/
coins.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
// Add states inProgress and score, player, canvas (platform),
// Add methods start() and changeScore(), move player?, define canvas,
class Coin {
constructor(x, y, radius, startAngle, endAngle, color) {
//this.width = width;
// this.height = height;
this.x = x;
this.y = y;
this.radius = radius;
this.startAngle = startAngle;
this.endAngle = endAngle;
this.color = color;
}
makeCoin() {
let ctx = document.querySelector('canvas').getContext('2d'); // comment out later?
//ctx.fillRect(this.x, this.y, this.width, this.height);
ctx.beginPath();
ctx.fillStyle = this.color;
ctx.strokeStyle = this.color;
ctx.arc(this.x, this.y, this.radius, this.startAngle, this.endAngle);
ctx.fill();
ctx.stroke();
}
moveCoin() {
this.x = Math.floor(Math.random() * 470) + 10;
this.y = Math.floor(Math.random() * 180) + 10;
}
updateCoin() {
let ctx = document.querySelector('canvas').getContext('2d');
//ctx.clearRect(0, 0, 480, 200); // added in
//ctx.fillRect(this.x, this.y, this.width, this.height);
ctx.beginPath();
ctx.fillStyle = this.color;
ctx.arc(this.x, this.y, this.radius, this.startAngle, this.endAngle);
ctx.fill();
ctx.stroke();
}
}