Ben Evans / Mbed 2 deprecated Defender_Game

Dependencies:   mbed

Committer:
evanso
Date:
Tue May 26 19:38:48 2020 +0000
Revision:
85:87bc28b151d8
Parent:
84:f61c85a5f13a
Child:
86:eecd168c3a23
Spell checked all of code and comments

Who changed what in which revision?

UserRevisionLine numberNew contents of line
evanso 11:ab578a151f67 1 #ifndef GAMEENGINE_H
evanso 11:ab578a151f67 2 #define GAMEENGINE_H
evanso 7:0af4ced868f5 3
evanso 82:3211b31e9421 4 // Included Headers ------------------------------------------------------------
evanso 7:0af4ced868f5 5 #include "mbed.h"
evanso 39:fc5586b930e3 6 #include "HUD.h"
evanso 40:71f947254fda 7 #include "Menu.h"
evanso 47:49fa1adc10b4 8 #include "FXOS8700CQ.h"
evanso 49:ed569eceeaa4 9 #include "SDFileSystem.h"
evanso 56:663d0546c235 10 #include "SavedGames.h"
evanso 69:753ba27325ce 11 #include "Settings.h"
evanso 72:e7492591307e 12 #include "Sounds.h"
evanso 76:6daba3002424 13 #include "HighScore.h"
evanso 80:870bc6b4bf08 14 #include "PlayEngine.h"
evanso 67:a2984682d641 15
evanso 47:49fa1adc10b4 16
evanso 11:ab578a151f67 17 /** GameEngine class
evanso 85:87bc28b151d8 18 * @brief Runs the different parts of the menu and playable part of game
evanso 27:8bb2bd97c319 19 * @author Benjamin Evans, University of Leeds
evanso 27:8bb2bd97c319 20 * @date April 2020
evanso 27:8bb2bd97c319 21 */
evanso 80:870bc6b4bf08 22 class GameEngine:private PlayEngine {
evanso 7:0af4ced868f5 23 public:
evanso 7:0af4ced868f5 24 /** Constructor */
evanso 7:0af4ced868f5 25 GameEngine();
evanso 7:0af4ced868f5 26
evanso 7:0af4ced868f5 27 /** Destructor */
evanso 7:0af4ced868f5 28 ~GameEngine();
evanso 7:0af4ced868f5 29
evanso 85:87bc28b151d8 30 /** Initialises GameEngine */
evanso 13:12276eed13ac 31 void init();
evanso 7:0af4ced868f5 32
evanso 85:87bc28b151d8 33 /** Switch statement to run different menu options */
evanso 42:3aed75338272 34 void game_select_part();
evanso 11:ab578a151f67 35
evanso 11:ab578a151f67 36 private:
evanso 27:8bb2bd97c319 37 // Function prototypes -----------------------------------------------------
evanso 64:e9dfc35a1738 38
evanso 41:5959256f4aab 39 // Menu Control
evanso 64:e9dfc35a1738 40 /** Runs the menu */
evanso 64:e9dfc35a1738 41 void run_menu();
evanso 84:f61c85a5f13a 42
evanso 84:f61c85a5f13a 43 /** Draws loading screen */
evanso 84:f61c85a5f13a 44 void loading_screen();
evanso 84:f61c85a5f13a 45
evanso 85:87bc28b151d8 46 /** Selects the different parts of the playable game like the pause
evanso 84:f61c85a5f13a 47 * screen and save screen
evanso 84:f61c85a5f13a 48 */
evanso 85:87bc28b151d8 49 void play_select();
evanso 64:e9dfc35a1738 50
evanso 64:e9dfc35a1738 51 // Menu Play
evanso 64:e9dfc35a1738 52 /** Runs the play game */
evanso 64:e9dfc35a1738 53 void run_play();
evanso 42:3aed75338272 54
evanso 64:e9dfc35a1738 55 /** Initialises the play part of the game*/
evanso 64:e9dfc35a1738 56 void play_init();
evanso 71:bcbac2cfe005 57
evanso 71:bcbac2cfe005 58 /** Only runs movement when the spaceship is not destroyed */
evanso 71:bcbac2cfe005 59 void spaceship_not_detroyed();
evanso 64:e9dfc35a1738 60
evanso 42:3aed75338272 61 /** Main gameplay loop that runs playable part of game */
evanso 42:3aed75338272 62 void gameplay_loop();
evanso 41:5959256f4aab 63
evanso 64:e9dfc35a1738 64 /** Draws the game over screen*/
evanso 64:e9dfc35a1738 65 void draw_game_over_screen();
evanso 41:5959256f4aab 66
evanso 56:663d0546c235 67 /** Runs the paused screen */
evanso 56:663d0546c235 68 void run_paused_game();
evanso 56:663d0546c235 69
evanso 55:c04568b25617 70 /** Draws the pause screen*/
evanso 55:c04568b25617 71 void draw_pause_screen();
evanso 55:c04568b25617 72
evanso 64:e9dfc35a1738 73 /** Runs saved games screen */
evanso 64:e9dfc35a1738 74 void run_saved_games();
evanso 64:e9dfc35a1738 75
evanso 64:e9dfc35a1738 76 /** Time-triggered interrupt to wake MCU from sleep */
evanso 64:e9dfc35a1738 77 void lcd_frame_time_isr();
evanso 57:d4ce42c24561 78
evanso 74:6827b43c689d 79 /** Plays the music if its turned on */
evanso 74:6827b43c689d 80 void play_music();
evanso 74:6827b43c689d 81
evanso 74:6827b43c689d 82 /** Stops the music if its turned off */
evanso 74:6827b43c689d 83 void stop_music();
evanso 74:6827b43c689d 84
evanso 64:e9dfc35a1738 85 // Menu Setting
evanso 64:e9dfc35a1738 86 /** Runs settings screen*/
evanso 64:e9dfc35a1738 87 void run_settings();
evanso 58:a9a39424df52 88
evanso 64:e9dfc35a1738 89 // Menu Saved Games
evanso 59:0b2e43312d6b 90 /** Initialises the play part of the game and sets the variables to
evanso 59:0b2e43312d6b 91 * saved values
evanso 59:0b2e43312d6b 92 */
evanso 64:e9dfc35a1738 93 void saved_games_overide_init();
evanso 59:0b2e43312d6b 94
evanso 62:f0c86a854a9e 95 /** Runs save a game screen */
evanso 64:e9dfc35a1738 96 void run_save_a_game();
evanso 62:f0c86a854a9e 97
evanso 76:6daba3002424 98 // Menu High Score
evanso 76:6daba3002424 99 /** Runs high score screen */
evanso 76:6daba3002424 100 void run_highscore();
evanso 76:6daba3002424 101
evanso 76:6daba3002424 102 /** Calculates if the current end game score is a new high score and
evanso 76:6daba3002424 103 * saves it if it is
evanso 76:6daba3002424 104 * @return new_high_score @detials bool true if there is new high score
evanso 76:6daba3002424 105 */
evanso 76:6daba3002424 106 bool calculate_new_score();
evanso 36:27aa597db3d2 107
evanso 27:8bb2bd97c319 108 // Variables ---------------------------------------------------------------
evanso 41:5959256f4aab 109
evanso 41:5959256f4aab 110 // Menu Control
evanso 43:d43759dbddb9 111 /** The part of the menu that is currently selected and in*/
evanso 41:5959256f4aab 112 MenuParts current_menu_part_;
evanso 42:3aed75338272 113
evanso 42:3aed75338272 114 /** Volatile flag for ISR */
evanso 45:fc3238cd28c6 115 volatile int lcd_frame_time_flag_;
evanso 56:663d0546c235 116
evanso 62:f0c86a854a9e 117 /** Flag to exit the play part of the game */
evanso 57:d4ce42c24561 118 bool exit_flag_;
evanso 62:f0c86a854a9e 119
evanso 62:f0c86a854a9e 120 /** Flag to run the save game screen */
evanso 64:e9dfc35a1738 121 bool run_save_a_game_flag_;
evanso 68:bb1650c657ef 122
evanso 85:87bc28b151d8 123 /** Counter for pause screen so pause button doesn’t double press */
evanso 68:bb1650c657ef 124 int paused_counter_;
evanso 73:d1aea9b8da92 125
evanso 74:6827b43c689d 126 /** Hold on or off depending if music is set on or off */
evanso 74:6827b43c689d 127 MusicParts music_fx_;
evanso 33:7fedd8029473 128
evanso 85:87bc28b151d8 129 /** Paused button pressed flag for pausing during the game */
evanso 85:87bc28b151d8 130 bool paused_button_pressed_;
evanso 85:87bc28b151d8 131
evanso 27:8bb2bd97c319 132 // Objects -----------------------------------------------------------------
evanso 27:8bb2bd97c319 133
evanso 43:d43759dbddb9 134 /** Define HUD object */
evanso 39:fc5586b930e3 135 HUD hud;
evanso 40:71f947254fda 136
evanso 43:d43759dbddb9 137 /** Define Menu object */
evanso 40:71f947254fda 138 Menu menu;
evanso 42:3aed75338272 139
evanso 69:753ba27325ce 140 /** Define Setting object */
evanso 69:753ba27325ce 141 Settings setting;
evanso 69:753ba27325ce 142
evanso 64:e9dfc35a1738 143 /** Define Ticker object for lcd framerate */
evanso 47:49fa1adc10b4 144 Ticker ticker;
evanso 56:663d0546c235 145
evanso 64:e9dfc35a1738 146 /** Define SavedGames object */
evanso 56:663d0546c235 147 SavedGames saved;
evanso 76:6daba3002424 148
evanso 76:6daba3002424 149 /** Define HighScore object */
evanso 76:6daba3002424 150 HighScore h_score;
evanso 7:0af4ced868f5 151 };
evanso 7:0af4ced868f5 152
evanso 85:87bc28b151d8 153 #endif