ELEC2645 (2018/19) / Mbed 2 deprecated ml16c5l

Dependencies:   mbed

Committer:
ml16c5l
Date:
Wed May 08 18:17:45 2019 +0000
Revision:
13:5dd6f2d443cf
Parent:
9:192ad897ec95
Child:
14:b2a89c6426c8
ml16c5l

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