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