The sequence of events in the main game loop
Here is a high-level look at the main program flow, from the "Please wait" screen at the start, all the way to a crash landing via the main game loop.
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.
Start-up sequence
-----------------
On starting up, the game loads the dashboard and displays a "Please wait" message while it gets everything ready for the start of a new game.
- Move blocks of code in memory
- Set the screen mode
- Print "Please wait"
- Load the dashboard image
- Move more blocks of code in memory
- Draw the canopy edges and rivets
- Reset the high score
- Define sound envelopes
- Clear the canopy view
- Reset game variables
- Reset the key logger
- Initialise the flight model
- Reset the line lists
- Update the flaps indicator
- Update the brakes indicator
- Reset the 6522 User VIA timers
Main game loop
--------------
The main game loop starts when we begin a new game, and runs until we crash.
1/15: Main game loop (Part 1 of 15)
- If the Theme is enabled and the current wave does not yet have eight aliens in it, call SpawnAlien to spawn a new alien
- Scan for key presses and update the key logger
- If the fire key is being pressed and there aren't already bullets in the air, spawn the bullets and start making the firing sound
- Call UpdateFlightModel to update the matrices and the flight model
2/15: Main game loop (Part 2 of 15)
- Set the runway dashes to be visible
- Reset the objectStatus table
- Reset the relatedPoints list
3/15: Main game loop (Part 3 of 15)
- If there are bullets in the air, call UpdateBullets to update the bullet positions
- If we are need to make the sound of our guns firing, keep making the sound and decrement the sound counter
4/15: Main game loop (Part 4 of 15)
- If the Theme is enabled, call AlienInAcornsville to implement alien tactics and see whether an alien has reached Acornsville
5/15: Main game loop (Part 5 of 15)
- Call UpdateLinesToShow to prune the linesToShow list
- Call ExplodeAlien to process any exploding aliens
- Call CheckFlyingSkills to check whether we are flying under the suspension bridge or down the main street of Acornsville, and award points if we are
- Increment the main loop counter
- once every 8 iterations of the main loop, call UpdateRadarBlip to update the runway and (if applicable) the attacking alien on the radar
6/15: Main game loop (Part 6 of 15)
- If the Theme is enabled and there are bullets in the air, call CheckIfAlienIsHit for each alien in turn to see whether it has been hit
- If an alien has been hit, store the distance from the alien so the flight model can apply turbulence, and remove the bullets
- If the Theme is enabled, call UpdateAliens to update the aliens so they progress through their feeding or attack cycles
7/15: Main game loop (Part 7 of 15)
- If we are on the ground, check to see if the reset key is being pressed (right arrow), and if so call TerminateGame to terminate the current game and wait for a key press, and then jump to NewGame to start a new game
8/15: Main game loop (Part 8 of 15)
- If we are on the ground and fire the guns, enable the Theme and update the Theme indicator
9/15: Main game loop (Part 9 of 15)
- If we are on the ground and the engine is off, call FillUpFuelTank to fill up the fuel tank
- Call ProcessVolumeKeys to check the volume keys and adjust the sound volume accordingly
10/15: Main game loop (Part 10 of 15)
- If we have just landed on the runway and have previously reached an altitude of 512 feet, call ScorePoints to award 150 points for a successful landing
11/15: Main game loop (Part 11 of 15)
- Update the fuel gauge
- If "T" is being pressed, call SetEngine to toggle the engine on and off
12/15: Main game loop (Part 12 of 15)
- If there are fewer than 35 points in the relatedPoints list, then call ProcessLinesToHide in batches of three to check the hidden lines list for lines that are now visible, making sure that we don't spend too much time doing this
13/15: Main game loop (Part 13 of 15)
- Call ProcessLinesToShow to process the lines in the linesToShow list, calculating their on-screen coordinates by projecting them onto the screen
- Call DrawCanopyView to update the main view out of the canopy by erasing what's currently there and drawing all the visible lines in their new positions, all using flicker-free animation through colour cycling
- Call SetRandomNumber to generate a new random number to add to the random number list
14/15: Main game loop (Part 14 of 15)
- If "P" is being pressed, call DisplayScore to show the scores
- If the score is already being displayed and it's time to remove it, call RemoveScore
15/15: Main game loop (Part 15 of 15)
- If we have added any lines to the linesToHide list during the main loop, reset their status bytes so they are no longer marked as visible
Crashing
--------
The Crash routine is called when we hit the bridge or the town's buildings, or we hit the ground dangerously (as opposed to a controlled landing). It's a one-way street and eventually loops back to the NewGame routine to start a new game.
- Turn off the engine sound
- Flash the canopy screen
- Pause for a short time
- Call TerminateGame to terminate the current game and wait for a key press
- Jump to NewGame to start a new game