Mochu Yao explorer game

Dependencies:   mbed

Committer:
el17my
Date:
Tue Apr 28 17:58:00 2020 +0000
Revision:
27:354d91d59b6d
Parent:
26:4d193529b447
Child:
28:4a1260ad0346
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 14:5e73a6e34c17 14 struct Coordinate {
el17my 14:5e73a6e34c17 15 Vector2D coord; /**< Vector 2D for joystick coords */
el17my 14:5e73a6e34c17 16 };
el17my 10:559487aac60e 17
el17my 27:354d91d59b6d 18 /** Gameengine Class
el17my 27:354d91d59b6d 19 * @1 make the whole explorer game run and set the score the reset process
el17my 27:354d91d59b6d 20 * @2 cheak the collision and the reset or fall flag
el17my 27:354d91d59b6d 21 * @3 draw on the lcd screen and load the gamepad controll
el17my 27:354d91d59b6d 22 * @date April 24th 2020
el17my 27:354d91d59b6d 23 * @author Yaomochu
el17my 27:354d91d59b6d 24 * @code
el17my 27:354d91d59b6d 25
el17my 27:354d91d59b6d 26 #include "mbed.h"
el17my 27:354d91d59b6d 27 #include "N5110.h"
el17my 27:354d91d59b6d 28 #include "Gamepad.h"
el17my 27:354d91d59b6d 29 #include "Gameengine.h"
el17my 27:354d91d59b6d 30
el17my 27:354d91d59b6d 31 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
el17my 27:354d91d59b6d 32 Gamepad gamepad;
el17my 27:354d91d59b6d 33 Gameengine _game_engine;
el17my 27:354d91d59b6d 34
el17my 27:354d91d59b6d 35 bool _start_flag;
el17my 27:354d91d59b6d 36 int _player_score;
el17my 27:354d91d59b6d 37
el17my 27:354d91d59b6d 38 int main() {
el17my 27:354d91d59b6d 39 _game_engine.init();
el17my 27:354d91d59b6d 40 while(1) {
el17my 27:354d91d59b6d 41 _game_engine.check_reset(lcd, gamepad);
el17my 27:354d91d59b6d 42 _start_flag = _game_engine.get_start_flag();
el17my 27:354d91d59b6d 43 _game_engine.read_input(gamepad);
el17my 27:354d91d59b6d 44 _game_engine.get_sprite();
el17my 27:354d91d59b6d 45 _game_engine.get_explorer_direction();
el17my 27:354d91d59b6d 46 _game_engine.get_explorer_y(gamepad);
el17my 27:354d91d59b6d 47 _game_engine.get_explorer_x();
el17my 27:354d91d59b6d 48 _game_engine.generate_lines();
el17my 27:354d91d59b6d 49 _game_engine.check_collision(gamepad);
el17my 27:354d91d59b6d 50 _game_engine.update_lcd(lcd);
el17my 27:354d91d59b6d 51 _player_score = _game_engine.get_score();
el17my 27:354d91d59b6d 52 _game_engine.run_engine(lcd, gamepad);
el17my 27:354d91d59b6d 53 }
el17my 27:354d91d59b6d 54 }
el17my 27:354d91d59b6d 55
el17my 27:354d91d59b6d 56 * @endcode
el17my 27:354d91d59b6d 57 */
el17my 27:354d91d59b6d 58
el17my 9:e11bb7cef050 59 class Gameengine {
el17my 9:e11bb7cef050 60 // Constructor and destructor.
el17my 9:e11bb7cef050 61 public:
el17my 9:e11bb7cef050 62 Gameengine();
el17my 9:e11bb7cef050 63 ~Gameengine();
el17my 9:e11bb7cef050 64 //first init all the parameter
el17my 9:e11bb7cef050 65 void init();
el17my 9:e11bb7cef050 66 void reset_game_engine();
el17my 9:e11bb7cef050 67 void read_input(Gamepad &pad);
el17my 9:e11bb7cef050 68 void check_reset(N5110 &lcd, Gamepad &gamepad);
el17my 9:e11bb7cef050 69 void check_collision(Gamepad &gamepad);
el17my 9:e11bb7cef050 70 void check_start(N5110 &lcd, Gamepad &gamepad);
el17my 9:e11bb7cef050 71 void set_fall_flag();
el17my 9:e11bb7cef050 72 bool get_start_flag();
el17my 9:e11bb7cef050 73 void generate_lines();
el17my 9:e11bb7cef050 74 int get_score();
el17my 9:e11bb7cef050 75 void get_explorer_direction();
el17my 9:e11bb7cef050 76 void get_sprite();
el17my 9:e11bb7cef050 77 void get_explorer_y(Gamepad &gamepad);
el17my 9:e11bb7cef050 78 void get_explorer_x();
el17my 9:e11bb7cef050 79 void update_lcd(N5110 &lcd);
el17my 9:e11bb7cef050 80 void run_engine(N5110 &lcd, Gamepad &gamepad);
el17my 9:e11bb7cef050 81
el17my 9:e11bb7cef050 82
el17my 9:e11bb7cef050 83 private:
el17my 9:e11bb7cef050 84 Coordinate _coordinate;
el17my 9:e11bb7cef050 85 item _item;
el17my 9:e11bb7cef050 86 Explorer _player;
el17my 9:e11bb7cef050 87 Surface _surface;
el17my 23:7be9701fc1b8 88 bool X_flag;
el17my 23:7be9701fc1b8 89 int _player_x;
el17my 23:7be9701fc1b8 90 int _player_y;
el17my 23:7be9701fc1b8 91 bool _collision_flag;
el17my 23:7be9701fc1b8 92 bool _f_flag;
el17my 23:7be9701fc1b8 93 bool _r_flag;
el17my 23:7be9701fc1b8 94 bool _start_flag;
el17my 23:7be9701fc1b8 95 int _speed;
el17my 23:7be9701fc1b8 96 int _jump_height;
el17my 23:7be9701fc1b8 97 int _player_score;
el17my 9:e11bb7cef050 98 Line set_line_1;
el17my 9:e11bb7cef050 99 Line set_line_2;
el17my 9:e11bb7cef050 100 Line set_line_3;
el17my 9:e11bb7cef050 101 Line line_1_value;
el17my 9:e11bb7cef050 102 Line line_2_value;
el17my 9:e11bb7cef050 103 Line line_3_value;
el17my 9:e11bb7cef050 104 Line line_4_value;
el17my 9:e11bb7cef050 105 Line line_5_value;
el17my 9:e11bb7cef050 106 Line line_6_value;
el17my 9:e11bb7cef050 107 Player_direction _player_direction;
el17my 9:e11bb7cef050 108 Explorer_sprite _explorer_sprite;
el17my 9:e11bb7cef050 109 };
el17my 9:e11bb7cef050 110 #endif
el17my 9:e11bb7cef050 111
el17my 9:e11bb7cef050 112