Workshop › Scorched Earth-style Artillery › Step 15 of 23
On its turn the computer "thinks" for one second (60 frames) and then fires with its barrel as it is. It doesn't aim yet; that comes later. A small triangle above a tank shows whose turn it is.
```js
let thinking // frames until the computer shoots
if (turn === 1) thinking = 60
if (state === 'aiming' && turn === 1 && --thinking === 0) {
fire()
}
for (const [i, t] of tanks.entries()) {
if (i === turn && state === 'aiming') {
ctx.fillStyle = '#0f172a'
ctx.beginPath()
ctx.moveTo(t.x - 5, t.y - 34)
ctx.lineTo(t.x + 5, t.y - 34)
ctx.lineTo(t.x, t.y - 27)
ctx.fill()
}
```thinking counts down from 60 on the computer's turn; at 0 it fires.fire already uses tanks[turn], so the same function fires for the computer.tanks.entries() gives each tank with its number i, to compare with turn.state, write thinking; in endTurn, start thinking on the computer's turn.update, after the explosion block, fire when thinking is over.draw, number the tanks in the loop, and draw the triangle after the health bar.Skills: Game states, The game loop
← Taking turns Hitting a tank →