ELEC2645 (2018/19) / Mbed 2 deprecated el17aio

Dependencies:   mbed

Committer:
ikenna1
Date:
Sat Apr 20 14:10:47 2019 +0000
Revision:
33:7a814c874c57
Parent:
32:098fbc1222cd
Child:
34:6d0786582d81
started working on ship to shooter collision

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