demo

Dependencies:   mbed Gamepad N5110

Committer:
Ting12138
Date:
Thu May 14 13:00:19 2020 +0000
Revision:
1:7b5a843acc05
Parent:
0:ba32cfe0051e
homework

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Ting12138 0:ba32cfe0051e 1 #ifndef ENGINE_H
Ting12138 0:ba32cfe0051e 2 #define ENGINE_H
Ting12138 0:ba32cfe0051e 3
Ting12138 0:ba32cfe0051e 4 #include "mbed.h"
Ting12138 0:ba32cfe0051e 5 #include "N5110.h"
Ting12138 0:ba32cfe0051e 6 #include "Gamepad.h"
Ting12138 0:ba32cfe0051e 7 #include "foods.h"
Ting12138 0:ba32cfe0051e 8 #include "rocket.h"
Ting12138 0:ba32cfe0051e 9 #include "the_wall.h"
Ting12138 0:ba32cfe0051e 10
Ting12138 0:ba32cfe0051e 11
Ting12138 0:ba32cfe0051e 12 class Engine
Ting12138 0:ba32cfe0051e 13 {
Ting12138 0:ba32cfe0051e 14
Ting12138 0:ba32cfe0051e 15 public:
Ting12138 0:ba32cfe0051e 16 Engine();
Ting12138 0:ba32cfe0051e 17 ~Engine();
Ting12138 0:ba32cfe0051e 18 // constructors
Ting12138 0:ba32cfe0051e 19 /**
Ting12138 0:ba32cfe0051e 20 * @brief Initiates the parameters for every objects
Ting12138 0:ba32cfe0051e 21 * @param wall_width @details Width of Wall
Ting12138 0:ba32cfe0051e 22 * @param wall_gap @details Gap of Wall
Ting12138 0:ba32cfe0051e 23 * @param foods_size and the details Radius of foods
Ting12138 0:ba32cfe0051e 24 * @param speed and details Speed of the moving objects
Ting12138 0:ba32cfe0051e 25 */
Ting12138 0:ba32cfe0051e 26 void init(int wall_width,int wall_gap,int foods_size,int speed);
Ting12138 0:ba32cfe0051e 27 /**
Ting12138 0:ba32cfe0051e 28 * @brief Reads the data input from the joystick
Ting12138 0:ba32cfe0051e 29 * @param Gamepad and details Gamepad that holds the parameters of the joystick
Ting12138 0:ba32cfe0051e 30 */
Ting12138 0:ba32cfe0051e 31 void read_input(Gamepad &pad);
Ting12138 0:ba32cfe0051e 32 /**
Ting12138 0:ba32cfe0051e 33 * @brief Draws every objects on the screen using initiate data/update data
Ting12138 0:ba32cfe0051e 34 * @param N5110
Ting12138 0:ba32cfe0051e 35 * @details LCD which diaplay the game
Ting12138 0:ba32cfe0051e 36 */
Ting12138 0:ba32cfe0051e 37 void draw(N5110 &lcd);
Ting12138 0:ba32cfe0051e 38 /**
Ting12138 0:ba32cfe0051e 39 * @brief Renews positions for all the objects
Ting12138 0:ba32cfe0051e 40 * @param Gamepad @details Gamepad that holds the parameters of the joystick
Ting12138 0:ba32cfe0051e 41 */
Ting12138 0:ba32cfe0051e 42 void update(Gamepad &pad);
Ting12138 0:ba32cfe0051e 43 /**
Ting12138 0:ba32cfe0051e 44 * @brief Gets the score
Ting12138 0:ba32cfe0051e 45 * @returns The number of score
Ting12138 0:ba32cfe0051e 46 */
Ting12138 0:ba32cfe0051e 47 int get_final_score(); // get score for the incoming events
Ting12138 0:ba32cfe0051e 48
Ting12138 0:ba32cfe0051e 49 private:
Ting12138 0:ba32cfe0051e 50 void check_wall_collision(Gamepad &pad);
Ting12138 0:ba32cfe0051e 51 void check_score(Gamepad &pad);
Ting12138 0:ba32cfe0051e 52
Ting12138 0:ba32cfe0051e 53 the_wall _w0;
Ting12138 0:ba32cfe0051e 54 the_wall _w1;
Ting12138 0:ba32cfe0051e 55 the_wall _w2;
Ting12138 0:ba32cfe0051e 56 the_wall _w3;
Ting12138 0:ba32cfe0051e 57 the_wall _w4;
Ting12138 0:ba32cfe0051e 58
Ting12138 0:ba32cfe0051e 59 int _wall_width;
Ting12138 0:ba32cfe0051e 60 int _wall_gap;
Ting12138 0:ba32cfe0051e 61 int _foods_size;
Ting12138 0:ba32cfe0051e 62 int _velocity;
Ting12138 0:ba32cfe0051e 63
Ting12138 0:ba32cfe0051e 64 // x positions of the walls
Ting12138 0:ba32cfe0051e 65 int _w0x;
Ting12138 0:ba32cfe0051e 66 int _w1x;
Ting12138 0:ba32cfe0051e 67 int _w2x;
Ting12138 0:ba32cfe0051e 68 int _w3x;
Ting12138 0:ba32cfe0051e 69 int _w4x;
Ting12138 0:ba32cfe0051e 70 int _rocketx;
Ting12138 0:ba32cfe0051e 71 int _foodsx;
Ting12138 0:ba32cfe0051e 72
Ting12138 0:ba32cfe0051e 73 rocket _rocket;
Ting12138 0:ba32cfe0051e 74 foods _foods;
Ting12138 0:ba32cfe0051e 75
Ting12138 0:ba32cfe0051e 76 Direction _d;
Ting12138 0:ba32cfe0051e 77 float _mag;
Ting12138 0:ba32cfe0051e 78 Vector2D _mapped_coord;
Ting12138 0:ba32cfe0051e 79
Ting12138 0:ba32cfe0051e 80
Ting12138 0:ba32cfe0051e 81 };
Ting12138 0:ba32cfe0051e 82
Ting12138 0:ba32cfe0051e 83 #endif