respawn, better death message

This commit is contained in:
biglyderv 2024-09-28 20:06:48 -04:00
parent 969e30f263
commit a5b1436769
No known key found for this signature in database
GPG key ID: 33AC87E9ACE66954
3 changed files with 18 additions and 26 deletions

View file

@ -31,20 +31,6 @@ p {
margin: 10px;
}
.message {
position: relative;
margin-bottom: -768px;
bottom: 768px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background: rgba(0, 0, 0, 0.5);
}
.message span {
display: block;
text-align: center;
@ -59,7 +45,7 @@ p {
padding: 10px;
}
#canvas, .message {
#canvas {
width: 768px;
height: 768px;
/*image-rendering: pixelated;*/
@ -71,13 +57,8 @@ section#main {
}
@media (max-width: 1920px) {
#canvas, .message {
#canvas {
width: min(512px, 90vw);
height: min(512px, 90vw);
}
.message {
margin-bottom: min(512px, 90vw);
bottom: min(512px, 90vw);
}
}

View file

@ -11,10 +11,9 @@
<h1>UniButton</h1>
<p>The <b>left mouse</b> is the only button. Click to launch... figure out the rest of the combos yourself.</p>
<p><i>By <a href='https://zenoverse.net/'>Onez</a>, more games at <a
href='https://discord.gg/EpsRZrHswB'>Discord</a></i></p>
href='https://discord.gg/EpsRZrHswBu'>Discord</a></i></p>
<div>
<canvas id='canvas'></canvas>
<div class='message' style='display: none;'><span>You are dead.</span></div>
</div>
<div class='ui-text'>
placeholder

View file

@ -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();