Mochu Yao explorer game

Dependencies:   mbed

Committer:
el17my
Date:
Tue Apr 28 18:21:22 2020 +0000
Revision:
28:4a1260ad0346
Parent:
27:354d91d59b6d
Child:
33:ea83f08fa466
4.29

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el17my 9:e11bb7cef050 1 #ifndef GAMEENGINE_H
el17my 9:e11bb7cef050 2 #define GAMEENGINE_H
el17my 9:e11bb7cef050 3
el17my 14:5e73a6e34c17 4
el17my 14:5e73a6e34c17 5 #include "N5110.h"
el17my 14:5e73a6e34c17 6 #include "mbed.h"
el17my 14:5e73a6e34c17 7 #include "Gamepad.h"
el17my 14:5e73a6e34c17 8 #include "item.h"
el17my 14:5e73a6e34c17 9 #include "explorer.h"
el17my 14:5e73a6e34c17 10 #include "surface.h"
el17my 14:5e73a6e34c17 11 #include <cstdlib>
el17my 14:5e73a6e34c17 12 #include <ctime>
el17my 14:5e73a6e34c17 13
el17my 28:4a1260ad0346 14 /** Coordinate struct */
el17my 14:5e73a6e34c17 15 struct Coordinate {
el17my 14:5e73a6e34c17 16 Vector2D coord; /**< Vector 2D for joystick coords */
el17my 14:5e73a6e34c17 17 };
el17my 10:559487aac60e 18
el17my 27:354d91d59b6d 19 /** Gameengine Class
el17my 27:354d91d59b6d 20 * @1 make the whole explorer game run and set the score the reset process
el17my 27:354d91d59b6d 21 * @2 cheak the collision and the reset or fall flag
el17my 27:354d91d59b6d 22 * @3 draw on the lcd screen and load the gamepad controll
el17my 27:354d91d59b6d 23 * @date April 24th 2020
el17my 27:354d91d59b6d 24 * @author Yaomochu
el17my 28:4a1260ad0346 25
el17my 28:4a1260ad0346 26 @code
el17my 27:354d91d59b6d 27
el17my 27:354d91d59b6d 28 #include "mbed.h"
el17my 27:354d91d59b6d 29 #include "N5110.h"
el17my 27:354d91d59b6d 30 #include "Gamepad.h"
el17my 27:354d91d59b6d 31 #include "Gameengine.h"
el17my 27:354d91d59b6d 32
el17my 27:354d91d59b6d 33 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
el17my 27:354d91d59b6d 34 Gamepad gamepad;
el17my 27:354d91d59b6d 35 Gameengine _game_engine;
el17my 27:354d91d59b6d 36
el17my 27:354d91d59b6d 37 bool _start_flag;
el17my 27:354d91d59b6d 38 int _player_score;
el17my 27:354d91d59b6d 39
el17my 27:354d91d59b6d 40 int main() {
el17my 27:354d91d59b6d 41 _game_engine.init();
el17my 27:354d91d59b6d 42 while(1) {
el17my 27:354d91d59b6d 43 _game_engine.check_reset(lcd, gamepad);
el17my 27:354d91d59b6d 44 _start_flag = _game_engine.get_start_flag();
el17my 27:354d91d59b6d 45 _game_engine.read_input(gamepad);
el17my 27:354d91d59b6d 46 _game_engine.get_sprite();
el17my 27:354d91d59b6d 47 _game_engine.get_explorer_direction();
el17my 27:354d91d59b6d 48 _game_engine.get_explorer_y(gamepad);
el17my 27:354d91d59b6d 49 _game_engine.get_explorer_x();
el17my 27:354d91d59b6d 50 _game_engine.generate_lines();
el17my 27:354d91d59b6d 51 _game_engine.check_collision(gamepad);
el17my 27:354d91d59b6d 52 _game_engine.update_lcd(lcd);
el17my 27:354d91d59b6d 53 _player_score = _game_engine.get_score();
el17my 27:354d91d59b6d 54 _game_engine.run_engine(lcd, gamepad);
el17my 27:354d91d59b6d 55 }
el17my 27:354d91d59b6d 56 }
el17my 27:354d91d59b6d 57
el17my 28:4a1260ad0346 58 @endcode
el17my 27:354d91d59b6d 59 */
el17my 27:354d91d59b6d 60
el17my 9:e11bb7cef050 61 class Gameengine {
el17my 9:e11bb7cef050 62 // Constructor and destructor.
el17my 9:e11bb7cef050 63 public:
el17my 28:4a1260ad0346 64 // Constructor and destructor.
el17my 28:4a1260ad0346 65 /**
el17my 28:4a1260ad0346 66 * @brief Constructor
el17my 28:4a1260ad0346 67 * @details Non user specified.
el17my 28:4a1260ad0346 68 */
el17my 9:e11bb7cef050 69 Gameengine();
el17my 28:4a1260ad0346 70 /**
el17my 28:4a1260ad0346 71 * @brief Destructor
el17my 28:4a1260ad0346 72 * @details Non user specified.
el17my 28:4a1260ad0346 73 */
el17my 9:e11bb7cef050 74 ~Gameengine();
el17my 28:4a1260ad0346 75 // Mutators.
el17my 28:4a1260ad0346 76 /**
el17my 28:4a1260ad0346 77 * @brief Initalises the Gameengine.
el17my 28:4a1260ad0346 78 */
el17my 9:e11bb7cef050 79 void init();
el17my 28:4a1260ad0346 80 /**
el17my 28:4a1260ad0346 81 * @brief reset the gameengine.
el17my 28:4a1260ad0346 82 */
el17my 9:e11bb7cef050 83 void reset_game_engine();
el17my 28:4a1260ad0346 84 /**
el17my 28:4a1260ad0346 85 * @brief get the coordinate and the button_flag.
el17my 28:4a1260ad0346 86 * @param &gamepad @details The gamepad object from Gamepad class.
el17my 28:4a1260ad0346 87 */
el17my 9:e11bb7cef050 88 void read_input(Gamepad &pad);
el17my 28:4a1260ad0346 89 /**
el17my 28:4a1260ad0346 90 * @brief check and flesh the reset flag.
el17my 28:4a1260ad0346 91 * @param &gamepad @details The gamepad object from Gamepad class.
el17my 28:4a1260ad0346 92 * @param &lcd @details The lcd object from the N5110 class
el17my 28:4a1260ad0346 93 */
el17my 9:e11bb7cef050 94 void check_reset(N5110 &lcd, Gamepad &gamepad);
el17my 28:4a1260ad0346 95 /**
el17my 28:4a1260ad0346 96 * @brief check and flesh the collision flag.
el17my 28:4a1260ad0346 97 * @param &gamepad @details The gamepad object from Gamepad class.
el17my 28:4a1260ad0346 98 */
el17my 9:e11bb7cef050 99 void check_collision(Gamepad &gamepad);
el17my 28:4a1260ad0346 100 /**
el17my 28:4a1260ad0346 101 * @brief check and flesh the start flag.
el17my 28:4a1260ad0346 102 * @param &gamepad @details The gamepad object from Gamepad class.
el17my 28:4a1260ad0346 103 * @param &lcd @details The lcd object from the N5110 class
el17my 28:4a1260ad0346 104 */
el17my 9:e11bb7cef050 105 void check_start(N5110 &lcd, Gamepad &gamepad);
el17my 28:4a1260ad0346 106 /**
el17my 28:4a1260ad0346 107 * @brief set the fall flag for engine.
el17my 28:4a1260ad0346 108 */
el17my 9:e11bb7cef050 109 void set_fall_flag();
el17my 28:4a1260ad0346 110 /**
el17my 28:4a1260ad0346 111 * @brief get the start flag.
el17my 28:4a1260ad0346 112 */
el17my 9:e11bb7cef050 113 bool get_start_flag();
el17my 28:4a1260ad0346 114 /**
el17my 28:4a1260ad0346 115 * @brief generate the upper and lower lines.
el17my 28:4a1260ad0346 116 */
el17my 9:e11bb7cef050 117 void generate_lines();
el17my 28:4a1260ad0346 118 /**
el17my 28:4a1260ad0346 119 * @brief get the player score.
el17my 28:4a1260ad0346 120 */
el17my 9:e11bb7cef050 121 int get_score();
el17my 28:4a1260ad0346 122 /**
el17my 28:4a1260ad0346 123 * @brief get the player's direction.
el17my 28:4a1260ad0346 124 */
el17my 9:e11bb7cef050 125 void get_explorer_direction();
el17my 28:4a1260ad0346 126 /**
el17my 28:4a1260ad0346 127 * @brief get the item and explorer sprite.
el17my 28:4a1260ad0346 128 */
el17my 9:e11bb7cef050 129 void get_sprite();
el17my 28:4a1260ad0346 130 /**
el17my 28:4a1260ad0346 131 * @brief get player's y.
el17my 28:4a1260ad0346 132 * @param &gamepad @details The gamepad object from Gamepad class.
el17my 28:4a1260ad0346 133 */
el17my 9:e11bb7cef050 134 void get_explorer_y(Gamepad &gamepad);
el17my 28:4a1260ad0346 135 /**
el17my 28:4a1260ad0346 136 * @brief get player's y.
el17my 28:4a1260ad0346 137 */
el17my 9:e11bb7cef050 138 void get_explorer_x();
el17my 28:4a1260ad0346 139 /**
el17my 28:4a1260ad0346 140 * @brief Updates the LCD display.
el17my 28:4a1260ad0346 141 * @param &lcd @details The lcd object from the N5110 class.
el17my 28:4a1260ad0346 142 */
el17my 9:e11bb7cef050 143 void update_lcd(N5110 &lcd);
el17my 28:4a1260ad0346 144 /**
el17my 28:4a1260ad0346 145 * @brief run the game.
el17my 28:4a1260ad0346 146 */
el17my 9:e11bb7cef050 147 void run_engine(N5110 &lcd, Gamepad &gamepad);
el17my 9:e11bb7cef050 148
el17my 9:e11bb7cef050 149
el17my 9:e11bb7cef050 150 private:
el17my 9:e11bb7cef050 151 Coordinate _coordinate;
el17my 9:e11bb7cef050 152 item _item;
el17my 9:e11bb7cef050 153 Explorer _player;
el17my 9:e11bb7cef050 154 Surface _surface;
el17my 23:7be9701fc1b8 155 bool X_flag;
el17my 23:7be9701fc1b8 156 int _player_x;
el17my 23:7be9701fc1b8 157 int _player_y;
el17my 23:7be9701fc1b8 158 bool _collision_flag;
el17my 23:7be9701fc1b8 159 bool _f_flag;
el17my 23:7be9701fc1b8 160 bool _r_flag;
el17my 23:7be9701fc1b8 161 bool _start_flag;
el17my 23:7be9701fc1b8 162 int _speed;
el17my 23:7be9701fc1b8 163 int _jump_height;
el17my 23:7be9701fc1b8 164 int _player_score;
el17my 9:e11bb7cef050 165 Line set_line_1;
el17my 9:e11bb7cef050 166 Line set_line_2;
el17my 9:e11bb7cef050 167 Line set_line_3;
el17my 9:e11bb7cef050 168 Line line_1_value;
el17my 9:e11bb7cef050 169 Line line_2_value;
el17my 9:e11bb7cef050 170 Line line_3_value;
el17my 9:e11bb7cef050 171 Line line_4_value;
el17my 9:e11bb7cef050 172 Line line_5_value;
el17my 9:e11bb7cef050 173 Line line_6_value;
el17my 9:e11bb7cef050 174 Player_direction _player_direction;
el17my 9:e11bb7cef050 175 Explorer_sprite _explorer_sprite;
el17my 9:e11bb7cef050 176 };
el17my 9:e11bb7cef050 177 #endif
el17my 9:e11bb7cef050 178
el17my 9:e11bb7cef050 179