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:
hugohu
Date:
Thu Mar 25 03:56:22 2021 +0000
Branch:
BRAVEHEART
Revision:
21:e19709a07756
Parent:
19:89c3eeb3761b
Combined some files, removed codes for my personal needs, created new maps, new ways to play.

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