Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed N5110 ShiftReg PinDetect
StateManger.cpp
00001 #include "StateManager.h " 00002 00003 /// @file StateManager.cpp 00004 00005 void StateManager::changeState(MainState newState) 00006 { 00007 if (currentState != 0) // if a state exist 00008 delete currentState; // delete the old state 00009 00010 // Create new state 00011 switch (newState) 00012 { 00013 case MAIN_MENU: 00014 currentState = new MainMenu(this, lcd, input, sound, shiftreg); 00015 break; 00016 00017 case GAME: 00018 currentState = new Game(this, lcd, input, sound, shiftreg); 00019 break; 00020 00021 case TITLE_SCREEN: 00022 currentState = new CoverPage(this, lcd, input, sound, shiftreg); 00023 break; 00024 00025 case SUBMIT_HIGHSCORE: 00026 currentState = new Achievement(this, lcd, input, sound, shiftreg); 00027 break; 00028 00029 case GAME_OVER: 00030 currentState = new GameOver(this, lcd, input, sound, shiftreg); 00031 break; 00032 00033 default: 00034 ; // error: this shouldn't happen 00035 } 00036 } 00037 00038 void StateManager::requestStateChange(MainState requestedState) 00039 { 00040 if (nextState != NO_STATE) 00041 error("Invalid - can't request new state before the first request has been processed!"); 00042 00043 nextState = requestedState; 00044 } 00045 00046 void StateManager::update(float dt) 00047 { 00048 currentState->update(dt); 00049 } 00050 00051 void StateManager::render() 00052 { 00053 currentState->render(); 00054 } 00055 00056 void StateManager::processRequest() 00057 { 00058 // Check if there has been a request to change the state 00059 if (nextState != NO_STATE) 00060 { 00061 changeState(nextState); 00062 nextState = NO_STATE; // reset, state has been changed 00063 } 00064 }
Generated on Tue Jul 12 2022 21:30:55 by
