Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed Gamepad N5110 mbed-rtos
GameEngine/GameEngine.cpp@5:016a7315b75d, 2019-05-06 (annotated)
- Committer:
- RexRoshan
- Date:
- Mon May 06 18:29:49 2019 +0000
- Revision:
- 5:016a7315b75d
- Parent:
- 4:4d673fb2d9dc
- Child:
- 6:1fcfd331c047
Commented almost every class
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| RexRoshan | 0:99fa5a619081 | 1 | #include "GameEngine.h" |
| RexRoshan | 0:99fa5a619081 | 2 | |
| RexRoshan | 0:99fa5a619081 | 3 | GameEngine::GameEngine() |
| RexRoshan | 0:99fa5a619081 | 4 | { |
| RexRoshan | 0:99fa5a619081 | 5 | |
| RexRoshan | 0:99fa5a619081 | 6 | } |
| RexRoshan | 0:99fa5a619081 | 7 | |
| RexRoshan | 0:99fa5a619081 | 8 | GameEngine::~GameEngine() |
| RexRoshan | 0:99fa5a619081 | 9 | { |
| RexRoshan | 0:99fa5a619081 | 10 | |
| RexRoshan | 0:99fa5a619081 | 11 | } |
| RexRoshan | 5:016a7315b75d | 12 | |
| RexRoshan | 5:016a7315b75d | 13 | // draws the background of the game |
| RexRoshan | 0:99fa5a619081 | 14 | int backgrounds [48][84] = { |
| RexRoshan | 0:99fa5a619081 | 15 | |
| RexRoshan | 0:99fa5a619081 | 16 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
| RexRoshan | 0:99fa5a619081 | 17 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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7315b75d | 66 | |
| RexRoshan | 5:016a7315b75d | 67 | // draws alphabet r in morse code |
| RexRoshan | 0:99fa5a619081 | 68 | int r [3][13] = { |
| RexRoshan | 0:99fa5a619081 | 69 | |
| RexRoshan | 0:99fa5a619081 | 70 | {0,1,0,0,0,0,0,0,0,0,0,1,0}, |
| RexRoshan | 0:99fa5a619081 | 71 | {1,1,1,0,0,0,0,0,0,0,1,1,1}, |
| RexRoshan | 0:99fa5a619081 | 72 | {0,1,0,0,1,1,1,1,1,0,0,1,0}, |
| RexRoshan | 0:99fa5a619081 | 73 | |
| RexRoshan | 0:99fa5a619081 | 74 | }; |
| RexRoshan | 0:99fa5a619081 | 75 | |
| RexRoshan | 5:016a7315b75d | 76 | // draws alphabet e in morse code |
| RexRoshan | 0:99fa5a619081 | 77 | int e [3][3] = { |
| RexRoshan | 0:99fa5a619081 | 78 | |
| RexRoshan | 0:99fa5a619081 | 79 | {0,1,0}, |
| RexRoshan | 0:99fa5a619081 | 80 | {1,1,1}, |
| RexRoshan | 0:99fa5a619081 | 81 | {0,1,0}, |
| RexRoshan | 0:99fa5a619081 | 82 | |
| RexRoshan | 0:99fa5a619081 | 83 | }; |
| RexRoshan | 0:99fa5a619081 | 84 | |
| RexRoshan | 5:016a7315b75d | 85 | // draws alphabet x in morse code |
| RexRoshan | 0:99fa5a619081 | 86 | int x [3][19] = { |
| RexRoshan | 0:99fa5a619081 | 87 | |
| RexRoshan | 0:99fa5a619081 | 88 | {0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0}, |
| RexRoshan | 0:99fa5a619081 | 89 | {0,0,0,0,0,0,1,1,1,0,1,1,1,0,0,0,0,0,0}, |
| RexRoshan | 0:99fa5a619081 | 90 | {1,1,1,1,1,0,0,1,0,0,0,1,0,0,1,1,1,1,1}, |
| RexRoshan | 0:99fa5a619081 | 91 | |
| RexRoshan | 0:99fa5a619081 | 92 | }; |
| RexRoshan | 0:99fa5a619081 | 93 | |
| RexRoshan | 5:016a7315b75d | 94 | // draws explosion |
| RexRoshan | 0:99fa5a619081 | 95 | int explosion [23] [23] = { |
| RexRoshan | 0:99fa5a619081 | 96 | |
| RexRoshan | 0:99fa5a619081 | 97 | {0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0}, |
| RexRoshan | 0:99fa5a619081 | 98 | {0,0,0,0,0,0,1,1,1,1,0,0,1,1,1,1,1,0,0,0,0,0,0}, |
| RexRoshan | 0:99fa5a619081 | 99 | {0,0,0,0,0,1,1,1,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0}, |
| RexRoshan | 0:99fa5a619081 | 100 | {0,0,0,0,1,1,1,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0}, |
| RexRoshan | 0:99fa5a619081 | 101 | {0,0,0,1,1,1,0,0,0,0,0,1,0,0,0,0,1,0,0,1,0,0,0}, |
| RexRoshan | 0:99fa5a619081 | 102 | {0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0}, |
| RexRoshan | 0:99fa5a619081 | 103 | {0,1,1,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,1,1,1,0}, |
| RexRoshan | 0:99fa5a619081 | 104 | {0,1,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,1,1,0}, |
| RexRoshan | 0:99fa5a619081 | 105 | {0,1,1,0,0,0,0,1,1,1,0,0,0,0,1,0,0,0,0,0,1,0,0}, |
| RexRoshan | 0:99fa5a619081 | 106 | {0,1,1,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,1,1,0}, |
| RexRoshan | 0:99fa5a619081 | 107 | {0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, |
| RexRoshan | 0:99fa5a619081 | 108 | {0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,1}, |
| RexRoshan | 0:99fa5a619081 | 109 | {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,1}, |
| RexRoshan | 0:99fa5a619081 | 110 | {0,1,1,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0}, |
| RexRoshan | 0:99fa5a619081 | 111 | {0,1,1,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0}, |
| RexRoshan | 0:99fa5a619081 | 112 | {0,0,1,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,1,0,0}, |
| RexRoshan | 0:99fa5a619081 | 113 | {0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0}, |
| RexRoshan | 0:99fa5a619081 | 114 | {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0}, |
| RexRoshan | 0:99fa5a619081 | 115 | {0,1,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,1,1,1,1,0,0}, |
| RexRoshan | 0:99fa5a619081 | 116 | {0,0,1,1,1,1,0,0,0,1,1,1,0,0,0,0,1,1,1,1,0,0,0}, |
| RexRoshan | 0:99fa5a619081 | 117 | {0,0,0,1,1,1,0,0,1,1,0,1,1,0,0,0,1,1,0,0,0,0,0}, |
| RexRoshan | 0:99fa5a619081 | 118 | {0,0,0,0,0,0,1,1,1,0,0,0,0,0,1,1,0,0,0,0,0,0,0}, |
| RexRoshan | 0:99fa5a619081 | 119 | {0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0}, |
| RexRoshan | 0:99fa5a619081 | 120 | |
| RexRoshan | 0:99fa5a619081 | 121 | }; |
| RexRoshan | 0:99fa5a619081 | 122 | |
| RexRoshan | 1:45493d1d0689 | 123 | void GameEngine::init(int spacecraft_xpos,int spacecraft_ypos,int enemy_xpos, int enemy_ypos,int enemy2_xpos, int enemy2_ypos,int enemy3_xpos, int enemy3_ypos,int beam_size,int beam2_size, int speed) |
| RexRoshan | 0:99fa5a619081 | 124 | { |
| RexRoshan | 2:b5c1bb7a39de | 125 | // initialise the game parameters |
| RexRoshan | 2:b5c1bb7a39de | 126 | _spacecraft_xpos = spacecraft_xpos; |
| RexRoshan | 2:b5c1bb7a39de | 127 | _spacecraft_ypos = spacecraft_ypos; |
| RexRoshan | 0:99fa5a619081 | 128 | |
| RexRoshan | 2:b5c1bb7a39de | 129 | _enemy_xpos = enemy_xpos; |
| RexRoshan | 2:b5c1bb7a39de | 130 | _enemy_ypos = enemy_ypos; |
| RexRoshan | 0:99fa5a619081 | 131 | |
| RexRoshan | 2:b5c1bb7a39de | 132 | _enemy2_xpos = enemy2_xpos; |
| RexRoshan | 2:b5c1bb7a39de | 133 | _enemy2_ypos = enemy2_ypos; |
| RexRoshan | 1:45493d1d0689 | 134 | |
| RexRoshan | 2:b5c1bb7a39de | 135 | _enemy3_xpos = enemy3_xpos; |
| RexRoshan | 2:b5c1bb7a39de | 136 | _enemy3_ypos = enemy3_ypos; |
| RexRoshan | 0:99fa5a619081 | 137 | |
| RexRoshan | 0:99fa5a619081 | 138 | |
| RexRoshan | 2:b5c1bb7a39de | 139 | _beam_size = beam_size; // beam size for 1st and 3rd enemy |
| RexRoshan | 2:b5c1bb7a39de | 140 | _beam2_size = beam2_size; // beam size for 2nd enemy |
| RexRoshan | 2:b5c1bb7a39de | 141 | _speed = speed; // Speed of the enemy travelling |
| RexRoshan | 0:99fa5a619081 | 142 | |
| RexRoshan | 0:99fa5a619081 | 143 | |
| RexRoshan | 2:b5c1bb7a39de | 144 | _p1x = GAP; |
| RexRoshan | 0:99fa5a619081 | 145 | // x position on screen - WIDTH is defined in N5110.h |
| RexRoshan | 2:b5c1bb7a39de | 146 | _e1a = WIDTH-_enemy_xpos; //enemy_xpos = 12 |
| RexRoshan | 2:b5c1bb7a39de | 147 | // y position on screen - HEIGHT is defined in N5110.h |
| RexRoshan | 2:b5c1bb7a39de | 148 | _e1b = HEIGHT/2-_enemy_ypos; //enemy_ypos = 4 |
| RexRoshan | 0:99fa5a619081 | 149 | |
| RexRoshan | 2:b5c1bb7a39de | 150 | _e2a = WIDTH-_enemy2_xpos; //enemy2_xpos = 12 |
| RexRoshan | 2:b5c1bb7a39de | 151 | _e21b = HEIGHT/2 +_enemy2_ypos; //enemy2_ypos = 10 |
| RexRoshan | 2:b5c1bb7a39de | 152 | _e22b = HEIGHT/2 -_enemy2_ypos; |
| RexRoshan | 1:45493d1d0689 | 153 | |
| RexRoshan | 2:b5c1bb7a39de | 154 | _e3a = WIDTH-_enemy3_xpos; //enemy3_xpos = 20 |
| RexRoshan | 2:b5c1bb7a39de | 155 | _e3b = HEIGHT/2 -_enemy3_ypos; //enemy3_ypos = 7 |
| RexRoshan | 1:45493d1d0689 | 156 | _e3c = WIDTH-_enemy3_xpos - 12; |
| RexRoshan | 1:45493d1d0689 | 157 | _e3d = HEIGHT/2 + _enemy3_ypos;; |
| RexRoshan | 1:45493d1d0689 | 158 | _e3f = HEIGHT/2 - _enemy3_ypos;; |
| RexRoshan | 1:45493d1d0689 | 159 | |
| RexRoshan | 2:b5c1bb7a39de | 160 | // Initialising the player's spacecraft and all enemy spacecrafts |
| RexRoshan | 2:b5c1bb7a39de | 161 | _p1.init(_spacecraft_xpos,_spacecraft_ypos); |
| RexRoshan | 2:b5c1bb7a39de | 162 | _e1.init(_e1a,_e1b); |
| RexRoshan | 2:b5c1bb7a39de | 163 | _e21.init(_e2a,_e21b,_speed); |
| RexRoshan | 2:b5c1bb7a39de | 164 | _e22.init(_e2a,_e22b,_speed); |
| RexRoshan | 2:b5c1bb7a39de | 165 | _e3.init(_e3a,_e3b,_e3c,_e3d,_e3c,_e3f,_speed); |
| RexRoshan | 2:b5c1bb7a39de | 166 | // Initialising the stage of the game |
| RexRoshan | 2:b5c1bb7a39de | 167 | _stage = 0; |
| RexRoshan | 0:99fa5a619081 | 168 | |
| RexRoshan | 0:99fa5a619081 | 169 | } |
| RexRoshan | 0:99fa5a619081 | 170 | |
| RexRoshan | 0:99fa5a619081 | 171 | void GameEngine::read_input(Gamepad &pad) |
| RexRoshan | 0:99fa5a619081 | 172 | { |
| RexRoshan | 2:b5c1bb7a39de | 173 | _d = pad.get_direction(); // Get the direction of the joystick |
| RexRoshan | 2:b5c1bb7a39de | 174 | _mag = pad.get_mag(); // Get the magnitude value |
| RexRoshan | 2:b5c1bb7a39de | 175 | _R = pad.check_event(Gamepad::R_PRESSED); // Check if the R button is being pressed |
| RexRoshan | 3:bf9624e5b0c3 | 176 | _L = pad.check_event(Gamepad::L_PRESSED); // Check if the L button is being pressed |
| RexRoshan | 0:99fa5a619081 | 177 | |
| RexRoshan | 0:99fa5a619081 | 178 | } |
| RexRoshan | 0:99fa5a619081 | 179 | |
| RexRoshan | 2:b5c1bb7a39de | 180 | void GameEngine::draw_mission_one(Gamepad &pad,N5110 &lcd) |
| RexRoshan | 0:99fa5a619081 | 181 | { |
| RexRoshan | 0:99fa5a619081 | 182 | // draw the background of the game |
| RexRoshan | 0:99fa5a619081 | 183 | lcd.drawSprite(0,0,48,84,(int *)backgrounds); |
| RexRoshan | 2:b5c1bb7a39de | 184 | // draw the easter egg of the game |
| RexRoshan | 0:99fa5a619081 | 185 | lcd.drawSprite(6,4,3,13,(int *)r); |
| RexRoshan | 0:99fa5a619081 | 186 | //health |
| RexRoshan | 0:99fa5a619081 | 187 | draw_enemy_health(lcd); |
| RexRoshan | 0:99fa5a619081 | 188 | draw_spacecraft_health(pad); |
| RexRoshan | 2:b5c1bb7a39de | 189 | // player spacecraft |
| RexRoshan | 0:99fa5a619081 | 190 | _p1.character(lcd); |
| RexRoshan | 2:b5c1bb7a39de | 191 | // first enemy |
| RexRoshan | 0:99fa5a619081 | 192 | _e1.enemy(lcd); |
| RexRoshan | 2:b5c1bb7a39de | 193 | // player spacecraft beam |
| RexRoshan | 0:99fa5a619081 | 194 | _beam.draw(lcd); |
| RexRoshan | 2:b5c1bb7a39de | 195 | // enemy spacecraft beam |
| RexRoshan | 0:99fa5a619081 | 196 | _enemybeam.draw(lcd); |
| RexRoshan | 0:99fa5a619081 | 197 | |
| RexRoshan | 0:99fa5a619081 | 198 | } |
| RexRoshan | 2:b5c1bb7a39de | 199 | void GameEngine::draw_mission_two(Gamepad &pad,N5110 &lcd) |
| RexRoshan | 0:99fa5a619081 | 200 | { |
| RexRoshan | 2:b5c1bb7a39de | 201 | // draw the background of the game |
| RexRoshan | 0:99fa5a619081 | 202 | lcd.drawSprite(0,0,48,84,(int *)backgrounds); |
| RexRoshan | 2:b5c1bb7a39de | 203 | // draw the easter egg of the game |
| RexRoshan | 0:99fa5a619081 | 204 | lcd.drawSprite(6,4,3,3,(int *)e); |
| RexRoshan | 2:b5c1bb7a39de | 205 | //health |
| RexRoshan | 0:99fa5a619081 | 206 | draw_spacecraft_health(pad); |
| RexRoshan | 0:99fa5a619081 | 207 | draw_enemy21_health(lcd); |
| RexRoshan | 0:99fa5a619081 | 208 | draw_enemy22_health(lcd); |
| RexRoshan | 2:b5c1bb7a39de | 209 | // player spacecraft |
| RexRoshan | 0:99fa5a619081 | 210 | _p1.character(lcd); |
| RexRoshan | 2:b5c1bb7a39de | 211 | // second enemy |
| RexRoshan | 0:99fa5a619081 | 212 | _e21.enemy2(lcd); |
| RexRoshan | 0:99fa5a619081 | 213 | _e22.enemy2(lcd); |
| RexRoshan | 2:b5c1bb7a39de | 214 | // player spacecraft beam |
| RexRoshan | 0:99fa5a619081 | 215 | _beam.draw(lcd); |
| RexRoshan | 2:b5c1bb7a39de | 216 | // second enemy spacecraft beam |
| RexRoshan | 0:99fa5a619081 | 217 | _enemybeam2.draw(lcd); |
| RexRoshan | 0:99fa5a619081 | 218 | |
| RexRoshan | 0:99fa5a619081 | 219 | } |
| RexRoshan | 0:99fa5a619081 | 220 | |
| RexRoshan | 2:b5c1bb7a39de | 221 | void GameEngine::draw_mission_three(Gamepad &pad,N5110 &lcd) |
| RexRoshan | 1:45493d1d0689 | 222 | { |
| RexRoshan | 2:b5c1bb7a39de | 223 | // draw the background of the game |
| RexRoshan | 1:45493d1d0689 | 224 | lcd.drawSprite(0,0,48,84,(int *)backgrounds); |
| RexRoshan | 2:b5c1bb7a39de | 225 | // draw the easter egg of the game |
| RexRoshan | 2:b5c1bb7a39de | 226 | lcd.drawSprite(6,4,3,19,(int *)x); |
| RexRoshan | 2:b5c1bb7a39de | 227 | //health |
| RexRoshan | 1:45493d1d0689 | 228 | draw_spacecraft_health(pad); |
| RexRoshan | 1:45493d1d0689 | 229 | draw_enemyboss_health(lcd); |
| RexRoshan | 2:b5c1bb7a39de | 230 | // player spacecraft |
| RexRoshan | 1:45493d1d0689 | 231 | _p1.character(lcd); |
| RexRoshan | 2:b5c1bb7a39de | 232 | // third and final enemy |
| RexRoshan | 1:45493d1d0689 | 233 | _e3.enemyboss(lcd); |
| RexRoshan | 2:b5c1bb7a39de | 234 | // player spacecraft beam |
| RexRoshan | 1:45493d1d0689 | 235 | _beam.draw(lcd); |
| RexRoshan | 2:b5c1bb7a39de | 236 | // third enemy spacecraft beam |
| RexRoshan | 1:45493d1d0689 | 237 | _enemybeam3.draw(lcd); |
| RexRoshan | 1:45493d1d0689 | 238 | |
| RexRoshan | 1:45493d1d0689 | 239 | } |
| RexRoshan | 1:45493d1d0689 | 240 | |
| RexRoshan | 2:b5c1bb7a39de | 241 | void GameEngine::update_mission_one(Gamepad &pad,N5110 &lcd) |
| RexRoshan | 0:99fa5a619081 | 242 | { |
| RexRoshan | 2:b5c1bb7a39de | 243 | check_playerbeam_collision(pad); // Check if L/R is being pressed to initiate the player beam |
| RexRoshan | 2:b5c1bb7a39de | 244 | check_enemybeam_collisions(pad); // Check if first enemy's beam has passed the wall to initiate a new beam |
| RexRoshan | 2:b5c1bb7a39de | 245 | // updating spacecraft and enemy before checking collisions so that |
| RexRoshan | 2:b5c1bb7a39de | 246 | // it displays the right value |
| RexRoshan | 2:b5c1bb7a39de | 247 | _p1.update(_d,_mag); // Player spacecraft movement update |
| RexRoshan | 2:b5c1bb7a39de | 248 | _beam.update(); // Player spacecraft's beam update |
| RexRoshan | 2:b5c1bb7a39de | 249 | |
| RexRoshan | 2:b5c1bb7a39de | 250 | // The enemy spacecraft is stationery in mission one |
| RexRoshan | 2:b5c1bb7a39de | 251 | _enemybeam.update(); // Enemy spacecraft's beam update |
| RexRoshan | 2:b5c1bb7a39de | 252 | |
| RexRoshan | 2:b5c1bb7a39de | 253 | check_enemy_collisions(pad); // Check if the player spacecraft beam collides with the enemy spacecraft |
| RexRoshan | 2:b5c1bb7a39de | 254 | check_spacecraft_collisions(pad); // Check if the enemy spacecraft beam collides with the player spacecraft |
| RexRoshan | 2:b5c1bb7a39de | 255 | |
| RexRoshan | 2:b5c1bb7a39de | 256 | // Animations and sound effect for the both the player's and enemy' spacecraft when they are dead |
| RexRoshan | 0:99fa5a619081 | 257 | spacecraft_dead(lcd,pad); |
| RexRoshan | 0:99fa5a619081 | 258 | enemy_dead(lcd,pad); |
| RexRoshan | 2:b5c1bb7a39de | 259 | |
| RexRoshan | 0:99fa5a619081 | 260 | } |
| RexRoshan | 0:99fa5a619081 | 261 | |
| RexRoshan | 2:b5c1bb7a39de | 262 | void GameEngine::update_mission_two(Gamepad &pad,N5110 &lcd) |
| RexRoshan | 0:99fa5a619081 | 263 | { |
| RexRoshan | 2:b5c1bb7a39de | 264 | check_playerbeam_collision(pad); // Check if L/R is being pressed to initiate the player beam |
| RexRoshan | 2:b5c1bb7a39de | 265 | check_enemybeam2_collisions(pad); // Check if first enemy's beam has passed the wall to initiate a new beam |
| RexRoshan | 2:b5c1bb7a39de | 266 | // updating spacecraft and enemy before checking collisions so that |
| RexRoshan | 2:b5c1bb7a39de | 267 | // it displays the right value |
| RexRoshan | 2:b5c1bb7a39de | 268 | _p1.update(_d,_mag); // Player spacecraft movement update |
| RexRoshan | 2:b5c1bb7a39de | 269 | _beam.update(); // Player spacecraft's beam update |
| RexRoshan | 2:b5c1bb7a39de | 270 | |
| RexRoshan | 2:b5c1bb7a39de | 271 | _enemybeam2.update(); // Enemy spacecraft's beam update |
| RexRoshan | 2:b5c1bb7a39de | 272 | _e21.update(); // Second-one enemy spacecraft movement update |
| RexRoshan | 2:b5c1bb7a39de | 273 | _e22.update(); // Second-two enemy spacecraft movement update |
| RexRoshan | 2:b5c1bb7a39de | 274 | |
| RexRoshan | 2:b5c1bb7a39de | 275 | check_enemy2_collisions(pad); // Check if the player spacecraft beam collides with the enemy spacecraft |
| RexRoshan | 2:b5c1bb7a39de | 276 | check_spacecraft2_collisions(pad); // Check if the enemy spacecraft beam collides with the player spacecraft |
| RexRoshan | 2:b5c1bb7a39de | 277 | check_wall_collisions(pad); // Check if enemy spacecraft hits the top and bottom wall to bounce off |
| RexRoshan | 2:b5c1bb7a39de | 278 | |
| RexRoshan | 2:b5c1bb7a39de | 279 | // Animations and sound effect for the both the player's and enemy' spacecraft when they are dead |
| RexRoshan | 0:99fa5a619081 | 280 | spacecraft2_dead(lcd,pad); |
| RexRoshan | 0:99fa5a619081 | 281 | enemy2_dead(lcd,pad); |
| RexRoshan | 0:99fa5a619081 | 282 | |
| RexRoshan | 0:99fa5a619081 | 283 | } |
| RexRoshan | 0:99fa5a619081 | 284 | |
| RexRoshan | 2:b5c1bb7a39de | 285 | void GameEngine::update_mission_three(Gamepad &pad,N5110 &lcd) |
| RexRoshan | 1:45493d1d0689 | 286 | { |
| RexRoshan | 2:b5c1bb7a39de | 287 | check_playerbeam_collision(pad); |
| RexRoshan | 1:45493d1d0689 | 288 | check_enemybeam3_collisions(pad); |
| RexRoshan | 2:b5c1bb7a39de | 289 | |
| RexRoshan | 2:b5c1bb7a39de | 290 | _p1.update(_d,_mag); // Player spacecraft movement update |
| RexRoshan | 2:b5c1bb7a39de | 291 | _beam.update(); // Player spacecraft beam update |
| RexRoshan | 2:b5c1bb7a39de | 292 | _enemybeam3.update(); // Third enemy's spacecraft's beam update |
| RexRoshan | 2:b5c1bb7a39de | 293 | _e3.update(); // Third enemy spacecraft movement update |
| RexRoshan | 2:b5c1bb7a39de | 294 | check_enemy3_collisions(pad); // Check if the player spacecraft beam collides with the third enemy spacecraft |
| RexRoshan | 2:b5c1bb7a39de | 295 | check_spacecraft3_collisions(pad); // Check if the third enemy spacecraft beam collides with the player spacecraft |
| RexRoshan | 2:b5c1bb7a39de | 296 | check_wall2_collisions(pad); // Check if enemy spacecraft hits the top,bottom, wall to bounce off |
| RexRoshan | 2:b5c1bb7a39de | 297 | // Animations and sound effect for the both the player's and enemy' spacecraft |
| RexRoshan | 1:45493d1d0689 | 298 | spacecraft3_dead(lcd,pad); |
| RexRoshan | 1:45493d1d0689 | 299 | enemy3_dead(lcd,pad); |
| RexRoshan | 1:45493d1d0689 | 300 | |
| RexRoshan | 1:45493d1d0689 | 301 | } |
| RexRoshan | 0:99fa5a619081 | 302 | void GameEngine::check_enemy_collisions(Gamepad &pad) |
| RexRoshan | 0:99fa5a619081 | 303 | { |
| RexRoshan | 2:b5c1bb7a39de | 304 | // read current enemy spacecraft's and player spacecraft's beam attributes |
| RexRoshan | 0:99fa5a619081 | 305 | Vector2D beam_pos = _beam.get_pos(); |
| RexRoshan | 0:99fa5a619081 | 306 | Vector2D e1_pos = _e1.get_enemy_pos(); |
| RexRoshan | 0:99fa5a619081 | 307 | |
| RexRoshan | 2:b5c1bb7a39de | 308 | // see if player's spacecraft beam has hit the enemy's spacecraft by checking for overlaps |
| RexRoshan | 0:99fa5a619081 | 309 | if ( |
| RexRoshan | 0:99fa5a619081 | 310 | (beam_pos.y >= e1_pos.y) && //top |
| RexRoshan | 0:99fa5a619081 | 311 | (beam_pos.y <= e1_pos.y + 7) && //bottom |
| RexRoshan | 0:99fa5a619081 | 312 | (beam_pos.x + _beam_size >= _e1a) && //left |
| RexRoshan | 0:99fa5a619081 | 313 | (beam_pos.x + _beam_size <= _e1a + 8) //right |
| RexRoshan | 0:99fa5a619081 | 314 | ) { |
| RexRoshan | 2:b5c1bb7a39de | 315 | // add first enemy health |
| RexRoshan | 0:99fa5a619081 | 316 | _e1.add_health(); |
| RexRoshan | 1:45493d1d0689 | 317 | spacebeam = true; |
| RexRoshan | 2:b5c1bb7a39de | 318 | // audio feedback |
| RexRoshan | 0:99fa5a619081 | 319 | pad.tone(1000.0,0.1); |
| RexRoshan | 0:99fa5a619081 | 320 | } |
| RexRoshan | 0:99fa5a619081 | 321 | |
| RexRoshan | 0:99fa5a619081 | 322 | // write new attributes |
| RexRoshan | 0:99fa5a619081 | 323 | _beam.set_pos(beam_pos); |
| RexRoshan | 0:99fa5a619081 | 324 | } |
| RexRoshan | 0:99fa5a619081 | 325 | |
| RexRoshan | 0:99fa5a619081 | 326 | void GameEngine::check_enemy2_collisions(Gamepad &pad) |
| RexRoshan | 0:99fa5a619081 | 327 | { |
| RexRoshan | 2:b5c1bb7a39de | 328 | // read curent player spacecraft's beam attributes |
| RexRoshan | 0:99fa5a619081 | 329 | Vector2D beam_pos = _beam.get_pos(); |
| RexRoshan | 2:b5c1bb7a39de | 330 | // check e21 first |
| RexRoshan | 0:99fa5a619081 | 331 | Vector2D e21_pos = _e21.get_enemy21_pos(); |
| RexRoshan | 0:99fa5a619081 | 332 | |
| RexRoshan | 2:b5c1bb7a39de | 333 | // see if player's spacecraft beam has hit the enemy's spacecraft by checking for overlaps |
| RexRoshan | 0:99fa5a619081 | 334 | if ( |
| RexRoshan | 0:99fa5a619081 | 335 | (beam_pos.y >= e21_pos.y) && //top |
| RexRoshan | 0:99fa5a619081 | 336 | (beam_pos.y <= e21_pos.y + 7) && //bottom |
| RexRoshan | 0:99fa5a619081 | 337 | (beam_pos.x + _beam_size >= _e2a) && //left |
| RexRoshan | 0:99fa5a619081 | 338 | (beam_pos.x + _beam_size <= _e2a + 7) //right |
| RexRoshan | 0:99fa5a619081 | 339 | ) { |
| RexRoshan | 2:b5c1bb7a39de | 340 | // add health to first second level enemy |
| RexRoshan | 2:b5c1bb7a39de | 341 | _e21.add_health(); |
| RexRoshan | 2:b5c1bb7a39de | 342 | // set boolean spacebeam true |
| RexRoshan | 2:b5c1bb7a39de | 343 | spacebeam = true; |
| RexRoshan | 0:99fa5a619081 | 344 | // audio feedback |
| RexRoshan | 0:99fa5a619081 | 345 | pad.tone(1000.0,0.1); |
| RexRoshan | 0:99fa5a619081 | 346 | } |
| RexRoshan | 2:b5c1bb7a39de | 347 | // check e22 next |
| RexRoshan | 2:b5c1bb7a39de | 348 | Vector2D e22_pos = _e22.get_enemy22_pos(); |
| RexRoshan | 2:b5c1bb7a39de | 349 | |
| RexRoshan | 0:99fa5a619081 | 350 | if ( |
| RexRoshan | 0:99fa5a619081 | 351 | (beam_pos.y >= e22_pos.y) && //top |
| RexRoshan | 0:99fa5a619081 | 352 | (beam_pos.y <= e22_pos.y + 7) && //bottom |
| RexRoshan | 0:99fa5a619081 | 353 | (beam_pos.x + _beam_size >= _e2a) && //left |
| RexRoshan | 0:99fa5a619081 | 354 | (beam_pos.x + _beam_size <= _e2a + 7) //right |
| RexRoshan | 0:99fa5a619081 | 355 | ) { |
| RexRoshan | 2:b5c1bb7a39de | 356 | // add health to second, second level enemy |
| RexRoshan | 2:b5c1bb7a39de | 357 | _e22.add_health(); |
| RexRoshan | 2:b5c1bb7a39de | 358 | // set boolean spacebeam true |
| RexRoshan | 2:b5c1bb7a39de | 359 | spacebeam = true; |
| RexRoshan | 0:99fa5a619081 | 360 | // audio feedback |
| RexRoshan | 1:45493d1d0689 | 361 | pad.tone(1000.0,0.1); |
| RexRoshan | 1:45493d1d0689 | 362 | } |
| RexRoshan | 2:b5c1bb7a39de | 363 | |
| RexRoshan | 1:45493d1d0689 | 364 | // write new attributes |
| RexRoshan | 1:45493d1d0689 | 365 | _beam.set_pos(beam_pos); |
| RexRoshan | 1:45493d1d0689 | 366 | } |
| RexRoshan | 1:45493d1d0689 | 367 | |
| RexRoshan | 1:45493d1d0689 | 368 | void GameEngine::check_enemy3_collisions(Gamepad &pad) |
| RexRoshan | 1:45493d1d0689 | 369 | { |
| RexRoshan | 2:b5c1bb7a39de | 370 | // read curent player's spacecraft beam attributes |
| RexRoshan | 1:45493d1d0689 | 371 | Vector2D beam_pos = _beam.get_pos(); |
| RexRoshan | 1:45493d1d0689 | 372 | |
| RexRoshan | 2:b5c1bb7a39de | 373 | // check e3boss first |
| RexRoshan | 1:45493d1d0689 | 374 | Vector2D e3boss_pos = _e3.get_enemyboss_pos(); |
| RexRoshan | 1:45493d1d0689 | 375 | |
| RexRoshan | 2:b5c1bb7a39de | 376 | // see if player's spacecraft beam has hit the enemy's spacecraft by checking for overlaps |
| RexRoshan | 1:45493d1d0689 | 377 | if ( |
| RexRoshan | 1:45493d1d0689 | 378 | (beam_pos.y >= e3boss_pos.y) && //top |
| RexRoshan | 1:45493d1d0689 | 379 | (beam_pos.y <= e3boss_pos.y + 12) && //bottom |
| RexRoshan | 1:45493d1d0689 | 380 | (beam_pos.x + _beam_size >= _e3a) && //left |
| RexRoshan | 1:45493d1d0689 | 381 | (beam_pos.x + _beam_size <= _e3a + 12) //right |
| RexRoshan | 1:45493d1d0689 | 382 | ) { |
| RexRoshan | 2:b5c1bb7a39de | 383 | // add health to enemy boss |
| RexRoshan | 2:b5c1bb7a39de | 384 | _e3.add_health_boss(); |
| RexRoshan | 2:b5c1bb7a39de | 385 | // set boolean spacebeam true |
| RexRoshan | 2:b5c1bb7a39de | 386 | spacebeam = true; |
| RexRoshan | 1:45493d1d0689 | 387 | // audio feedback |
| RexRoshan | 1:45493d1d0689 | 388 | pad.tone(1000.0,0.1); |
| RexRoshan | 1:45493d1d0689 | 389 | } |
| RexRoshan | 2:b5c1bb7a39de | 390 | // check e3enemy1 next |
| RexRoshan | 2:b5c1bb7a39de | 391 | Vector2D e3enemy1_pos = _e3.get_enemy1_pos(); |
| RexRoshan | 2:b5c1bb7a39de | 392 | |
| RexRoshan | 1:45493d1d0689 | 393 | if ( |
| RexRoshan | 1:45493d1d0689 | 394 | (beam_pos.y >= e3enemy1_pos.y) && //top |
| RexRoshan | 1:45493d1d0689 | 395 | (beam_pos.y <= e3enemy1_pos.y + 6) && //bottom |
| RexRoshan | 1:45493d1d0689 | 396 | (beam_pos.x + _beam_size >= _e3c) && //left |
| RexRoshan | 1:45493d1d0689 | 397 | (beam_pos.x + _beam_size <= _e3c + 7) //right |
| RexRoshan | 1:45493d1d0689 | 398 | ) { |
| RexRoshan | 2:b5c1bb7a39de | 399 | // add health to first third level enemy |
| RexRoshan | 2:b5c1bb7a39de | 400 | _e3.add_health_enemy1(); |
| RexRoshan | 2:b5c1bb7a39de | 401 | // set boolean spacebeam true |
| RexRoshan | 2:b5c1bb7a39de | 402 | spacebeam = true; |
| RexRoshan | 1:45493d1d0689 | 403 | // audio feedback |
| RexRoshan | 1:45493d1d0689 | 404 | pad.tone(1000.0,0.1); |
| RexRoshan | 1:45493d1d0689 | 405 | } |
| RexRoshan | 2:b5c1bb7a39de | 406 | // check e3enemy2 next |
| RexRoshan | 2:b5c1bb7a39de | 407 | Vector2D e3enemy2_pos = _e3.get_enemy2_pos(); |
| RexRoshan | 2:b5c1bb7a39de | 408 | |
| RexRoshan | 1:45493d1d0689 | 409 | if ( |
| RexRoshan | 1:45493d1d0689 | 410 | (beam_pos.y >= e3enemy2_pos.y) && //top |
| RexRoshan | 1:45493d1d0689 | 411 | (beam_pos.y <= e3enemy2_pos.y + 6) && //bottom |
| RexRoshan | 1:45493d1d0689 | 412 | (beam_pos.x + _beam_size >= _e3c) && //left |
| RexRoshan | 1:45493d1d0689 | 413 | (beam_pos.x + _beam_size <= _e3c + 7) //right |
| RexRoshan | 1:45493d1d0689 | 414 | ) { |
| RexRoshan | 2:b5c1bb7a39de | 415 | // add health to second third level enemy |
| RexRoshan | 1:45493d1d0689 | 416 | _e3.add_health_enemy2(); |
| RexRoshan | 2:b5c1bb7a39de | 417 | // set boolean spacebeam true |
| RexRoshan | 1:45493d1d0689 | 418 | spacebeam = true; |
| RexRoshan | 2:b5c1bb7a39de | 419 | // audio feedback |
| RexRoshan | 0:99fa5a619081 | 420 | pad.tone(1000.0,0.1); |
| RexRoshan | 0:99fa5a619081 | 421 | } |
| RexRoshan | 0:99fa5a619081 | 422 | // write new attributes |
| RexRoshan | 0:99fa5a619081 | 423 | _beam.set_pos(beam_pos); |
| RexRoshan | 0:99fa5a619081 | 424 | } |
| RexRoshan | 0:99fa5a619081 | 425 | |
| RexRoshan | 5:016a7315b75d | 426 | void GameEngine::check_playerbeam_collision(Gamepad &pad) // check if player's spacecraft beam has collided with the edges of screen or enemy |
| RexRoshan | 0:99fa5a619081 | 427 | { |
| RexRoshan | 2:b5c1bb7a39de | 428 | Vector2D p1_pos = _p1.get_pos(); // Get player's spacecraft position |
| RexRoshan | 2:b5c1bb7a39de | 429 | Vector2D beam_pos = _beam.get_pos(); // Get player's spacecraft beam position |
| RexRoshan | 2:b5c1bb7a39de | 430 | |
| RexRoshan | 5:016a7315b75d | 431 | if((_R == true)|| (_L == true)){ |
| RexRoshan | 4:4d673fb2d9dc | 432 | _beam.init(_beam_size,p1_pos.x,p1_pos.y); //Initialise the beam |
| RexRoshan | 5:016a7315b75d | 433 | if ((beam_pos.x + _beam_size > WIDTH) || (spacebeam == true)){ // if hits the enemy or the wall |
| RexRoshan | 5:016a7315b75d | 434 | _R = false; // Then set the boolean _R and _L to false |
| RexRoshan | 2:b5c1bb7a39de | 435 | _L = false; |
| RexRoshan | 4:4d673fb2d9dc | 436 | } |
| RexRoshan | 0:99fa5a619081 | 437 | } |
| RexRoshan | 0:99fa5a619081 | 438 | } |
| RexRoshan | 0:99fa5a619081 | 439 | |
| RexRoshan | 5:016a7315b75d | 440 | void GameEngine::check_enemybeam_collisions(Gamepad &pad) // check if enemy beam has collided with the edges of screen or spacecraft in stage one |
| RexRoshan | 0:99fa5a619081 | 441 | { |
| RexRoshan | 4:4d673fb2d9dc | 442 | Vector2D enemybeam_pos = _enemybeam.get_pos(); // Get first enemy's beam position |
| RexRoshan | 4:4d673fb2d9dc | 443 | |
| RexRoshan | 5:016a7315b75d | 444 | if ((_ebeam == true)||(enemybeam_pos.x - _beam_size < 0)) { // if hits the speacecraft or the wall |
| RexRoshan | 5:016a7315b75d | 445 | _enemybeam.init(_beam_size,_e1a,_e1b); // Initialise the enemy beam in stage one |
| RexRoshan | 5:016a7315b75d | 446 | _ebeam = false; // Then set the boolean _ebeam to false |
| RexRoshan | 0:99fa5a619081 | 447 | } |
| RexRoshan | 0:99fa5a619081 | 448 | } |
| RexRoshan | 0:99fa5a619081 | 449 | |
| RexRoshan | 5:016a7315b75d | 450 | void GameEngine::check_enemybeam2_collisions(Gamepad &pad) // check if enemy beam has collided with the edges of screen or spacecraft in stage two |
| RexRoshan | 0:99fa5a619081 | 451 | { |
| RexRoshan | 5:016a7315b75d | 452 | Vector2D enemy21_pos = _e21.get_enemy21_pos(); // Get first enemy's position in stage two |
| RexRoshan | 5:016a7315b75d | 453 | Vector2D enemy22_pos = _e22.get_enemy22_pos(); // Get second enemy's position in stage two |
| RexRoshan | 5:016a7315b75d | 454 | Vector2D enemybeam21_pos = _enemybeam2.get_pos_21(); // Get first enemy's beam position in stage two |
| RexRoshan | 5:016a7315b75d | 455 | Vector2D enemybeam22_pos = _enemybeam2.get_pos_22(); // Get second enemy's beam position in stage two |
| RexRoshan | 5:016a7315b75d | 456 | |
| RexRoshan | 5:016a7315b75d | 457 | if ((_ebeam21 == true)||(_ebeam22 == true)||(enemybeam21_pos.x - _beam2_size < 0)||(enemybeam22_pos.x - _beam2_size < 0)) { // if hits the speacecraft or the wall |
| RexRoshan | 5:016a7315b75d | 458 | _enemybeam2.init(_beam2_size,enemy21_pos.x,enemy21_pos.y,enemy22_pos.x,enemy22_pos.y); // Initialise the enemy beam in stage two |
| RexRoshan | 5:016a7315b75d | 459 | _ebeam21 = false; // Then set the boolean _ebeam21 and _ebeam22 to false |
| RexRoshan | 0:99fa5a619081 | 460 | _ebeam22 = false; |
| RexRoshan | 0:99fa5a619081 | 461 | } |
| RexRoshan | 0:99fa5a619081 | 462 | } |
| RexRoshan | 0:99fa5a619081 | 463 | |
| RexRoshan | 5:016a7315b75d | 464 | void GameEngine::check_enemybeam3_collisions(Gamepad &pad) // check if enemy beam has collided with the edges of screen or spacecraft in stage three |
| RexRoshan | 1:45493d1d0689 | 465 | { |
| RexRoshan | 5:016a7315b75d | 466 | Vector2D enemyboss_pos = _e3.get_enemyboss_pos(); // Get boss enemy's position in stage three |
| RexRoshan | 5:016a7315b75d | 467 | Vector2D enemy1_pos = _e3.get_enemy1_pos(); // Get first regular enemy's position in stage three |
| RexRoshan | 5:016a7315b75d | 468 | Vector2D enemy2_pos = _e3.get_enemy2_pos(); // Get second regular enemy's position in stage three |
| RexRoshan | 1:45493d1d0689 | 469 | |
| RexRoshan | 5:016a7315b75d | 470 | Vector2D enemybossbeam3_pos = _enemybeam3.get_pos_boss(); // Get boss enemy's beam position in stage three |
| RexRoshan | 5:016a7315b75d | 471 | Vector2D enemy1beam3_pos = _enemybeam3.get_pos_enemy1(); // Get first regular enemy's beam position in stage three |
| RexRoshan | 5:016a7315b75d | 472 | Vector2D enemy2beam3_pos = _enemybeam3.get_pos_enemy2(); // Get second regular enemy's beam position in stage three |
| RexRoshan | 5:016a7315b75d | 473 | |
| RexRoshan | 5:016a7315b75d | 474 | if ((_ebeam3boss == true)||(_ebeam31 == true)||(_ebeam32 == true)||(enemybossbeam3_pos.x - _beam_size < 0)||(enemy1beam3_pos.x - _beam_size < 0)||(enemy2beam3_pos.x - _beam_size < 0)) { // if hits the speacecraft or the wall |
| RexRoshan | 5:016a7315b75d | 475 | _enemybeam3.init(_beam_size,enemyboss_pos.x,enemyboss_pos.y,enemy1_pos.x,enemy1_pos.y,enemy2_pos.x,enemy2_pos.y); // Initialise the enemy beam in stage three |
| RexRoshan | 5:016a7315b75d | 476 | _ebeam3boss = false; // Then set boolean _ebeam3boss,_ebeam31, _ebeam32 to false |
| RexRoshan | 1:45493d1d0689 | 477 | _ebeam31 = false; |
| RexRoshan | 1:45493d1d0689 | 478 | _ebeam32 = false; |
| RexRoshan | 1:45493d1d0689 | 479 | } |
| RexRoshan | 1:45493d1d0689 | 480 | } |
| RexRoshan | 1:45493d1d0689 | 481 | |
| RexRoshan | 5:016a7315b75d | 482 | void GameEngine::check_spacecraft_collisions(Gamepad &pad) // check spacecraft collision with enemy beam in stage one |
| RexRoshan | 0:99fa5a619081 | 483 | { |
| RexRoshan | 5:016a7315b75d | 484 | Vector2D enemybeam_pos = _enemybeam.get_pos(); // Gets the position of the enemy's beam in stage one |
| RexRoshan | 5:016a7315b75d | 485 | Vector2D p1_pos = _p1.get_pos(); // Gets the position of the player's spacecraft |
| RexRoshan | 0:99fa5a619081 | 486 | |
| RexRoshan | 0:99fa5a619081 | 487 | // see if beam has hit the enemy by checking for overlaps |
| RexRoshan | 0:99fa5a619081 | 488 | if ( |
| RexRoshan | 0:99fa5a619081 | 489 | (enemybeam_pos.y >= p1_pos.y) && //top |
| RexRoshan | 0:99fa5a619081 | 490 | (enemybeam_pos.y <= p1_pos.y + 11) && //bottom |
| RexRoshan | 0:99fa5a619081 | 491 | (enemybeam_pos.x >= _p1x) && //left |
| RexRoshan | 0:99fa5a619081 | 492 | (enemybeam_pos.x <= _p1x + 11) //right |
| RexRoshan | 0:99fa5a619081 | 493 | ) { |
| RexRoshan | 5:016a7315b75d | 494 | _p1.add_health(); // adds health |
| RexRoshan | 5:016a7315b75d | 495 | _ebeam = true; // sets boolean to true to initialise beam |
| RexRoshan | 5:016a7315b75d | 496 | pad.tone(1000.0,0.1); // outputs sound if it hits the player's spacecraft |
| RexRoshan | 0:99fa5a619081 | 497 | } |
| RexRoshan | 5:016a7315b75d | 498 | // write new attributes |
| RexRoshan | 0:99fa5a619081 | 499 | _enemybeam.set_pos(enemybeam_pos); |
| RexRoshan | 0:99fa5a619081 | 500 | |
| RexRoshan | 0:99fa5a619081 | 501 | } |
| RexRoshan | 0:99fa5a619081 | 502 | |
| RexRoshan | 5:016a7315b75d | 503 | void GameEngine::check_spacecraft2_collisions(Gamepad &pad) // check spacecraft collision with enemy beam in stage two |
| RexRoshan | 0:99fa5a619081 | 504 | { |
| RexRoshan | 5:016a7315b75d | 505 | Vector2D enemybeam21_pos = _enemybeam2.get_pos_21(); // Gets the position of the first enemy's beam in stage two |
| RexRoshan | 5:016a7315b75d | 506 | Vector2D enemybeam22_pos = _enemybeam2.get_pos_22(); // Gets the position of the second enemy's beam in stage two |
| RexRoshan | 5:016a7315b75d | 507 | Vector2D p1_pos = _p1.get_pos(); // Gets the position of the player's spacecraft |
| RexRoshan | 0:99fa5a619081 | 508 | |
| RexRoshan | 0:99fa5a619081 | 509 | // see if beam has hit the enemy by checking for overlaps |
| RexRoshan | 0:99fa5a619081 | 510 | if ( |
| RexRoshan | 0:99fa5a619081 | 511 | (enemybeam21_pos.y >= p1_pos.y) && //top |
| RexRoshan | 0:99fa5a619081 | 512 | (enemybeam21_pos.y <= p1_pos.y + 11) && //bottom |
| RexRoshan | 0:99fa5a619081 | 513 | (enemybeam21_pos.x >= _p1x) && //left |
| RexRoshan | 0:99fa5a619081 | 514 | (enemybeam21_pos.x <= _p1x + 11) //right |
| RexRoshan | 0:99fa5a619081 | 515 | ) { |
| RexRoshan | 5:016a7315b75d | 516 | _p1.add_health(); // adds health |
| RexRoshan | 5:016a7315b75d | 517 | _ebeam21 = true; // sets boolean to true to initialise beam |
| RexRoshan | 5:016a7315b75d | 518 | pad.tone(1000.0,0.1); // outputs sound if it hits the player's spacecraft |
| RexRoshan | 0:99fa5a619081 | 519 | } |
| RexRoshan | 1:45493d1d0689 | 520 | else if ( |
| RexRoshan | 0:99fa5a619081 | 521 | (enemybeam22_pos.y >= p1_pos.y) && //top |
| RexRoshan | 0:99fa5a619081 | 522 | (enemybeam22_pos.y <= p1_pos.y + 11) && //bottom |
| RexRoshan | 0:99fa5a619081 | 523 | (enemybeam22_pos.x >= _p1x) && //left |
| RexRoshan | 0:99fa5a619081 | 524 | (enemybeam22_pos.x <= _p1x + 11) //right |
| RexRoshan | 0:99fa5a619081 | 525 | ) { |
| RexRoshan | 5:016a7315b75d | 526 | _p1.add_health(); // adds health |
| RexRoshan | 5:016a7315b75d | 527 | _ebeam22 = true; // sets boolean to true to initialise beam |
| RexRoshan | 5:016a7315b75d | 528 | pad.tone(1000.0,0.1); // outputs sound if it hits the player's spacecraft |
| RexRoshan | 0:99fa5a619081 | 529 | } |
| RexRoshan | 5:016a7315b75d | 530 | // write new attributes |
| RexRoshan | 0:99fa5a619081 | 531 | _enemybeam2.set_pos_21(enemybeam21_pos); |
| RexRoshan | 0:99fa5a619081 | 532 | _enemybeam2.set_pos_22(enemybeam22_pos); |
| RexRoshan | 0:99fa5a619081 | 533 | |
| RexRoshan | 0:99fa5a619081 | 534 | } |
| RexRoshan | 1:45493d1d0689 | 535 | |
| RexRoshan | 5:016a7315b75d | 536 | void GameEngine::check_spacecraft3_collisions(Gamepad &pad) // check spacecraft collision with enemy beam in stage three |
| RexRoshan | 1:45493d1d0689 | 537 | { |
| RexRoshan | 5:016a7315b75d | 538 | Vector2D enemybossbeam_pos = _enemybeam3.get_pos_boss(); // Gets the position of the boss enemy's beam in stage three |
| RexRoshan | 5:016a7315b75d | 539 | Vector2D enemy1beam_pos = _enemybeam3.get_pos_enemy1(); // Gets the position of the first enemy's beam in stage three |
| RexRoshan | 5:016a7315b75d | 540 | Vector2D enemy2beam_pos = _enemybeam3.get_pos_enemy2(); // Gets the position of the second enemy's beam in stage three |
| RexRoshan | 1:45493d1d0689 | 541 | |
| RexRoshan | 5:016a7315b75d | 542 | Vector2D p1_pos = _p1.get_pos(); // Gets the position of the player's spacecraft |
| RexRoshan | 1:45493d1d0689 | 543 | |
| RexRoshan | 1:45493d1d0689 | 544 | // see if beam has hit the enemy by checking for overlaps |
| RexRoshan | 1:45493d1d0689 | 545 | if ( |
| RexRoshan | 1:45493d1d0689 | 546 | (enemybossbeam_pos.y >= p1_pos.y) && //top |
| RexRoshan | 1:45493d1d0689 | 547 | (enemybossbeam_pos.y <= p1_pos.y + 11) && //bottom |
| RexRoshan | 1:45493d1d0689 | 548 | (enemybossbeam_pos.x >= _p1x) && //left |
| RexRoshan | 1:45493d1d0689 | 549 | (enemybossbeam_pos.x <= _p1x + 11) //right |
| RexRoshan | 1:45493d1d0689 | 550 | ) { |
| RexRoshan | 5:016a7315b75d | 551 | _p1.add_health(); // adds health |
| RexRoshan | 5:016a7315b75d | 552 | _ebeam3boss = true; // sets boolean to true to initialise beam |
| RexRoshan | 1:45493d1d0689 | 553 | pad.tone(1000.0,0.1); |
| RexRoshan | 1:45493d1d0689 | 554 | } |
| RexRoshan | 1:45493d1d0689 | 555 | else if ( |
| RexRoshan | 1:45493d1d0689 | 556 | (enemy1beam_pos.y >= p1_pos.y) && //top |
| RexRoshan | 1:45493d1d0689 | 557 | (enemy1beam_pos.y <= p1_pos.y + 11) && //bottom |
| RexRoshan | 1:45493d1d0689 | 558 | (enemy1beam_pos.x >= _p1x) && //left |
| RexRoshan | 1:45493d1d0689 | 559 | (enemy1beam_pos.x <= _p1x + 11) //right |
| RexRoshan | 1:45493d1d0689 | 560 | ) { |
| RexRoshan | 5:016a7315b75d | 561 | _p1.add_health(); // adds health |
| RexRoshan | 5:016a7315b75d | 562 | _ebeam31 = true; // sets boolean to true to initialise beam |
| RexRoshan | 1:45493d1d0689 | 563 | pad.tone(1000.0,0.1); |
| RexRoshan | 1:45493d1d0689 | 564 | } |
| RexRoshan | 1:45493d1d0689 | 565 | else if ( |
| RexRoshan | 1:45493d1d0689 | 566 | (enemy2beam_pos.y >= p1_pos.y) && //top |
| RexRoshan | 1:45493d1d0689 | 567 | (enemy2beam_pos.y <= p1_pos.y + 11) && //bottom |
| RexRoshan | 1:45493d1d0689 | 568 | (enemy2beam_pos.x >= _p1x) && //left |
| RexRoshan | 1:45493d1d0689 | 569 | (enemy2beam_pos.x <= _p1x + 11) //right |
| RexRoshan | 1:45493d1d0689 | 570 | ) { |
| RexRoshan | 5:016a7315b75d | 571 | _p1.add_health(); // adds health |
| RexRoshan | 5:016a7315b75d | 572 | _ebeam32 = true; // sets boolean to true to initialise beam |
| RexRoshan | 5:016a7315b75d | 573 | pad.tone(1000.0,0.1); // outputs sound if it hits the player's spacecraft |
| RexRoshan | 1:45493d1d0689 | 574 | } |
| RexRoshan | 5:016a7315b75d | 575 | // write new attributes |
| RexRoshan | 1:45493d1d0689 | 576 | _enemybeam3.set_pos_boss(enemybossbeam_pos); |
| RexRoshan | 1:45493d1d0689 | 577 | _enemybeam3.set_pos_enemy1(enemy1beam_pos); |
| RexRoshan | 1:45493d1d0689 | 578 | _enemybeam3.set_pos_enemy2(enemy2beam_pos); |
| RexRoshan | 1:45493d1d0689 | 579 | |
| RexRoshan | 1:45493d1d0689 | 580 | } |
| RexRoshan | 1:45493d1d0689 | 581 | |
| RexRoshan | 5:016a7315b75d | 582 | void GameEngine::check_wall_collisions(Gamepad &pad) // check wall collision for enemies in stage two |
| RexRoshan | 0:99fa5a619081 | 583 | { |
| RexRoshan | 5:016a7315b75d | 584 | // read current attributes of the enemies |
| RexRoshan | 0:99fa5a619081 | 585 | Vector2D enemy21_pos = _e21.get_enemy21_pos(); |
| RexRoshan | 0:99fa5a619081 | 586 | Vector2D enemy22_pos = _e22.get_enemy22_pos(); |
| RexRoshan | 0:99fa5a619081 | 587 | Vector2D enemy21_movement = _e21.get_movement(); |
| RexRoshan | 0:99fa5a619081 | 588 | Vector2D enemy22_movement = _e22.get_movement(); |
| RexRoshan | 0:99fa5a619081 | 589 | |
| RexRoshan | 0:99fa5a619081 | 590 | // check if hit top wall |
| RexRoshan | 5:016a7315b75d | 591 | // first enemy |
| RexRoshan | 0:99fa5a619081 | 592 | if (enemy21_pos.y <= 1) { // 1 due to 1 pixel boundary |
| RexRoshan | 0:99fa5a619081 | 593 | enemy21_pos.y = 1; // bounce off ceiling without going off screen |
| RexRoshan | 0:99fa5a619081 | 594 | enemy21_movement.y = -enemy21_movement.y; |
| RexRoshan | 0:99fa5a619081 | 595 | } |
| RexRoshan | 5:016a7315b75d | 596 | //second enemy |
| RexRoshan | 5:016a7315b75d | 597 | else if (enemy22_pos.y <= 1) { |
| RexRoshan | 5:016a7315b75d | 598 | enemy22_pos.y = 1; |
| RexRoshan | 5:016a7315b75d | 599 | enemy22_movement.y = -enemy22_movement.y; |
| RexRoshan | 5:016a7315b75d | 600 | } |
| RexRoshan | 0:99fa5a619081 | 601 | // check if hit bottom wall |
| RexRoshan | 5:016a7315b75d | 602 | // first enemy |
| RexRoshan | 0:99fa5a619081 | 603 | else if (enemy21_pos.y + 7 >= (HEIGHT-1) ) { // bottom pixel is 47 |
| RexRoshan | 0:99fa5a619081 | 604 | enemy21_pos.y = (HEIGHT-1) - 7; // stops ball going off screen |
| RexRoshan | 0:99fa5a619081 | 605 | enemy21_movement.y = -enemy21_movement.y; |
| RexRoshan | 5:016a7315b75d | 606 | // second enemy |
| RexRoshan | 5:016a7315b75d | 607 | } else if (enemy22_pos.y + 7 >= (HEIGHT-1) ) { |
| RexRoshan | 5:016a7315b75d | 608 | enemy22_pos.y = (HEIGHT-1) - 7; |
| RexRoshan | 0:99fa5a619081 | 609 | enemy22_movement.y = -enemy22_movement.y; |
| RexRoshan | 5:016a7315b75d | 610 | |
| RexRoshan | 5:016a7315b75d | 611 | } |
| RexRoshan | 0:99fa5a619081 | 612 | |
| RexRoshan | 5:016a7315b75d | 613 | // update first and second enemy parameters |
| RexRoshan | 0:99fa5a619081 | 614 | _e21.set_movement(enemy21_movement); |
| RexRoshan | 0:99fa5a619081 | 615 | _e22.set_movement(enemy22_movement); |
| RexRoshan | 0:99fa5a619081 | 616 | _e21.set_enemy21_pos(enemy21_pos); |
| RexRoshan | 0:99fa5a619081 | 617 | _e22.set_enemy22_pos(enemy22_pos); |
| RexRoshan | 0:99fa5a619081 | 618 | } |
| RexRoshan | 1:45493d1d0689 | 619 | |
| RexRoshan | 5:016a7315b75d | 620 | void GameEngine::check_wall2_collisions(Gamepad &pad) // check wall collision for enemies in stage three |
| RexRoshan | 1:45493d1d0689 | 621 | { |
| RexRoshan | 5:016a7315b75d | 622 | // read current enemy attributes for boss in stage three |
| RexRoshan | 1:45493d1d0689 | 623 | Vector2D enemyboss_pos = _e3.get_enemyboss_pos(); |
| RexRoshan | 1:45493d1d0689 | 624 | Vector2D enemyboss_movement = _e3.get_movement(); |
| RexRoshan | 1:45493d1d0689 | 625 | |
| RexRoshan | 1:45493d1d0689 | 626 | // check if hit top wall |
| RexRoshan | 1:45493d1d0689 | 627 | if (enemyboss_pos.y <= 1) { // 1 due to 1 pixel boundary |
| RexRoshan | 1:45493d1d0689 | 628 | enemyboss_pos.y = 1; // bounce off ceiling without going off screen |
| RexRoshan | 1:45493d1d0689 | 629 | enemyboss_movement.y = -enemyboss_movement.y; |
| RexRoshan | 1:45493d1d0689 | 630 | } |
| RexRoshan | 1:45493d1d0689 | 631 | // check if hit bottom wall |
| RexRoshan | 1:45493d1d0689 | 632 | else if (enemyboss_pos.y + 12 >= (HEIGHT-1) ) { // bottom pixel is 47 |
| RexRoshan | 1:45493d1d0689 | 633 | enemyboss_pos.y = (HEIGHT-1) - 12; // stops ball going off screen |
| RexRoshan | 1:45493d1d0689 | 634 | enemyboss_movement.y = -enemyboss_movement.y; |
| RexRoshan | 5:016a7315b75d | 635 | // check if hit right wall |
| RexRoshan | 5:016a7315b75d | 636 | }else if (enemyboss_pos.x + 12 >= (WIDTH-1) ) { // right pixel is 83 |
| RexRoshan | 1:45493d1d0689 | 637 | enemyboss_pos.x = (WIDTH-1) - 12; // stops ball going off screen |
| RexRoshan | 1:45493d1d0689 | 638 | enemyboss_movement.x = -enemyboss_movement.x; |
| RexRoshan | 5:016a7315b75d | 639 | // check if left right wall |
| RexRoshan | 5:016a7315b75d | 640 | }else if (enemyboss_pos.x <= WIDTH/2) { // half the width (42) |
| RexRoshan | 1:45493d1d0689 | 641 | enemyboss_pos.x = WIDTH/2; // bounce off ceiling without going halfway |
| RexRoshan | 1:45493d1d0689 | 642 | enemyboss_movement.x = -enemyboss_movement.x; |
| RexRoshan | 1:45493d1d0689 | 643 | } |
| RexRoshan | 5:016a7315b75d | 644 | // update boss enemy parameters |
| RexRoshan | 1:45493d1d0689 | 645 | _e3.set_movement(enemyboss_movement); |
| RexRoshan | 1:45493d1d0689 | 646 | _e3.set_enemyboss_pos(enemyboss_pos); |
| RexRoshan | 1:45493d1d0689 | 647 | |
| RexRoshan | 1:45493d1d0689 | 648 | } |
| RexRoshan | 1:45493d1d0689 | 649 | |
| RexRoshan | 5:016a7315b75d | 650 | void GameEngine::enemy_dead(N5110 &lcd, Gamepad &pad){ // animation when the enemy is dead in stage one |
| RexRoshan | 5:016a7315b75d | 651 | |
| RexRoshan | 5:016a7315b75d | 652 | int e1_health = _e1.get_health(); // Gets the health of the enemy |
| RexRoshan | 5:016a7315b75d | 653 | Vector2D e1_pos = _e1.get_enemy_pos(); // Gets the position of the enemy |
| RexRoshan | 5:016a7315b75d | 654 | |
| RexRoshan | 5:016a7315b75d | 655 | if (e1_health == 10){ |
| RexRoshan | 5:016a7315b75d | 656 | // explodes and outputs sound if the enemy is dead |
| RexRoshan | 0:99fa5a619081 | 657 | lcd.drawSprite(e1_pos.x-10,e1_pos.y-10,23,23,(int *)explosion); |
| RexRoshan | 0:99fa5a619081 | 658 | pad.tone(1000.0,0.5); |
| RexRoshan | 0:99fa5a619081 | 659 | pad.tone(800.0,0.5); |
| RexRoshan | 0:99fa5a619081 | 660 | pad.tone(600.0,0.5); |
| RexRoshan | 0:99fa5a619081 | 661 | pad.tone(400.0,0.5); |
| RexRoshan | 0:99fa5a619081 | 662 | wait(0.5); |
| RexRoshan | 0:99fa5a619081 | 663 | _e1.update(); |
| RexRoshan | 5:016a7315b75d | 664 | lcd.drawSprite(e1_pos.x-10,e1_pos.y-10,23,23,(int *)explosion); |
| RexRoshan | 5:016a7315b75d | 665 | _stage = 2; // mission one pass |
| RexRoshan | 0:99fa5a619081 | 666 | lcd.refresh(); |
| RexRoshan | 0:99fa5a619081 | 667 | } |
| RexRoshan | 0:99fa5a619081 | 668 | |
| RexRoshan | 0:99fa5a619081 | 669 | } |
| RexRoshan | 0:99fa5a619081 | 670 | |
| RexRoshan | 5:016a7315b75d | 671 | void GameEngine::enemy2_dead(N5110 &lcd, Gamepad &pad){ // animation when the enemy is dead in stage two |
| RexRoshan | 0:99fa5a619081 | 672 | |
| RexRoshan | 5:016a7315b75d | 673 | int e21_health = _e21.get_health(); // Gets the health of the first enemy |
| RexRoshan | 5:016a7315b75d | 674 | int e22_health = _e22.get_health(); // Gets the health of the second enemy |
| RexRoshan | 0:99fa5a619081 | 675 | |
| RexRoshan | 5:016a7315b75d | 676 | Vector2D e21_pos = _e21.get_enemy21_pos(); // Gets the position of the first enemy |
| RexRoshan | 5:016a7315b75d | 677 | Vector2D e22_pos = _e22.get_enemy22_pos(); // Gets the position of the second enemy |
| RexRoshan | 0:99fa5a619081 | 678 | |
| RexRoshan | 5:016a7315b75d | 679 | if ((e21_health >= 10) && (e22_health >= 10)){ |
| RexRoshan | 5:016a7315b75d | 680 | // explodes and outputs sound if the enemy is dead |
| RexRoshan | 0:99fa5a619081 | 681 | lcd.drawSprite(e21_pos.x-10,e21_pos.y-10,23,23,(int *)explosion); |
| RexRoshan | 0:99fa5a619081 | 682 | lcd.drawSprite(e22_pos.x-10,e22_pos.y-10,23,23,(int *)explosion); |
| RexRoshan | 0:99fa5a619081 | 683 | pad.tone(1000.0,0.5); |
| RexRoshan | 0:99fa5a619081 | 684 | pad.tone(800.0,0.5); |
| RexRoshan | 0:99fa5a619081 | 685 | pad.tone(600.0,0.5); |
| RexRoshan | 0:99fa5a619081 | 686 | pad.tone(400.0,0.5); |
| RexRoshan | 0:99fa5a619081 | 687 | wait(0.2); |
| RexRoshan | 0:99fa5a619081 | 688 | lcd.drawSprite(e21_pos.x-10,e21_pos.y-10,23,23,(int *)explosion); |
| RexRoshan | 0:99fa5a619081 | 689 | lcd.drawSprite(e22_pos.x-10,e22_pos.y-10,23,23,(int *)explosion); |
| RexRoshan | 5:016a7315b75d | 690 | _stage = 4; // mission two pass |
| RexRoshan | 0:99fa5a619081 | 691 | lcd.refresh(); |
| RexRoshan | 0:99fa5a619081 | 692 | } |
| RexRoshan | 0:99fa5a619081 | 693 | |
| RexRoshan | 0:99fa5a619081 | 694 | } |
| RexRoshan | 1:45493d1d0689 | 695 | |
| RexRoshan | 5:016a7315b75d | 696 | void GameEngine::enemy3_dead(N5110 &lcd, Gamepad &pad){ // animation when the enemy is dead in stage three |
| RexRoshan | 5:016a7315b75d | 697 | |
| RexRoshan | 5:016a7315b75d | 698 | int e3boss_health = _e3.get_health_boss(); // Gets the health of the boss enemy |
| RexRoshan | 5:016a7315b75d | 699 | int e31_health = _e3.get_health_enemy1(); // Gets the health of the first enemy |
| RexRoshan | 5:016a7315b75d | 700 | int e32_health = _e3.get_health_enemy2(); // Gets the health of the second enemy |
| RexRoshan | 1:45493d1d0689 | 701 | |
| RexRoshan | 5:016a7315b75d | 702 | Vector2D e3boss_pos = _e3.get_enemyboss_pos(); // Gets the position of the boss enemy |
| RexRoshan | 5:016a7315b75d | 703 | Vector2D e31_pos = _e3.get_enemy1_pos(); // Gets the position of the first enemy |
| RexRoshan | 5:016a7315b75d | 704 | Vector2D e32_pos = _e3.get_enemy2_pos(); // Gets the position of the second enemy |
| RexRoshan | 1:45493d1d0689 | 705 | |
| RexRoshan | 5:016a7315b75d | 706 | // explodes and outputs sound if the enemy is dead |
| RexRoshan | 1:45493d1d0689 | 707 | if ((e3boss_health >= 10) && (e31_health >= 10) && (e32_health >= 10)){ |
| RexRoshan | 1:45493d1d0689 | 708 | lcd.drawSprite(e3boss_pos.x-10,e3boss_pos.y-10,23,23,(int *)explosion); |
| RexRoshan | 1:45493d1d0689 | 709 | lcd.drawSprite(e31_pos.x-10,e31_pos.y-10,23,23,(int *)explosion); |
| RexRoshan | 1:45493d1d0689 | 710 | lcd.drawSprite(e32_pos.x-10,e32_pos.y-10,23,23,(int *)explosion); |
| RexRoshan | 1:45493d1d0689 | 711 | pad.tone(1000.0,0.5); |
| RexRoshan | 1:45493d1d0689 | 712 | pad.tone(800.0,0.5); |
| RexRoshan | 1:45493d1d0689 | 713 | pad.tone(600.0,0.5); |
| RexRoshan | 1:45493d1d0689 | 714 | pad.tone(400.0,0.5); |
| RexRoshan | 1:45493d1d0689 | 715 | wait(0.2); |
| RexRoshan | 1:45493d1d0689 | 716 | lcd.drawSprite(e3boss_pos.x-10,e3boss_pos.y-10,23,23,(int *)explosion); |
| RexRoshan | 1:45493d1d0689 | 717 | lcd.drawSprite(e31_pos.x-10,e31_pos.y-10,23,23,(int *)explosion); |
| RexRoshan | 1:45493d1d0689 | 718 | lcd.drawSprite(e32_pos.x-10,e32_pos.y-10,23,23,(int *)explosion); |
| RexRoshan | 5:016a7315b75d | 719 | _stage = 6; // mission three pass |
| RexRoshan | 1:45493d1d0689 | 720 | lcd.refresh(); |
| RexRoshan | 1:45493d1d0689 | 721 | } |
| RexRoshan | 1:45493d1d0689 | 722 | |
| RexRoshan | 1:45493d1d0689 | 723 | } |
| RexRoshan | 1:45493d1d0689 | 724 | |
| RexRoshan | 5:016a7315b75d | 725 | void GameEngine::spacecraft_dead(N5110 &lcd, Gamepad &pad) // animation when the player's spacecraft is dead in stage one |
| RexRoshan | 5:016a7315b75d | 726 | { |
| RexRoshan | 5:016a7315b75d | 727 | int p1_health = _p1.get_health(); // Gets the health of the player spacecraft |
| RexRoshan | 5:016a7315b75d | 728 | Vector2D p1_pos = _p1.get_pos(); // Gets the position of the player's spacecraft |
| RexRoshan | 0:99fa5a619081 | 729 | |
| RexRoshan | 0:99fa5a619081 | 730 | if (p1_health == 6){ |
| RexRoshan | 0:99fa5a619081 | 731 | |
| RexRoshan | 5:016a7315b75d | 732 | // explodes and outputs sound if the enemy is dead |
| RexRoshan | 0:99fa5a619081 | 733 | lcd.drawSprite(p1_pos.x-5,p1_pos.y-7,23,23,(int *)explosion); |
| RexRoshan | 0:99fa5a619081 | 734 | pad.tone(1000.0,0.5); |
| RexRoshan | 0:99fa5a619081 | 735 | pad.tone(800.0,0.5); |
| RexRoshan | 0:99fa5a619081 | 736 | pad.tone(600.0,0.5); |
| RexRoshan | 0:99fa5a619081 | 737 | pad.tone(400.0,0.5); |
| RexRoshan | 0:99fa5a619081 | 738 | wait(0.5); |
| RexRoshan | 0:99fa5a619081 | 739 | lcd.refresh(); |
| RexRoshan | 0:99fa5a619081 | 740 | wait(0.1); |
| RexRoshan | 0:99fa5a619081 | 741 | lcd.drawSprite(p1_pos.x-5,p1_pos.y-7,23,23,(int *)explosion); |
| RexRoshan | 0:99fa5a619081 | 742 | _p1.update_move(); |
| RexRoshan | 5:016a7315b75d | 743 | _stage = 1; // mission one fail |
| RexRoshan | 0:99fa5a619081 | 744 | lcd.refresh(); |
| RexRoshan | 0:99fa5a619081 | 745 | } |
| RexRoshan | 0:99fa5a619081 | 746 | |
| RexRoshan | 0:99fa5a619081 | 747 | } |
| RexRoshan | 0:99fa5a619081 | 748 | |
| RexRoshan | 5:016a7315b75d | 749 | void GameEngine::spacecraft2_dead(N5110 &lcd, Gamepad &pad) // animation when the player's spacecraft is dead in stage two |
| RexRoshan | 0:99fa5a619081 | 750 | { |
| RexRoshan | 0:99fa5a619081 | 751 | |
| RexRoshan | 5:016a7315b75d | 752 | int p1_health = _p1.get_health(); // Gets the health of the player spacecraft |
| RexRoshan | 5:016a7315b75d | 753 | Vector2D p1_pos = _p1.get_pos(); // Gets the position of the player's spacecraft |
| RexRoshan | 0:99fa5a619081 | 754 | |
| RexRoshan | 0:99fa5a619081 | 755 | if (p1_health == 6){ |
| RexRoshan | 0:99fa5a619081 | 756 | |
| RexRoshan | 5:016a7315b75d | 757 | // explodes and outputs sound if the enemy is dead |
| RexRoshan | 1:45493d1d0689 | 758 | lcd.drawSprite(p1_pos.x-5,p1_pos.y-7,23,23,(int *)explosion); |
| RexRoshan | 1:45493d1d0689 | 759 | pad.tone(1000.0,0.5); |
| RexRoshan | 1:45493d1d0689 | 760 | pad.tone(800.0,0.5); |
| RexRoshan | 1:45493d1d0689 | 761 | pad.tone(600.0,0.5); |
| RexRoshan | 1:45493d1d0689 | 762 | pad.tone(400.0,0.5); |
| RexRoshan | 1:45493d1d0689 | 763 | wait(0.5); |
| RexRoshan | 1:45493d1d0689 | 764 | lcd.refresh(); |
| RexRoshan | 1:45493d1d0689 | 765 | wait(0.1); |
| RexRoshan | 1:45493d1d0689 | 766 | lcd.drawSprite(p1_pos.x-5,p1_pos.y-7,23,23,(int *)explosion); |
| RexRoshan | 1:45493d1d0689 | 767 | _p1.update_move(); |
| RexRoshan | 5:016a7315b75d | 768 | _stage = 3; // mission two fail |
| RexRoshan | 1:45493d1d0689 | 769 | lcd.refresh(); |
| RexRoshan | 1:45493d1d0689 | 770 | } |
| RexRoshan | 1:45493d1d0689 | 771 | |
| RexRoshan | 1:45493d1d0689 | 772 | } |
| RexRoshan | 1:45493d1d0689 | 773 | |
| RexRoshan | 5:016a7315b75d | 774 | void GameEngine::spacecraft3_dead(N5110 &lcd, Gamepad &pad) // animation when the player's spacecraft is dead in stage three |
| RexRoshan | 5:016a7315b75d | 775 | { |
| RexRoshan | 5:016a7315b75d | 776 | int p1_health = _p1.get_health(); // Gets the health of the player spacecraft |
| RexRoshan | 5:016a7315b75d | 777 | Vector2D p1_pos = _p1.get_pos(); // Gets the position of the player's spacecraft |
| RexRoshan | 0:99fa5a619081 | 778 | |
| RexRoshan | 5:016a7315b75d | 779 | if (p1_health == 6){ |
| RexRoshan | 5:016a7315b75d | 780 | |
| RexRoshan | 5:016a7315b75d | 781 | // explodes and outputs sound if the enemy is dead |
| RexRoshan | 5:016a7315b75d | 782 | lcd.drawSprite(p1_pos.x-5,p1_pos.y-7,23,23,(int *)explosion); |
| RexRoshan | 5:016a7315b75d | 783 | pad.tone(1000.0,0.5); |
| RexRoshan | 5:016a7315b75d | 784 | pad.tone(800.0,0.5); |
| RexRoshan | 5:016a7315b75d | 785 | pad.tone(600.0,0.5); |
| RexRoshan | 5:016a7315b75d | 786 | pad.tone(400.0,0.5); |
| RexRoshan | 5:016a7315b75d | 787 | wait(0.5); |
| RexRoshan | 5:016a7315b75d | 788 | lcd.refresh(); |
| RexRoshan | 5:016a7315b75d | 789 | wait(0.1); |
| RexRoshan | 5:016a7315b75d | 790 | lcd.drawSprite(p1_pos.x-5,p1_pos.y-7,23,23,(int *)explosion); |
| RexRoshan | 5:016a7315b75d | 791 | _p1.update_move(); |
| RexRoshan | 5:016a7315b75d | 792 | _stage = 5; // mission three fail |
| RexRoshan | 5:016a7315b75d | 793 | lcd.refresh(); |
| RexRoshan | 5:016a7315b75d | 794 | } |
| RexRoshan | 1:45493d1d0689 | 795 | |
| RexRoshan | 1:45493d1d0689 | 796 | } |
| RexRoshan | 0:99fa5a619081 | 797 | |
| RexRoshan | 0:99fa5a619081 | 798 | void GameEngine::draw_enemy_health(N5110 &lcd) |
| RexRoshan | 0:99fa5a619081 | 799 | { |
| RexRoshan | 0:99fa5a619081 | 800 | // get health of the enemy |
| RexRoshan | 0:99fa5a619081 | 801 | int e1_health = _e1.get_health(); |
| RexRoshan | 0:99fa5a619081 | 802 | |
| RexRoshan | 5:016a7315b75d | 803 | if (e1_health <= 10){ |
| RexRoshan | 1:45493d1d0689 | 804 | lcd.drawRect(62,42,20,4,FILL_TRANSPARENT); |
| RexRoshan | 1:45493d1d0689 | 805 | lcd.drawRect(62,42,20-2*e1_health,4,FILL_BLACK); |
| RexRoshan | 3:bf9624e5b0c3 | 806 | } |
| RexRoshan | 3:bf9624e5b0c3 | 807 | else { |
| RexRoshan | 3:bf9624e5b0c3 | 808 | lcd.drawRect(62,42,20,4,FILL_TRANSPARENT); |
| RexRoshan | 3:bf9624e5b0c3 | 809 | } |
| RexRoshan | 0:99fa5a619081 | 810 | |
| RexRoshan | 0:99fa5a619081 | 811 | |
| RexRoshan | 0:99fa5a619081 | 812 | } |
| RexRoshan | 0:99fa5a619081 | 813 | |
| RexRoshan | 0:99fa5a619081 | 814 | void GameEngine::draw_enemy21_health(N5110 &lcd) |
| RexRoshan | 0:99fa5a619081 | 815 | { |
| RexRoshan | 0:99fa5a619081 | 816 | // get health of the enemy |
| RexRoshan | 0:99fa5a619081 | 817 | int e21_health = _e21.get_health(); |
| RexRoshan | 0:99fa5a619081 | 818 | |
| RexRoshan | 5:016a7315b75d | 819 | if (e21_health <= 10){ |
| RexRoshan | 1:45493d1d0689 | 820 | lcd.drawRect(2,42,20,4,FILL_TRANSPARENT); |
| RexRoshan | 1:45493d1d0689 | 821 | lcd.drawRect(2,42,20-2*e21_health,4,FILL_BLACK); |
| RexRoshan | 0:99fa5a619081 | 822 | } |
| RexRoshan | 0:99fa5a619081 | 823 | else { |
| RexRoshan | 1:45493d1d0689 | 824 | lcd.drawRect(2,42,20,4,FILL_TRANSPARENT); |
| RexRoshan | 0:99fa5a619081 | 825 | } |
| RexRoshan | 0:99fa5a619081 | 826 | } |
| RexRoshan | 0:99fa5a619081 | 827 | |
| RexRoshan | 0:99fa5a619081 | 828 | void GameEngine::draw_enemy22_health(N5110 &lcd) |
| RexRoshan | 0:99fa5a619081 | 829 | { |
| RexRoshan | 0:99fa5a619081 | 830 | // get health of the enemy |
| RexRoshan | 0:99fa5a619081 | 831 | int e22_health = _e22.get_health(); |
| RexRoshan | 0:99fa5a619081 | 832 | |
| RexRoshan | 5:016a7315b75d | 833 | if (e22_health <= 10){ |
| RexRoshan | 1:45493d1d0689 | 834 | lcd.drawRect(62,42,20,4,FILL_TRANSPARENT); |
| RexRoshan | 1:45493d1d0689 | 835 | lcd.drawRect(62,42,20-2*e22_health,4,FILL_BLACK); |
| RexRoshan | 0:99fa5a619081 | 836 | } |
| RexRoshan | 0:99fa5a619081 | 837 | else { |
| RexRoshan | 1:45493d1d0689 | 838 | lcd.drawRect(62,42,20,4,FILL_TRANSPARENT); |
| RexRoshan | 0:99fa5a619081 | 839 | } |
| RexRoshan | 0:99fa5a619081 | 840 | |
| RexRoshan | 0:99fa5a619081 | 841 | } |
| RexRoshan | 0:99fa5a619081 | 842 | |
| RexRoshan | 1:45493d1d0689 | 843 | void GameEngine::draw_enemyboss_health(N5110 &lcd) |
| RexRoshan | 1:45493d1d0689 | 844 | { |
| RexRoshan | 1:45493d1d0689 | 845 | // get health of the enemy |
| RexRoshan | 1:45493d1d0689 | 846 | int e3boss_health = _e3.get_health_boss(); |
| RexRoshan | 1:45493d1d0689 | 847 | int e3enemy1_health = _e3.get_health_enemy1(); |
| RexRoshan | 1:45493d1d0689 | 848 | int e3enemy2_health = _e3.get_health_enemy2(); |
| RexRoshan | 1:45493d1d0689 | 849 | |
| RexRoshan | 5:016a7315b75d | 850 | if (e3boss_health <= 10){ |
| RexRoshan | 1:45493d1d0689 | 851 | lcd.drawRect(62,42,20,4,FILL_TRANSPARENT); |
| RexRoshan | 1:45493d1d0689 | 852 | lcd.drawRect(62,42,20-2*e3boss_health,4,FILL_BLACK); |
| RexRoshan | 1:45493d1d0689 | 853 | } |
| RexRoshan | 1:45493d1d0689 | 854 | else { |
| RexRoshan | 1:45493d1d0689 | 855 | lcd.drawRect(62,42,20,4,FILL_TRANSPARENT); |
| RexRoshan | 1:45493d1d0689 | 856 | } |
| RexRoshan | 5:016a7315b75d | 857 | if (e3enemy1_health <= 10){ |
| RexRoshan | 1:45493d1d0689 | 858 | lcd.drawRect(2,42,20,4,FILL_TRANSPARENT); |
| RexRoshan | 1:45493d1d0689 | 859 | lcd.drawRect(2,42,20-2*e3enemy1_health,4,FILL_BLACK); |
| RexRoshan | 1:45493d1d0689 | 860 | } |
| RexRoshan | 1:45493d1d0689 | 861 | else { |
| RexRoshan | 1:45493d1d0689 | 862 | lcd.drawRect(2,42,20,4,FILL_TRANSPARENT); |
| RexRoshan | 1:45493d1d0689 | 863 | } |
| RexRoshan | 5:016a7315b75d | 864 | if (e3enemy2_health <= 10){ |
| RexRoshan | 1:45493d1d0689 | 865 | lcd.drawRect(62,2,20,4,FILL_TRANSPARENT); |
| RexRoshan | 1:45493d1d0689 | 866 | lcd.drawRect(62,2,20-2*e3enemy2_health,4,FILL_BLACK); |
| RexRoshan | 1:45493d1d0689 | 867 | } |
| RexRoshan | 1:45493d1d0689 | 868 | else { |
| RexRoshan | 1:45493d1d0689 | 869 | lcd.drawRect(62,2,20,4,FILL_TRANSPARENT); |
| RexRoshan | 1:45493d1d0689 | 870 | } |
| RexRoshan | 1:45493d1d0689 | 871 | } |
| RexRoshan | 1:45493d1d0689 | 872 | |
| RexRoshan | 0:99fa5a619081 | 873 | void GameEngine::draw_spacecraft_health(Gamepad &pad) |
| RexRoshan | 0:99fa5a619081 | 874 | { |
| RexRoshan | 0:99fa5a619081 | 875 | //get the health of the spacecraft |
| RexRoshan | 0:99fa5a619081 | 876 | int p1_health = _p1.get_health(); |
| RexRoshan | 0:99fa5a619081 | 877 | |
| RexRoshan | 5:016a7315b75d | 878 | if (p1_health == 0){ // All the lights are switched on |
| RexRoshan | 0:99fa5a619081 | 879 | pad.leds_on(); |
| RexRoshan | 5:016a7315b75d | 880 | |
| RexRoshan | 5:016a7315b75d | 881 | }else if (p1_health == 1){ // Switches off the left most light |
| RexRoshan | 0:99fa5a619081 | 882 | pad.led(1,0); |
| RexRoshan | 0:99fa5a619081 | 883 | pad.led(2,1); |
| RexRoshan | 0:99fa5a619081 | 884 | pad.led(3,1); |
| RexRoshan | 0:99fa5a619081 | 885 | pad.led(4,1); |
| RexRoshan | 0:99fa5a619081 | 886 | pad.led(5,1); |
| RexRoshan | 0:99fa5a619081 | 887 | pad.led(6,1); |
| RexRoshan | 0:99fa5a619081 | 888 | |
| RexRoshan | 5:016a7315b75d | 889 | }else if (p1_health == 2){ // Switches of the two left most lights |
| RexRoshan | 0:99fa5a619081 | 890 | pad.led(1,0); |
| RexRoshan | 0:99fa5a619081 | 891 | pad.led(2,0); |
| RexRoshan | 0:99fa5a619081 | 892 | pad.led(3,1); |
| RexRoshan | 0:99fa5a619081 | 893 | pad.led(4,1); |
| RexRoshan | 0:99fa5a619081 | 894 | pad.led(5,1); |
| RexRoshan | 0:99fa5a619081 | 895 | pad.led(6,1); |
| RexRoshan | 5:016a7315b75d | 896 | }else if (p1_health == 3){ // Swtiches of the three left most lights |
| RexRoshan | 0:99fa5a619081 | 897 | pad.led(1,0); |
| RexRoshan | 0:99fa5a619081 | 898 | pad.led(2,0); |
| RexRoshan | 0:99fa5a619081 | 899 | pad.led(3,0); |
| RexRoshan | 0:99fa5a619081 | 900 | pad.led(4,1); |
| RexRoshan | 0:99fa5a619081 | 901 | pad.led(5,1); |
| RexRoshan | 0:99fa5a619081 | 902 | pad.led(6,1); |
| RexRoshan | 0:99fa5a619081 | 903 | |
| RexRoshan | 5:016a7315b75d | 904 | }else if (p1_health == 4){ // Switches off the four left most lights |
| RexRoshan | 0:99fa5a619081 | 905 | pad.led(1,0); |
| RexRoshan | 0:99fa5a619081 | 906 | pad.led(2,0); |
| RexRoshan | 0:99fa5a619081 | 907 | pad.led(3,0); |
| RexRoshan | 0:99fa5a619081 | 908 | pad.led(4,0); |
| RexRoshan | 0:99fa5a619081 | 909 | pad.led(5,1); |
| RexRoshan | 0:99fa5a619081 | 910 | pad.led(6,1); |
| RexRoshan | 0:99fa5a619081 | 911 | |
| RexRoshan | 5:016a7315b75d | 912 | }else if (p1_health == 5){ // Switches the five left most light |
| RexRoshan | 0:99fa5a619081 | 913 | pad.led(1,0); |
| RexRoshan | 0:99fa5a619081 | 914 | pad.led(2,0); |
| RexRoshan | 0:99fa5a619081 | 915 | pad.led(3,0); |
| RexRoshan | 0:99fa5a619081 | 916 | pad.led(4,0); |
| RexRoshan | 0:99fa5a619081 | 917 | pad.led(5,0); |
| RexRoshan | 0:99fa5a619081 | 918 | pad.led(6,1); |
| RexRoshan | 0:99fa5a619081 | 919 | |
| RexRoshan | 0:99fa5a619081 | 920 | } else { |
| RexRoshan | 5:016a7315b75d | 921 | pad.leds_off(); // Switches all the Led light off |
| RexRoshan | 0:99fa5a619081 | 922 | } |
| RexRoshan | 0:99fa5a619081 | 923 | |
| RexRoshan | 0:99fa5a619081 | 924 | } |
| RexRoshan | 0:99fa5a619081 | 925 | |
| RexRoshan | 0:99fa5a619081 | 926 | int GameEngine::get_game_stage() { |
| RexRoshan | 0:99fa5a619081 | 927 | int stage = _stage; |
| RexRoshan | 5:016a7315b75d | 928 | return stage; // Gets the value of the stage |
| RexRoshan | 0:99fa5a619081 | 929 | } |
| RexRoshan | 0:99fa5a619081 | 930 | |
| RexRoshan | 0:99fa5a619081 | 931 | int GameEngine::restart_game_stage() { |
| RexRoshan | 5:016a7315b75d | 932 | |
| RexRoshan | 0:99fa5a619081 | 933 | int stage = _stage; |
| RexRoshan | 5:016a7315b75d | 934 | stage = 0; // sets the stage to be zero |
| RexRoshan | 0:99fa5a619081 | 935 | return stage; |
| RexRoshan | 0:99fa5a619081 | 936 | } |