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.
GameEngine/GameEngine.h@84:f61c85a5f13a, 2020-05-26 (annotated)
- Committer:
- evanso
- Date:
- Tue May 26 14:39:45 2020 +0000
- Revision:
- 84:f61c85a5f13a
- Parent:
- 82:3211b31e9421
- Child:
- 85:87bc28b151d8
Fixed bugs in the game and separated out long functions.
Who changed what in which revision?
| User | Revision | Line number | New 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 | 80:870bc6b4bf08 | 18 | * @brief Runs the different parts of the menu and playble 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 | 14:7419c680656f | 30 | /** Initalises GameEngine */ |
| evanso | 13:12276eed13ac | 31 | void init(); |
| evanso | 7:0af4ced868f5 | 32 | |
| evanso | 47:49fa1adc10b4 | 33 | /** Switch statement to run 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 | 84:f61c85a5f13a | 46 | /** Selects the differnt parts of the playable game like the pause |
| evanso | 84:f61c85a5f13a | 47 | * screen and save screen |
| evanso | 84:f61c85a5f13a | 48 | * @param paused_flag |
| evanso | 84:f61c85a5f13a | 49 | */ |
| evanso | 84:f61c85a5f13a | 50 | void play_select(bool paused_flag); |
| evanso | 64:e9dfc35a1738 | 51 | |
| evanso | 64:e9dfc35a1738 | 52 | // Menu Play |
| evanso | 64:e9dfc35a1738 | 53 | /** Runs the play game */ |
| evanso | 64:e9dfc35a1738 | 54 | void run_play(); |
| evanso | 42:3aed75338272 | 55 | |
| evanso | 64:e9dfc35a1738 | 56 | /** Initialises the play part of the game*/ |
| evanso | 64:e9dfc35a1738 | 57 | void play_init(); |
| evanso | 71:bcbac2cfe005 | 58 | |
| evanso | 71:bcbac2cfe005 | 59 | /** Only runs movement when the spaceship is not destroyed */ |
| evanso | 71:bcbac2cfe005 | 60 | void spaceship_not_detroyed(); |
| evanso | 64:e9dfc35a1738 | 61 | |
| evanso | 42:3aed75338272 | 62 | /** Main gameplay loop that runs playable part of game */ |
| evanso | 42:3aed75338272 | 63 | void gameplay_loop(); |
| evanso | 41:5959256f4aab | 64 | |
| evanso | 64:e9dfc35a1738 | 65 | /** Draws the game over screen*/ |
| evanso | 64:e9dfc35a1738 | 66 | void draw_game_over_screen(); |
| evanso | 41:5959256f4aab | 67 | |
| evanso | 56:663d0546c235 | 68 | /** Runs the paused screen */ |
| evanso | 56:663d0546c235 | 69 | void run_paused_game(); |
| evanso | 56:663d0546c235 | 70 | |
| evanso | 55:c04568b25617 | 71 | /** Draws the pause screen*/ |
| evanso | 55:c04568b25617 | 72 | void draw_pause_screen(); |
| evanso | 55:c04568b25617 | 73 | |
| evanso | 64:e9dfc35a1738 | 74 | /** Runs saved games screen */ |
| evanso | 64:e9dfc35a1738 | 75 | void run_saved_games(); |
| evanso | 64:e9dfc35a1738 | 76 | |
| evanso | 64:e9dfc35a1738 | 77 | /** Time-triggered interrupt to wake MCU from sleep */ |
| evanso | 64:e9dfc35a1738 | 78 | void lcd_frame_time_isr(); |
| evanso | 57:d4ce42c24561 | 79 | |
| evanso | 74:6827b43c689d | 80 | /** Plays the music if its turned on */ |
| evanso | 74:6827b43c689d | 81 | void play_music(); |
| evanso | 74:6827b43c689d | 82 | |
| evanso | 74:6827b43c689d | 83 | /** Stops the music if its turned off */ |
| evanso | 74:6827b43c689d | 84 | void stop_music(); |
| evanso | 74:6827b43c689d | 85 | |
| evanso | 64:e9dfc35a1738 | 86 | // Menu Setting |
| evanso | 64:e9dfc35a1738 | 87 | /** Runs settings screen*/ |
| evanso | 64:e9dfc35a1738 | 88 | void run_settings(); |
| evanso | 58:a9a39424df52 | 89 | |
| evanso | 64:e9dfc35a1738 | 90 | // Menu Saved Games |
| evanso | 59:0b2e43312d6b | 91 | /** Initialises the play part of the game and sets the variables to |
| evanso | 59:0b2e43312d6b | 92 | * saved values |
| evanso | 59:0b2e43312d6b | 93 | */ |
| evanso | 64:e9dfc35a1738 | 94 | void saved_games_overide_init(); |
| evanso | 59:0b2e43312d6b | 95 | |
| evanso | 62:f0c86a854a9e | 96 | /** Runs save a game screen */ |
| evanso | 64:e9dfc35a1738 | 97 | void run_save_a_game(); |
| evanso | 62:f0c86a854a9e | 98 | |
| evanso | 76:6daba3002424 | 99 | // Menu High Score |
| evanso | 76:6daba3002424 | 100 | /** Runs high score screen */ |
| evanso | 76:6daba3002424 | 101 | void run_highscore(); |
| evanso | 76:6daba3002424 | 102 | |
| evanso | 76:6daba3002424 | 103 | /** Calculates if the current end game score is a new high score and |
| evanso | 76:6daba3002424 | 104 | * saves it if it is |
| evanso | 76:6daba3002424 | 105 | * @return new_high_score @detials bool true if there is new high score |
| evanso | 76:6daba3002424 | 106 | */ |
| evanso | 76:6daba3002424 | 107 | bool calculate_new_score(); |
| evanso | 36:27aa597db3d2 | 108 | |
| evanso | 27:8bb2bd97c319 | 109 | // Variables --------------------------------------------------------------- |
| evanso | 41:5959256f4aab | 110 | |
| evanso | 41:5959256f4aab | 111 | // Menu Control |
| evanso | 43:d43759dbddb9 | 112 | /** The part of the menu that is currently selected and in*/ |
| evanso | 41:5959256f4aab | 113 | MenuParts current_menu_part_; |
| evanso | 42:3aed75338272 | 114 | |
| evanso | 42:3aed75338272 | 115 | /** Volatile flag for ISR */ |
| evanso | 45:fc3238cd28c6 | 116 | volatile int lcd_frame_time_flag_; |
| evanso | 56:663d0546c235 | 117 | |
| evanso | 56:663d0546c235 | 118 | /** Paused flag */ |
| evanso | 56:663d0546c235 | 119 | bool paused_flag_; |
| evanso | 56:663d0546c235 | 120 | |
| evanso | 62:f0c86a854a9e | 121 | /** Flag to exit the play part of the game */ |
| evanso | 57:d4ce42c24561 | 122 | bool exit_flag_; |
| evanso | 62:f0c86a854a9e | 123 | |
| evanso | 62:f0c86a854a9e | 124 | /** Flag to run the save game screen */ |
| evanso | 64:e9dfc35a1738 | 125 | bool run_save_a_game_flag_; |
| evanso | 68:bb1650c657ef | 126 | |
| evanso | 68:bb1650c657ef | 127 | /** Counter for pause screen so pause button doesnt double press */ |
| evanso | 68:bb1650c657ef | 128 | int paused_counter_; |
| evanso | 73:d1aea9b8da92 | 129 | |
| evanso | 74:6827b43c689d | 130 | /** Hold on or off depending if music is set on or off */ |
| evanso | 74:6827b43c689d | 131 | MusicParts music_fx_; |
| evanso | 33:7fedd8029473 | 132 | |
| evanso | 27:8bb2bd97c319 | 133 | // Objects ----------------------------------------------------------------- |
| evanso | 27:8bb2bd97c319 | 134 | |
| evanso | 43:d43759dbddb9 | 135 | /** Define HUD object */ |
| evanso | 39:fc5586b930e3 | 136 | HUD hud; |
| evanso | 40:71f947254fda | 137 | |
| evanso | 43:d43759dbddb9 | 138 | /** Define Menu object */ |
| evanso | 40:71f947254fda | 139 | Menu menu; |
| evanso | 42:3aed75338272 | 140 | |
| evanso | 69:753ba27325ce | 141 | /** Define Setting object */ |
| evanso | 69:753ba27325ce | 142 | Settings setting; |
| evanso | 69:753ba27325ce | 143 | |
| evanso | 64:e9dfc35a1738 | 144 | /** Define Ticker object for lcd framerate */ |
| evanso | 47:49fa1adc10b4 | 145 | Ticker ticker; |
| evanso | 56:663d0546c235 | 146 | |
| evanso | 64:e9dfc35a1738 | 147 | /** Define SavedGames object */ |
| evanso | 56:663d0546c235 | 148 | SavedGames saved; |
| evanso | 76:6daba3002424 | 149 | |
| evanso | 76:6daba3002424 | 150 | /** Define HighScore object */ |
| evanso | 76:6daba3002424 | 151 | HighScore h_score; |
| evanso | 7:0af4ced868f5 | 152 | }; |
| evanso | 7:0af4ced868f5 | 153 | |
| evanso | 7:0af4ced868f5 | 154 | #endif |