ELEC2645 (2018/19) / Mbed 2 deprecated ll16o2l_ELEC2645

Dependencies:   mbed Gamepad

Committer:
ll16o2l
Date:
Tue May 07 18:08:58 2019 +0000
Revision:
16:f1b5ea92facd
Parent:
15:807eba7c7811
Fixed an accident in commenting

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ll16o2l 2:888634fff8ff 1 #ifndef DODGENGINE_H
ll16o2l 2:888634fff8ff 2 #define DODGEENGINE_H
ll16o2l 2:888634fff8ff 3
ll16o2l 2:888634fff8ff 4 #include "mbed.h"
ll16o2l 2:888634fff8ff 5 #include "N5110.h"
ll16o2l 2:888634fff8ff 6 #include "Gamepad.h"
ll16o2l 2:888634fff8ff 7 #include "Objects.h"
ll16o2l 2:888634fff8ff 8 #include "Player.h"
ll16o2l 3:aa82968b7a8e 9 #include "Health_Kit.h"
ll16o2l 2:888634fff8ff 10
ll16o2l 7:67c00839f188 11 /** DodgeEngine Class
ll16o2l 15:807eba7c7811 12
ll16o2l 15:807eba7c7811 13 @brief Controls the functionality of the Dodge game .
ll16o2l 15:807eba7c7811 14 @breif Controls when the objects are generated into the game and the conditions when the objects collide with the walls
ll16o2l 15:807eba7c7811 15 @brief also when the player collides with the objects and health pack what should be done to the lives and the output.
ll16o2l 15:807eba7c7811 16
ll16o2l 15:807eba7c7811 17 @brief Revisions 1.0
ll16o2l 15:807eba7c7811 18
ll16o2l 15:807eba7c7811 19
ll16o2l 15:807eba7c7811 20 @author Oliver Luong, University of Leeds
ll16o2l 15:807eba7c7811 21 @date 22/04/2019
ll16o2l 3:aa82968b7a8e 22 */
ll16o2l 2:888634fff8ff 23
ll16o2l 15:807eba7c7811 24
ll16o2l 2:888634fff8ff 25 class DodgeEngine
ll16o2l 2:888634fff8ff 26 {
ll16o2l 2:888634fff8ff 27
ll16o2l 2:888634fff8ff 28 public:
ll16o2l 15:807eba7c7811 29 /** Contructor / Destructor */
ll16o2l 2:888634fff8ff 30 DodgeEngine();
ll16o2l 2:888634fff8ff 31 ~DodgeEngine();
ll16o2l 6:98ddf5eade49 32
ll16o2l 15:807eba7c7811 33 /**
ll16o2l 15:807eba7c7811 34 This method will be used to set the global variables to local variable
ll16o2l 15:807eba7c7811 35 @author Oliver Luong
ll16o2l 15:807eba7c7811 36 @param player_width fetches the initialised player width from main.
ll16o2l 15:807eba7c7811 37 @param player_height fetches the initialised player height from main.
ll16o2l 15:807eba7c7811 38 @param objects_size fetches the initialised object size from main.
ll16o2l 15:807eba7c7811 39 @param speed fetches the initialised speed from main.
ll16o2l 15:807eba7c7811 40 @param lives fetches the initialised lives from main.
ll16o2l 15:807eba7c7811 41 @param kit_size fetches the initialised kit size from main.
ll16o2l 15:807eba7c7811 42 */
ll16o2l 3:aa82968b7a8e 43 void init(int player_width,int player_height,int objetcs_size,int speed,int lives, int kit_size);
ll16o2l 15:807eba7c7811 44
ll16o2l 15:807eba7c7811 45 /** Fetch direction and magintude of the joystick and save to local variables. */
ll16o2l 2:888634fff8ff 46 void read_input(Gamepad &pad);
ll16o2l 6:98ddf5eade49 47
ll16o2l 15:807eba7c7811 48 /**
ll16o2l 15:807eba7c7811 49 This method will be used to update the direction of the player
ll16o2l 15:807eba7c7811 50 and call the methods to check objects for collisions/overlaps
ll16o2l 15:807eba7c7811 51 */
ll16o2l 2:888634fff8ff 52 void update(Gamepad &pad);
ll16o2l 15:807eba7c7811 53
ll16o2l 15:807eba7c7811 54 /** Drawing the player, objects and the health kit to the LCD */
ll16o2l 2:888634fff8ff 55 void draw(N5110 &lcd);
ll16o2l 15:807eba7c7811 56
ll16o2l 15:807eba7c7811 57 /**
ll16o2l 15:807eba7c7811 58 This method will be used to return the value of lose when called
ll16o2l 15:807eba7c7811 59 */
ll16o2l 2:888634fff8ff 60 int get_lose();
ll16o2l 2:888634fff8ff 61
ll16o2l 16:f1b5ea92facd 62 /**
ll16o2l 16:f1b5ea92facd 63 This method will be used to store the time value to a local variable.
ll16o2l 16:f1b5ea92facd 64 @param time fetched from main.
ll16o2l 16:f1b5ea92facd 65 */
ll16o2l 16:f1b5ea92facd 66 void time(float time);
ll16o2l 16:f1b5ea92facd 67
ll16o2l 2:888634fff8ff 68 private:
ll16o2l 2:888634fff8ff 69
ll16o2l 15:807eba7c7811 70 // Methods
ll16o2l 15:807eba7c7811 71
ll16o2l 15:807eba7c7811 72 /**
ll16o2l 15:807eba7c7811 73 This method will be used to check for object 1 collisions to the wall
ll16o2l 15:807eba7c7811 74 and reposition the objects as to bounce off the walls.
ll16o2l 15:807eba7c7811 75 */
ll16o2l 3:aa82968b7a8e 76 void check_wall_collision1(Gamepad &pad);
ll16o2l 15:807eba7c7811 77
ll16o2l 15:807eba7c7811 78 /**
ll16o2l 15:807eba7c7811 79 This method will be used to check for object 2 collisions to the wall
ll16o2l 15:807eba7c7811 80 and reposition the objects as to bounce off the walls.
ll16o2l 15:807eba7c7811 81 */
ll16o2l 3:aa82968b7a8e 82 void check_wall_collision2(Gamepad &pad);
ll16o2l 15:807eba7c7811 83
ll16o2l 15:807eba7c7811 84 /**
ll16o2l 15:807eba7c7811 85 This method will be used to check for object 3 collisions to the wall
ll16o2l 15:807eba7c7811 86 and reposition the objects as to bounce off the walls.
ll16o2l 15:807eba7c7811 87 */
ll16o2l 3:aa82968b7a8e 88 void check_wall_collision3(Gamepad &pad);
ll16o2l 15:807eba7c7811 89
ll16o2l 15:807eba7c7811 90 /**
ll16o2l 15:807eba7c7811 91 This method will be used to check for object 4 collisions to the wall
ll16o2l 15:807eba7c7811 92 and reposition the objects as to bounce off the walls.
ll16o2l 15:807eba7c7811 93 */
ll16o2l 3:aa82968b7a8e 94 void check_wall_collision4(Gamepad &pad);
ll16o2l 15:807eba7c7811 95
ll16o2l 15:807eba7c7811 96 /**
ll16o2l 15:807eba7c7811 97 This method will be used to check for player collisions with object 1
ll16o2l 15:807eba7c7811 98 and calls on the player_hit method if condition is met.
ll16o2l 15:807eba7c7811 99 */
ll16o2l 3:aa82968b7a8e 100 void check_player_collisions1(Gamepad &pad);
ll16o2l 15:807eba7c7811 101
ll16o2l 15:807eba7c7811 102 /**
ll16o2l 15:807eba7c7811 103 This method will be used to check for player collisions with object 2
ll16o2l 15:807eba7c7811 104 and calls on the player_hit method if condition is met.
ll16o2l 15:807eba7c7811 105 */
ll16o2l 3:aa82968b7a8e 106 void check_player_collisions2(Gamepad &pad);
ll16o2l 15:807eba7c7811 107
ll16o2l 15:807eba7c7811 108 /**
ll16o2l 15:807eba7c7811 109 This method will be used to check for player collisions with object 3
ll16o2l 15:807eba7c7811 110 and calls on the player_hit method if condition is met.
ll16o2l 15:807eba7c7811 111 */
ll16o2l 3:aa82968b7a8e 112 void check_player_collisions3(Gamepad &pad);
ll16o2l 15:807eba7c7811 113
ll16o2l 15:807eba7c7811 114 /**
ll16o2l 15:807eba7c7811 115 This method will be used to check for player collisions with object 4
ll16o2l 15:807eba7c7811 116 and calls on the player_hit method if condition is met.
ll16o2l 15:807eba7c7811 117 */
ll16o2l 3:aa82968b7a8e 118 void check_player_collisions4(Gamepad &pad);
ll16o2l 15:807eba7c7811 119
ll16o2l 15:807eba7c7811 120 /**
ll16o2l 15:807eba7c7811 121 This method will be used to check for player collisions with health kit
ll16o2l 15:807eba7c7811 122 and sets collect to true.
ll16o2l 15:807eba7c7811 123 */
ll16o2l 3:aa82968b7a8e 124 void check_player_health_kit_collison(Gamepad &pad);
ll16o2l 15:807eba7c7811 125
ll16o2l 15:807eba7c7811 126 /**
ll16o2l 15:807eba7c7811 127 This method is used to increase the lives variable value by 1 if
ll16o2l 15:807eba7c7811 128 the conditions are met and with user input.
ll16o2l 15:807eba7c7811 129 */
ll16o2l 3:aa82968b7a8e 130 void life_up(Gamepad &pad);
ll16o2l 15:807eba7c7811 131
ll16o2l 15:807eba7c7811 132 /**
ll16o2l 15:807eba7c7811 133 This method will be used to display the players lives using
ll16o2l 15:807eba7c7811 134 the LEDs.
ll16o2l 15:807eba7c7811 135 */
ll16o2l 3:aa82968b7a8e 136 void life_leds(Gamepad &pad);
ll16o2l 2:888634fff8ff 137
ll16o2l 15:807eba7c7811 138 /**
ll16o2l 15:807eba7c7811 139 This method is used to reduce a life if the condition is met.
ll16o2l 15:807eba7c7811 140 */
ll16o2l 3:aa82968b7a8e 141 void player_hit(Gamepad &pad);
ll16o2l 15:807eba7c7811 142
ll16o2l 15:807eba7c7811 143 /**
ll16o2l 15:807eba7c7811 144 This method will be used to print the lives and time to LCD
ll16o2l 15:807eba7c7811 145 */
ll16o2l 3:aa82968b7a8e 146 void print_lives_time(N5110 &lcd);
ll16o2l 3:aa82968b7a8e 147
ll16o2l 15:807eba7c7811 148 // Objects
ll16o2l 2:888634fff8ff 149 Player _player;
ll16o2l 15:807eba7c7811 150 Objects _objects1;
ll16o2l 15:807eba7c7811 151 Objects _objects2;
ll16o2l 15:807eba7c7811 152 Objects _objects3;
ll16o2l 15:807eba7c7811 153 Objects _objects4;
ll16o2l 15:807eba7c7811 154 Health_Kit _health_kit;
ll16o2l 15:807eba7c7811 155
ll16o2l 15:807eba7c7811 156
ll16o2l 15:807eba7c7811 157 // Vairables
ll16o2l 2:888634fff8ff 158 int _player_width;
ll16o2l 2:888634fff8ff 159 int _player_height;
ll16o2l 2:888634fff8ff 160 int _objects_size;
ll16o2l 2:888634fff8ff 161 int _speed;
ll16o2l 2:888634fff8ff 162 int lose;
ll16o2l 3:aa82968b7a8e 163 int _lives;
ll16o2l 3:aa82968b7a8e 164 int l; //counter for loop
ll16o2l 3:aa82968b7a8e 165 int n; //counter for loop
ll16o2l 3:aa82968b7a8e 166 int m; //counter for loop
ll16o2l 2:888634fff8ff 167
ll16o2l 3:aa82968b7a8e 168 float _time;
ll16o2l 15:807eba7c7811 169
ll16o2l 2:888634fff8ff 170 Direction _d;
ll16o2l 2:888634fff8ff 171 float _mag;
ll16o2l 3:aa82968b7a8e 172
ll16o2l 3:aa82968b7a8e 173 int _kit_size;
ll16o2l 3:aa82968b7a8e 174 bool collect;
ll16o2l 3:aa82968b7a8e 175 bool used;
ll16o2l 2:888634fff8ff 176 };
ll16o2l 2:888634fff8ff 177
ll16o2l 2:888634fff8ff 178 #endif