Workshop › Asteroids › Step 30 of 41
If a rock drifts through the middle when the ship respawns, the player loses another life without touching a key. The fix: two seconds of invulnerability. The ship remembers until when it is safe.
```js
const SAFE_TIME = 2000 // milliseconds of invulnerability after respawning
ship = { x: canvas.width / 2, y: canvas.height / 2, angle: -Math.PI / 2, vx: 0, vy: 0, safeUntil: now + SAFE_TIME }
if (now >= ship.safeUntil && asteroids.some((asteroid) => hits(ship, SHIP_R * 0.7, asteroid, asteroid.r))) {
```safeUntil, two seconds from now.now >= ship.safeUntil, that is, once the safe time is over.POINTS write SAFE_TIME.resetShip, add safeUntil: now + SAFE_TIME to the ship.update, put now >= ship.safeUntil && at the start of the crash condition.Skills: Game states, Collision detection
← What time is it? Blink while safe →