Add brief red damage flash for T-Rex on hit
This commit is contained in:
parent
94d371d901
commit
eb9908839d
13
js/game.js
13
js/game.js
@ -448,7 +448,8 @@ function createInitialState(config = gameConfig) {
|
||||
speed: 300 * DIFFICULTY[config.difficulty].moveSpeed,
|
||||
jumpPower: 760,
|
||||
onGround: true,
|
||||
ducking: false
|
||||
ducking: false,
|
||||
damageFlashTimer: 0
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -648,9 +649,13 @@ function drawBackground() {
|
||||
|
||||
function drawTRex(p) {
|
||||
const sx = p.x - state.cameraX;
|
||||
ctx.fillStyle = '#35535f';
|
||||
const isDamageFlashing = p.damageFlashTimer > 0;
|
||||
const bodyColor = isDamageFlashing ? '#d94b4b' : '#35535f';
|
||||
const detailColor = isDamageFlashing ? '#a52828' : '#27404a';
|
||||
|
||||
ctx.fillStyle = bodyColor;
|
||||
ctx.fillRect(sx, p.y, p.width, p.height);
|
||||
ctx.fillStyle = '#27404a';
|
||||
ctx.fillStyle = detailColor;
|
||||
ctx.fillRect(sx + p.width - 12, p.y + 14, 7, 7);
|
||||
ctx.fillRect(sx + 10, p.y + p.height - 8, 14, 8);
|
||||
ctx.fillRect(sx + p.width - 24, p.y + p.height - 8, 14, 8);
|
||||
@ -901,6 +906,7 @@ function applyHit(reason) {
|
||||
if (state.hitCooldown > 0 || state.dead) return;
|
||||
state.hearts -= 1;
|
||||
state.hitCooldown = DIFFICULTY[gameConfig.difficulty].hitCooldown;
|
||||
state.player.damageFlashTimer = 0.18;
|
||||
playSfx('hit');
|
||||
if (state.hearts <= 0) kill(reason);
|
||||
}
|
||||
@ -1103,6 +1109,7 @@ function tick(ts) {
|
||||
|
||||
if (state.running) {
|
||||
state.hitCooldown = Math.max(0, state.hitCooldown - dt);
|
||||
state.player.damageFlashTimer = Math.max(0, state.player.damageFlashTimer - dt);
|
||||
updatePlayer(dt);
|
||||
updatePortal(dt);
|
||||
updateAnts(dt);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user