Workshop › Scorched Earth-style Artillery › Step 14 of 23
After each shot the turn passes to the other tank. When it's the computer's turn, your keys don't aim and Space doesn't fire. The top right says whose turn it is. (The computer learns to shoot in the next step.)
```js
function endTurn() {
turn = 1 - turn
state = 'aiming'
}
endTurn()
if (state !== 'aiming' || turn !== 0) return
if (turn === 0) fire()
ctx.textAlign = 'right'
ctx.fillText(turn === 0 ? 'Your turn' : 'Computer', W - 10, 20)
```1 - turn flips 0 to 1 and 1 to 0.endTurn() instead of going back to aiming.aimBy and Space only work on your turn, while aiming.update, write endTurn; when the explosion ends, call it.aimBy, aim only on your turn; on Space, fire only on your turn.draw, show whose turn it is.Skills: Game states
← Damage The computer's shot →