Workshop › Scorched Earth-style Artillery › Step 11 of 23

Craters

What we are doing

An explosion digs a round hole. For each column within the blast, the bottom of a circle of radius 30 is found; if it is lower than the ground there, the ground drops to it. Holes never go through the bottom of the screen.

```js
// Blow a round hole in the ground and hurt the tanks nearby.
  for (let cx = Math.floor(x - BLAST); cx <= x + BLAST; cx++) {
    if (cx < 0 || cx >= W) continue
    const bottom = y + Math.sqrt(BLAST * BLAST - (cx - x) ** 2)
    if (bottom > ground[cx]) ground[cx] = Math.min(H - 2, bottom)
  }
```

What it means

Your turn

  1. Above explode, write the comment.
  2. At the top of explode, dig the hole.

Skills: Velocity and gravity, Arrays and objects

All steps

  1. The ground
  2. Hills
  3. Two tanks
  4. The barrel
  5. The game loop
  6. Aim
  7. Angle and power
  8. Fire!
  9. Flight
  10. Boom
  11. Craters
  12. Falling tanks
  13. Damage
  14. Taking turns
  15. The computer's shot
  16. Hitting a tank
  17. Win or lose
  18. Wind
  19. The computer aims
  20. Aim with the mouse
  21. Drag and let go
  22. The atan2 trap
  23. Build it yourself: a trail