Skip to navigation

Elite on the BBC Micro and NES

Program flow of the main game loop

The sequence of events in the main game loop and the main flight loop

Here is a high-level look at the main program flow, from the title screen to the end of life as we know it, via the main game loop and the main flight loop. The following is mainly about the flight aspects of the game, as the docked screens don't really have much of a flow, they just get shown when the relevant keys are pressed.

Each section is broken down into parts that mirror the structure of the source code, so it should be easy enough to find the relevant parts mentioned below.

Title sequence
--------------

The main title sequence, with its iconic rotating ships, is shown when the game starts, or restarts following a "GAME OVER" message.

1/2: TT170

  • Show "load commander?" title screen (TITLE)
  • Process loading of commander file, if selected
  • Copy last saved commander NA% to current commander TP
  • Show "press fire or space" title screen (TITLE)
  • Set target system to home system
  • Process arrival in system closest to target

2/2: BAY

  • Set the docked flag
  • Jump to the docked section of the main game loop (FRCE, see below) with f8 "pressed" to show Status Mode

Main game loop
--------------

The main game loop starts when we begin a new game. When docked, only parts 5 and 6 form the game loop, but the whole loop from parts 2 to 6 is run when we are in space (part 1 is a subroutine that's called from part 2).

1/6: Main game loop (Part 1 of 6)

  • Potentially called from part 2
  • Spawn a trader

2/6: Main game loop (Part 2 of 6)

  • Call the main flight loop (see below)
  • Clear any expired in-flight messages from the screen
  • On 255 out of 256 iterations, skip straight to MLOOP in part 5
  • Potentially spawn a trader by jumping up to part 1
  • Potentially spawn a cargo canister or an asteroid

3/6: Main game loop (Part 3 of 6)

  • Potentially spawn a cop, with a higher chance if we've been bad

4/6: Main game loop (Part 4 of 6)

  • Potentially spawn a lone bounty hunter, a Thargoid, or a group of 1-4 pirates

5/6: Main game loop (Part 5 of 6)

  • Main entry point for main game loop at MLOOP
  • Cool down the lasers
  • Update the dashboard (DIALS)
  • If this is not a space view, scan for cursor keys

6/6: Main game loop (Part 6 of 6)

  • Entry point for displaying a specific screen at FRCE
  • Process function keys and other non-flight keys (TT102)
  • If docked, loop back to part 5 (MLOOP)
  • If in-flight, loop back to part 2

Main flight loop
----------------

The main flight loop is called from the main game loop, but only if we are in space. It deals with all the flight aspects of the game, calling the various moving and tactics routines as required.

1/16: Main flight loop (Part 1 of 16)

  • Main entry point for main flight loop at M%
  • Seed the random number generator

2/16: Main flight loop (Part 2 of 16)

  • Calculate the alpha and beta angles from the current pitch and roll

3/16: Main flight loop (Part 3 of 16)

  • Scan for flight keys and process the results

Now start looping through all the ships in the local bubble, and for each one, do parts 4-12:

4/16: Main flight loop (Part 4 of 16)

  • Copy the ship's data block from K% to INWK
  • Set XX0 to point to the ship's blueprint (if this is a ship)

5/16: Main flight loop (Part 5 of 16)

  • If an energy bomb has been set off and this ship can be killed, kill it and increase the kill tally

6/16: Main flight loop (Part 6 of 16)

7/16: Main flight loop (Part 7 of 16)

  • Check how close we are to this ship and work out if we are docking, scooping or colliding with it

8/16: Main flight loop (Part 8 of 16)

  • Process us potentially scooping this item

9/16: Main flight loop (Part 9 of 16)

  • Entry point for docking checks at ISDK
  • Process docking with space station, which can take us to the main loop via BAY (if we dock successfully) or DEATH (if we don't)

10/16: Main flight loop (Part 10 of 16)

  • Remove scooped item after both successful and failed scooping attempts
  • Process collisions, which can lead to DEATH

11/16: Main flight loop (Part 11 of 16)

  • If this isn't the front space view, flip the ship coordinates' axes (PLUT)
  • Process missile lock
  • Process our laser firing

12/16: Main flight loop (Part 12 of 16)

  • Draw the ship (LL9)
  • Process the removal of killed ships

Loop back up to part 4 to do the next ship in the local bubble until we have processed them all

13/16: Main flight loop (Part 13 of 16)

  • Show energy bomb effect (if applicable)
  • Charge shields and energy banks

14/16: Main flight loop (Part 14 of 16)

  • Spawn a space station if we are close enough to the planet

15/16: Main flight loop (Part 15 of 16)

  • Perform an altitude check with the planet, which can lead to DEATH
  • Perform an altitude check with the sun, which can also lead to DEATH
  • Process fuel scooping

16/16: Main flight loop (Part 16 of 16)

  • Process laser pulsing
  • Process E.C.M. energy drain
  • Call the stardust routine if we are on a space view (STARS)
  • Return from the main flight loop

Death
-----

The death routine is called when we die (or quit the game by pausing and pressing ESCAPE). It's a one-way street and eventually loops back to the start to show the title screen again.

1/1: DEATH

  • We have been killed, so display the chaos of our destruction above a "GAME OVER" sign
  • Clean up a number of variables and workspaces, ready for the next attempt
  • Jump up to TT170 to start the whole process again