Moved classes his own files
This commit is contained in:
25
Score.js
Normal file
25
Score.js
Normal file
@ -0,0 +1,25 @@
|
||||
class Score {
|
||||
constructor(ctx) {
|
||||
this.ctx = ctx;
|
||||
this.reset();
|
||||
|
||||
this.ctx.font = "30px Consolas";
|
||||
let m = ctx.measureText('Score: 00000');
|
||||
this.x = ctx.canvas.width - m.width;
|
||||
this.y = -10;
|
||||
}
|
||||
reset() {
|
||||
this.points = 0;
|
||||
}
|
||||
add(x) {
|
||||
this.points += x;
|
||||
}
|
||||
update() {
|
||||
if (this.y != 30) this.y++;
|
||||
if (this.y > 0) {
|
||||
this.ctx.font = "30px Consolas";
|
||||
this.ctx.fillStyle = 'Black';
|
||||
this.ctx.fillText('Score: ' + this.points, this.x, this.y);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user