respawn, better death message
This commit is contained in:
parent
e9885e3615
commit
4260eefafe
3 changed files with 18 additions and 26 deletions
18
js/index.js
18
js/index.js
|
@ -34,9 +34,7 @@ Game.prototype.main = function () {
|
|||
let { entities, player } = this;
|
||||
|
||||
if (player.health <= 0) {
|
||||
document.querySelector('.message').style.display = 'flex';
|
||||
return;
|
||||
} else {
|
||||
}
|
||||
|
||||
for (let ent of entities) {
|
||||
|
@ -98,6 +96,16 @@ Game.prototype.render = function () {
|
|||
}
|
||||
|
||||
ctx.restore();
|
||||
|
||||
if (player.health <= 0) {
|
||||
ctx.fillStyle = 'rgba(0,0,0,0.5)';
|
||||
ctx.fillRect(0,0,cs,cs);
|
||||
ctx.fillStyle = 'rgb(255,255,255)';
|
||||
ctx.textAlign = "center";
|
||||
ctx.textBaseline = "middle";
|
||||
ctx.font = "bold 48px sans-serif";
|
||||
ctx.fillText('You died! Click to respawn',cs/2,cs/2);
|
||||
}
|
||||
}
|
||||
|
||||
Game.prototype.ui = function() {
|
||||
|
@ -107,7 +115,11 @@ Game.prototype.ui = function() {
|
|||
Game.prototype.click = function () {
|
||||
let { player } = this;
|
||||
|
||||
player.bump(game);
|
||||
if (player.health <= 0) {
|
||||
game = new Game();
|
||||
} else {
|
||||
player.bump(game);
|
||||
}
|
||||
}
|
||||
|
||||
var game = new Game();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue