ELEC2645 (2018/19) / Mbed 2 deprecated el17aio

Dependencies:   mbed

Committer:
ikenna1
Date:
Tue Apr 30 05:03:15 2019 +0000
Revision:
34:6d0786582d81
Parent:
33:7a814c874c57
Child:
35:3341f2bd0408
Changed declaration of _shooter1_pos

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 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 14:88ca5b1a111a 37 // printf("_xjoystick ,_yjoystick = %f , %f\n",_xjoystick, _yjoystick);
ikenna1 4:740e14ebbc97 38 }
ikenna1 4:740e14ebbc97 39
ikenna1 14:88ca5b1a111a 40 void RosenEngine::draw(N5110 &lcd, Gamepad &pad)
ikenna1 7:ed5870cfb3e0 41 {
ikenna1 31:c7bd3ed16840 42 lcd.drawRect(0,0,78,48,FILL_TRANSPARENT);
ikenna1 27:f99249e727fd 43 _health.draw_health(lcd,_shipno);
ikenna1 18:2cc6898de6b2 44 _health.draw_shields(lcd);
ikenna1 15:009ccc07bb57 45 _enemy.draw_seeker(lcd);
ikenna1 34:6d0786582d81 46 _enemy.draw_shooter(lcd);
ikenna1 34:6d0786582d81 47 _enemy.draw_shw(lcd,pad);
ikenna1 21:628fb703188f 48 if(_shipno == 0) {
ikenna1 14:88ca5b1a111a 49 _ship.set_dimensions(9,6);
ikenna1 26:a53d41adf40b 50 _ship.draw_ship(lcd,_shipno);
ikenna1 23:0301effce801 51 _weapons.draw(lcd,pad,_shipno);
ikenna1 13:e114d362186d 52 }
ikenna1 21:628fb703188f 53 if(_shipno == 1) {
ikenna1 14:88ca5b1a111a 54 _ship.set_dimensions(7,10);
ikenna1 26:a53d41adf40b 55 _ship.draw_ship(lcd,_shipno);
ikenna1 26:a53d41adf40b 56 _weapons.draw(lcd,pad,_shipno);
ikenna1 26:a53d41adf40b 57 }
ikenna1 26:a53d41adf40b 58 if(_shipno == 2) {
ikenna1 26:a53d41adf40b 59 _ship.set_dimensions(7,10);
ikenna1 26:a53d41adf40b 60 _ship.draw_ship(lcd,_shipno);
ikenna1 23:0301effce801 61 _weapons.draw(lcd,pad,_shipno);
ikenna1 13:e114d362186d 62 }
ikenna1 11:73cd744ffa80 63 }
ikenna1 7:ed5870cfb3e0 64
ikenna1 7:ed5870cfb3e0 65 void RosenEngine::update(Gamepad &pad)
ikenna1 7:ed5870cfb3e0 66 {
ikenna1 34:6d0786582d81 67 /// _enemy.update_seeker(ship_xpos, ship_ypos);
ikenna1 30:711d722f3cef 68 _enemy.update_shooter(ship_xpos, ship_ypos);
ikenna1 32:098fbc1222cd 69 _enemy.update_shw();
ikenna1 21:628fb703188f 70 if(_shipno == 0) {
ikenna1 14:88ca5b1a111a 71 _ship.update_ship(_xjoystick,_yjoystick);
ikenna1 14:88ca5b1a111a 72 _weapons.update();
ikenna1 14:88ca5b1a111a 73 }
ikenna1 23:0301effce801 74 if(_shipno == 1 && A == false) {
ikenna1 14:88ca5b1a111a 75 _ship.update_ship(_xjoystick,_yjoystick);
ikenna1 14:88ca5b1a111a 76 _weapons.update();
ikenna1 14:88ca5b1a111a 77 }
ikenna1 27:f99249e727fd 78 if(_shipno == 2) {
ikenna1 27:f99249e727fd 79 _ship.update_ship(_xjoystick,_yjoystick);
ikenna1 27:f99249e727fd 80 _weapons.update();
ikenna1 27:f99249e727fd 81 }
ikenna1 33:7a814c874c57 82 if(shooter_weapon_collision(3) == true) {
ikenna1 32:098fbc1222cd 83 _health.update(1,pad);
ikenna1 32:098fbc1222cd 84 pad.tone(500,0.05);
ikenna1 32:098fbc1222cd 85 wait(0.05);
ikenna1 33:7a814c874c57 86 }
ikenna1 34:6d0786582d81 87 /*
ikenna1 33:7a814c874c57 88 if(seeker_ship_collision() == true) {
ikenna1 28:6319e928f0aa 89 _health.update(1,pad);
ikenna1 26:a53d41adf40b 90 _enemy.reset_seeker();
ikenna1 28:6319e928f0aa 91 pad.tone(500,0.05);
ikenna1 28:6319e928f0aa 92 wait(0.05);
ikenna1 34:6d0786582d81 93 }*/
ikenna1 28:6319e928f0aa 94 if(enemy_projectile_collision() == true) {
ikenna1 26:a53d41adf40b 95 _enemy.reset_seeker();
ikenna1 28:6319e928f0aa 96 pad.tone(1000,0.05);
ikenna1 28:6319e928f0aa 97 wait(0.05);
ikenna1 28:6319e928f0aa 98 pad.tone(1500,0.05);
ikenna1 28:6319e928f0aa 99 wait(0.05);
ikenna1 28:6319e928f0aa 100 }
ikenna1 34:6d0786582d81 101 Vector2D sh_col = shooter_projectile_collision(); // first vlaue is 1 if col occured and 0 otherwise. second is the shooter that actually collided
ikenna1 34:6d0786582d81 102 if(sh_col.x == 1){
ikenna1 34:6d0786582d81 103 _health.update(2,pad);
ikenna1 34:6d0786582d81 104 pad.tone(500,0.05);
ikenna1 34:6d0786582d81 105 }
ikenna1 34:6d0786582d81 106
ikenna1 28:6319e928f0aa 107 // printf("collision check complete");
ikenna1 33:7a814c874c57 108
ikenna1 28:6319e928f0aa 109 // warning sound
ikenna1 28:6319e928f0aa 110 Vector2D hp = _health.get_hp();
ikenna1 28:6319e928f0aa 111 int health = hp.x;
ikenna1 29:4c7b16b5b6df 112 if(_shipno == 0 || _shipno == 1) {
ikenna1 28:6319e928f0aa 113 if(health <= 2 ) {
ikenna1 29:4c7b16b5b6df 114 pad.tone(1300,0.05);
ikenna1 29:4c7b16b5b6df 115 wait(0.05);
ikenna1 26:a53d41adf40b 116 }
ikenna1 33:7a814c874c57 117 } else if(_shipno == 2) {
ikenna1 28:6319e928f0aa 118 if(health <= 1 ) {
ikenna1 34:6d0786582d81 119 pad.tone(2000,0.05);
ikenna1 29:4c7b16b5b6df 120 wait(0.05);
ikenna1 28:6319e928f0aa 121 }
ikenna1 28:6319e928f0aa 122 }
ikenna1 34:6d0786582d81 123 // printf("health = %d||shipno = %d",health,_shipno);
ikenna1 7:ed5870cfb3e0 124 }
ikenna1 9:241a1a7d8527 125 void RosenEngine::get_pos()
ikenna1 9:241a1a7d8527 126 {
ikenna1 9:241a1a7d8527 127 Vector2D ship_pos = _ship.get_pos();
ikenna1 9:241a1a7d8527 128 ship_xpos = ship_pos.x;
ikenna1 9:241a1a7d8527 129 ship_ypos = ship_pos.y;
ikenna1 34:6d0786582d81 130 _shooter1_pos = _enemy.get_sh1pos();
ikenna1 34:6d0786582d81 131 _shooter2_pos = _enemy.get_sh2pos();
ikenna1 34:6d0786582d81 132 _shooter3_pos = _enemy.get_sh3pos();
ikenna1 9:241a1a7d8527 133 _weapons.init(ship_xpos, ship_ypos, ship_width);
ikenna1 13:e114d362186d 134 _ycursor = _menu.get_ycursor();
ikenna1 25:faba9eb44514 135
ikenna1 25:faba9eb44514 136 if(_shipno == 0) {
ikenna1 25:faba9eb44514 137 ship_width = 9;
ikenna1 25:faba9eb44514 138 ship_height = 6;
ikenna1 25:faba9eb44514 139 }
ikenna1 25:faba9eb44514 140 if(_shipno == 1) {
ikenna1 25:faba9eb44514 141 ship_width = 7;
ikenna1 25:faba9eb44514 142 ship_height = 10;
ikenna1 25:faba9eb44514 143 }
ikenna1 9:241a1a7d8527 144 }
ikenna1 9:241a1a7d8527 145 void RosenEngine::title(N5110 &lcd)
ikenna1 9:241a1a7d8527 146 {
ikenna1 30:711d722f3cef 147 _menu.title(lcd,_shipno);
ikenna1 10:c33d7593a275 148 _menu.update(_d);
ikenna1 10:c33d7593a275 149 }
ikenna1 13:e114d362186d 150 int RosenEngine::get_ycursor()
ikenna1 10:c33d7593a275 151 {
ikenna1 13:e114d362186d 152 _ycursor = _menu.get_ycursor();
ikenna1 10:c33d7593a275 153 return _ycursor;
ikenna1 12:47578eb9ea73 154 }
ikenna1 21:628fb703188f 155 int RosenEngine::get_shipno()
ikenna1 13:e114d362186d 156 {
ikenna1 21:628fb703188f 157 _shipno = _menu.get_xcursor();
ikenna1 21:628fb703188f 158 return _shipno;
ikenna1 13:e114d362186d 159 }
ikenna1 12:47578eb9ea73 160 void RosenEngine::ship_select(N5110 &lcd)
ikenna1 12:47578eb9ea73 161 {
ikenna1 12:47578eb9ea73 162 _menu.update(_d);
ikenna1 12:47578eb9ea73 163 _menu.disp_ships(lcd);
ikenna1 17:e65a9f981834 164 }
ikenna1 33:7a814c874c57 165 bool RosenEngine::seeker_ship_collision()
ikenna1 18:2cc6898de6b2 166 {
ikenna1 25:faba9eb44514 167 // Vector2D ship_pos = _ship.get_pos();
ikenna1 19:3316dba9787e 168 Vector2D seeker_pos = _enemy.get_seekerpos();
ikenna1 25:faba9eb44514 169 int seeker_xpos = seeker_pos.x, seeker_ypos = seeker_pos.y;
ikenna1 25:faba9eb44514 170 int sxcol = 0;
ikenna1 25:faba9eb44514 171 int sycol = 0;
ikenna1 25:faba9eb44514 172 int ship_x[9],ship_y[6],seeker_x[9],seeker_y[6];
ikenna1 25:faba9eb44514 173 // printf("shipx = %d, shipy = %d\n",ship_xpos,ship_ypos);
ikenna1 19:3316dba9787e 174 // create an array of all x positions for the ship sprite i.e along its width (ship_x)
ikenna1 25:faba9eb44514 175 for(int cx = 0; cx<=9; cx=cx+1) {
ikenna1 25:faba9eb44514 176 ship_x[cx] = ship_xpos + cx;
ikenna1 25:faba9eb44514 177 seeker_x[cx] = seeker_xpos + cx;
ikenna1 25:faba9eb44514 178 // printf("ship_x = %d, seeker_x = %d\n", ship_x[cx], seeker_x[cx]);
ikenna1 19:3316dba9787e 179 }
ikenna1 19:3316dba9787e 180
ikenna1 19:3316dba9787e 181 // create an array of all y positions for the ship sprite i.e along its height (ship_y)
ikenna1 25:faba9eb44514 182 for(int cy = 0; cy<=6; cy=cy+1) {
ikenna1 25:faba9eb44514 183 ship_y[cy] = (ship_ypos ) + cy ;
ikenna1 25:faba9eb44514 184 seeker_y[cy] = seeker_ypos + cy;
ikenna1 25:faba9eb44514 185 // printf("ship_y = %d, seeker_y = %d\n", ship_y[cy], seeker_y[cy]);
ikenna1 19:3316dba9787e 186 }
ikenna1 19:3316dba9787e 187 // check all values of ship position against all values of seekers x position
ikenna1 20:5b4b3bf5795c 188 for(int nx = 0; nx<=9; nx=nx+1) {
ikenna1 20:5b4b3bf5795c 189 for(int mx = 0; mx<=9; mx=mx+1) {
ikenna1 19:3316dba9787e 190 if(ship_x[nx] == seeker_x[mx]) {
ikenna1 25:faba9eb44514 191 sxcol = 1;
ikenna1 19:3316dba9787e 192 }
ikenna1 19:3316dba9787e 193 }
ikenna1 19:3316dba9787e 194 }
ikenna1 20:5b4b3bf5795c 195 for(int ny = 0; ny<=6; ny=ny+1) {
ikenna1 20:5b4b3bf5795c 196 for(int my = 0; my<=6; my=my+1) {
ikenna1 19:3316dba9787e 197 if(ship_y[ny] == seeker_y[my]) {
ikenna1 25:faba9eb44514 198 sycol = 1;
ikenna1 19:3316dba9787e 199 }
ikenna1 19:3316dba9787e 200 }
ikenna1 19:3316dba9787e 201 }
ikenna1 20:5b4b3bf5795c 202
ikenna1 34:6d0786582d81 203 printf("sxcol = %d, sycol = %d\n", sxcol, sycol); //************brocken, function stops without it
ikenna1 25:faba9eb44514 204 if(sxcol == 1 && sycol == 1) {
ikenna1 26:a53d41adf40b 205 return true;
ikenna1 26:a53d41adf40b 206 } else {
ikenna1 26:a53d41adf40b 207 return false;
ikenna1 18:2cc6898de6b2 208 }
ikenna1 23:0301effce801 209 }
ikenna1 33:7a814c874c57 210 Vector2D RosenEngine::shooter_projectile_collision()
ikenna1 33:7a814c874c57 211 {
ikenna1 34:6d0786582d81 212 int shooter1_x[11],shooter1_y[10],shooter2_x[11],shooter2_y[10],shooter3_x[11],shooter3_y[10], lazer_x[3];
ikenna1 33:7a814c874c57 213 int wx1col = 0;
ikenna1 33:7a814c874c57 214 int wx2col = 0;
ikenna1 33:7a814c874c57 215 int wx3col = 0;
ikenna1 33:7a814c874c57 216 int wy1col = 0;
ikenna1 33:7a814c874c57 217 int wy2col = 0;
ikenna1 33:7a814c874c57 218 int wy3col = 0;
ikenna1 34:6d0786582d81 219 float shnum; // the shooter that was hit
ikenna1 34:6d0786582d81 220 float coloc; // if collision coocured 1, else 0
ikenna1 33:7a814c874c57 221
ikenna1 33:7a814c874c57 222 // get shooters x any y values and put into arrays
ikenna1 33:7a814c874c57 223 for(int cx = 0; cx<=11; cx=cx+1) {
ikenna1 34:6d0786582d81 224 shooter1_x[cx]= _shooter1_pos.x + cx;
ikenna1 33:7a814c874c57 225 }
ikenna1 33:7a814c874c57 226 for(int cy = 0; cy<=10; cy=cy+1) {
ikenna1 34:6d0786582d81 227 shooter1_y[cy]= _shooter1_pos.y + cy;
ikenna1 33:7a814c874c57 228 }
ikenna1 33:7a814c874c57 229 for(int cx = 0; cx<=11; cx=cx+1) {
ikenna1 34:6d0786582d81 230 shooter2_x[cx]= _shooter2_pos.x + cx;
ikenna1 33:7a814c874c57 231 }
ikenna1 33:7a814c874c57 232 for(int cy = 0; cy<=10; cy=cy+1) {
ikenna1 34:6d0786582d81 233 shooter2_y[cy]= _shooter2_pos.y + cy;
ikenna1 33:7a814c874c57 234 }
ikenna1 33:7a814c874c57 235 for(int cx = 0; cx<=11; cx=cx+1) {
ikenna1 34:6d0786582d81 236 shooter3_x[cx]= _shooter3_pos.x + cx;
ikenna1 33:7a814c874c57 237 }
ikenna1 33:7a814c874c57 238 for(int cy = 0; cy<=10; cy=cy+1) {
ikenna1 34:6d0786582d81 239 shooter3_y[cy]= _shooter3_pos.y + cy;
ikenna1 33:7a814c874c57 240 }
ikenna1 33:7a814c874c57 241
ikenna1 33:7a814c874c57 242 if(_shipno == 0) {
ikenna1 33:7a814c874c57 243 Vector2D missle_pos = _weapons.get_pos(_shipno);
ikenna1 33:7a814c874c57 244
ikenna1 33:7a814c874c57 245 for(int cx = 0; cx<=11; cx=cx+1) {
ikenna1 33:7a814c874c57 246 if(shooter1_x[cx] == missle_pos.x) {
ikenna1 33:7a814c874c57 247 wx1col = 1;
ikenna1 33:7a814c874c57 248 }
ikenna1 33:7a814c874c57 249 if(shooter2_x[cx] == missle_pos.x) {
ikenna1 33:7a814c874c57 250 wx2col = 1;
ikenna1 33:7a814c874c57 251 }
ikenna1 33:7a814c874c57 252 if(shooter3_x[cx] == missle_pos.x) {
ikenna1 33:7a814c874c57 253 wx3col = 1;
ikenna1 33:7a814c874c57 254 }
ikenna1 34:6d0786582d81 255 // printf("shooter1_x = %d,shooter2_x = %d,shooter3_x = %d,missle_pos.x = %f\n",shooter1_x[cx],shooter2_x[cx],shooter3_x[cx],missle_pos.x);
ikenna1 34:6d0786582d81 256 // printf("wx1col = %d,wx2col = %d,wx3col = %d\n",wx1col,wx2col,wx3col);
ikenna1 33:7a814c874c57 257 }
ikenna1 33:7a814c874c57 258
ikenna1 33:7a814c874c57 259 for(int cy = 0; cy<=10; cy=cy+1) {
ikenna1 34:6d0786582d81 260 if(shooter1_y[cy] == missle_pos.y - 5) {
ikenna1 33:7a814c874c57 261 wy1col = 1;
ikenna1 33:7a814c874c57 262 }
ikenna1 34:6d0786582d81 263 if(shooter2_y[cy] == missle_pos.y - 5) {
ikenna1 33:7a814c874c57 264 wy2col = 1;
ikenna1 33:7a814c874c57 265 }
ikenna1 34:6d0786582d81 266 if(shooter3_y[cy] == missle_pos.y - 5) {
ikenna1 33:7a814c874c57 267 wy3col = 1;
ikenna1 33:7a814c874c57 268 }
ikenna1 34:6d0786582d81 269 //printf("shooter1_y = %d,shooter2_y = %d,shooter3_y = %d,missle_pos.y = %f\n",shooter1_y[cy],shooter2_y[cy],shooter3_y[cy],missle_pos.y);
ikenna1 34:6d0786582d81 270 //printf("wy1col = %d,wy2col = %d,wy3col = %d\n",wy1col,wy2col,wy3col);
ikenna1 34:6d0786582d81 271 // it seems to be iffy move the ship to the right to fire at stationary seekers to test uncomment draw seeker
ikenna1 33:7a814c874c57 272 }
ikenna1 33:7a814c874c57 273 if(wx1col == 1 && wy1col == 1) {
ikenna1 33:7a814c874c57 274 _weapons.set_pos(ship_xpos,ship_ypos); // reset missle after contact
ikenna1 34:6d0786582d81 275 shnum = 1;
ikenna1 34:6d0786582d81 276 coloc = 1;
ikenna1 33:7a814c874c57 277 } else if(wx2col == 1 && wy2col == 1) {
ikenna1 33:7a814c874c57 278 _weapons.set_pos(ship_xpos,ship_ypos); // reset missle after contact
ikenna1 34:6d0786582d81 279 shnum = 2;
ikenna1 34:6d0786582d81 280 coloc = 1;
ikenna1 33:7a814c874c57 281 } else if(wx3col == 1 && wy3col == 1) {
ikenna1 33:7a814c874c57 282 _weapons.set_pos(ship_xpos,ship_ypos); // reset missle after contact
ikenna1 34:6d0786582d81 283 shnum = 3;
ikenna1 34:6d0786582d81 284 coloc = 1;
ikenna1 33:7a814c874c57 285 } else {
ikenna1 34:6d0786582d81 286 shnum = 0;
ikenna1 34:6d0786582d81 287 coloc = 0;
ikenna1 33:7a814c874c57 288 }
ikenna1 34:6d0786582d81 289
ikenna1 34:6d0786582d81 290 printf("shnum = %f, coloc = %f\n",shnum,coloc);
ikenna1 33:7a814c874c57 291 }
ikenna1 33:7a814c874c57 292
ikenna1 33:7a814c874c57 293
ikenna1 33:7a814c874c57 294 // imperion lazer
ikenna1 33:7a814c874c57 295 if(_shipno == 1) {
ikenna1 33:7a814c874c57 296 for(int cx = 0; cx<=3; cx=cx+1) {
ikenna1 33:7a814c874c57 297 lazer_x[cx] = (ship_xpos + 2) + cx;
ikenna1 33:7a814c874c57 298 }
ikenna1 33:7a814c874c57 299 // ony register collision if seeker is above ship
ikenna1 34:6d0786582d81 300 if(_shooter1_pos.y + 6 < ship_ypos) {
ikenna1 33:7a814c874c57 301 // check all values of ship position against all values of seekers x position
ikenna1 33:7a814c874c57 302 for(int nx = 0; nx<=3; nx=nx+1) {
ikenna1 33:7a814c874c57 303 for(int mx = 0; mx<=11; mx=mx+1) {
ikenna1 33:7a814c874c57 304 if(lazer_x[nx] == shooter1_x[mx]) {
ikenna1 33:7a814c874c57 305 wx1col = 1;
ikenna1 34:6d0786582d81 306 // printf("lazer_x = %d,shooter1_x = %d\n",lazer_x[nx],shooter1_x[mx]);
ikenna1 33:7a814c874c57 307 }
ikenna1 33:7a814c874c57 308 }
ikenna1 33:7a814c874c57 309 }
ikenna1 33:7a814c874c57 310 }
ikenna1 34:6d0786582d81 311 if(_shooter2_pos.y + 6 < ship_ypos) {
ikenna1 33:7a814c874c57 312 // check all values of ship position against all values of seekers x position
ikenna1 33:7a814c874c57 313 for(int nx = 0; nx<=3; nx=nx+1) {
ikenna1 33:7a814c874c57 314 for(int mx = 0; mx<=11; mx=mx+1) {
ikenna1 33:7a814c874c57 315 if(lazer_x[nx] == shooter2_x[mx]) {
ikenna1 33:7a814c874c57 316 wx2col = 1;
ikenna1 34:6d0786582d81 317 // printf("lazer_x = %d,shooter2_x = %d\n",lazer_x[nx],shooter2_x[mx]);
ikenna1 33:7a814c874c57 318 }
ikenna1 33:7a814c874c57 319 }
ikenna1 33:7a814c874c57 320 }
ikenna1 33:7a814c874c57 321 }
ikenna1 34:6d0786582d81 322 if(_shooter3_pos.y + 6 < ship_ypos) {
ikenna1 33:7a814c874c57 323 // check all values of ship position against all values of seekers x position
ikenna1 33:7a814c874c57 324 for(int nx = 0; nx<=3; nx=nx+1) {
ikenna1 33:7a814c874c57 325 for(int mx = 0; mx<=11; mx=mx+1) {
ikenna1 33:7a814c874c57 326 if(lazer_x[nx] == shooter3_x[mx]) {
ikenna1 33:7a814c874c57 327 wx3col = 1;
ikenna1 34:6d0786582d81 328 // printf("lazer_x = %d,shooter3x = %d\n",lazer_x[nx],shooter3_x[mx]);
ikenna1 33:7a814c874c57 329 }
ikenna1 33:7a814c874c57 330 }
ikenna1 33:7a814c874c57 331 }
ikenna1 33:7a814c874c57 332 }
ikenna1 33:7a814c874c57 333 if(wx1col == 1 && A == true) {
ikenna1 34:6d0786582d81 334 shnum = 1;
ikenna1 34:6d0786582d81 335 coloc = 1;
ikenna1 34:6d0786582d81 336 } else if(wx2col == 1 && A == true) {
ikenna1 34:6d0786582d81 337 shnum = 2;
ikenna1 34:6d0786582d81 338 coloc = 1;
ikenna1 34:6d0786582d81 339 } else if(wx3col == 1 && A == true) {
ikenna1 34:6d0786582d81 340 shnum = 3;
ikenna1 34:6d0786582d81 341 coloc = 1;
ikenna1 34:6d0786582d81 342 } else {
ikenna1 34:6d0786582d81 343 shnum = 0;
ikenna1 34:6d0786582d81 344 coloc = 0;
ikenna1 34:6d0786582d81 345 }
ikenna1 33:7a814c874c57 346 }
ikenna1 33:7a814c874c57 347 if(_shipno == 2) {
ikenna1 34:6d0786582d81 348 shnum = 0;
ikenna1 34:6d0786582d81 349 coloc = 0;
ikenna1 33:7a814c874c57 350 }
ikenna1 34:6d0786582d81 351 return {coloc,shnum};
ikenna1 33:7a814c874c57 352 }
ikenna1 26:a53d41adf40b 353 bool RosenEngine::enemy_projectile_collision()
ikenna1 23:0301effce801 354 {
ikenna1 25:faba9eb44514 355 Vector2D seeker_pos = _enemy.get_seekerpos();
ikenna1 25:faba9eb44514 356 int lazer_x[3],seeker_x[9],seeker_y[38];
ikenna1 25:faba9eb44514 357 int wxcol = 0;
ikenna1 25:faba9eb44514 358 int wycol = 0;
ikenna1 24:ab821bfeb383 359
ikenna1 24:ab821bfeb383 360 // get seekers x any y values and put into arrays
ikenna1 25:faba9eb44514 361 for(int cx = 0; cx<=9; cx=cx+1) {
ikenna1 25:faba9eb44514 362 seeker_x[cx] = seeker_pos.x + cx;
ikenna1 24:ab821bfeb383 363 }
ikenna1 25:faba9eb44514 364 for(int cy = 0; cy<=6; cy=cy+1) {
ikenna1 25:faba9eb44514 365 seeker_y[cy] = seeker_pos.y + cy;
ikenna1 24:ab821bfeb383 366 }
ikenna1 25:faba9eb44514 367
ikenna1 25:faba9eb44514 368 // kestrel artemis missle
ikenna1 24:ab821bfeb383 369 if(_shipno == 0) {
ikenna1 25:faba9eb44514 370 Vector2D missle_pos = _weapons.get_pos(_shipno);
ikenna1 24:ab821bfeb383 371
ikenna1 25:faba9eb44514 372 for(int cx = 0; cx<=9; cx=cx+1) {
ikenna1 25:faba9eb44514 373 seeker_x[cx] = seeker_pos.x + cx;
ikenna1 25:faba9eb44514 374 if(seeker_x[cx] == missle_pos.x) {
ikenna1 34:6d0786582d81 375 // printf("seeker_xpos = %f, missle_xpos = %f\n",seeker_pos.x,missle_pos.x);
ikenna1 25:faba9eb44514 376 wxcol = 1;
ikenna1 25:faba9eb44514 377 }
ikenna1 25:faba9eb44514 378 }
ikenna1 25:faba9eb44514 379 for(int cy = 0; cy<=7; cy=cy+1) {
ikenna1 25:faba9eb44514 380 seeker_y[cy] = seeker_pos.y + cy;
ikenna1 26:a53d41adf40b 381 if(seeker_y[cy] == missle_pos.y + 4) {
ikenna1 34:6d0786582d81 382 // printf("seeker_ypos = %f, missle_ypos = %f\n",seeker_pos.y,missle_pos.y);
ikenna1 25:faba9eb44514 383 wycol = 1;
ikenna1 25:faba9eb44514 384 }
ikenna1 25:faba9eb44514 385 }
ikenna1 25:faba9eb44514 386 if(wxcol == 1 && wycol == 1) {
ikenna1 27:f99249e727fd 387 _weapons.set_pos(ship_xpos,ship_ypos); // reset missle after contact
ikenna1 26:a53d41adf40b 388 return true;
ikenna1 25:faba9eb44514 389 }
ikenna1 24:ab821bfeb383 390 }
ikenna1 25:faba9eb44514 391
ikenna1 25:faba9eb44514 392
ikenna1 25:faba9eb44514 393 // imperion lazer
ikenna1 24:ab821bfeb383 394 if(_shipno == 1) {
ikenna1 25:faba9eb44514 395 for(int cx = 0; cx<=3; cx=cx+1) {
ikenna1 25:faba9eb44514 396 lazer_x[cx] = (ship_xpos + 2) + cx;
ikenna1 24:ab821bfeb383 397 }
ikenna1 24:ab821bfeb383 398 // ony register collision if seeker is above ship
ikenna1 25:faba9eb44514 399 if(seeker_pos.y + 6 < ship_ypos) {
ikenna1 24:ab821bfeb383 400 // check all values of ship position against all values of seekers x position
ikenna1 24:ab821bfeb383 401 for(int nx = 0; nx<=3; nx=nx+1) {
ikenna1 24:ab821bfeb383 402 for(int mx = 0; mx<=9; mx=mx+1) {
ikenna1 24:ab821bfeb383 403 if(lazer_x[nx] == seeker_x[mx]) {
ikenna1 25:faba9eb44514 404 wxcol = 1;
ikenna1 34:6d0786582d81 405 // printf("lazer_x = %d,seeker_x = %f\n",lazer_x[nx],seeker_x[mx]);
ikenna1 24:ab821bfeb383 406 }
ikenna1 24:ab821bfeb383 407 }
ikenna1 24:ab821bfeb383 408 }
ikenna1 24:ab821bfeb383 409 }
ikenna1 25:faba9eb44514 410 if(wxcol == 1 && A == true) {
ikenna1 26:a53d41adf40b 411 return true;
ikenna1 28:6319e928f0aa 412 } else {
ikenna1 26:a53d41adf40b 413 return false;
ikenna1 24:ab821bfeb383 414 }
ikenna1 23:0301effce801 415 }
ikenna1 27:f99249e727fd 416 if(_shipno == 2) {
ikenna1 27:f99249e727fd 417 return false;
ikenna1 28:6319e928f0aa 418 }
ikenna1 29:4c7b16b5b6df 419 }
ikenna1 32:098fbc1222cd 420 bool RosenEngine::shooter_weapon_collision(int sh_no)
ikenna1 32:098fbc1222cd 421 {
ikenna1 32:098fbc1222cd 422 Vector2D shw1_pos = _enemy.get_sh1pos();
ikenna1 32:098fbc1222cd 423 Vector2D shw2_pos = _enemy.get_sh2pos();
ikenna1 32:098fbc1222cd 424 Vector2D shw3_pos = _enemy.get_sh3pos();
ikenna1 33:7a814c874c57 425
ikenna1 32:098fbc1222cd 426 bool shw1xcol = false;
ikenna1 32:098fbc1222cd 427 bool shw1ycol = false;
ikenna1 32:098fbc1222cd 428 bool shw2xcol = false;
ikenna1 32:098fbc1222cd 429 bool shw2ycol = false;
ikenna1 32:098fbc1222cd 430 bool shw3xcol = false;
ikenna1 32:098fbc1222cd 431 bool shw3ycol = false;
ikenna1 33:7a814c874c57 432
ikenna1 32:098fbc1222cd 433 int ship_x[9];
ikenna1 32:098fbc1222cd 434 int ship_y[6];
ikenna1 33:7a814c874c57 435
ikenna1 32:098fbc1222cd 436 for(int cx = 0; cx<=9; cx=cx+1) {
ikenna1 32:098fbc1222cd 437 ship_x[cx] = ship_xpos + cx;
ikenna1 33:7a814c874c57 438 if(ship_x[cx] == shw1_pos.x) {
ikenna1 32:098fbc1222cd 439 shw1xcol = true;
ikenna1 33:7a814c874c57 440 }
ikenna1 33:7a814c874c57 441 if(ship_x[cx] == shw2_pos.x) {
ikenna1 32:098fbc1222cd 442 shw2xcol = true;
ikenna1 33:7a814c874c57 443 }
ikenna1 33:7a814c874c57 444 if(ship_x[cx] == shw3_pos.x) {
ikenna1 32:098fbc1222cd 445 shw3xcol = true;
ikenna1 33:7a814c874c57 446 }
ikenna1 32:098fbc1222cd 447 }
ikenna1 32:098fbc1222cd 448 for(int cy = 0; cy<=6; cy=cy+1) {
ikenna1 32:098fbc1222cd 449 ship_y[cy] = (ship_ypos ) + cy ;
ikenna1 33:7a814c874c57 450 if(ship_y[cy] == shw1_pos.y) {
ikenna1 32:098fbc1222cd 451 shw1ycol = true;
ikenna1 32:098fbc1222cd 452 }
ikenna1 33:7a814c874c57 453 if(ship_y[cy] == shw2_pos.y) {
ikenna1 32:098fbc1222cd 454 shw2ycol = true;
ikenna1 33:7a814c874c57 455 }
ikenna1 33:7a814c874c57 456 if(ship_y[cy] == shw3_pos.y) {
ikenna1 32:098fbc1222cd 457 shw3ycol = true;
ikenna1 33:7a814c874c57 458 }
ikenna1 32:098fbc1222cd 459 }
ikenna1 33:7a814c874c57 460 if(sh_no == 1) {
ikenna1 33:7a814c874c57 461 shw2xcol = false;
ikenna1 32:098fbc1222cd 462 shw2ycol = false;
ikenna1 33:7a814c874c57 463 shw3xcol = false;
ikenna1 32:098fbc1222cd 464 shw3ycol = false;
ikenna1 33:7a814c874c57 465 }
ikenna1 33:7a814c874c57 466 if(sh_no == 2) {
ikenna1 33:7a814c874c57 467 shw3xcol = false;
ikenna1 32:098fbc1222cd 468 shw3ycol = false;
ikenna1 33:7a814c874c57 469 }
ikenna1 33:7a814c874c57 470
ikenna1 33:7a814c874c57 471 if(shw1xcol && shw1ycol == true || shw2xcol && shw2ycol == true || shw3xcol && shw3ycol == true) {
ikenna1 32:098fbc1222cd 472 return true;
ikenna1 33:7a814c874c57 473 } else {
ikenna1 32:098fbc1222cd 474 return false;
ikenna1 33:7a814c874c57 475 }
ikenna1 32:098fbc1222cd 476 }
ikenna1 33:7a814c874c57 477 void RosenEngine::score(int points)
ikenna1 33:7a814c874c57 478 {
ikenna1 30:711d722f3cef 479 _score = _score + points;
ikenna1 18:2cc6898de6b2 480 }