A complex 2D-dungeon game on LPC1768 in SWJTU-Leeds Joint School XJEL2645 project. Referenced from the framework contributed by https://os.mbed.com/users/Siriagus/code/SimplePlatformGame/

Dependencies:   mbed N5110 ShiftReg PinDetect

Committer:
Siriagus
Date:
Fri May 08 14:39:36 2015 +0000
Revision:
10:f2488a0ecab7
Parent:
8:9ac6a428fa26
Child:
17:d6a3b29cab31
Encapsluated PinDetect buttons in InputManager (made private)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Siriagus 4:d6661b976359 1 #ifndef STATE_MANAGER_H
Siriagus 4:d6661b976359 2 #define STATE_MANAGER_H
Siriagus 4:d6661b976359 3
Siriagus 4:d6661b976359 4 #include "State.h"
Siriagus 5:100d960fc6d5 5 #include "MainMenu.h"
Siriagus 7:678873947b29 6 #include "Game.h"
Siriagus 8:9ac6a428fa26 7 #include "TitleScreen.h"
Siriagus 4:d6661b976359 8
Siriagus 10:f2488a0ecab7 9 /** @file StateManager.h
Siriagus 10:f2488a0ecab7 10 * @author Andreas Garmannslund
Siriagus 10:f2488a0ecab7 11 * @date April 2015
Siriagus 10:f2488a0ecab7 12 */
Siriagus 10:f2488a0ecab7 13
Siriagus 10:f2488a0ecab7 14 /// Finite State Machine for program flow
Siriagus 4:d6661b976359 15 class StateManager
Siriagus 4:d6661b976359 16 {
Siriagus 4:d6661b976359 17 public:
Siriagus 10:f2488a0ecab7 18 /** Creates a new finite state machine. The states are defined in State.h
Siriagus 10:f2488a0ecab7 19 * @param lcd Pointer to the lcd
Siriagus 10:f2488a0ecab7 20 * @param input Pointer to the InputManager which is controlling user input.
Siriagus 10:f2488a0ecab7 21 * @param firstState The initial state of the finite state machine.
Siriagus 10:f2488a0ecab7 22 */
Siriagus 7:678873947b29 23 StateManager(N5110 *lcd, InputManager* input, MainState firstState)
Siriagus 7:678873947b29 24 : lcd(lcd), input(input){currentState = 0; nextState = NO_STATE; changeState(firstState);}
Siriagus 10:f2488a0ecab7 25
Siriagus 10:f2488a0ecab7 26 /// Frees allocated memory
Siriagus 5:100d960fc6d5 27 ~StateManager() {if (currentState != 0) delete currentState;}
Siriagus 4:d6661b976359 28
Siriagus 10:f2488a0ecab7 29 /// Update logic of the current state
Siriagus 7:678873947b29 30 void update(float dt);
Siriagus 10:f2488a0ecab7 31
Siriagus 10:f2488a0ecab7 32 /// Draw the current state to the lcd
Siriagus 4:d6661b976359 33 void render();
Siriagus 4:d6661b976359 34
Siriagus 10:f2488a0ecab7 35 /** Can be used to request the fsm to switch state.
Siriagus 10:f2488a0ecab7 36 * @param newState The requested state
Siriagus 10:f2488a0ecab7 37 */
Siriagus 7:678873947b29 38 void requestStateChange(MainState newState);
Siriagus 7:678873947b29 39
Siriagus 10:f2488a0ecab7 40 /// Sees if any requests to change the state have been made
Siriagus 10:f2488a0ecab7 41 void processRequest();
Siriagus 7:678873947b29 42
Siriagus 7:678873947b29 43 private:
Siriagus 10:f2488a0ecab7 44 /** Deletes the current state and create a new one
Siriagus 10:f2488a0ecab7 45 * @param newState The state which the finite state machine switches to
Siriagus 10:f2488a0ecab7 46 */
Siriagus 10:f2488a0ecab7 47 void changeState(MainState newState);
Siriagus 7:678873947b29 48
Siriagus 10:f2488a0ecab7 49 // Variables
Siriagus 4:d6661b976359 50 private:
Siriagus 4:d6661b976359 51 N5110 *lcd;
Siriagus 4:d6661b976359 52 InputManager *input;
Siriagus 4:d6661b976359 53 State* currentState; // Current state object
Siriagus 10:f2488a0ecab7 54 MainState nextState; // requested state, NONE if no state is requested
Siriagus 4:d6661b976359 55 };
Siriagus 4:d6661b976359 56
Siriagus 5:100d960fc6d5 57 #endif