ELEC2645 (2018/19) / Mbed 2 deprecated el17aio

Dependencies:   mbed

Committer:
ikenna1
Date:
Sat May 04 05:37:33 2019 +0000
Revision:
37:8d8c8cce0bc7
Parent:
36:c25417f0d150
Child:
38:4571537238ed
Add random enemy spawning.; made a new function rand_no which uses the ctime library to seed srand() and generate random numbers which are used to set initial and reset positions of enemies.

Who changed what in which revision?

UserRevisionLine numberNew 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 37:8d8c8cce0bc7 21 _enemy.init(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 37:8d8c8cce0bc7 95 rand_no();
ikenna1 7:ed5870cfb3e0 96 }
ikenna1 9:241a1a7d8527 97 void RosenEngine::get_pos()
ikenna1 9:241a1a7d8527 98 {
ikenna1 9:241a1a7d8527 99 Vector2D ship_pos = _ship.get_pos();
ikenna1 9:241a1a7d8527 100 ship_xpos = ship_pos.x;
ikenna1 9:241a1a7d8527 101 ship_ypos = ship_pos.y;
ikenna1 35:3341f2bd0408 102
ikenna1 37:8d8c8cce0bc7 103 _shooter1_pos = _enemy.get_shooterpos(1);
ikenna1 37:8d8c8cce0bc7 104 _shooter2_pos = _enemy.get_shooterpos(2);
ikenna1 37:8d8c8cce0bc7 105 _shooter3_pos = _enemy.get_shooterpos(3);
ikenna1 35:3341f2bd0408 106
ikenna1 9:241a1a7d8527 107 _weapons.init(ship_xpos, ship_ypos, ship_width);
ikenna1 13:e114d362186d 108 _ycursor = _menu.get_ycursor();
ikenna1 25:faba9eb44514 109
ikenna1 25:faba9eb44514 110 if(_shipno == 0) {
ikenna1 25:faba9eb44514 111 ship_width = 9;
ikenna1 25:faba9eb44514 112 ship_height = 6;
ikenna1 25:faba9eb44514 113 }
ikenna1 25:faba9eb44514 114 if(_shipno == 1) {
ikenna1 25:faba9eb44514 115 ship_width = 7;
ikenna1 25:faba9eb44514 116 ship_height = 10;
ikenna1 25:faba9eb44514 117 }
ikenna1 9:241a1a7d8527 118 }
ikenna1 9:241a1a7d8527 119 void RosenEngine::title(N5110 &lcd)
ikenna1 9:241a1a7d8527 120 {
ikenna1 30:711d722f3cef 121 _menu.title(lcd,_shipno);
ikenna1 10:c33d7593a275 122 _menu.update(_d);
ikenna1 10:c33d7593a275 123 }
ikenna1 13:e114d362186d 124 int RosenEngine::get_ycursor()
ikenna1 10:c33d7593a275 125 {
ikenna1 13:e114d362186d 126 _ycursor = _menu.get_ycursor();
ikenna1 10:c33d7593a275 127 return _ycursor;
ikenna1 12:47578eb9ea73 128 }
ikenna1 21:628fb703188f 129 int RosenEngine::get_shipno()
ikenna1 13:e114d362186d 130 {
ikenna1 21:628fb703188f 131 _shipno = _menu.get_xcursor();
ikenna1 21:628fb703188f 132 return _shipno;
ikenna1 13:e114d362186d 133 }
ikenna1 12:47578eb9ea73 134 void RosenEngine::ship_select(N5110 &lcd)
ikenna1 12:47578eb9ea73 135 {
ikenna1 12:47578eb9ea73 136 _menu.update(_d);
ikenna1 12:47578eb9ea73 137 _menu.disp_ships(lcd);
ikenna1 17:e65a9f981834 138 }
ikenna1 35:3341f2bd0408 139 bool RosenEngine::check_collision(int xpos1, int ypos1,int width1,int height1,int xpos2, int ypos2,int width2,int height2)
ikenna1 35:3341f2bd0408 140 {
ikenna1 35:3341f2bd0408 141 // Create arrays of all positions with appropriate height and length
ikenna1 35:3341f2bd0408 142 int xpos1_array[width1];
ikenna1 35:3341f2bd0408 143 int ypos1_array[height1];
ikenna1 35:3341f2bd0408 144 int xpos2_array[width2];
ikenna1 35:3341f2bd0408 145 int ypos2_array[height2];
ikenna1 35:3341f2bd0408 146 bool xcol = false;
ikenna1 35:3341f2bd0408 147 bool ycol = false;
ikenna1 35:3341f2bd0408 148 bool col = false;
ikenna1 35:3341f2bd0408 149 //printf("variables declared\n");
ikenna1 35:3341f2bd0408 150 // Loop through both height and width to get a 2D aray of the sprites position
ikenna1 35:3341f2bd0408 151 for(int cx = 0; cx<width1; cx=cx+1) {
ikenna1 35:3341f2bd0408 152 xpos1_array[cx]= xpos1 + cx;
ikenna1 35:3341f2bd0408 153 for(int nx = 0; nx<width2; nx=nx+1) {
ikenna1 35:3341f2bd0408 154 xpos2_array[nx]= xpos2 + nx;
ikenna1 35:3341f2bd0408 155 if(xpos2_array[nx] == xpos1_array[cx]) {
ikenna1 35:3341f2bd0408 156 xcol = true;
ikenna1 35:3341f2bd0408 157 }
ikenna1 35:3341f2bd0408 158 // printf("xarray = %d,x2array = %d,xcol = %d\n",xpos2_array[nx],xpos1_array[cx],xcol);
ikenna1 35:3341f2bd0408 159 }
ikenna1 35:3341f2bd0408 160 }
ikenna1 35:3341f2bd0408 161 //printf("first loop done\n");
ikenna1 35:3341f2bd0408 162 for(int cy = 0; cy<height1; cy=cy+1) {
ikenna1 35:3341f2bd0408 163 ypos1_array[cy]= ypos1 + cy;
ikenna1 35:3341f2bd0408 164 for(int ny = 0; ny<height2; ny=ny+1) {
ikenna1 35:3341f2bd0408 165 ypos2_array[ny]= ypos2 + ny;
ikenna1 35:3341f2bd0408 166 if(ypos2_array[ny] == ypos1_array[cy]) {
ikenna1 35:3341f2bd0408 167 ycol = true;
ikenna1 35:3341f2bd0408 168 }
ikenna1 35:3341f2bd0408 169 // printf("yarray = %d,y2array = %d,ycol = %d\n",ypos2_array[ny],ypos1_array[cy],ycol);
ikenna1 35:3341f2bd0408 170 }
ikenna1 35:3341f2bd0408 171 }
ikenna1 35:3341f2bd0408 172 //printf("second loop done\n");
ikenna1 35:3341f2bd0408 173 // if both the hight and width position values are equal a collision has occured
ikenna1 35:3341f2bd0408 174 col = (xcol & ycol);
ikenna1 35:3341f2bd0408 175 //printf("col gotten, col = %d\n",col);
ikenna1 35:3341f2bd0408 176 return col;
ikenna1 35:3341f2bd0408 177 }
ikenna1 35:3341f2bd0408 178 bool RosenEngine::check_collision1(int xpos1,int width1,int xpos2,int width2)
ikenna1 35:3341f2bd0408 179 {
ikenna1 35:3341f2bd0408 180 // Create arrays of all positions with appropriate height and length
ikenna1 35:3341f2bd0408 181 int xpos1_array[width1];
ikenna1 35:3341f2bd0408 182 int xpos2_array[width2];
ikenna1 35:3341f2bd0408 183 bool xcol = false;
ikenna1 35:3341f2bd0408 184
ikenna1 35:3341f2bd0408 185 for(int cx = 0; cx<width1; cx=cx+1) {
ikenna1 35:3341f2bd0408 186 xpos1_array[cx]= xpos1 + cx;
ikenna1 35:3341f2bd0408 187 for(int nx = 0; nx<width2; nx=nx+1) {
ikenna1 35:3341f2bd0408 188 xpos2_array[nx]= xpos2 + nx;
ikenna1 35:3341f2bd0408 189 if(xpos2_array[nx] == xpos1_array[cx]) {
ikenna1 35:3341f2bd0408 190 xcol = true;
ikenna1 35:3341f2bd0408 191 }
ikenna1 35:3341f2bd0408 192 // printf("xarray = %d,x2array = %d,xcol = %d\n",xpos2_array[nx],xpos1_array[cx],xcol);
ikenna1 35:3341f2bd0408 193 }
ikenna1 35:3341f2bd0408 194 }
ikenna1 35:3341f2bd0408 195 return xcol;
ikenna1 35:3341f2bd0408 196 }
ikenna1 35:3341f2bd0408 197
ikenna1 35:3341f2bd0408 198 void RosenEngine::test()
ikenna1 35:3341f2bd0408 199 {
ikenna1 35:3341f2bd0408 200 bool test;
ikenna1 35:3341f2bd0408 201 test = check_collision(5,5,5,5,5,5,5,5);
ikenna1 35:3341f2bd0408 202 if (test == false) {
ikenna1 35:3341f2bd0408 203 printf("fail\n");
ikenna1 35:3341f2bd0408 204 } else {
ikenna1 35:3341f2bd0408 205 printf("pass\n");
ikenna1 35:3341f2bd0408 206 }
ikenna1 35:3341f2bd0408 207 test = check_collision(0,0,1,1,24,24,1,1);
ikenna1 35:3341f2bd0408 208 if (test == true) {
ikenna1 35:3341f2bd0408 209 printf("fail\n");
ikenna1 35:3341f2bd0408 210 } else {
ikenna1 35:3341f2bd0408 211 printf("pass\n");
ikenna1 35:3341f2bd0408 212 }
ikenna1 35:3341f2bd0408 213 }
ikenna1 35:3341f2bd0408 214 // make function resemble test
ikenna1 35:3341f2bd0408 215
ikenna1 35:3341f2bd0408 216 void RosenEngine::seeker_ship_collision(Gamepad &pad)
ikenna1 35:3341f2bd0408 217 {
ikenna1 35:3341f2bd0408 218 Vector2D seeker_pos = _enemy.get_seekerpos();
ikenna1 35:3341f2bd0408 219 bool collision;
ikenna1 35:3341f2bd0408 220 collision = check_collision(seeker_pos.x,seeker_pos.y,5,5,ship_xpos,ship_ypos,5,5);
ikenna1 35:3341f2bd0408 221 if (collision == true) {
ikenna1 35:3341f2bd0408 222 _health.update(1,pad);
ikenna1 35:3341f2bd0408 223 _enemy.reset_seeker();
ikenna1 35:3341f2bd0408 224 pad.tone(500,0.05);
ikenna1 35:3341f2bd0408 225 wait(0.05);
ikenna1 35:3341f2bd0408 226 }
ikenna1 35:3341f2bd0408 227 }
ikenna1 35:3341f2bd0408 228 void RosenEngine::shooter_ship_collision(Gamepad &pad)
ikenna1 35:3341f2bd0408 229 {
ikenna1 35:3341f2bd0408 230 bool collision1;
ikenna1 35:3341f2bd0408 231 bool collision2;
ikenna1 35:3341f2bd0408 232 bool collision3;
ikenna1 35:3341f2bd0408 233
ikenna1 35:3341f2bd0408 234 collision1 = check_collision(ship_xpos,ship_ypos,9,6,_shooter1_pos.x, _shooter1_pos.y,10,7);
ikenna1 35:3341f2bd0408 235 collision2 = check_collision(ship_xpos,ship_ypos,9,6,_shooter2_pos.x, _shooter2_pos.y,10,7);
ikenna1 35:3341f2bd0408 236 collision3 = check_collision(ship_xpos,ship_ypos,9,6,_shooter3_pos.x, _shooter3_pos.y,10,7);
ikenna1 35:3341f2bd0408 237
ikenna1 35:3341f2bd0408 238 if(collision1 == true) {
ikenna1 35:3341f2bd0408 239 _health.update(1,pad);
ikenna1 35:3341f2bd0408 240 pad.tone(500,0.05);
ikenna1 35:3341f2bd0408 241 wait(0.05);
ikenna1 35:3341f2bd0408 242 }
ikenna1 35:3341f2bd0408 243 if(collision2 == true) {
ikenna1 35:3341f2bd0408 244 _health.update(1,pad);
ikenna1 35:3341f2bd0408 245 pad.tone(500,0.05);
ikenna1 35:3341f2bd0408 246 wait(0.05);
ikenna1 35:3341f2bd0408 247 }
ikenna1 35:3341f2bd0408 248 if(collision3 == true) {
ikenna1 35:3341f2bd0408 249 _health.update(1,pad);
ikenna1 35:3341f2bd0408 250 pad.tone(500,0.05);
ikenna1 35:3341f2bd0408 251 wait(0.05);
ikenna1 35:3341f2bd0408 252 }
ikenna1 35:3341f2bd0408 253 }
ikenna1 35:3341f2bd0408 254 void RosenEngine::shooterw_ship_collision(Gamepad &pad)
ikenna1 35:3341f2bd0408 255 {
ikenna1 37:8d8c8cce0bc7 256 Vector2D _shooterw1_pos = _enemy.get_shwpos(1);
ikenna1 37:8d8c8cce0bc7 257 Vector2D _shooterw2_pos = _enemy.get_shwpos(2);
ikenna1 37:8d8c8cce0bc7 258 Vector2D _shooterw3_pos = _enemy.get_shwpos(3);
ikenna1 35:3341f2bd0408 259
ikenna1 35:3341f2bd0408 260 bool collision1;
ikenna1 35:3341f2bd0408 261 bool collision2;
ikenna1 35:3341f2bd0408 262 bool collision3;
ikenna1 35:3341f2bd0408 263
ikenna1 35:3341f2bd0408 264 collision1 = check_collision(ship_xpos,ship_ypos,9,6,_shooterw1_pos.x, _shooterw1_pos.y,2,2);
ikenna1 35:3341f2bd0408 265 collision2 = check_collision(ship_xpos,ship_ypos,9,6,_shooterw2_pos.x, _shooterw2_pos.y,2,2);
ikenna1 35:3341f2bd0408 266 collision3 = check_collision(ship_xpos,ship_ypos,9,6,_shooterw3_pos.x, _shooterw3_pos.y,2,2);
ikenna1 35:3341f2bd0408 267
ikenna1 35:3341f2bd0408 268 if(collision1 == true) {
ikenna1 35:3341f2bd0408 269 _health.update(1,pad);
ikenna1 35:3341f2bd0408 270 pad.tone(500,0.05);
ikenna1 35:3341f2bd0408 271 wait(0.05);
ikenna1 35:3341f2bd0408 272 }
ikenna1 35:3341f2bd0408 273 if(collision2 == true) {
ikenna1 35:3341f2bd0408 274 _health.update(1,pad);
ikenna1 35:3341f2bd0408 275 pad.tone(500,0.05);
ikenna1 35:3341f2bd0408 276 wait(0.05);
ikenna1 35:3341f2bd0408 277 }
ikenna1 35:3341f2bd0408 278 if(collision3 == true) {
ikenna1 35:3341f2bd0408 279 _health.update(1,pad);
ikenna1 35:3341f2bd0408 280 pad.tone(500,0.05);
ikenna1 35:3341f2bd0408 281 wait(0.05);
ikenna1 35:3341f2bd0408 282 }
ikenna1 35:3341f2bd0408 283 }
ikenna1 35:3341f2bd0408 284 void RosenEngine::kestrelw_seeker_collision(Gamepad &pad)
ikenna1 35:3341f2bd0408 285 {
ikenna1 35:3341f2bd0408 286 Vector2D seeker_pos = _enemy.get_seekerpos();
ikenna1 35:3341f2bd0408 287 Vector2D missle_pos = _weapons.get_pos(_shipno);
ikenna1 35:3341f2bd0408 288 bool collision;
ikenna1 35:3341f2bd0408 289 collision = check_collision(seeker_pos.x,seeker_pos.y,9,6,missle_pos.x,missle_pos.y,1,1);
ikenna1 35:3341f2bd0408 290 if (collision == true) {
ikenna1 36:c25417f0d150 291 _health.seekerh_update(5);
ikenna1 35:3341f2bd0408 292 pad.tone(500,0.05);
ikenna1 35:3341f2bd0408 293 wait(0.05);
ikenna1 35:3341f2bd0408 294 }
ikenna1 35:3341f2bd0408 295 }
ikenna1 35:3341f2bd0408 296 void RosenEngine::imperionw_seeker_collision(Gamepad &pad)
ikenna1 35:3341f2bd0408 297 {
ikenna1 35:3341f2bd0408 298 Vector2D seeker_pos = _enemy.get_seekerpos();
ikenna1 35:3341f2bd0408 299 bool collision;
ikenna1 35:3341f2bd0408 300 if(ship_ypos > seeker_pos.y + 6) {
ikenna1 35:3341f2bd0408 301 collision = check_collision1(seeker_pos.x,9,ship_xpos + 2,3);
ikenna1 35:3341f2bd0408 302 if (collision == true && A == true) {
ikenna1 36:c25417f0d150 303 _health.seekerh_update(5);
ikenna1 35:3341f2bd0408 304 pad.tone(500,0.05);
ikenna1 35:3341f2bd0408 305 wait(0.05);
ikenna1 35:3341f2bd0408 306 }
ikenna1 35:3341f2bd0408 307 }
ikenna1 35:3341f2bd0408 308 }
ikenna1 35:3341f2bd0408 309 void RosenEngine::kestrelw_shooter_collision(Gamepad &pad)
ikenna1 35:3341f2bd0408 310 {
ikenna1 35:3341f2bd0408 311 Vector2D missle_pos = _weapons.get_pos(_shipno);
ikenna1 35:3341f2bd0408 312 bool col1, col2, col3;
ikenna1 35:3341f2bd0408 313 col1 = check_collision(_shooter1_pos.x,_shooter1_pos.y,9,6,missle_pos.x,missle_pos.y,1,1);
ikenna1 35:3341f2bd0408 314 col2 = check_collision(_shooter2_pos.x,_shooter2_pos.y,9,6,missle_pos.x,missle_pos.y,1,1);
ikenna1 35:3341f2bd0408 315 col3 = check_collision(_shooter3_pos.x,_shooter3_pos.y,9,6,missle_pos.x,missle_pos.y,1,1);
ikenna1 35:3341f2bd0408 316 if (col1 == true) {
ikenna1 35:3341f2bd0408 317 pad.tone(500,0.05);
ikenna1 36:c25417f0d150 318 _health.shooterh_update(1,5);
ikenna1 35:3341f2bd0408 319 wait(0.05);
ikenna1 35:3341f2bd0408 320 }
ikenna1 35:3341f2bd0408 321 if (col2 == true) {
ikenna1 36:c25417f0d150 322 _health.shooterh_update(2,5);
ikenna1 35:3341f2bd0408 323 pad.tone(500,0.05);
ikenna1 35:3341f2bd0408 324 wait(0.05);
ikenna1 35:3341f2bd0408 325 }
ikenna1 35:3341f2bd0408 326 if (col3 == true) {
ikenna1 36:c25417f0d150 327 _health.shooterh_update(3,5);
ikenna1 35:3341f2bd0408 328 pad.tone(500,0.05);
ikenna1 35:3341f2bd0408 329 wait(0.05);
ikenna1 35:3341f2bd0408 330 }
ikenna1 35:3341f2bd0408 331 }
ikenna1 35:3341f2bd0408 332 void RosenEngine::imperionw_shooter_collision(Gamepad &pad)
ikenna1 35:3341f2bd0408 333 {
ikenna1 35:3341f2bd0408 334 bool col1;
ikenna1 35:3341f2bd0408 335 bool col2;
ikenna1 35:3341f2bd0408 336 bool col3;
ikenna1 35:3341f2bd0408 337 if(ship_ypos > _shooter1_pos.y + 6) {
ikenna1 35:3341f2bd0408 338 col1 = check_collision1(_shooter1_pos.x,9,ship_xpos + 2,3);
ikenna1 35:3341f2bd0408 339 if (col1 == true && A == true) {
ikenna1 36:c25417f0d150 340 _health.shooterh_update(1,5);
ikenna1 35:3341f2bd0408 341 pad.tone(500,0.05);
ikenna1 35:3341f2bd0408 342 wait(0.05);
ikenna1 35:3341f2bd0408 343 }
ikenna1 35:3341f2bd0408 344 }
ikenna1 35:3341f2bd0408 345 if(ship_ypos > _shooter2_pos.y + 6) {
ikenna1 35:3341f2bd0408 346 col2 = check_collision1(_shooter2_pos.x,9,ship_xpos + 2,3);
ikenna1 35:3341f2bd0408 347 if (col2 == true && A == true) {
ikenna1 36:c25417f0d150 348 _health.shooterh_update(2,5);
ikenna1 35:3341f2bd0408 349 pad.tone(500,0.05);
ikenna1 35:3341f2bd0408 350 wait(0.05);
ikenna1 35:3341f2bd0408 351 }
ikenna1 35:3341f2bd0408 352 }
ikenna1 35:3341f2bd0408 353 if(ship_ypos > _shooter3_pos.y + 6) {
ikenna1 35:3341f2bd0408 354 col3 = check_collision1(_shooter3_pos.x,9,ship_xpos + 2,3);
ikenna1 35:3341f2bd0408 355 if (col3 == true && A == true) {
ikenna1 36:c25417f0d150 356 _health.shooterh_update(3,5);
ikenna1 35:3341f2bd0408 357 pad.tone(500,0.05);
ikenna1 35:3341f2bd0408 358 wait(0.05);
ikenna1 35:3341f2bd0408 359 }
ikenna1 35:3341f2bd0408 360 }
ikenna1 36:c25417f0d150 361 }
ikenna1 36:c25417f0d150 362 void RosenEngine::score(int points)
ikenna1 36:c25417f0d150 363 {
ikenna1 36:c25417f0d150 364 _score = _score + points;
ikenna1 36:c25417f0d150 365 }
ikenna1 36:c25417f0d150 366 void RosenEngine::check_health()
ikenna1 36:c25417f0d150 367 {
ikenna1 36:c25417f0d150 368 int seeker_health = _health.get_seekerh();
ikenna1 36:c25417f0d150 369 int shooter1_health = _health.get_shooterh(1);
ikenna1 36:c25417f0d150 370 int shooter2_health = _health.get_shooterh(2);
ikenna1 36:c25417f0d150 371 int shooter3_health = _health.get_shooterh(3);
ikenna1 36:c25417f0d150 372
ikenna1 36:c25417f0d150 373 if(seeker_health == 0){
ikenna1 36:c25417f0d150 374 _enemy.reset_seeker();
ikenna1 36:c25417f0d150 375 _health.reset_seekerh();
ikenna1 36:c25417f0d150 376 }
ikenna1 36:c25417f0d150 377 if(shooter1_health == 0){
ikenna1 36:c25417f0d150 378 _enemy.reset_shooter(1);
ikenna1 36:c25417f0d150 379 _health.reset_shooterh(1);
ikenna1 36:c25417f0d150 380 }
ikenna1 36:c25417f0d150 381 if(shooter2_health == 0){
ikenna1 36:c25417f0d150 382 _enemy.reset_shooter(2);
ikenna1 36:c25417f0d150 383 _health.reset_shooterh(2);
ikenna1 36:c25417f0d150 384 }
ikenna1 36:c25417f0d150 385 if(shooter3_health == 0){
ikenna1 36:c25417f0d150 386 _enemy.reset_shooter(3);
ikenna1 36:c25417f0d150 387 _health.reset_shooterh(3);
ikenna1 36:c25417f0d150 388 }
ikenna1 36:c25417f0d150 389
ikenna1 36:c25417f0d150 390 Vector2D hp = _health.get_hp();
ikenna1 36:c25417f0d150 391 if(hp.x <= 0){
ikenna1 36:c25417f0d150 392 printf("player deaad\n");
ikenna1 36:c25417f0d150 393 _dead = true;
ikenna1 36:c25417f0d150 394 }
ikenna1 37:8d8c8cce0bc7 395 }
ikenna1 37:8d8c8cce0bc7 396 int RosenEngine::rand_no()
ikenna1 37:8d8c8cce0bc7 397 {
ikenna1 37:8d8c8cce0bc7 398 srand(time(NULL));
ikenna1 37:8d8c8cce0bc7 399 int rand_no = (rand() %45) + 1;
ikenna1 37:8d8c8cce0bc7 400 printf("random no = %d\n",rand_no);
ikenna1 37:8d8c8cce0bc7 401 return rand_no;
ikenna1 18:2cc6898de6b2 402 }