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 "Sprites.h" 00008 #include "Levels.h" 00009 00010 /** Gameengine Class 00011 @details Builds all levels and sets game default values. Updates all game settings 00012 and contains functions for game conditions. 00013 00014 @author Andrew Milner University of Leeds 00015 00016 @date April 2019 00017 */ 00018 class Gameengine 00019 { 00020 00021 public: 00022 /** constructor 00023 */ 00024 Gameengine(); 00025 /** deconstructor 00026 */ 00027 ~Gameengine(); 00028 /** Initialises all default game settings. 00029 * @details Sets player starting position, number of lives, level start and timer. 00030 */ 00031 void game_init(); 00032 /** Updates all game game settings. 00033 * @details Contains all functions that update player position and game conditions 00034 such as lives left, timer, game over and level complete. 00035 */ 00036 void update(N5110 &lcd, Gamepad &pad); 00037 /** Updates and renders all level objects for level 1. 00038 */ 00039 void draw_l1(N5110 &lcd, Gamepad &pad); 00040 /** Updates and renders all level objects for level 2. 00041 */ 00042 void draw_l2(N5110 &lcd, Gamepad &pad); 00043 /** Updates and renders all level objects for level 3. 00044 */ 00045 void draw_l3(N5110 &lcd, Gamepad &pad); 00046 /** Updates and renders all level objects for level 4. 00047 */ 00048 void draw_l4(N5110 &lcd, Gamepad &pad); 00049 /** 00050 * @brief Reads direction the player is moving. 00051 * @details Uses get_direction() function from Gamepad library. 00052 */ 00053 void read_direction(Gamepad &pad); 00054 /** Calculates lives remaining. 00055 * @returns integer value to control lives fsm state in leds() main.cpp 00056 */ 00057 int lives_leds(); 00058 /** Calculates time remaining. 00059 * @details Calculates time remaining, every 1/3 of total time passed the return 00060 * value changes. 00061 * @return integer value to control oxygen fsm state in leds() main.cpp 00062 */ 00063 int oxygen_leds(); 00064 /** 00065 * @brief Calculates and displays player score. 00066 * @details At game over or game completed the players score is calculated and 00067 * displayed. It takes time remaining and multiplies this by lives remaining, then 00068 * adds on 10 points for every key collected. 00069 */ 00070 void get_score(N5110 &lcd); 00071 /** Returns true if game completed. 00072 * @details calculates when _level variable has gone beyond number of levels in game. 00073 * @return true if game complete 00074 */ 00075 bool game_complete(N5110 &lcd); 00076 /** Reduces number of lives on player death. 00077 * @details After reducing lives, makes tone to signify player death, resets player 00078 * back to start, creates small pause. 00079 */ 00080 void lose_life(Gamepad &pad, N5110 &lcd); 00081 /** States whether game over condition met 00082 * @return returns true if game over. 00083 */ 00084 bool game_over(); 00085 /** Returns true when player at exit. 00086 * @return Function returns true when the player is in contact with the level exit. 00087 */ 00088 bool level_exit(N5110 &lcd); 00089 /** Moves player to next level when level complete conditions met. 00090 * @details When all 5 keys have been collected using _sprites.keys_collected() 00091 * and player is in contact with the level exit using level_exit() function. 00092 * Calculates time reamining (for score) then resets, resets enemy and key flags 00093 * so they can be initialised for the next level, increases _level by 1 so next 00094 * level will be drawn, keys needed increased by 5 and miner position reset. 00095 */ 00096 void next_level(N5110 &lcd, Gamepad &pad); 00097 /** Returns true if player in contact with trap 00098 * @details Function sets all trap poisitons and collision rules. Usues int i 00099 * to select which level positions to use. 00100 */ 00101 bool trap_death(N5110 &lcd); 00102 /** Draws keys for each level. 00103 * @details Function sets key positions and collision rules stated in 00104 * Sprites class. Uses int i to select which level positions to use, these are 00105 * specified in Level class. 00106 */ 00107 void key_draw(N5110 &lcd,Gamepad &pad); 00108 /** Sets all block positions and collision rules. 00109 * @details Function sets all block positons and collision rules stated in 00110 * Sprites class. Blocks are indexed so each one is treated independently 00111 * otherwise all will disappear if one is collected. Uses int i to select which 00112 * level positions to use, these are specified in Level class. Int i is set _level 00113 * so function knows which level settings to use. 00114 */ 00115 void blocks(N5110 &lcd); 00116 /** Initialises enemies, updates movements and detects collision with player. 00117 * @details Only initialises enemies when enem_flag set to false and sets it true 00118 * once done. Function also updates enemy position and detects collision with players, 00119 * int i states which level settings to use. 00120 * @return true if player collides with enemy. 00121 */ 00122 bool enemies(N5110 &lcd); 00123 /** Reinitialises keys once new level starts. 00124 * @details Once level is complete the _key_reint flag is set to false and all 00125 * 5 level keys are set to false. This means they are drawn in new positions as 00126 * per int i which states which level settings to use in key_draw(). 00127 */ 00128 void key_reinit(); 00129 00130 private: 00131 00132 int _level; 00133 int _lives; 00134 bool _enem_flag; 00135 int _five_keys; 00136 bool _key_reinit; 00137 int _oxy_state; 00138 int _life_state; 00139 float _total_time; 00140 float _time; 00141 00142 Sprites _sprites; 00143 Direction _d; 00144 Levels _lev; 00145 Timer _t; 00146 00147 00148 }; 00149 #endif
Generated on Wed Jul 13 2022 01:25:31 by
 1.7.2
 1.7.2