ELEC2645 (2018/19) / Mbed 2 deprecated ll16o2l_ELEC2645

Dependencies:   mbed Gamepad

Committer:
ll16o2l
Date:
Tue May 07 18:01:54 2019 +0000
Revision:
15:807eba7c7811
Parent:
8:c3153fd4d8ce
Child:
16:f1b5ea92facd
Re-organised the documentation and finished the project.

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 3:aa82968b7a8e 59 void time(float time);
ll16o2l 15:807eba7c7811 60 */
ll16o2l 2:888634fff8ff 61 int get_lose();
ll16o2l 2:888634fff8ff 62
ll16o2l 2:888634fff8ff 63 private:
ll16o2l 2:888634fff8ff 64
ll16o2l 15:807eba7c7811 65 // Methods
ll16o2l 15:807eba7c7811 66
ll16o2l 15:807eba7c7811 67 /**
ll16o2l 15:807eba7c7811 68 This method will be used to check for object 1 collisions to the wall
ll16o2l 15:807eba7c7811 69 and reposition the objects as to bounce off the walls.
ll16o2l 15:807eba7c7811 70 */
ll16o2l 3:aa82968b7a8e 71 void check_wall_collision1(Gamepad &pad);
ll16o2l 15:807eba7c7811 72
ll16o2l 15:807eba7c7811 73 /**
ll16o2l 15:807eba7c7811 74 This method will be used to check for object 2 collisions to the wall
ll16o2l 15:807eba7c7811 75 and reposition the objects as to bounce off the walls.
ll16o2l 15:807eba7c7811 76 */
ll16o2l 3:aa82968b7a8e 77 void check_wall_collision2(Gamepad &pad);
ll16o2l 15:807eba7c7811 78
ll16o2l 15:807eba7c7811 79 /**
ll16o2l 15:807eba7c7811 80 This method will be used to check for object 3 collisions to the wall
ll16o2l 15:807eba7c7811 81 and reposition the objects as to bounce off the walls.
ll16o2l 15:807eba7c7811 82 */
ll16o2l 3:aa82968b7a8e 83 void check_wall_collision3(Gamepad &pad);
ll16o2l 15:807eba7c7811 84
ll16o2l 15:807eba7c7811 85 /**
ll16o2l 15:807eba7c7811 86 This method will be used to check for object 4 collisions to the wall
ll16o2l 15:807eba7c7811 87 and reposition the objects as to bounce off the walls.
ll16o2l 15:807eba7c7811 88 */
ll16o2l 3:aa82968b7a8e 89 void check_wall_collision4(Gamepad &pad);
ll16o2l 15:807eba7c7811 90
ll16o2l 15:807eba7c7811 91 /**
ll16o2l 15:807eba7c7811 92 This method will be used to check for player collisions with object 1
ll16o2l 15:807eba7c7811 93 and calls on the player_hit method if condition is met.
ll16o2l 15:807eba7c7811 94 */
ll16o2l 3:aa82968b7a8e 95 void check_player_collisions1(Gamepad &pad);
ll16o2l 15:807eba7c7811 96
ll16o2l 15:807eba7c7811 97 /**
ll16o2l 15:807eba7c7811 98 This method will be used to check for player collisions with object 2
ll16o2l 15:807eba7c7811 99 and calls on the player_hit method if condition is met.
ll16o2l 15:807eba7c7811 100 */
ll16o2l 3:aa82968b7a8e 101 void check_player_collisions2(Gamepad &pad);
ll16o2l 15:807eba7c7811 102
ll16o2l 15:807eba7c7811 103 /**
ll16o2l 15:807eba7c7811 104 This method will be used to check for player collisions with object 3
ll16o2l 15:807eba7c7811 105 and calls on the player_hit method if condition is met.
ll16o2l 15:807eba7c7811 106 */
ll16o2l 3:aa82968b7a8e 107 void check_player_collisions3(Gamepad &pad);
ll16o2l 15:807eba7c7811 108
ll16o2l 15:807eba7c7811 109 /**
ll16o2l 15:807eba7c7811 110 This method will be used to check for player collisions with object 4
ll16o2l 15:807eba7c7811 111 and calls on the player_hit method if condition is met.
ll16o2l 15:807eba7c7811 112 */
ll16o2l 3:aa82968b7a8e 113 void check_player_collisions4(Gamepad &pad);
ll16o2l 15:807eba7c7811 114
ll16o2l 15:807eba7c7811 115 /**
ll16o2l 15:807eba7c7811 116 This method will be used to check for player collisions with health kit
ll16o2l 15:807eba7c7811 117 and sets collect to true.
ll16o2l 15:807eba7c7811 118 */
ll16o2l 3:aa82968b7a8e 119 void check_player_health_kit_collison(Gamepad &pad);
ll16o2l 15:807eba7c7811 120
ll16o2l 15:807eba7c7811 121 /**
ll16o2l 15:807eba7c7811 122 This method is used to increase the lives variable value by 1 if
ll16o2l 15:807eba7c7811 123 the conditions are met and with user input.
ll16o2l 15:807eba7c7811 124 */
ll16o2l 3:aa82968b7a8e 125 void life_up(Gamepad &pad);
ll16o2l 15:807eba7c7811 126
ll16o2l 15:807eba7c7811 127 /**
ll16o2l 15:807eba7c7811 128 This method will be used to display the players lives using
ll16o2l 15:807eba7c7811 129 the LEDs.
ll16o2l 15:807eba7c7811 130 */
ll16o2l 3:aa82968b7a8e 131 void life_leds(Gamepad &pad);
ll16o2l 2:888634fff8ff 132
ll16o2l 15:807eba7c7811 133 /**
ll16o2l 15:807eba7c7811 134 This method is used to reduce a life if the condition is met.
ll16o2l 15:807eba7c7811 135 */
ll16o2l 3:aa82968b7a8e 136 void player_hit(Gamepad &pad);
ll16o2l 15:807eba7c7811 137
ll16o2l 15:807eba7c7811 138 /**
ll16o2l 15:807eba7c7811 139 This method will be used to print the lives and time to LCD
ll16o2l 15:807eba7c7811 140 */
ll16o2l 3:aa82968b7a8e 141 void print_lives_time(N5110 &lcd);
ll16o2l 3:aa82968b7a8e 142
ll16o2l 15:807eba7c7811 143 // Objects
ll16o2l 2:888634fff8ff 144 Player _player;
ll16o2l 15:807eba7c7811 145 Objects _objects1;
ll16o2l 15:807eba7c7811 146 Objects _objects2;
ll16o2l 15:807eba7c7811 147 Objects _objects3;
ll16o2l 15:807eba7c7811 148 Objects _objects4;
ll16o2l 15:807eba7c7811 149 Health_Kit _health_kit;
ll16o2l 15:807eba7c7811 150
ll16o2l 15:807eba7c7811 151
ll16o2l 15:807eba7c7811 152 // Vairables
ll16o2l 2:888634fff8ff 153 int _player_width;
ll16o2l 2:888634fff8ff 154 int _player_height;
ll16o2l 2:888634fff8ff 155 int _objects_size;
ll16o2l 2:888634fff8ff 156 int _speed;
ll16o2l 2:888634fff8ff 157 int lose;
ll16o2l 3:aa82968b7a8e 158 int _lives;
ll16o2l 3:aa82968b7a8e 159 int l; //counter for loop
ll16o2l 3:aa82968b7a8e 160 int n; //counter for loop
ll16o2l 3:aa82968b7a8e 161 int m; //counter for loop
ll16o2l 2:888634fff8ff 162
ll16o2l 3:aa82968b7a8e 163 float _time;
ll16o2l 15:807eba7c7811 164
ll16o2l 2:888634fff8ff 165 Direction _d;
ll16o2l 2:888634fff8ff 166 float _mag;
ll16o2l 3:aa82968b7a8e 167
ll16o2l 3:aa82968b7a8e 168 int _kit_size;
ll16o2l 3:aa82968b7a8e 169 bool collect;
ll16o2l 3:aa82968b7a8e 170 bool used;
ll16o2l 2:888634fff8ff 171 };
ll16o2l 2:888634fff8ff 172
ll16o2l 2:888634fff8ff 173 #endif