Workshop › Zelda-style Dungeon › Step 14 of 22
While safe, the hero blinks: shown for 5 frames, hidden for 5. The top strip shows three hearts, red for the ones you still have, gray for the lost ones.
```js
// The player blinks while it cannot be hurt.
if (hurt === 0 || Math.floor(hurt / 5) % 2 === 0) {
ctx.fillStyle = '#16a34a'
ctx.fillRect(player.x, player.y, SIZE, SIZE)
}
for (let i = 0; i < 3; i++) {
ctx.fillStyle = i < hearts ? '#e11d48' : '#44403c'
ctx.fillRect(12 + i * 26, 14, 20, 20)
}
```Math.floor(hurt / 5) % 2 switches between 0 and 1 every 5 frames: shown on 0, hidden on 1.i is red when i < hearts: with 2 hearts, hearts 0 and 1 are red.ctx.restore(), in the top strip.ctx.restore(), draw the three hearts.Skills: Drawing on a canvas, Game states