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
RosenEngine/RosenEngine.cpp@36:c25417f0d150, 2019-05-03 (annotated)
- Committer:
- ikenna1
- Date:
- Fri May 03 18:56:06 2019 +0000
- Revision:
- 36:c25417f0d150
- Parent:
- 35:3341f2bd0408
- Child:
- 37:8d8c8cce0bc7
Add health to enemies.; enemies no longer die in a single hit and now have health like the player which like the players health is handled in the health folder. Also fixed issue where game would run in menu background.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ikenna1 | 3:f9cd1a38d5c6 | 1 | #include "RosenEngine.h" |
ikenna1 | 23:0301effce801 | 2 | DigitalIn A(PTB9); |
ikenna1 | 3:f9cd1a38d5c6 | 3 | |
ikenna1 | 2:66a4e5d7a7cd | 4 | // Constructor |
ikenna1 | 2:66a4e5d7a7cd | 5 | RosenEngine::RosenEngine() |
ikenna1 | 2:66a4e5d7a7cd | 6 | { |
ikenna1 | 2:66a4e5d7a7cd | 7 | |
ikenna1 | 2:66a4e5d7a7cd | 8 | } |
ikenna1 | 2:66a4e5d7a7cd | 9 | // Destructor |
ikenna1 | 2:66a4e5d7a7cd | 10 | RosenEngine::~RosenEngine() |
ikenna1 | 2:66a4e5d7a7cd | 11 | { |
ikenna1 | 2:66a4e5d7a7cd | 12 | |
ikenna1 | 2:66a4e5d7a7cd | 13 | } |
ikenna1 | 3:f9cd1a38d5c6 | 14 | |
ikenna1 | 4:740e14ebbc97 | 15 | |
ikenna1 | 9:241a1a7d8527 | 16 | void RosenEngine::init(int ship_width,int ship_height,int ship_speed,int ship_xpos,int ship_ypos) |
ikenna1 | 2:66a4e5d7a7cd | 17 | { |
ikenna1 | 4:740e14ebbc97 | 18 | // initialise the game parameters |
ikenna1 | 9:241a1a7d8527 | 19 | _ship.init(ship_width,ship_height,ship_speed,ship_xpos,ship_ypos); |
ikenna1 | 15:009ccc07bb57 | 20 | // place seeker above the ship |
ikenna1 | 34:6d0786582d81 | 21 | _enemy.init(48,0,3); |
ikenna1 | 9:241a1a7d8527 | 22 | _menu.init(16); |
ikenna1 | 21:628fb703188f | 23 | _health.init(_shipno); |
ikenna1 | 13:e114d362186d | 24 | |
ikenna1 | 3:f9cd1a38d5c6 | 25 | } |
ikenna1 | 27:f99249e727fd | 26 | void RosenEngine::reset() |
ikenna1 | 27:f99249e727fd | 27 | { |
ikenna1 | 27:f99249e727fd | 28 | _health.init(_shipno); |
ikenna1 | 27:f99249e727fd | 29 | } |
ikenna1 | 4:740e14ebbc97 | 30 | |
ikenna1 | 5:bb6edc5b5be3 | 31 | void RosenEngine::read_input(Gamepad &pad) |
ikenna1 | 4:740e14ebbc97 | 32 | { |
ikenna1 | 4:740e14ebbc97 | 33 | Vector2D mapped_coord = pad.get_coord(); |
ikenna1 | 8:87a845b8575e | 34 | _xjoystick = mapped_coord.x; |
ikenna1 | 8:87a845b8575e | 35 | _yjoystick = mapped_coord.y; |
ikenna1 | 9:241a1a7d8527 | 36 | _d = pad.get_direction(); |
ikenna1 | 35:3341f2bd0408 | 37 | wait(0.1); |
ikenna1 | 14:88ca5b1a111a | 38 | // printf("_xjoystick ,_yjoystick = %f , %f\n",_xjoystick, _yjoystick); |
ikenna1 | 4:740e14ebbc97 | 39 | } |
ikenna1 | 4:740e14ebbc97 | 40 | |
ikenna1 | 14:88ca5b1a111a | 41 | void RosenEngine::draw(N5110 &lcd, Gamepad &pad) |
ikenna1 | 7:ed5870cfb3e0 | 42 | { |
ikenna1 | 31:c7bd3ed16840 | 43 | lcd.drawRect(0,0,78,48,FILL_TRANSPARENT); |
ikenna1 | 27:f99249e727fd | 44 | _health.draw_health(lcd,_shipno); |
ikenna1 | 18:2cc6898de6b2 | 45 | _health.draw_shields(lcd); |
ikenna1 | 15:009ccc07bb57 | 46 | _enemy.draw_seeker(lcd); |
ikenna1 | 34:6d0786582d81 | 47 | _enemy.draw_shooter(lcd); |
ikenna1 | 34:6d0786582d81 | 48 | _enemy.draw_shw(lcd,pad); |
ikenna1 | 21:628fb703188f | 49 | if(_shipno == 0) { |
ikenna1 | 14:88ca5b1a111a | 50 | _ship.set_dimensions(9,6); |
ikenna1 | 26:a53d41adf40b | 51 | _ship.draw_ship(lcd,_shipno); |
ikenna1 | 23:0301effce801 | 52 | _weapons.draw(lcd,pad,_shipno); |
ikenna1 | 13:e114d362186d | 53 | } |
ikenna1 | 21:628fb703188f | 54 | if(_shipno == 1) { |
ikenna1 | 14:88ca5b1a111a | 55 | _ship.set_dimensions(7,10); |
ikenna1 | 26:a53d41adf40b | 56 | _ship.draw_ship(lcd,_shipno); |
ikenna1 | 26:a53d41adf40b | 57 | _weapons.draw(lcd,pad,_shipno); |
ikenna1 | 26:a53d41adf40b | 58 | } |
ikenna1 | 26:a53d41adf40b | 59 | if(_shipno == 2) { |
ikenna1 | 26:a53d41adf40b | 60 | _ship.set_dimensions(7,10); |
ikenna1 | 26:a53d41adf40b | 61 | _ship.draw_ship(lcd,_shipno); |
ikenna1 | 23:0301effce801 | 62 | _weapons.draw(lcd,pad,_shipno); |
ikenna1 | 13:e114d362186d | 63 | } |
ikenna1 | 11:73cd744ffa80 | 64 | } |
ikenna1 | 7:ed5870cfb3e0 | 65 | |
ikenna1 | 7:ed5870cfb3e0 | 66 | void RosenEngine::update(Gamepad &pad) |
ikenna1 | 7:ed5870cfb3e0 | 67 | { |
ikenna1 | 35:3341f2bd0408 | 68 | _enemy.update_seeker(ship_xpos, ship_ypos); |
ikenna1 | 30:711d722f3cef | 69 | _enemy.update_shooter(ship_xpos, ship_ypos); |
ikenna1 | 35:3341f2bd0408 | 70 | //printf("update_shooter\n"); |
ikenna1 | 32:098fbc1222cd | 71 | _enemy.update_shw(); |
ikenna1 | 21:628fb703188f | 72 | if(_shipno == 0) { |
ikenna1 | 14:88ca5b1a111a | 73 | _ship.update_ship(_xjoystick,_yjoystick); |
ikenna1 | 14:88ca5b1a111a | 74 | _weapons.update(); |
ikenna1 | 35:3341f2bd0408 | 75 | kestrelw_seeker_collision(pad); |
ikenna1 | 14:88ca5b1a111a | 76 | } |
ikenna1 | 35:3341f2bd0408 | 77 | //printf("if shipno == 0\n"); |
ikenna1 | 23:0301effce801 | 78 | if(_shipno == 1 && A == false) { |
ikenna1 | 14:88ca5b1a111a | 79 | _ship.update_ship(_xjoystick,_yjoystick); |
ikenna1 | 14:88ca5b1a111a | 80 | _weapons.update(); |
ikenna1 | 14:88ca5b1a111a | 81 | } |
ikenna1 | 35:3341f2bd0408 | 82 | //printf("if shipno == 1\n"); |
ikenna1 | 27:f99249e727fd | 83 | if(_shipno == 2) { |
ikenna1 | 27:f99249e727fd | 84 | _ship.update_ship(_xjoystick,_yjoystick); |
ikenna1 | 27:f99249e727fd | 85 | _weapons.update(); |
ikenna1 | 27:f99249e727fd | 86 | } |
ikenna1 | 35:3341f2bd0408 | 87 | // test(); |
ikenna1 | 35:3341f2bd0408 | 88 | shooter_ship_collision(pad); |
ikenna1 | 35:3341f2bd0408 | 89 | seeker_ship_collision(pad); |
ikenna1 | 35:3341f2bd0408 | 90 | shooterw_ship_collision(pad); |
ikenna1 | 35:3341f2bd0408 | 91 | imperionw_seeker_collision(pad); |
ikenna1 | 35:3341f2bd0408 | 92 | kestrelw_shooter_collision(pad); |
ikenna1 | 35:3341f2bd0408 | 93 | imperionw_shooter_collision(pad); |
ikenna1 | 36:c25417f0d150 | 94 | check_health(); |
ikenna1 | 7:ed5870cfb3e0 | 95 | } |
ikenna1 | 9:241a1a7d8527 | 96 | void RosenEngine::get_pos() |
ikenna1 | 9:241a1a7d8527 | 97 | { |
ikenna1 | 9:241a1a7d8527 | 98 | Vector2D ship_pos = _ship.get_pos(); |
ikenna1 | 9:241a1a7d8527 | 99 | ship_xpos = ship_pos.x; |
ikenna1 | 9:241a1a7d8527 | 100 | ship_ypos = ship_pos.y; |
ikenna1 | 35:3341f2bd0408 | 101 | |
ikenna1 | 35:3341f2bd0408 | 102 | _shooter1_pos = _enemy.get_shooter1pos(); |
ikenna1 | 35:3341f2bd0408 | 103 | _shooter2_pos = _enemy.get_shooter2pos(); |
ikenna1 | 35:3341f2bd0408 | 104 | _shooter3_pos = _enemy.get_shooter3pos(); |
ikenna1 | 35:3341f2bd0408 | 105 | |
ikenna1 | 9:241a1a7d8527 | 106 | _weapons.init(ship_xpos, ship_ypos, ship_width); |
ikenna1 | 13:e114d362186d | 107 | _ycursor = _menu.get_ycursor(); |
ikenna1 | 25:faba9eb44514 | 108 | |
ikenna1 | 25:faba9eb44514 | 109 | if(_shipno == 0) { |
ikenna1 | 25:faba9eb44514 | 110 | ship_width = 9; |
ikenna1 | 25:faba9eb44514 | 111 | ship_height = 6; |
ikenna1 | 25:faba9eb44514 | 112 | } |
ikenna1 | 25:faba9eb44514 | 113 | if(_shipno == 1) { |
ikenna1 | 25:faba9eb44514 | 114 | ship_width = 7; |
ikenna1 | 25:faba9eb44514 | 115 | ship_height = 10; |
ikenna1 | 25:faba9eb44514 | 116 | } |
ikenna1 | 9:241a1a7d8527 | 117 | } |
ikenna1 | 9:241a1a7d8527 | 118 | void RosenEngine::title(N5110 &lcd) |
ikenna1 | 9:241a1a7d8527 | 119 | { |
ikenna1 | 30:711d722f3cef | 120 | _menu.title(lcd,_shipno); |
ikenna1 | 10:c33d7593a275 | 121 | _menu.update(_d); |
ikenna1 | 10:c33d7593a275 | 122 | } |
ikenna1 | 13:e114d362186d | 123 | int RosenEngine::get_ycursor() |
ikenna1 | 10:c33d7593a275 | 124 | { |
ikenna1 | 13:e114d362186d | 125 | _ycursor = _menu.get_ycursor(); |
ikenna1 | 10:c33d7593a275 | 126 | return _ycursor; |
ikenna1 | 12:47578eb9ea73 | 127 | } |
ikenna1 | 21:628fb703188f | 128 | int RosenEngine::get_shipno() |
ikenna1 | 13:e114d362186d | 129 | { |
ikenna1 | 21:628fb703188f | 130 | _shipno = _menu.get_xcursor(); |
ikenna1 | 21:628fb703188f | 131 | return _shipno; |
ikenna1 | 13:e114d362186d | 132 | } |
ikenna1 | 12:47578eb9ea73 | 133 | void RosenEngine::ship_select(N5110 &lcd) |
ikenna1 | 12:47578eb9ea73 | 134 | { |
ikenna1 | 12:47578eb9ea73 | 135 | _menu.update(_d); |
ikenna1 | 12:47578eb9ea73 | 136 | _menu.disp_ships(lcd); |
ikenna1 | 17:e65a9f981834 | 137 | } |
ikenna1 | 35:3341f2bd0408 | 138 | bool RosenEngine::check_collision(int xpos1, int ypos1,int width1,int height1,int xpos2, int ypos2,int width2,int height2) |
ikenna1 | 35:3341f2bd0408 | 139 | { |
ikenna1 | 35:3341f2bd0408 | 140 | // Create arrays of all positions with appropriate height and length |
ikenna1 | 35:3341f2bd0408 | 141 | int xpos1_array[width1]; |
ikenna1 | 35:3341f2bd0408 | 142 | int ypos1_array[height1]; |
ikenna1 | 35:3341f2bd0408 | 143 | int xpos2_array[width2]; |
ikenna1 | 35:3341f2bd0408 | 144 | int ypos2_array[height2]; |
ikenna1 | 35:3341f2bd0408 | 145 | bool xcol = false; |
ikenna1 | 35:3341f2bd0408 | 146 | bool ycol = false; |
ikenna1 | 35:3341f2bd0408 | 147 | bool col = false; |
ikenna1 | 35:3341f2bd0408 | 148 | //printf("variables declared\n"); |
ikenna1 | 35:3341f2bd0408 | 149 | // Loop through both height and width to get a 2D aray of the sprites position |
ikenna1 | 35:3341f2bd0408 | 150 | for(int cx = 0; cx<width1; cx=cx+1) { |
ikenna1 | 35:3341f2bd0408 | 151 | xpos1_array[cx]= xpos1 + cx; |
ikenna1 | 35:3341f2bd0408 | 152 | for(int nx = 0; nx<width2; nx=nx+1) { |
ikenna1 | 35:3341f2bd0408 | 153 | xpos2_array[nx]= xpos2 + nx; |
ikenna1 | 35:3341f2bd0408 | 154 | if(xpos2_array[nx] == xpos1_array[cx]) { |
ikenna1 | 35:3341f2bd0408 | 155 | xcol = true; |
ikenna1 | 35:3341f2bd0408 | 156 | } |
ikenna1 | 35:3341f2bd0408 | 157 | // printf("xarray = %d,x2array = %d,xcol = %d\n",xpos2_array[nx],xpos1_array[cx],xcol); |
ikenna1 | 35:3341f2bd0408 | 158 | } |
ikenna1 | 35:3341f2bd0408 | 159 | } |
ikenna1 | 35:3341f2bd0408 | 160 | //printf("first loop done\n"); |
ikenna1 | 35:3341f2bd0408 | 161 | for(int cy = 0; cy<height1; cy=cy+1) { |
ikenna1 | 35:3341f2bd0408 | 162 | ypos1_array[cy]= ypos1 + cy; |
ikenna1 | 35:3341f2bd0408 | 163 | for(int ny = 0; ny<height2; ny=ny+1) { |
ikenna1 | 35:3341f2bd0408 | 164 | ypos2_array[ny]= ypos2 + ny; |
ikenna1 | 35:3341f2bd0408 | 165 | if(ypos2_array[ny] == ypos1_array[cy]) { |
ikenna1 | 35:3341f2bd0408 | 166 | ycol = true; |
ikenna1 | 35:3341f2bd0408 | 167 | } |
ikenna1 | 35:3341f2bd0408 | 168 | // printf("yarray = %d,y2array = %d,ycol = %d\n",ypos2_array[ny],ypos1_array[cy],ycol); |
ikenna1 | 35:3341f2bd0408 | 169 | } |
ikenna1 | 35:3341f2bd0408 | 170 | } |
ikenna1 | 35:3341f2bd0408 | 171 | //printf("second loop done\n"); |
ikenna1 | 35:3341f2bd0408 | 172 | // if both the hight and width position values are equal a collision has occured |
ikenna1 | 35:3341f2bd0408 | 173 | col = (xcol & ycol); |
ikenna1 | 35:3341f2bd0408 | 174 | //printf("col gotten, col = %d\n",col); |
ikenna1 | 35:3341f2bd0408 | 175 | return col; |
ikenna1 | 35:3341f2bd0408 | 176 | } |
ikenna1 | 35:3341f2bd0408 | 177 | bool RosenEngine::check_collision1(int xpos1,int width1,int xpos2,int width2) |
ikenna1 | 35:3341f2bd0408 | 178 | { |
ikenna1 | 35:3341f2bd0408 | 179 | // Create arrays of all positions with appropriate height and length |
ikenna1 | 35:3341f2bd0408 | 180 | int xpos1_array[width1]; |
ikenna1 | 35:3341f2bd0408 | 181 | int xpos2_array[width2]; |
ikenna1 | 35:3341f2bd0408 | 182 | bool xcol = false; |
ikenna1 | 35:3341f2bd0408 | 183 | |
ikenna1 | 35:3341f2bd0408 | 184 | for(int cx = 0; cx<width1; cx=cx+1) { |
ikenna1 | 35:3341f2bd0408 | 185 | xpos1_array[cx]= xpos1 + cx; |
ikenna1 | 35:3341f2bd0408 | 186 | for(int nx = 0; nx<width2; nx=nx+1) { |
ikenna1 | 35:3341f2bd0408 | 187 | xpos2_array[nx]= xpos2 + nx; |
ikenna1 | 35:3341f2bd0408 | 188 | if(xpos2_array[nx] == xpos1_array[cx]) { |
ikenna1 | 35:3341f2bd0408 | 189 | xcol = true; |
ikenna1 | 35:3341f2bd0408 | 190 | } |
ikenna1 | 35:3341f2bd0408 | 191 | // printf("xarray = %d,x2array = %d,xcol = %d\n",xpos2_array[nx],xpos1_array[cx],xcol); |
ikenna1 | 35:3341f2bd0408 | 192 | } |
ikenna1 | 35:3341f2bd0408 | 193 | } |
ikenna1 | 35:3341f2bd0408 | 194 | return xcol; |
ikenna1 | 35:3341f2bd0408 | 195 | } |
ikenna1 | 35:3341f2bd0408 | 196 | |
ikenna1 | 35:3341f2bd0408 | 197 | void RosenEngine::test() |
ikenna1 | 35:3341f2bd0408 | 198 | { |
ikenna1 | 35:3341f2bd0408 | 199 | bool test; |
ikenna1 | 35:3341f2bd0408 | 200 | test = check_collision(5,5,5,5,5,5,5,5); |
ikenna1 | 35:3341f2bd0408 | 201 | if (test == false) { |
ikenna1 | 35:3341f2bd0408 | 202 | printf("fail\n"); |
ikenna1 | 35:3341f2bd0408 | 203 | } else { |
ikenna1 | 35:3341f2bd0408 | 204 | printf("pass\n"); |
ikenna1 | 35:3341f2bd0408 | 205 | } |
ikenna1 | 35:3341f2bd0408 | 206 | test = check_collision(0,0,1,1,24,24,1,1); |
ikenna1 | 35:3341f2bd0408 | 207 | if (test == true) { |
ikenna1 | 35:3341f2bd0408 | 208 | printf("fail\n"); |
ikenna1 | 35:3341f2bd0408 | 209 | } else { |
ikenna1 | 35:3341f2bd0408 | 210 | printf("pass\n"); |
ikenna1 | 35:3341f2bd0408 | 211 | } |
ikenna1 | 35:3341f2bd0408 | 212 | } |
ikenna1 | 35:3341f2bd0408 | 213 | // make function resemble test |
ikenna1 | 35:3341f2bd0408 | 214 | |
ikenna1 | 35:3341f2bd0408 | 215 | void RosenEngine::seeker_ship_collision(Gamepad &pad) |
ikenna1 | 35:3341f2bd0408 | 216 | { |
ikenna1 | 35:3341f2bd0408 | 217 | Vector2D seeker_pos = _enemy.get_seekerpos(); |
ikenna1 | 35:3341f2bd0408 | 218 | bool collision; |
ikenna1 | 35:3341f2bd0408 | 219 | collision = check_collision(seeker_pos.x,seeker_pos.y,5,5,ship_xpos,ship_ypos,5,5); |
ikenna1 | 35:3341f2bd0408 | 220 | if (collision == true) { |
ikenna1 | 35:3341f2bd0408 | 221 | _health.update(1,pad); |
ikenna1 | 35:3341f2bd0408 | 222 | _enemy.reset_seeker(); |
ikenna1 | 35:3341f2bd0408 | 223 | pad.tone(500,0.05); |
ikenna1 | 35:3341f2bd0408 | 224 | wait(0.05); |
ikenna1 | 35:3341f2bd0408 | 225 | } |
ikenna1 | 35:3341f2bd0408 | 226 | } |
ikenna1 | 35:3341f2bd0408 | 227 | void RosenEngine::shooter_ship_collision(Gamepad &pad) |
ikenna1 | 35:3341f2bd0408 | 228 | { |
ikenna1 | 35:3341f2bd0408 | 229 | bool collision1; |
ikenna1 | 35:3341f2bd0408 | 230 | bool collision2; |
ikenna1 | 35:3341f2bd0408 | 231 | bool collision3; |
ikenna1 | 35:3341f2bd0408 | 232 | |
ikenna1 | 35:3341f2bd0408 | 233 | collision1 = check_collision(ship_xpos,ship_ypos,9,6,_shooter1_pos.x, _shooter1_pos.y,10,7); |
ikenna1 | 35:3341f2bd0408 | 234 | collision2 = check_collision(ship_xpos,ship_ypos,9,6,_shooter2_pos.x, _shooter2_pos.y,10,7); |
ikenna1 | 35:3341f2bd0408 | 235 | collision3 = check_collision(ship_xpos,ship_ypos,9,6,_shooter3_pos.x, _shooter3_pos.y,10,7); |
ikenna1 | 35:3341f2bd0408 | 236 | |
ikenna1 | 35:3341f2bd0408 | 237 | if(collision1 == true) { |
ikenna1 | 35:3341f2bd0408 | 238 | _health.update(1,pad); |
ikenna1 | 35:3341f2bd0408 | 239 | pad.tone(500,0.05); |
ikenna1 | 35:3341f2bd0408 | 240 | wait(0.05); |
ikenna1 | 35:3341f2bd0408 | 241 | } |
ikenna1 | 35:3341f2bd0408 | 242 | if(collision2 == true) { |
ikenna1 | 35:3341f2bd0408 | 243 | _health.update(1,pad); |
ikenna1 | 35:3341f2bd0408 | 244 | pad.tone(500,0.05); |
ikenna1 | 35:3341f2bd0408 | 245 | wait(0.05); |
ikenna1 | 35:3341f2bd0408 | 246 | } |
ikenna1 | 35:3341f2bd0408 | 247 | if(collision3 == true) { |
ikenna1 | 35:3341f2bd0408 | 248 | _health.update(1,pad); |
ikenna1 | 35:3341f2bd0408 | 249 | pad.tone(500,0.05); |
ikenna1 | 35:3341f2bd0408 | 250 | wait(0.05); |
ikenna1 | 35:3341f2bd0408 | 251 | } |
ikenna1 | 35:3341f2bd0408 | 252 | } |
ikenna1 | 35:3341f2bd0408 | 253 | void RosenEngine::shooterw_ship_collision(Gamepad &pad) |
ikenna1 | 35:3341f2bd0408 | 254 | { |
ikenna1 | 35:3341f2bd0408 | 255 | Vector2D _shooterw1_pos = _enemy.get_sh1wpos(); |
ikenna1 | 35:3341f2bd0408 | 256 | Vector2D _shooterw2_pos = _enemy.get_sh2wpos(); |
ikenna1 | 35:3341f2bd0408 | 257 | Vector2D _shooterw3_pos = _enemy.get_sh3wpos(); |
ikenna1 | 35:3341f2bd0408 | 258 | |
ikenna1 | 35:3341f2bd0408 | 259 | bool collision1; |
ikenna1 | 35:3341f2bd0408 | 260 | bool collision2; |
ikenna1 | 35:3341f2bd0408 | 261 | bool collision3; |
ikenna1 | 35:3341f2bd0408 | 262 | |
ikenna1 | 35:3341f2bd0408 | 263 | collision1 = check_collision(ship_xpos,ship_ypos,9,6,_shooterw1_pos.x, _shooterw1_pos.y,2,2); |
ikenna1 | 35:3341f2bd0408 | 264 | collision2 = check_collision(ship_xpos,ship_ypos,9,6,_shooterw2_pos.x, _shooterw2_pos.y,2,2); |
ikenna1 | 35:3341f2bd0408 | 265 | collision3 = check_collision(ship_xpos,ship_ypos,9,6,_shooterw3_pos.x, _shooterw3_pos.y,2,2); |
ikenna1 | 35:3341f2bd0408 | 266 | |
ikenna1 | 35:3341f2bd0408 | 267 | if(collision1 == true) { |
ikenna1 | 35:3341f2bd0408 | 268 | _health.update(1,pad); |
ikenna1 | 35:3341f2bd0408 | 269 | pad.tone(500,0.05); |
ikenna1 | 35:3341f2bd0408 | 270 | wait(0.05); |
ikenna1 | 35:3341f2bd0408 | 271 | } |
ikenna1 | 35:3341f2bd0408 | 272 | if(collision2 == true) { |
ikenna1 | 35:3341f2bd0408 | 273 | _health.update(1,pad); |
ikenna1 | 35:3341f2bd0408 | 274 | pad.tone(500,0.05); |
ikenna1 | 35:3341f2bd0408 | 275 | wait(0.05); |
ikenna1 | 35:3341f2bd0408 | 276 | } |
ikenna1 | 35:3341f2bd0408 | 277 | if(collision3 == true) { |
ikenna1 | 35:3341f2bd0408 | 278 | _health.update(1,pad); |
ikenna1 | 35:3341f2bd0408 | 279 | pad.tone(500,0.05); |
ikenna1 | 35:3341f2bd0408 | 280 | wait(0.05); |
ikenna1 | 35:3341f2bd0408 | 281 | } |
ikenna1 | 35:3341f2bd0408 | 282 | } |
ikenna1 | 35:3341f2bd0408 | 283 | void RosenEngine::kestrelw_seeker_collision(Gamepad &pad) |
ikenna1 | 35:3341f2bd0408 | 284 | { |
ikenna1 | 35:3341f2bd0408 | 285 | Vector2D seeker_pos = _enemy.get_seekerpos(); |
ikenna1 | 35:3341f2bd0408 | 286 | Vector2D missle_pos = _weapons.get_pos(_shipno); |
ikenna1 | 35:3341f2bd0408 | 287 | bool collision; |
ikenna1 | 35:3341f2bd0408 | 288 | collision = check_collision(seeker_pos.x,seeker_pos.y,9,6,missle_pos.x,missle_pos.y,1,1); |
ikenna1 | 35:3341f2bd0408 | 289 | if (collision == true) { |
ikenna1 | 36:c25417f0d150 | 290 | _health.seekerh_update(5); |
ikenna1 | 35:3341f2bd0408 | 291 | pad.tone(500,0.05); |
ikenna1 | 35:3341f2bd0408 | 292 | wait(0.05); |
ikenna1 | 35:3341f2bd0408 | 293 | } |
ikenna1 | 35:3341f2bd0408 | 294 | } |
ikenna1 | 35:3341f2bd0408 | 295 | void RosenEngine::imperionw_seeker_collision(Gamepad &pad) |
ikenna1 | 35:3341f2bd0408 | 296 | { |
ikenna1 | 35:3341f2bd0408 | 297 | Vector2D seeker_pos = _enemy.get_seekerpos(); |
ikenna1 | 35:3341f2bd0408 | 298 | bool collision; |
ikenna1 | 35:3341f2bd0408 | 299 | if(ship_ypos > seeker_pos.y + 6) { |
ikenna1 | 35:3341f2bd0408 | 300 | collision = check_collision1(seeker_pos.x,9,ship_xpos + 2,3); |
ikenna1 | 35:3341f2bd0408 | 301 | if (collision == true && A == true) { |
ikenna1 | 36:c25417f0d150 | 302 | _health.seekerh_update(5); |
ikenna1 | 35:3341f2bd0408 | 303 | pad.tone(500,0.05); |
ikenna1 | 35:3341f2bd0408 | 304 | wait(0.05); |
ikenna1 | 35:3341f2bd0408 | 305 | } |
ikenna1 | 35:3341f2bd0408 | 306 | } |
ikenna1 | 35:3341f2bd0408 | 307 | } |
ikenna1 | 35:3341f2bd0408 | 308 | void RosenEngine::kestrelw_shooter_collision(Gamepad &pad) |
ikenna1 | 35:3341f2bd0408 | 309 | { |
ikenna1 | 35:3341f2bd0408 | 310 | Vector2D missle_pos = _weapons.get_pos(_shipno); |
ikenna1 | 35:3341f2bd0408 | 311 | bool col1, col2, col3; |
ikenna1 | 35:3341f2bd0408 | 312 | col1 = check_collision(_shooter1_pos.x,_shooter1_pos.y,9,6,missle_pos.x,missle_pos.y,1,1); |
ikenna1 | 35:3341f2bd0408 | 313 | col2 = check_collision(_shooter2_pos.x,_shooter2_pos.y,9,6,missle_pos.x,missle_pos.y,1,1); |
ikenna1 | 35:3341f2bd0408 | 314 | col3 = check_collision(_shooter3_pos.x,_shooter3_pos.y,9,6,missle_pos.x,missle_pos.y,1,1); |
ikenna1 | 35:3341f2bd0408 | 315 | if (col1 == true) { |
ikenna1 | 35:3341f2bd0408 | 316 | pad.tone(500,0.05); |
ikenna1 | 36:c25417f0d150 | 317 | _health.shooterh_update(1,5); |
ikenna1 | 35:3341f2bd0408 | 318 | wait(0.05); |
ikenna1 | 35:3341f2bd0408 | 319 | } |
ikenna1 | 35:3341f2bd0408 | 320 | if (col2 == true) { |
ikenna1 | 36:c25417f0d150 | 321 | _health.shooterh_update(2,5); |
ikenna1 | 35:3341f2bd0408 | 322 | pad.tone(500,0.05); |
ikenna1 | 35:3341f2bd0408 | 323 | wait(0.05); |
ikenna1 | 35:3341f2bd0408 | 324 | } |
ikenna1 | 35:3341f2bd0408 | 325 | if (col3 == true) { |
ikenna1 | 36:c25417f0d150 | 326 | _health.shooterh_update(3,5); |
ikenna1 | 35:3341f2bd0408 | 327 | pad.tone(500,0.05); |
ikenna1 | 35:3341f2bd0408 | 328 | wait(0.05); |
ikenna1 | 35:3341f2bd0408 | 329 | } |
ikenna1 | 35:3341f2bd0408 | 330 | } |
ikenna1 | 35:3341f2bd0408 | 331 | void RosenEngine::imperionw_shooter_collision(Gamepad &pad) |
ikenna1 | 35:3341f2bd0408 | 332 | { |
ikenna1 | 35:3341f2bd0408 | 333 | bool col1; |
ikenna1 | 35:3341f2bd0408 | 334 | bool col2; |
ikenna1 | 35:3341f2bd0408 | 335 | bool col3; |
ikenna1 | 35:3341f2bd0408 | 336 | if(ship_ypos > _shooter1_pos.y + 6) { |
ikenna1 | 35:3341f2bd0408 | 337 | col1 = check_collision1(_shooter1_pos.x,9,ship_xpos + 2,3); |
ikenna1 | 35:3341f2bd0408 | 338 | if (col1 == true && A == true) { |
ikenna1 | 36:c25417f0d150 | 339 | _health.shooterh_update(1,5); |
ikenna1 | 35:3341f2bd0408 | 340 | pad.tone(500,0.05); |
ikenna1 | 35:3341f2bd0408 | 341 | wait(0.05); |
ikenna1 | 35:3341f2bd0408 | 342 | } |
ikenna1 | 35:3341f2bd0408 | 343 | } |
ikenna1 | 35:3341f2bd0408 | 344 | if(ship_ypos > _shooter2_pos.y + 6) { |
ikenna1 | 35:3341f2bd0408 | 345 | col2 = check_collision1(_shooter2_pos.x,9,ship_xpos + 2,3); |
ikenna1 | 35:3341f2bd0408 | 346 | if (col2 == true && A == true) { |
ikenna1 | 36:c25417f0d150 | 347 | _health.shooterh_update(2,5); |
ikenna1 | 35:3341f2bd0408 | 348 | pad.tone(500,0.05); |
ikenna1 | 35:3341f2bd0408 | 349 | wait(0.05); |
ikenna1 | 35:3341f2bd0408 | 350 | } |
ikenna1 | 35:3341f2bd0408 | 351 | } |
ikenna1 | 35:3341f2bd0408 | 352 | if(ship_ypos > _shooter3_pos.y + 6) { |
ikenna1 | 35:3341f2bd0408 | 353 | col3 = check_collision1(_shooter3_pos.x,9,ship_xpos + 2,3); |
ikenna1 | 35:3341f2bd0408 | 354 | if (col3 == true && A == true) { |
ikenna1 | 36:c25417f0d150 | 355 | _health.shooterh_update(3,5); |
ikenna1 | 35:3341f2bd0408 | 356 | pad.tone(500,0.05); |
ikenna1 | 35:3341f2bd0408 | 357 | wait(0.05); |
ikenna1 | 35:3341f2bd0408 | 358 | } |
ikenna1 | 35:3341f2bd0408 | 359 | } |
ikenna1 | 36:c25417f0d150 | 360 | } |
ikenna1 | 36:c25417f0d150 | 361 | void RosenEngine::score(int points) |
ikenna1 | 36:c25417f0d150 | 362 | { |
ikenna1 | 36:c25417f0d150 | 363 | _score = _score + points; |
ikenna1 | 36:c25417f0d150 | 364 | } |
ikenna1 | 36:c25417f0d150 | 365 | void RosenEngine::check_health() |
ikenna1 | 36:c25417f0d150 | 366 | { |
ikenna1 | 36:c25417f0d150 | 367 | int seeker_health = _health.get_seekerh(); |
ikenna1 | 36:c25417f0d150 | 368 | int shooter1_health = _health.get_shooterh(1); |
ikenna1 | 36:c25417f0d150 | 369 | int shooter2_health = _health.get_shooterh(2); |
ikenna1 | 36:c25417f0d150 | 370 | int shooter3_health = _health.get_shooterh(3); |
ikenna1 | 36:c25417f0d150 | 371 | |
ikenna1 | 36:c25417f0d150 | 372 | if(seeker_health == 0){ |
ikenna1 | 36:c25417f0d150 | 373 | _enemy.reset_seeker(); |
ikenna1 | 36:c25417f0d150 | 374 | _health.reset_seekerh(); |
ikenna1 | 36:c25417f0d150 | 375 | } |
ikenna1 | 36:c25417f0d150 | 376 | if(shooter1_health == 0){ |
ikenna1 | 36:c25417f0d150 | 377 | _enemy.reset_shooter(1); |
ikenna1 | 36:c25417f0d150 | 378 | _health.reset_shooterh(1); |
ikenna1 | 36:c25417f0d150 | 379 | } |
ikenna1 | 36:c25417f0d150 | 380 | if(shooter2_health == 0){ |
ikenna1 | 36:c25417f0d150 | 381 | _enemy.reset_shooter(2); |
ikenna1 | 36:c25417f0d150 | 382 | _health.reset_shooterh(2); |
ikenna1 | 36:c25417f0d150 | 383 | } |
ikenna1 | 36:c25417f0d150 | 384 | if(shooter3_health == 0){ |
ikenna1 | 36:c25417f0d150 | 385 | _enemy.reset_shooter(3); |
ikenna1 | 36:c25417f0d150 | 386 | _health.reset_shooterh(3); |
ikenna1 | 36:c25417f0d150 | 387 | } |
ikenna1 | 36:c25417f0d150 | 388 | |
ikenna1 | 36:c25417f0d150 | 389 | Vector2D hp = _health.get_hp(); |
ikenna1 | 36:c25417f0d150 | 390 | if(hp.x <= 0){ |
ikenna1 | 36:c25417f0d150 | 391 | printf("player deaad\n"); |
ikenna1 | 36:c25417f0d150 | 392 | _dead = true; |
ikenna1 | 36:c25417f0d150 | 393 | } |
ikenna1 | 18:2cc6898de6b2 | 394 | } |