Workshop › Scorched Earth-style Artillery › Step 18 of 23
Every shot has a new wind: a small push sideways, added to the speed each frame, like gravity but across. The top middle shows its direction and strength.
```js
let wind
const newWind = () => (wind = Math.round((Math.random() - 0.5) * 10) / 100) // -0.05 to 0.05
newWind()
newWind()
// One frame of flight: wind pushes sideways, gravity pulls down. Returns what it hit, or null.
s.vx += wind
ctx.textAlign = 'center'
const arrow = wind > 0 ? '→' : wind < 0 ? '←' : ''
ctx.fillText('Wind ' + arrow + ' ' + Math.abs(Math.round(wind * 100)), W / 2, 20)
```(Math.random() - 0.5) * 10 is between −5 and 5; rounded and divided by 100 it is −0.05 to 0.05, in steps of 0.01.state, write wind; above fire, write newWind.newWind() in reset before state, and in endTurn after the turn changes.fly, add the wind; update the comment above it.draw, show the wind before the turn text.Skills: Velocity and gravity, Game states
← Win or lose The computer aims →