You are on page 1of 4

/**********

Pseudocode for Spaceship.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
- Spaceship.h
- UpdateOLED.h
- PIC32_AD_Lib.h
- Gameplay.h

Define the following variables:


- DEFAULT_SHIP_POS (value of 3)
- SPACESHIP (value of 1)
- Projectile (value of 2)
- ENEMY_SHIP (value of 3)
- LENGTH_OF_SCREEN (value of 128)
- WIDTH_OF_SCREEN (value of 64)
- TIME_STEP (value of 50)
- TIME_STEP_JOYSTICK (value of 250)

Initialize the following module-level variables:


- SpaceshipState_t variable CurrentState
- uint8 variable MyPriority
- uint32 array variable that can hold 2 values,
CalibrationJoystickLocation
- int16 variable ShipPositionX
- uint8 variable deltaT
- uint8 variable TimeDiscretization

/**********
Function: InitSpaceship
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 InitSpaceshipState
- Initialize pins B2 and B3 to read and sample analog inputs
ranging from 0 to 3.3 volts
- Set value of deltaT and timeDiscretization
- 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: PostSpaceship
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: RunSpaceship
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 CurrentState as parameter:
- Case InitSpaceshipState:
- if ThisEvent's EventType is ES_INIT, do the
following:
- Initialize the timer
JOYSTICK_TIMER with a time of TIME_STEP_JOYSTICK
- Read initial x-position and y-
position values from joystick using ADC_Multiread function for
calibration
- Set CurrentState to TitleState
- Case TitleState:
- Switch case with ThisEvent's EventType as
the parameter:
- Case ES_INIT_TITLE_JOYSTICK:
- Set ShipPositionX to be
LENGTH_OF_SCREEN / 2, setting initial position of TIE fighter
- Initialize the timer
JOYSTICK_TIMER with a time of TIME_STEP_JOYSTICK
- Case ES_TIMEOUT:
- If ThisEvent's EventParam
is JOYSTICK_TIMER, do the following:
- Initialize the
timer JOYSTICK_TIMER with a time of TIME_STEP_JOYSTICK
- Read the y-
position of the joystick and change difficulty of game (easy, medium,
hard) based on joystick y-movement
- Case ES_START_GAME:
- Sets CurrentState to
GameState
- Creates and posts the
event ES_INIT_JOYSTICK_MOVEMENT to itself
- Case GameState:
- Switch case with ThisEvent's EventType as
the parameter:
- Case ES_INIT_JOYSTICK_MOVEMENT:
- Initializes timer
SPACESHIP_TIMER with a time of TIME_STEP
- Case ES_TIMEOUT:
- Initializes timer
SPACESHIP_TIMER with a time of TIME_STEP
- Reads x-position of
joystick and updates ship position variable ShipPositionX based on
reading from joystick (note that x-position of joystick updates
velocity of ship position)
- If ship position reaches
either edge of OLED screen, stop ship from moving in the respective
direction
- Post event to UpdateOLED
service with EventType ES_UPDATE_OLED and EventParam spaceship ID
- Case ES_GAME_OVER:
- CurrentState is set to
TitleState
- Return ReturnEvent

/**********
Function: QuerySpaceship
Type: SpaceshipState_t
Parameter: None
Returns: SaceshipState_t variable containing the current state of the
service
***********/
QuerySpaceshp
- Return CurrentState

/**********
Function: QuerySpaceshipPosition
Type: uint8_t
Parameter: None
Returns: uint8_t variable containing the x-position of the TIE fighter
***********/
QuerySpaceshipPosition
- Return ShipPositionX

You might also like