CODE
Signaling Module: [Header File] [Pseudocode] [C Code] Timing Module: [Header File] [Pseudocode] [C Code] Pinout: [Pinout Diagram] |
Game Play Module: [Header File] [Pseudocode] [C Code] Main Module: [Header File] [Pseudocode] [C Code] |
Main Pseudocode
/* State machine for Railroad HandCar arcade game */ Main Set the current state to 'initializing' game settings Repeat forever Evaluate depending on the current state: /* Initialize timer and IO ports at startup */ If initializing: Initialize the following timers: Collision, recovery, overall game Initialize the following IO ports: T all input, M all output, AD at least 1 analog input Set the current state to 'waiting for penny insertion' /* Initialize/place villain. Wait for penny */ If waiting for penny insertion: Initialize the handcar speed to 0 Initialize the background scroll speed to 0 If the villain is not at his initial position Slowly back the villain to his initial position If a penny has been inserted Sound a single 'game ready' chime Set the current state to 'waiting for the game to start' /* Set ready light. Wait for 'start' button */ If waiting for the game to start: Light the 'game ready' lights If the start button has been pressed Sound a double 'game playing' chime Turn off the 'game ready' lights Start the overall game timer Set the current state to 'playing the game' /* Main game execution. Advance villain and */ /* poll every 10 msec whether player caught */ /* jumping or colliding. Advance background */ If currently playing the game: If the overall game timer has not expired If the player has not been caught Determine if the player is jumping or landing If the player is not colliding Set the handcar speed based on handpump speed Stop vibrating the pump handle Else (the player is colliding) Set the handcar speed to 0 Start vibrating the pump handle Set the background scroll speed based on the handcar speed Position the villain based on the handcar speed Else (the player has been caught) /* Game lost (caught by the villain) */ Sound a triple 'game over' chime Set the current state to 'initializing' Step forward the game play timer Else (the overall game timer has expired) /* Game won (played until GAME_TIME) */ Sound a triple 'game over' chime Set the current state to 'initializing' Dispense the SWAG