Asteroids game flow

Mini Arcade · Based on src/asteroids.c and its integration in src/main.c.

Screen captures

Views of this part running on the Mini Arcade.

Asteroids game screen on the Mini Arcade
Asteroids running on the Mini Arcade display.

Overall game flow

Read from top to bottom. Branches describe the condition and where execution goes next.

  1. Open Asteroids from GamesstartAsteroids() enters READY.
  2. Choose PLAY or AUTOD / B / joystick changes the selected mode.
  3. A / K pressed?Wait on the selection screen until Start is pressed.
  4. Begin a new gamebeginGame(): score 0, wave 1, three lives.
    Centre the ship, give 2.5 seconds of protection and spawn three large rocks.
  5. Read controlsUse player input or calculate AUTO steering, thrust and fire.
  6. Update gameplayRun available 10 ms simulation steps.
    See the detailed flow below.
  7. Draw the current gameRocks, bullets, ship, score, wave and lives.
  8. Still playing?
    Yes — PLAYINGLoop back to Read controls.
    No — FINISHEDShow GAME OVER for one second, then continue below.
  9. Which mode ended?
    AUTOReturn to Begin a new game automatically.
    PLAYOpen high-score entry. When complete, return to Choose PLAY or AUTO.

Other routes: C during AUTO play returns to READY and selects PLAY. BOOT leaves the game; stopAsteroids() cancels high-score entry and stops engine thrust audio.

Each 10 ms simulation step

simulateStep() advances movement, handles collisions and checks wave completion.

  1. Update timersReduce ship protection and firing cooldown.
  2. Update the shipRotate, apply thrust, limit speed and move.
    Wrap movement around the screen edges.
  3. Can the ship fire?If fire is requested, cooldown is clear and a slot is free:
    create a bullet and start the 180 ms cooldown.
    Otherwise continue without creating a bullet.
  4. Move the rocks and bulletsRotate rocks and reduce bullet lifetimes.
  5. Check each bullet against active rocks
    HitRemove the bullet and rock. Add points. A large or medium rock splits into two smaller rocks.
    No hitContinue to the next bullet.
  6. Unprotected ship hits a rock?
    Yes — lives remainLose one life. Reset ship, restore protection and clear bullets. Return from this step.
    Yes — final life lostEnter FINISHED, stop thrust audio and award whole thousands of score as Gold. Return from this step.

    If no ship collision occurs, continue to the wave check below.

  7. Any rocks remaining?
    YesReturn from this step.
    NoIncrease wave, clear bullets and spawn the next wave. Return from this step.
  8. Return to the update loopRun another step if enough accumulated time remains and the game is still PLAYING; otherwise draw.

Key game rules

RuleCurrent implementation
Rock pointsLarge: 20 · Medium: 50 · Small: 100
Wave sizeThree large rocks initially; increases to a maximum of eight.
GoldFinal score divided by 1,000, rounded down; saved to the player or AI balance.
AUTO controlTarget the nearest rock. Turn and fire when aligned; turn away and thrust when danger is close.
SimulationFixed 10 ms steps; elapsed catch-up time capped at 100 ms per update.
Screen edgesMovement and collision distances both account for wrapping.