ELEC2645 (2018/19) / Mbed 2 deprecated ml16c5l

Dependencies:   mbed

Committer:
ml16c5l
Date:
Wed May 08 18:30:35 2019 +0000
Revision:
16:fda4c36bffe9
Parent:
15:997278891dc1
Child:
17:b385e6ae8ef4
2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ml16c5l 9:192ad897ec95 1 /*
ml16c5l 9:192ad897ec95 2 ELEC2645 Embedded Systems Project
ml16c5l 9:192ad897ec95 3 School of Electronic & Electrical Engineering
ml16c5l 9:192ad897ec95 4 University of Leeds
ml16c5l 9:192ad897ec95 5 Name: Caiwenjing Liu
ml16c5l 9:192ad897ec95 6 Username:ml16c5l
ml16c5l 9:192ad897ec95 7 Student ID Number: 201165261
ml16c5l 9:192ad897ec95 8 Date: 24/04/2019
ml16c5l 9:192ad897ec95 9 */
ml16c5l 9:192ad897ec95 10
ml16c5l 9:192ad897ec95 11
ml16c5l 9:192ad897ec95 12
ml16c5l 8:ccf827ce0072 13 #ifndef COPTERENGINE_H
ml16c5l 8:ccf827ce0072 14 #define COPTERENGINE_H
ml16c5l 8:ccf827ce0072 15
ml16c5l 9:192ad897ec95 16
ml16c5l 8:ccf827ce0072 17 #include "mbed.h"
ml16c5l 8:ccf827ce0072 18 #include "N5110.h"
ml16c5l 8:ccf827ce0072 19 #include "Gamepad.h"
ml16c5l 8:ccf827ce0072 20 #include "Copter.h"
ml16c5l 9:192ad897ec95 21 #include "Wall.h"
ml16c5l 9:192ad897ec95 22
ml16c5l 8:ccf827ce0072 23
ml16c5l 9:192ad897ec95 24 // gap from edge of screen
ml16c5l 9:192ad897ec95 25 #define GAP 4
ml16c5l 8:ccf827ce0072 26
ml16c5l 16:fda4c36bffe9 27 /** CopterEgine Class
ml16c5l 15:997278891dc1 28 @author Caiwenjing Liu, University of Leeds
ml16c5l 15:997278891dc1 29 @brief the code of copter for the CopterGame
ml16c5l 15:997278891dc1 30 @date 11/04/2019
ml16c5l 15:997278891dc1 31 */
ml16c5l 8:ccf827ce0072 32
ml16c5l 8:ccf827ce0072 33 class CopterEngine
ml16c5l 8:ccf827ce0072 34 {
ml16c5l 8:ccf827ce0072 35
ml16c5l 8:ccf827ce0072 36 public:
ml16c5l 9:192ad897ec95 37 /** Constructor */
ml16c5l 8:ccf827ce0072 38 CopterEngine();
ml16c5l 9:192ad897ec95 39
ml16c5l 9:192ad897ec95 40 /** Destructor */
ml16c5l 9:192ad897ec95 41 ~CopterEngine();
ml16c5l 9:192ad897ec95 42
ml16c5l 9:192ad897ec95 43
ml16c5l 9:192ad897ec95 44 /** initialise Copter and wall parameters
ml16c5l 9:192ad897ec95 45 * @param the value of Copter_width,Copter_height,wall_size,speed.
ml16c5l 9:192ad897ec95 46 */
ml16c5l 9:192ad897ec95 47 void init(int Copter_width,int Copter_height,int wall_size,int speed);
ml16c5l 9:192ad897ec95 48
ml16c5l 9:192ad897ec95 49 /** get the input of the user
ml16c5l 9:192ad897ec95 50 * @return input from the user
ml16c5l 9:192ad897ec95 51 */
ml16c5l 9:192ad897ec95 52 void read_input(Gamepad &pad);
ml16c5l 9:192ad897ec95 53
ml16c5l 9:192ad897ec95 54
ml16c5l 9:192ad897ec95 55 /** update the gamepad
ml16c5l 9:192ad897ec95 56 * @param update the gamepad when users start the game
ml16c5l 9:192ad897ec95 57 */
ml16c5l 9:192ad897ec95 58 void update(Gamepad &pad);
ml16c5l 9:192ad897ec95 59
ml16c5l 9:192ad897ec95 60
ml16c5l 9:192ad897ec95 61 /** draw all those things on the screen, which are walls and the copter
ml16c5l 9:192ad897ec95 62 * @param draw wall copter and so on defined in classes
ml16c5l 9:192ad897ec95 63 */
ml16c5l 9:192ad897ec95 64 void draw(N5110 &lcd);
ml16c5l 9:192ad897ec95 65
ml16c5l 9:192ad897ec95 66 /** get the state of which the game is finished or not
ml16c5l 9:192ad897ec95 67 * @return current state of the end when the game is over
ml16c5l 9:192ad897ec95 68 */
ml16c5l 9:192ad897ec95 69 int GameOver();
ml16c5l 9:192ad897ec95 70
ml16c5l 9:192ad897ec95 71
ml16c5l 9:192ad897ec95 72 int gameover;
ml16c5l 9:192ad897ec95 73 int z;
ml16c5l 9:192ad897ec95 74
ml16c5l 9:192ad897ec95 75 private:
ml16c5l 9:192ad897ec95 76
ml16c5l 9:192ad897ec95 77
ml16c5l 9:192ad897ec95 78 // initiate all classes
ml16c5l 9:192ad897ec95 79 Copter _p1;
ml16c5l 9:192ad897ec95 80 Wall _wall;
ml16c5l 9:192ad897ec95 81
ml16c5l 9:192ad897ec95 82 /** Check the screen edgess
ml16c5l 9:192ad897ec95 83 * @param check edge of the copter
ml16c5l 9:192ad897ec95 84 */
ml16c5l 9:192ad897ec95 85 void check_wall_edge(Gamepad &pad);
ml16c5l 9:192ad897ec95 86
ml16c5l 9:192ad897ec95 87 /** Check the wall and Copter edges
ml16c5l 9:192ad897ec95 88 * @param check the edge of the copter when it collides with any wall
ml16c5l 9:192ad897ec95 89 */
ml16c5l 9:192ad897ec95 90 void check_WallCopter_edges(Gamepad &pad);
ml16c5l 9:192ad897ec95 91
ml16c5l 9:192ad897ec95 92 /** Check the goal
ml16c5l 9:192ad897ec95 93 * @param Check how much score have the user earned
ml16c5l 9:192ad897ec95 94 */
ml16c5l 9:192ad897ec95 95 void check_goal(Gamepad &pad);
ml16c5l 9:192ad897ec95 96 /** Print scores on LCD
ml16c5l 9:192ad897ec95 97 * @param Get the score and use sprint function to print it to LCD
ml16c5l 9:192ad897ec95 98 */
ml16c5l 9:192ad897ec95 99 void print_scores(N5110 &lcd);
ml16c5l 9:192ad897ec95 100
ml16c5l 9:192ad897ec95 101
ml16c5l 9:192ad897ec95 102 int _Copter_width;
ml16c5l 9:192ad897ec95 103 int _Copter_height;
ml16c5l 9:192ad897ec95 104 int _speed;
ml16c5l 9:192ad897ec95 105
ml16c5l 9:192ad897ec95 106 // x positions of the Copter
ml16c5l 9:192ad897ec95 107 int _posx;
ml16c5l 9:192ad897ec95 108
ml16c5l 9:192ad897ec95 109 int _wall_size;
ml16c5l 9:192ad897ec95 110
ml16c5l 9:192ad897ec95 111
ml16c5l 9:192ad897ec95 112
ml16c5l 9:192ad897ec95 113 Direction _d;
ml16c5l 9:192ad897ec95 114 float _mag;
ml16c5l 9:192ad897ec95 115
ml16c5l 9:192ad897ec95 116 };
ml16c5l 9:192ad897ec95 117
ml16c5l 9:192ad897ec95 118
ml16c5l 9:192ad897ec95 119
ml16c5l 9:192ad897ec95 120
ml16c5l 9:192ad897ec95 121 #endif