Mochu Yao explorer game

Dependencies:   mbed

Committer:
el17my
Date:
Tue Apr 28 11:55:05 2020 +0000
Revision:
14:5e73a6e34c17
Parent:
13:30330d61f09c
Child:
23:7be9701fc1b8
4.28

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