changed ball and bar for a sprite
This commit is contained in:
46
assets/js/Bricks.js
Normal file
46
assets/js/Bricks.js
Normal file
@ -0,0 +1,46 @@
|
||||
class Brick {
|
||||
constructor(type, column, row) {
|
||||
this.type = type;
|
||||
this.row = row;
|
||||
this.column = column;
|
||||
|
||||
this.vspace = 2;
|
||||
this.hspace = 2;
|
||||
|
||||
this.w = (360 / 8) - this.hspace;
|
||||
this.h = (20) - this.vspace;
|
||||
this.x = (this.w + this.hspace) * column;
|
||||
this.y = 80 + (this.h + this.vspace) * row;
|
||||
|
||||
switch (type) {
|
||||
case 2: this.lives = 2; break;
|
||||
case 3: this.lives = 3; break;
|
||||
default: this.lives = 1; break;
|
||||
}
|
||||
}
|
||||
|
||||
crack() {
|
||||
this.lives--;
|
||||
}
|
||||
|
||||
update(ctx) {
|
||||
if (this.lives == 0) return false;
|
||||
|
||||
switch (this.lives) {
|
||||
case 1:
|
||||
ctx.fillStyle = 'blue';
|
||||
ctx.fillRect(this.x + 1, this.y, this.w, this.h);
|
||||
break;
|
||||
case 2:
|
||||
ctx.fillStyle = 'orange';
|
||||
ctx.fillRect(this.x + 1, this.y, this.w, this.h);
|
||||
break;
|
||||
case 3:
|
||||
ctx.fillStyle = 'red';
|
||||
ctx.fillRect(this.x + 1, this.y, this.w, this.h);
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user