You are on page 1of 5

/**********

Pseudocode for updateOLED.c


This service file is responsible for controlling all joystick
movement, which includes
arrow selecting difficulty level on the title screen and TIE fighter
movement in game
***********/

Include the following files:


- ES_Configure.h
- ES_Framework.h
- UpdateOLED.h
- Projectile.h
- Spaceship.h
- EnemyShip.h
- Gameplay.h
- u8g2TestHarness_main.h (u8g2)
- common.h (u8g2)
- spi_master.h (u8g2)
- u8g2.h (u8g2)
- u8x8.h (u8g2)

Define the following variables:


- LENGTH_OF_SCREEN (value of 128)
- WIDTH_OF_SCREEN (value of 64)
- ONE_SECOND (value of 1000)

Define the following module-level functions:


- void updateALL, with void parameter
- void initOLED, with void parameter
- bool CheckOLEDStatus, with void parameter

Initialize the following module-level variables:


- extern uint8 variable u8x8_pic32_gpio_and_delay
- extern uint8 variable u8x8_byte_pic32_hw_spi
- u8g2 variable u8g2
- uint8 variable GameMode
- OLEDState variable CurrentState
- uint8 variiable MyPriority
- enemyArray variable enemyPositions
- uint8 variable spaceshipPosition
- ProjectileLoc array variable ProjectilePosition, with 11
possible values
- uint8 variable score
- uint8 array variable scoreBoard, with 3 possible values
- constant uint8 array variable upperLeftRowPixel, with values
3, 15, 27, and 39
- constant uint8 array variable upperLeftColPixel, with values
ranging from 6 to 144 in increments of 12 (total of 10 values)
/**********
Function: InitUpdateOLED
Type: Bool
Parameter: uint8_t Priority
Returns: boolean stating whether initialization was a success (true)
or failure (false)
***********/
InitSpaceship
- Initialize ES_Event_t variable ThisEvent
- Set MyPriority to Priority
- Set CurrentState to InitOLEDState
- Initialize scoreBoard array values to 0
- Set EventType of ThisEvent to ES_INIT
- If function call to ES_PostToService with parameters
MyPriority and ThisEvent returns true, do the following:
- Return true
- Else:
- Return false

/**********
Function: PostUpdateOLED
Type: Bool
Parameter: ES_Event_t variable ThisEvent
Returns: boolean stating whether post to service was a success (true)
or failure (false)
***********/
PostSpaceship
- return call to ES_PostToService with parameters MyPriority
and ThisEvent

/**********
Function: RunUpdateOLED
Type: ES_Event_t
Parameter: ES_Event_t variable ThisEvent
Returns: ES_Event_t variable that states if there are errors or not
***********/
RunSpaceship
- Create an ES_Event_t type variable ReturnEvent
- Assign ES_NO_EVENT to ReturnEvent's EventType
- Switch case with ThisEvent's EventType as the parameter
- Case ES_INIT:
- Call initOLED function for initialization
of OLED screen
- Initialize the timer OLED_REFRESH_TIMER
with a time of TIME_STEP
- Set CurrentState to OLEDTitle
- Case ES_START_GAME:
- Call updateAll function to get the
positions of spaceship, enemy spaceship, and projectile
- Set CurrentState to OLEDGame
- Case ES_JOYSTICK:
- Set GameMode qeual to ThisEvent's
EventParam
- Case ES_UPDATE_OLED:
- Switch case with ThisEvent's EventParam as
the parameter
- Case titlescreenID:
- Set CurrentState to
OLEDTitle
- Case gameoverID:
- Call function
QueryGameplayScore and set score variable equal to the output from
this function
- Check to see if score is
greater than any of the values in scoreBoard. If so, replace the
highest value in scoreBoard that score is greater than with the value
in score
- Case scoreboardID:
- Set CurrentState to
OLEDScoreBoard
- Case projectileID:
- Update projectile
positions using QueryProjectilePosition function
- Case spaceshipID:
- Set spaceshipPosition to
the output from function call QuerySpaceshipPosition
- Case enemyshipID:
- Creat an enemyArray array
variable called enemyPosArray, and update it with a call to function
QueryEnemyShipPosition
- Update score with a call
to function QueryGameplayScore
- Case ES_TIMEOUT:
- If ThisEvent's EventParam is equal to
OLED_REFRESH_TIMER, do the following:
- Initialize OLED_REFRESH_TIMER with
a time of TIME_STEP
- Switch case with CurrentState as
the parameter
- Case OLEDTitle:
- Write the title
"Galaga" to the OLED screen, along with text specifying the difficulty
of the game ("Easy", "Medium", "Hard")
- Draw an arrow on
the OLED screen corresponding to the user's selection of difficulty
level
- Case OLEDEnd:
- Write "GAME OVER"
to the OLED screen, along with the statement "You Lose" or "You Win",
depending if the user has won the game or not
- Case OLEDScoreBoard:
- Write
"Leaderboard" to the OLED screen, along with the top three scores from
the game
- Case OLEDGame:
- Draw the TIE
fighter, enemy X-Wing, and projectile icons onto the screen
- Return ReturnEvent

/**********
Function: QueryUpdateOLED
Type: OLEDState_t
Parameter: None
Returns: OLED_State_t variable containing the current state of the
game
***********/
QueryUpdateOLED
- Return CurrentState

/**********
Function: initOLED
Type: None
Parameter: None
Returns: None
***********/
initOLED
- Call SPI_INIT function to initialize settings for serial
peripheral interface (SPI)
- Call u8g2_Setup_ssd1306_128x64_noname_f function
- Call u8g2_InitDisplay function
- Call u8g2_SetPowerSave function
- Call u8g2_SetFont function
- Call u8g2_SetFontMode function
- Set GameMode to 0

/**********
Function: updateAll
Type: None
Parameter: None
Returns: None
***********/
updateAll
- Update projectile positions using the
QueryProjectilePosition function
- QueryProjectilePosition to get projectile positions
- Update spaceshipPosition with the QuerySpaceshipPosition
function
- Update enemy X-Wing positions using QueryEnemyShipPosition
- Update score using QueryGameplayScore function

You might also like