ELEC2645 (2018/19) / Mbed 2 deprecated ml16c5l

Dependencies:   mbed

Committer:
ml16c5l
Date:
Sun Apr 28 21:32:06 2019 +0000
Revision:
9:192ad897ec95
Parent:
8:ccf827ce0072
Child:
13:5dd6f2d443cf
change wall

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 8:ccf827ce0072 27
ml16c5l 8:ccf827ce0072 28
ml16c5l 8:ccf827ce0072 29 class CopterEngine
ml16c5l 8:ccf827ce0072 30 {
ml16c5l 8:ccf827ce0072 31
ml16c5l 8:ccf827ce0072 32 public:
ml16c5l 9:192ad897ec95 33 /** Constructor */
ml16c5l 8:ccf827ce0072 34 CopterEngine();
ml16c5l 9:192ad897ec95 35
ml16c5l 9:192ad897ec95 36 /** Destructor */
ml16c5l 9:192ad897ec95 37 ~CopterEngine();
ml16c5l 9:192ad897ec95 38
ml16c5l 9:192ad897ec95 39
ml16c5l 9:192ad897ec95 40 /** initialise Copter and wall parameters
ml16c5l 9:192ad897ec95 41 * @param the value of Copter_width,Copter_height,wall_size,speed.
ml16c5l 9:192ad897ec95 42 */
ml16c5l 9:192ad897ec95 43 void init(int Copter_width,int Copter_height,int wall_size,int speed);
ml16c5l 9:192ad897ec95 44
ml16c5l 9:192ad897ec95 45 /** get the input of the user
ml16c5l 9:192ad897ec95 46 * @return input from the user
ml16c5l 9:192ad897ec95 47 */
ml16c5l 9:192ad897ec95 48 void read_input(Gamepad &pad);
ml16c5l 9:192ad897ec95 49
ml16c5l 9:192ad897ec95 50
ml16c5l 9:192ad897ec95 51 /** update the gamepad
ml16c5l 9:192ad897ec95 52 * @param update the gamepad when users start the game
ml16c5l 9:192ad897ec95 53 */
ml16c5l 9:192ad897ec95 54 void update(Gamepad &pad);
ml16c5l 9:192ad897ec95 55
ml16c5l 9:192ad897ec95 56
ml16c5l 9:192ad897ec95 57 /** draw all those things on the screen, which are walls and the copter
ml16c5l 9:192ad897ec95 58 * @param draw wall copter and so on defined in classes
ml16c5l 9:192ad897ec95 59 */
ml16c5l 9:192ad897ec95 60 void draw(N5110 &lcd);
ml16c5l 9:192ad897ec95 61
ml16c5l 9:192ad897ec95 62 /** get the state of which the game is finished or not
ml16c5l 9:192ad897ec95 63 * @return current state of the end when the game is over
ml16c5l 9:192ad897ec95 64 */
ml16c5l 9:192ad897ec95 65 int GameOver();
ml16c5l 9:192ad897ec95 66
ml16c5l 9:192ad897ec95 67
ml16c5l 9:192ad897ec95 68 int gameover;
ml16c5l 9:192ad897ec95 69 int z;
ml16c5l 9:192ad897ec95 70
ml16c5l 9:192ad897ec95 71 private:
ml16c5l 9:192ad897ec95 72
ml16c5l 9:192ad897ec95 73
ml16c5l 9:192ad897ec95 74 // initiate all classes
ml16c5l 9:192ad897ec95 75 Copter _p1;
ml16c5l 9:192ad897ec95 76 Wall _wall;
ml16c5l 9:192ad897ec95 77
ml16c5l 9:192ad897ec95 78 /** Check the screen edgess
ml16c5l 9:192ad897ec95 79 * @param check edge of the copter
ml16c5l 9:192ad897ec95 80 */
ml16c5l 9:192ad897ec95 81 void check_wall_edge(Gamepad &pad);
ml16c5l 9:192ad897ec95 82
ml16c5l 9:192ad897ec95 83 /** Check the wall and Copter edges
ml16c5l 9:192ad897ec95 84 * @param check the edge of the copter when it collides with any wall
ml16c5l 9:192ad897ec95 85 */
ml16c5l 9:192ad897ec95 86 void check_WallCopter_edges(Gamepad &pad);
ml16c5l 9:192ad897ec95 87
ml16c5l 9:192ad897ec95 88 /** Check the goal
ml16c5l 9:192ad897ec95 89 * @param Check how much score have the user earned
ml16c5l 9:192ad897ec95 90 */
ml16c5l 9:192ad897ec95 91 void check_goal(Gamepad &pad);
ml16c5l 9:192ad897ec95 92 /** Print scores on LCD
ml16c5l 9:192ad897ec95 93 * @param Get the score and use sprint function to print it to LCD
ml16c5l 9:192ad897ec95 94 */
ml16c5l 9:192ad897ec95 95 void print_scores(N5110 &lcd);
ml16c5l 9:192ad897ec95 96
ml16c5l 9:192ad897ec95 97
ml16c5l 9:192ad897ec95 98 int _Copter_width;
ml16c5l 9:192ad897ec95 99 int _Copter_height;
ml16c5l 9:192ad897ec95 100 int _speed;
ml16c5l 9:192ad897ec95 101
ml16c5l 9:192ad897ec95 102 // x positions of the Copter
ml16c5l 9:192ad897ec95 103 int _posx;
ml16c5l 9:192ad897ec95 104
ml16c5l 9:192ad897ec95 105 int _wall_size;
ml16c5l 9:192ad897ec95 106
ml16c5l 9:192ad897ec95 107
ml16c5l 9:192ad897ec95 108
ml16c5l 9:192ad897ec95 109 Direction _d;
ml16c5l 9:192ad897ec95 110 float _mag;
ml16c5l 9:192ad897ec95 111
ml16c5l 9:192ad897ec95 112 };
ml16c5l 9:192ad897ec95 113
ml16c5l 9:192ad897ec95 114
ml16c5l 9:192ad897ec95 115
ml16c5l 9:192ad897ec95 116
ml16c5l 9:192ad897ec95 117 #endif