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