Beruflich Dokumente
Kultur Dokumente
*******
MODULE VARIABLES
Target CurrentTarget
GameState CurrentState
********************************************************************************
*******
********************************************************************************
*******
POSSIBLE STATES FOR GameStatemachine
Game_Race
Game_Obstacle
Game_Shoot
********************************************************************************
*******
////////////////////////////////////////////////////////////////////////////////
///////
PUBLIC FUNCTION RunGameSM
RECEIVE: ES_Event CurrentEvent
RETURN: ES_Event
LOCAL VARIABLES: boolean MakeTransition
GameState NextState
ES_Event ReturnEvent
set MakeTransition to false
set ReturnEvent to CurrentEvent since we assume that we are not consuming event
switch CurrentState
case Game_Race
call DuringRaceState to let lower level state machine deal with
CurrentEvent first
if there is still an active event
switch CurrentEvent.EventType
case ES_ToShoot
Set NextState to Game_Shoot
Set MakeTransition to true since we are
making transition
break
endcase
case ES_ToObstacle
Set NextState to Game_Obstacle
Set MakeTransition to true since we are
making transition
break
endcase
endswitch
endif
break
endcase
case Game_Obstacle
call DuringObstacleState to let lower level state machine deal w
ith CurrentEvent first
if there is still an active event
switch CurrentEvent.EventType
case ES_ToRace
Set NextState to Game_Race
Set MakeTransition to true since we are
making transition
break
endcase
endswitch
endif
break
endcase
case Game_Shoot
call DuringShootState to let lower level state machine deal with
CurrentEvent first
if there is still an active event
switch CurrentEvent.EventType
case ES_ToRace
Set NextState to Game_Race
Set MakeTransition to true since we are
making transition
break
endcase
endswitch
endif
break
endcase
endswitch
if MakeTransition equals true which means we are making transition of this GameS
tatemachine
call RunGameSM with the parameter of ES_EXIT to execute exit function fo
r current state
set CurrentEvent to NextState
call RunGameSM with the parameter of ES_ENTRY to execute exit function f
or next state
endif
return ReturnEvent
////////////////////////////////////////////////////////////////////////////////
///////
////////////////////////////////////////////////////////////////////////////////
///////
PUBLICE FUNCTION StartGameSM
ARGUMENT: ES_Event CurrentEvent (ES_ENTRY)
RETURN: no return
LOCAL VAR: LocalEvent
set LocalEvent to CurrentEvent
set CurrentState to Game_Race since we always assume that the game starts at rac
e region
endStartGameSM
////////////////////////////////////////////////////////////////////////////////
///////
////////////////////////////////////////////////////////////////////////////////
///////
PUBLIC FUNCTION SetTarget
else
call RunObstacleSM with parameter equals to CurrentEvent to let lower le
vel state machine deal with current state
endif
////////////////////////////////////////////////////////////////////////////////
///////
////////////////////////////////////////////////////////////////////////////////
///////
PRIVATE FUNCTION DuringShootState
ARGUMENT: ES_Event CurrentEvent
RETURN: ES_Event
LOCAL VAR:
if CurrentEvent.EventType is ES_ENTRY
call StartShootSM with parameter equals to CurrentEvent to start Shoot S
tatemachine
endif
else if CurrentEvent.EventType is ES_EXIT
endif
else
call RunShootSM with parameter equals to CurrentEvent to let lower level
state machine deal with current state
endif
////////////////////////////////////////////////////////////////////////////////
///////