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.
Dependencies: mbed
GameEngine.h
00001 #ifndef GAMEENGINE_H 00002 #define GAMEENGINE_H 00003 00004 #include "mbed.h" 00005 #include "N5110.h" 00006 #include "Gamepad.h" 00007 #include "Enemy.h" 00008 #include "CrossHairs.h" 00009 #include "EnemySpawner.h" 00010 #include "Wall.h" 00011 00012 00013 00014 /** GameEngine Class 00015 @author Adam Jones, University of Leeds 00016 @brief Controls Game 00017 @date April 2019 00018 @brief Revision 1.0 00019 00020 @code 00021 #include "mbed.h" 00022 #include "Gamepad.h" 00023 #include "N5110.h" 00024 #include "GameEngine.h" 00025 00026 00027 00028 00029 00030 00031 int main() 00032 { 00033 //initialise game object 00034 GameEngine game; 00035 int crossHairsSpeed = 5; 00036 int fps = 16 00037 game.init(crossHairsSpeed, fps); 00038 00039 //read input from gamepad 00040 Gamepad pad; 00041 game.read_input(pad); 00042 00043 //update game state 00044 game.update(pad); 00045 00046 /draw game state 00047 game.draw(lcd); 00048 00049 //returns if game is over or not 00050 bool isOver = game.get_game_over(); 00051 00052 //sets if game is over or not 00053 game.set_game_over(false); //false = not over, true = over 00054 00055 } 00056 00057 @endcode 00058 00059 */ 00060 00061 00062 class GameEngine 00063 { 00064 00065 public: 00066 GameEngine(); 00067 ~GameEngine(); 00068 00069 /** 00070 * @brief Initisalise the game with cross hair speed and frames per second 00071 * @param cross hairs speed @details max speed of the cross hairs in pixels per frame 00072 * @param fps @details the fps of the game 00073 */ 00074 void init(int CrossHairsSpeed, int fps); 00075 /** 00076 * @brief read input from gamepad 00077 * @param gamepad @details the gamepad object 00078 */ 00079 void read_input(Gamepad &pad); 00080 /** 00081 * @brief updates the gamepad based on inputs 00082 * @param gamepad @details the gamepad object 00083 */ 00084 void update(Gamepad &pad); 00085 /** 00086 * @brief draws sprites on the display 00087 * @param lcd @details the N5110 object 00088 */ 00089 void draw(N5110 &lcd); 00090 /** 00091 * @brief returns if the game is over or not 00092 * @return game over @details a boolean value 00093 */ 00094 bool get_game_over(); 00095 00096 /** 00097 * @brief sets if game is over or not 00098 * @param game over @details a boolean value 00099 */ 00100 void set_game_over(bool is_game_over); 00101 00102 private: 00103 00104 00105 void fireShot(Gamepad &gpad); 00106 00107 void was_enemy_shot(int i, Vector2D shotLoc); 00108 void game_over(); 00109 00110 bool _game_over; 00111 int _frame; 00112 int _fps; 00113 00114 int _levelNumber; 00115 int _killCount; 00116 00117 00118 float _angle; 00119 float _mag; 00120 00121 CrossHairs _crossHairs; 00122 00123 Wall _wall; 00124 00125 00126 Enemy *_enemies; 00127 EnemySpawner _level; 00128 00129 00130 00131 00132 00133 00134 00135 00136 00137 00138 00139 00140 00141 00142 00143 }; 00144 00145 #endif
Generated on Mon Nov 11 2024 22:48:00 by
1.7.2