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@80:870bc6b4bf08, 2020-05-25 (annotated)
- Committer:
- evanso
- Date:
- Mon May 25 15:07:24 2020 +0000
- Revision:
- 80:870bc6b4bf08
- Parent:
- 76:6daba3002424
- Child:
- 82:3211b31e9421
Split GameEngine class into two different classes to reduce its size The parent class PlayEngine was created to hold the function that control the interaction between classes in the playable part of the game and so they can be unit tested.
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 | 27:8bb2bd97c319 | 4 | // Included libraries ---------------------------------------------------------- |
| 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 | 64:e9dfc35a1738 | 42 | |
| evanso | 64:e9dfc35a1738 | 43 | // Menu Play |
| evanso | 64:e9dfc35a1738 | 44 | /** Runs the play game */ |
| evanso | 64:e9dfc35a1738 | 45 | void run_play(); |
| evanso | 42:3aed75338272 | 46 | |
| evanso | 64:e9dfc35a1738 | 47 | /** Initialises the play part of the game*/ |
| evanso | 64:e9dfc35a1738 | 48 | void play_init(); |
| evanso | 71:bcbac2cfe005 | 49 | |
| evanso | 71:bcbac2cfe005 | 50 | /** Only runs movement when the spaceship is not destroyed */ |
| evanso | 71:bcbac2cfe005 | 51 | void spaceship_not_detroyed(); |
| evanso | 64:e9dfc35a1738 | 52 | |
| evanso | 42:3aed75338272 | 53 | /** Main gameplay loop that runs playable part of game */ |
| evanso | 42:3aed75338272 | 54 | void gameplay_loop(); |
| evanso | 41:5959256f4aab | 55 | |
| evanso | 64:e9dfc35a1738 | 56 | /** Draws the game over screen*/ |
| evanso | 64:e9dfc35a1738 | 57 | void draw_game_over_screen(); |
| evanso | 41:5959256f4aab | 58 | |
| evanso | 56:663d0546c235 | 59 | /** Runs the paused screen */ |
| evanso | 56:663d0546c235 | 60 | void run_paused_game(); |
| evanso | 56:663d0546c235 | 61 | |
| evanso | 55:c04568b25617 | 62 | /** Draws the pause screen*/ |
| evanso | 55:c04568b25617 | 63 | void draw_pause_screen(); |
| evanso | 55:c04568b25617 | 64 | |
| evanso | 64:e9dfc35a1738 | 65 | /** Runs saved games screen */ |
| evanso | 64:e9dfc35a1738 | 66 | void run_saved_games(); |
| evanso | 64:e9dfc35a1738 | 67 | |
| evanso | 64:e9dfc35a1738 | 68 | /** Time-triggered interrupt to wake MCU from sleep */ |
| evanso | 64:e9dfc35a1738 | 69 | void lcd_frame_time_isr(); |
| evanso | 57:d4ce42c24561 | 70 | |
| evanso | 74:6827b43c689d | 71 | /** Plays the music if its turned on */ |
| evanso | 74:6827b43c689d | 72 | void play_music(); |
| evanso | 74:6827b43c689d | 73 | |
| evanso | 74:6827b43c689d | 74 | /** Stops the music if its turned off */ |
| evanso | 74:6827b43c689d | 75 | void stop_music(); |
| evanso | 74:6827b43c689d | 76 | |
| evanso | 64:e9dfc35a1738 | 77 | // Menu Setting |
| evanso | 64:e9dfc35a1738 | 78 | /** Runs settings screen*/ |
| evanso | 64:e9dfc35a1738 | 79 | void run_settings(); |
| evanso | 58:a9a39424df52 | 80 | |
| evanso | 64:e9dfc35a1738 | 81 | // Menu Saved Games |
| evanso | 59:0b2e43312d6b | 82 | /** Initialises the play part of the game and sets the variables to |
| evanso | 59:0b2e43312d6b | 83 | * saved values |
| evanso | 59:0b2e43312d6b | 84 | */ |
| evanso | 64:e9dfc35a1738 | 85 | void saved_games_overide_init(); |
| evanso | 59:0b2e43312d6b | 86 | |
| evanso | 62:f0c86a854a9e | 87 | /** Runs save a game screen */ |
| evanso | 64:e9dfc35a1738 | 88 | void run_save_a_game(); |
| evanso | 62:f0c86a854a9e | 89 | |
| evanso | 76:6daba3002424 | 90 | // Menu High Score |
| evanso | 76:6daba3002424 | 91 | /** Runs high score screen */ |
| evanso | 76:6daba3002424 | 92 | void run_highscore(); |
| evanso | 76:6daba3002424 | 93 | |
| evanso | 76:6daba3002424 | 94 | /** Calculates if the current end game score is a new high score and |
| evanso | 76:6daba3002424 | 95 | * saves it if it is |
| evanso | 76:6daba3002424 | 96 | * @return new_high_score @detials bool true if there is new high score |
| evanso | 76:6daba3002424 | 97 | */ |
| evanso | 76:6daba3002424 | 98 | bool calculate_new_score(); |
| evanso | 36:27aa597db3d2 | 99 | |
| evanso | 27:8bb2bd97c319 | 100 | // Variables --------------------------------------------------------------- |
| evanso | 41:5959256f4aab | 101 | |
| evanso | 41:5959256f4aab | 102 | // Menu Control |
| evanso | 43:d43759dbddb9 | 103 | /** The part of the menu that is currently selected and in*/ |
| evanso | 41:5959256f4aab | 104 | MenuParts current_menu_part_; |
| evanso | 42:3aed75338272 | 105 | |
| evanso | 42:3aed75338272 | 106 | /** Volatile flag for ISR */ |
| evanso | 45:fc3238cd28c6 | 107 | volatile int lcd_frame_time_flag_; |
| evanso | 56:663d0546c235 | 108 | |
| evanso | 56:663d0546c235 | 109 | /** Paused flag */ |
| evanso | 56:663d0546c235 | 110 | bool paused_flag_; |
| evanso | 56:663d0546c235 | 111 | |
| evanso | 62:f0c86a854a9e | 112 | /** Flag to exit the play part of the game */ |
| evanso | 57:d4ce42c24561 | 113 | bool exit_flag_; |
| evanso | 62:f0c86a854a9e | 114 | |
| evanso | 62:f0c86a854a9e | 115 | /** Flag to run the save game screen */ |
| evanso | 64:e9dfc35a1738 | 116 | bool run_save_a_game_flag_; |
| evanso | 68:bb1650c657ef | 117 | |
| evanso | 68:bb1650c657ef | 118 | /** Counter for pause screen so pause button doesnt double press */ |
| evanso | 68:bb1650c657ef | 119 | int paused_counter_; |
| evanso | 73:d1aea9b8da92 | 120 | |
| evanso | 74:6827b43c689d | 121 | |
| evanso | 74:6827b43c689d | 122 | /** Hold on or off depending if music is set on or off */ |
| evanso | 74:6827b43c689d | 123 | MusicParts music_fx_; |
| evanso | 33:7fedd8029473 | 124 | |
| evanso | 27:8bb2bd97c319 | 125 | // Objects ----------------------------------------------------------------- |
| evanso | 27:8bb2bd97c319 | 126 | |
| evanso | 43:d43759dbddb9 | 127 | /** Define HUD object */ |
| evanso | 39:fc5586b930e3 | 128 | HUD hud; |
| evanso | 40:71f947254fda | 129 | |
| evanso | 43:d43759dbddb9 | 130 | /** Define Menu object */ |
| evanso | 40:71f947254fda | 131 | Menu menu; |
| evanso | 42:3aed75338272 | 132 | |
| evanso | 69:753ba27325ce | 133 | /** Define Setting object */ |
| evanso | 69:753ba27325ce | 134 | Settings setting; |
| evanso | 69:753ba27325ce | 135 | |
| evanso | 64:e9dfc35a1738 | 136 | /** Define Ticker object for lcd framerate */ |
| evanso | 47:49fa1adc10b4 | 137 | Ticker ticker; |
| evanso | 56:663d0546c235 | 138 | |
| evanso | 64:e9dfc35a1738 | 139 | /** Define SavedGames object */ |
| evanso | 56:663d0546c235 | 140 | SavedGames saved; |
| evanso | 76:6daba3002424 | 141 | |
| evanso | 76:6daba3002424 | 142 | /** Define HighScore object */ |
| evanso | 76:6daba3002424 | 143 | HighScore h_score; |
| evanso | 7:0af4ced868f5 | 144 | }; |
| evanso | 7:0af4ced868f5 | 145 | |
| evanso | 7:0af4ced868f5 | 146 | #endif |