ELEC2645 (2018/19) / Mbed 2 deprecated el17aio

Dependencies:   mbed

Committer:
ikenna1
Date:
Sun May 05 08:50:15 2019 +0000
Revision:
38:4571537238ed
Parent:
37:8d8c8cce0bc7
Child:
39:7824f9080f59
*Add missions to game

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 38:4571537238ed 21 _no_shooters = 1;
ikenna1 38:4571537238ed 22 _enemy.init(_no_shooters);
ikenna1 9:241a1a7d8527 23 _menu.init(16);
ikenna1 21:628fb703188f 24 _health.init(_shipno);
ikenna1 38:4571537238ed 25 _times_run = 0;
ikenna1 38:4571537238ed 26 _score = 0;
ikenna1 38:4571537238ed 27 _dead = false;
ikenna1 13:e114d362186d 28
ikenna1 3:f9cd1a38d5c6 29 }
ikenna1 27:f99249e727fd 30 void RosenEngine::reset()
ikenna1 27:f99249e727fd 31 {
ikenna1 38:4571537238ed 32 _enemy.init(_no_shooters);
ikenna1 27:f99249e727fd 33 _health.init(_shipno);
ikenna1 38:4571537238ed 34 _times_run = 0;
ikenna1 38:4571537238ed 35 _score = 0;
ikenna1 38:4571537238ed 36 _no_shooters = 1;
ikenna1 38:4571537238ed 37 _dead = false;
ikenna1 27:f99249e727fd 38 }
ikenna1 4:740e14ebbc97 39
ikenna1 5:bb6edc5b5be3 40 void RosenEngine::read_input(Gamepad &pad)
ikenna1 4:740e14ebbc97 41 {
ikenna1 4:740e14ebbc97 42 Vector2D mapped_coord = pad.get_coord();
ikenna1 8:87a845b8575e 43 _xjoystick = mapped_coord.x;
ikenna1 8:87a845b8575e 44 _yjoystick = mapped_coord.y;
ikenna1 9:241a1a7d8527 45 _d = pad.get_direction();
ikenna1 35:3341f2bd0408 46 wait(0.1);
ikenna1 14:88ca5b1a111a 47 // printf("_xjoystick ,_yjoystick = %f , %f\n",_xjoystick, _yjoystick);
ikenna1 4:740e14ebbc97 48 }
ikenna1 4:740e14ebbc97 49
ikenna1 14:88ca5b1a111a 50 void RosenEngine::draw(N5110 &lcd, Gamepad &pad)
ikenna1 7:ed5870cfb3e0 51 {
ikenna1 31:c7bd3ed16840 52 lcd.drawRect(0,0,78,48,FILL_TRANSPARENT);
ikenna1 27:f99249e727fd 53 _health.draw_health(lcd,_shipno);
ikenna1 18:2cc6898de6b2 54 _health.draw_shields(lcd);
ikenna1 15:009ccc07bb57 55 _enemy.draw_seeker(lcd);
ikenna1 34:6d0786582d81 56 _enemy.draw_shooter(lcd);
ikenna1 34:6d0786582d81 57 _enemy.draw_shw(lcd,pad);
ikenna1 21:628fb703188f 58 if(_shipno == 0) {
ikenna1 14:88ca5b1a111a 59 _ship.set_dimensions(9,6);
ikenna1 26:a53d41adf40b 60 _ship.draw_ship(lcd,_shipno);
ikenna1 23:0301effce801 61 _weapons.draw(lcd,pad,_shipno);
ikenna1 13:e114d362186d 62 }
ikenna1 21:628fb703188f 63 if(_shipno == 1) {
ikenna1 14:88ca5b1a111a 64 _ship.set_dimensions(7,10);
ikenna1 26:a53d41adf40b 65 _ship.draw_ship(lcd,_shipno);
ikenna1 26:a53d41adf40b 66 _weapons.draw(lcd,pad,_shipno);
ikenna1 26:a53d41adf40b 67 }
ikenna1 26:a53d41adf40b 68 if(_shipno == 2) {
ikenna1 26:a53d41adf40b 69 _ship.set_dimensions(7,10);
ikenna1 26:a53d41adf40b 70 _ship.draw_ship(lcd,_shipno);
ikenna1 23:0301effce801 71 _weapons.draw(lcd,pad,_shipno);
ikenna1 13:e114d362186d 72 }
ikenna1 38:4571537238ed 73 if(_dead == true){
ikenna1 38:4571537238ed 74 game_over(lcd);
ikenna1 38:4571537238ed 75 }
ikenna1 11:73cd744ffa80 76 }
ikenna1 7:ed5870cfb3e0 77
ikenna1 7:ed5870cfb3e0 78 void RosenEngine::update(Gamepad &pad)
ikenna1 7:ed5870cfb3e0 79 {
ikenna1 35:3341f2bd0408 80 _enemy.update_seeker(ship_xpos, ship_ypos);
ikenna1 30:711d722f3cef 81 _enemy.update_shooter(ship_xpos, ship_ypos);
ikenna1 35:3341f2bd0408 82 //printf("update_shooter\n");
ikenna1 32:098fbc1222cd 83 _enemy.update_shw();
ikenna1 21:628fb703188f 84 if(_shipno == 0) {
ikenna1 14:88ca5b1a111a 85 _ship.update_ship(_xjoystick,_yjoystick);
ikenna1 14:88ca5b1a111a 86 _weapons.update();
ikenna1 35:3341f2bd0408 87 kestrelw_seeker_collision(pad);
ikenna1 14:88ca5b1a111a 88 }
ikenna1 35:3341f2bd0408 89 //printf("if shipno == 0\n");
ikenna1 23:0301effce801 90 if(_shipno == 1 && A == false) {
ikenna1 14:88ca5b1a111a 91 _ship.update_ship(_xjoystick,_yjoystick);
ikenna1 14:88ca5b1a111a 92 _weapons.update();
ikenna1 14:88ca5b1a111a 93 }
ikenna1 35:3341f2bd0408 94 //printf("if shipno == 1\n");
ikenna1 27:f99249e727fd 95 if(_shipno == 2) {
ikenna1 27:f99249e727fd 96 _ship.update_ship(_xjoystick,_yjoystick);
ikenna1 27:f99249e727fd 97 _weapons.update();
ikenna1 27:f99249e727fd 98 }
ikenna1 35:3341f2bd0408 99 // test();
ikenna1 35:3341f2bd0408 100 shooter_ship_collision(pad);
ikenna1 35:3341f2bd0408 101 seeker_ship_collision(pad);
ikenna1 35:3341f2bd0408 102 shooterw_ship_collision(pad);
ikenna1 35:3341f2bd0408 103 imperionw_seeker_collision(pad);
ikenna1 35:3341f2bd0408 104 kestrelw_shooter_collision(pad);
ikenna1 35:3341f2bd0408 105 imperionw_shooter_collision(pad);
ikenna1 36:c25417f0d150 106 check_health();
ikenna1 37:8d8c8cce0bc7 107 rand_no();
ikenna1 38:4571537238ed 108 scaling(timer(12));
ikenna1 38:4571537238ed 109
ikenna1 7:ed5870cfb3e0 110 }
ikenna1 9:241a1a7d8527 111 void RosenEngine::get_pos()
ikenna1 9:241a1a7d8527 112 {
ikenna1 9:241a1a7d8527 113 Vector2D ship_pos = _ship.get_pos();
ikenna1 9:241a1a7d8527 114 ship_xpos = ship_pos.x;
ikenna1 9:241a1a7d8527 115 ship_ypos = ship_pos.y;
ikenna1 35:3341f2bd0408 116
ikenna1 37:8d8c8cce0bc7 117 _shooter1_pos = _enemy.get_shooterpos(1);
ikenna1 37:8d8c8cce0bc7 118 _shooter2_pos = _enemy.get_shooterpos(2);
ikenna1 37:8d8c8cce0bc7 119 _shooter3_pos = _enemy.get_shooterpos(3);
ikenna1 35:3341f2bd0408 120
ikenna1 9:241a1a7d8527 121 _weapons.init(ship_xpos, ship_ypos, ship_width);
ikenna1 13:e114d362186d 122 _ycursor = _menu.get_ycursor();
ikenna1 25:faba9eb44514 123
ikenna1 25:faba9eb44514 124 if(_shipno == 0) {
ikenna1 25:faba9eb44514 125 ship_width = 9;
ikenna1 25:faba9eb44514 126 ship_height = 6;
ikenna1 25:faba9eb44514 127 }
ikenna1 25:faba9eb44514 128 if(_shipno == 1) {
ikenna1 25:faba9eb44514 129 ship_width = 7;
ikenna1 25:faba9eb44514 130 ship_height = 10;
ikenna1 25:faba9eb44514 131 }
ikenna1 9:241a1a7d8527 132 }
ikenna1 9:241a1a7d8527 133 void RosenEngine::title(N5110 &lcd)
ikenna1 9:241a1a7d8527 134 {
ikenna1 30:711d722f3cef 135 _menu.title(lcd,_shipno);
ikenna1 10:c33d7593a275 136 _menu.update(_d);
ikenna1 10:c33d7593a275 137 }
ikenna1 13:e114d362186d 138 int RosenEngine::get_ycursor()
ikenna1 10:c33d7593a275 139 {
ikenna1 13:e114d362186d 140 _ycursor = _menu.get_ycursor();
ikenna1 10:c33d7593a275 141 return _ycursor;
ikenna1 12:47578eb9ea73 142 }
ikenna1 21:628fb703188f 143 int RosenEngine::get_shipno()
ikenna1 13:e114d362186d 144 {
ikenna1 21:628fb703188f 145 _shipno = _menu.get_xcursor();
ikenna1 21:628fb703188f 146 return _shipno;
ikenna1 13:e114d362186d 147 }
ikenna1 12:47578eb9ea73 148 void RosenEngine::ship_select(N5110 &lcd)
ikenna1 12:47578eb9ea73 149 {
ikenna1 12:47578eb9ea73 150 _menu.update(_d);
ikenna1 12:47578eb9ea73 151 _menu.disp_ships(lcd);
ikenna1 17:e65a9f981834 152 }
ikenna1 35:3341f2bd0408 153 bool RosenEngine::check_collision(int xpos1, int ypos1,int width1,int height1,int xpos2, int ypos2,int width2,int height2)
ikenna1 35:3341f2bd0408 154 {
ikenna1 35:3341f2bd0408 155 // Create arrays of all positions with appropriate height and length
ikenna1 35:3341f2bd0408 156 int xpos1_array[width1];
ikenna1 35:3341f2bd0408 157 int ypos1_array[height1];
ikenna1 35:3341f2bd0408 158 int xpos2_array[width2];
ikenna1 35:3341f2bd0408 159 int ypos2_array[height2];
ikenna1 35:3341f2bd0408 160 bool xcol = false;
ikenna1 35:3341f2bd0408 161 bool ycol = false;
ikenna1 35:3341f2bd0408 162 bool col = false;
ikenna1 35:3341f2bd0408 163 //printf("variables declared\n");
ikenna1 35:3341f2bd0408 164 // Loop through both height and width to get a 2D aray of the sprites position
ikenna1 35:3341f2bd0408 165 for(int cx = 0; cx<width1; cx=cx+1) {
ikenna1 35:3341f2bd0408 166 xpos1_array[cx]= xpos1 + cx;
ikenna1 35:3341f2bd0408 167 for(int nx = 0; nx<width2; nx=nx+1) {
ikenna1 35:3341f2bd0408 168 xpos2_array[nx]= xpos2 + nx;
ikenna1 35:3341f2bd0408 169 if(xpos2_array[nx] == xpos1_array[cx]) {
ikenna1 35:3341f2bd0408 170 xcol = true;
ikenna1 35:3341f2bd0408 171 }
ikenna1 35:3341f2bd0408 172 // printf("xarray = %d,x2array = %d,xcol = %d\n",xpos2_array[nx],xpos1_array[cx],xcol);
ikenna1 35:3341f2bd0408 173 }
ikenna1 35:3341f2bd0408 174 }
ikenna1 35:3341f2bd0408 175 //printf("first loop done\n");
ikenna1 35:3341f2bd0408 176 for(int cy = 0; cy<height1; cy=cy+1) {
ikenna1 35:3341f2bd0408 177 ypos1_array[cy]= ypos1 + cy;
ikenna1 35:3341f2bd0408 178 for(int ny = 0; ny<height2; ny=ny+1) {
ikenna1 35:3341f2bd0408 179 ypos2_array[ny]= ypos2 + ny;
ikenna1 35:3341f2bd0408 180 if(ypos2_array[ny] == ypos1_array[cy]) {
ikenna1 35:3341f2bd0408 181 ycol = true;
ikenna1 35:3341f2bd0408 182 }
ikenna1 35:3341f2bd0408 183 // printf("yarray = %d,y2array = %d,ycol = %d\n",ypos2_array[ny],ypos1_array[cy],ycol);
ikenna1 35:3341f2bd0408 184 }
ikenna1 35:3341f2bd0408 185 }
ikenna1 35:3341f2bd0408 186 //printf("second loop done\n");
ikenna1 35:3341f2bd0408 187 // if both the hight and width position values are equal a collision has occured
ikenna1 35:3341f2bd0408 188 col = (xcol & ycol);
ikenna1 35:3341f2bd0408 189 //printf("col gotten, col = %d\n",col);
ikenna1 35:3341f2bd0408 190 return col;
ikenna1 35:3341f2bd0408 191 }
ikenna1 35:3341f2bd0408 192 bool RosenEngine::check_collision1(int xpos1,int width1,int xpos2,int width2)
ikenna1 35:3341f2bd0408 193 {
ikenna1 35:3341f2bd0408 194 // Create arrays of all positions with appropriate height and length
ikenna1 35:3341f2bd0408 195 int xpos1_array[width1];
ikenna1 35:3341f2bd0408 196 int xpos2_array[width2];
ikenna1 35:3341f2bd0408 197 bool xcol = false;
ikenna1 35:3341f2bd0408 198
ikenna1 35:3341f2bd0408 199 for(int cx = 0; cx<width1; cx=cx+1) {
ikenna1 35:3341f2bd0408 200 xpos1_array[cx]= xpos1 + cx;
ikenna1 35:3341f2bd0408 201 for(int nx = 0; nx<width2; nx=nx+1) {
ikenna1 35:3341f2bd0408 202 xpos2_array[nx]= xpos2 + nx;
ikenna1 35:3341f2bd0408 203 if(xpos2_array[nx] == xpos1_array[cx]) {
ikenna1 35:3341f2bd0408 204 xcol = true;
ikenna1 35:3341f2bd0408 205 }
ikenna1 35:3341f2bd0408 206 // printf("xarray = %d,x2array = %d,xcol = %d\n",xpos2_array[nx],xpos1_array[cx],xcol);
ikenna1 35:3341f2bd0408 207 }
ikenna1 35:3341f2bd0408 208 }
ikenna1 35:3341f2bd0408 209 return xcol;
ikenna1 35:3341f2bd0408 210 }
ikenna1 35:3341f2bd0408 211
ikenna1 35:3341f2bd0408 212 void RosenEngine::test()
ikenna1 35:3341f2bd0408 213 {
ikenna1 35:3341f2bd0408 214 bool test;
ikenna1 35:3341f2bd0408 215 test = check_collision(5,5,5,5,5,5,5,5);
ikenna1 35:3341f2bd0408 216 if (test == false) {
ikenna1 35:3341f2bd0408 217 printf("fail\n");
ikenna1 35:3341f2bd0408 218 } else {
ikenna1 35:3341f2bd0408 219 printf("pass\n");
ikenna1 35:3341f2bd0408 220 }
ikenna1 35:3341f2bd0408 221 test = check_collision(0,0,1,1,24,24,1,1);
ikenna1 35:3341f2bd0408 222 if (test == true) {
ikenna1 35:3341f2bd0408 223 printf("fail\n");
ikenna1 35:3341f2bd0408 224 } else {
ikenna1 35:3341f2bd0408 225 printf("pass\n");
ikenna1 35:3341f2bd0408 226 }
ikenna1 35:3341f2bd0408 227 }
ikenna1 35:3341f2bd0408 228 // make function resemble test
ikenna1 35:3341f2bd0408 229
ikenna1 35:3341f2bd0408 230 void RosenEngine::seeker_ship_collision(Gamepad &pad)
ikenna1 35:3341f2bd0408 231 {
ikenna1 35:3341f2bd0408 232 Vector2D seeker_pos = _enemy.get_seekerpos();
ikenna1 35:3341f2bd0408 233 bool collision;
ikenna1 35:3341f2bd0408 234 collision = check_collision(seeker_pos.x,seeker_pos.y,5,5,ship_xpos,ship_ypos,5,5);
ikenna1 35:3341f2bd0408 235 if (collision == true) {
ikenna1 35:3341f2bd0408 236 _health.update(1,pad);
ikenna1 35:3341f2bd0408 237 _enemy.reset_seeker();
ikenna1 35:3341f2bd0408 238 pad.tone(500,0.05);
ikenna1 35:3341f2bd0408 239 wait(0.05);
ikenna1 35:3341f2bd0408 240 }
ikenna1 35:3341f2bd0408 241 }
ikenna1 35:3341f2bd0408 242 void RosenEngine::shooter_ship_collision(Gamepad &pad)
ikenna1 35:3341f2bd0408 243 {
ikenna1 35:3341f2bd0408 244 bool collision1;
ikenna1 35:3341f2bd0408 245 bool collision2;
ikenna1 35:3341f2bd0408 246 bool collision3;
ikenna1 35:3341f2bd0408 247
ikenna1 35:3341f2bd0408 248 collision1 = check_collision(ship_xpos,ship_ypos,9,6,_shooter1_pos.x, _shooter1_pos.y,10,7);
ikenna1 35:3341f2bd0408 249 collision2 = check_collision(ship_xpos,ship_ypos,9,6,_shooter2_pos.x, _shooter2_pos.y,10,7);
ikenna1 35:3341f2bd0408 250 collision3 = check_collision(ship_xpos,ship_ypos,9,6,_shooter3_pos.x, _shooter3_pos.y,10,7);
ikenna1 35:3341f2bd0408 251
ikenna1 38:4571537238ed 252 if(collision1 == true && _no_shooters == 1) {
ikenna1 35:3341f2bd0408 253 _health.update(1,pad);
ikenna1 35:3341f2bd0408 254 pad.tone(500,0.05);
ikenna1 35:3341f2bd0408 255 wait(0.05);
ikenna1 35:3341f2bd0408 256 }
ikenna1 38:4571537238ed 257 if(collision2 == true && _no_shooters == 2) {
ikenna1 35:3341f2bd0408 258 _health.update(1,pad);
ikenna1 35:3341f2bd0408 259 pad.tone(500,0.05);
ikenna1 35:3341f2bd0408 260 wait(0.05);
ikenna1 35:3341f2bd0408 261 }
ikenna1 38:4571537238ed 262 if(collision3 == true && _no_shooters == 3) {
ikenna1 35:3341f2bd0408 263 _health.update(1,pad);
ikenna1 35:3341f2bd0408 264 pad.tone(500,0.05);
ikenna1 35:3341f2bd0408 265 wait(0.05);
ikenna1 35:3341f2bd0408 266 }
ikenna1 35:3341f2bd0408 267 }
ikenna1 35:3341f2bd0408 268 void RosenEngine::shooterw_ship_collision(Gamepad &pad)
ikenna1 35:3341f2bd0408 269 {
ikenna1 37:8d8c8cce0bc7 270 Vector2D _shooterw1_pos = _enemy.get_shwpos(1);
ikenna1 37:8d8c8cce0bc7 271 Vector2D _shooterw2_pos = _enemy.get_shwpos(2);
ikenna1 37:8d8c8cce0bc7 272 Vector2D _shooterw3_pos = _enemy.get_shwpos(3);
ikenna1 35:3341f2bd0408 273
ikenna1 35:3341f2bd0408 274 bool collision1;
ikenna1 35:3341f2bd0408 275 bool collision2;
ikenna1 35:3341f2bd0408 276 bool collision3;
ikenna1 35:3341f2bd0408 277
ikenna1 35:3341f2bd0408 278 collision1 = check_collision(ship_xpos,ship_ypos,9,6,_shooterw1_pos.x, _shooterw1_pos.y,2,2);
ikenna1 35:3341f2bd0408 279 collision2 = check_collision(ship_xpos,ship_ypos,9,6,_shooterw2_pos.x, _shooterw2_pos.y,2,2);
ikenna1 35:3341f2bd0408 280 collision3 = check_collision(ship_xpos,ship_ypos,9,6,_shooterw3_pos.x, _shooterw3_pos.y,2,2);
ikenna1 35:3341f2bd0408 281
ikenna1 38:4571537238ed 282 if(collision1 == true && _no_shooters == 1) {
ikenna1 35:3341f2bd0408 283 _health.update(1,pad);
ikenna1 35:3341f2bd0408 284 pad.tone(500,0.05);
ikenna1 35:3341f2bd0408 285 wait(0.05);
ikenna1 35:3341f2bd0408 286 }
ikenna1 38:4571537238ed 287 if(collision2 == true && _no_shooters == 2) {
ikenna1 35:3341f2bd0408 288 _health.update(1,pad);
ikenna1 35:3341f2bd0408 289 pad.tone(500,0.05);
ikenna1 35:3341f2bd0408 290 wait(0.05);
ikenna1 35:3341f2bd0408 291 }
ikenna1 38:4571537238ed 292 if(collision3 == true && _no_shooters == 3) {
ikenna1 35:3341f2bd0408 293 _health.update(1,pad);
ikenna1 35:3341f2bd0408 294 pad.tone(500,0.05);
ikenna1 35:3341f2bd0408 295 wait(0.05);
ikenna1 35:3341f2bd0408 296 }
ikenna1 35:3341f2bd0408 297 }
ikenna1 35:3341f2bd0408 298 void RosenEngine::kestrelw_seeker_collision(Gamepad &pad)
ikenna1 35:3341f2bd0408 299 {
ikenna1 35:3341f2bd0408 300 Vector2D seeker_pos = _enemy.get_seekerpos();
ikenna1 35:3341f2bd0408 301 Vector2D missle_pos = _weapons.get_pos(_shipno);
ikenna1 35:3341f2bd0408 302 bool collision;
ikenna1 35:3341f2bd0408 303 collision = check_collision(seeker_pos.x,seeker_pos.y,9,6,missle_pos.x,missle_pos.y,1,1);
ikenna1 35:3341f2bd0408 304 if (collision == true) {
ikenna1 36:c25417f0d150 305 _health.seekerh_update(5);
ikenna1 35:3341f2bd0408 306 pad.tone(500,0.05);
ikenna1 35:3341f2bd0408 307 wait(0.05);
ikenna1 35:3341f2bd0408 308 }
ikenna1 35:3341f2bd0408 309 }
ikenna1 35:3341f2bd0408 310 void RosenEngine::imperionw_seeker_collision(Gamepad &pad)
ikenna1 35:3341f2bd0408 311 {
ikenna1 35:3341f2bd0408 312 Vector2D seeker_pos = _enemy.get_seekerpos();
ikenna1 35:3341f2bd0408 313 bool collision;
ikenna1 35:3341f2bd0408 314 if(ship_ypos > seeker_pos.y + 6) {
ikenna1 35:3341f2bd0408 315 collision = check_collision1(seeker_pos.x,9,ship_xpos + 2,3);
ikenna1 35:3341f2bd0408 316 if (collision == true && A == true) {
ikenna1 36:c25417f0d150 317 _health.seekerh_update(5);
ikenna1 35:3341f2bd0408 318 pad.tone(500,0.05);
ikenna1 35:3341f2bd0408 319 wait(0.05);
ikenna1 35:3341f2bd0408 320 }
ikenna1 35:3341f2bd0408 321 }
ikenna1 35:3341f2bd0408 322 }
ikenna1 35:3341f2bd0408 323 void RosenEngine::kestrelw_shooter_collision(Gamepad &pad)
ikenna1 35:3341f2bd0408 324 {
ikenna1 35:3341f2bd0408 325 Vector2D missle_pos = _weapons.get_pos(_shipno);
ikenna1 35:3341f2bd0408 326 bool col1, col2, col3;
ikenna1 35:3341f2bd0408 327 col1 = check_collision(_shooter1_pos.x,_shooter1_pos.y,9,6,missle_pos.x,missle_pos.y,1,1);
ikenna1 35:3341f2bd0408 328 col2 = check_collision(_shooter2_pos.x,_shooter2_pos.y,9,6,missle_pos.x,missle_pos.y,1,1);
ikenna1 35:3341f2bd0408 329 col3 = check_collision(_shooter3_pos.x,_shooter3_pos.y,9,6,missle_pos.x,missle_pos.y,1,1);
ikenna1 38:4571537238ed 330 if (col1 == true && _no_shooters == 1) {
ikenna1 35:3341f2bd0408 331 pad.tone(500,0.05);
ikenna1 36:c25417f0d150 332 _health.shooterh_update(1,5);
ikenna1 35:3341f2bd0408 333 wait(0.05);
ikenna1 35:3341f2bd0408 334 }
ikenna1 38:4571537238ed 335 if (col2 == true && _no_shooters == 2) {
ikenna1 36:c25417f0d150 336 _health.shooterh_update(2,5);
ikenna1 35:3341f2bd0408 337 pad.tone(500,0.05);
ikenna1 35:3341f2bd0408 338 wait(0.05);
ikenna1 35:3341f2bd0408 339 }
ikenna1 38:4571537238ed 340 if (col3 == true && _no_shooters == 3) {
ikenna1 36:c25417f0d150 341 _health.shooterh_update(3,5);
ikenna1 35:3341f2bd0408 342 pad.tone(500,0.05);
ikenna1 35:3341f2bd0408 343 wait(0.05);
ikenna1 35:3341f2bd0408 344 }
ikenna1 35:3341f2bd0408 345 }
ikenna1 35:3341f2bd0408 346 void RosenEngine::imperionw_shooter_collision(Gamepad &pad)
ikenna1 35:3341f2bd0408 347 {
ikenna1 35:3341f2bd0408 348 bool col1;
ikenna1 35:3341f2bd0408 349 bool col2;
ikenna1 35:3341f2bd0408 350 bool col3;
ikenna1 35:3341f2bd0408 351 if(ship_ypos > _shooter1_pos.y + 6) {
ikenna1 35:3341f2bd0408 352 col1 = check_collision1(_shooter1_pos.x,9,ship_xpos + 2,3);
ikenna1 38:4571537238ed 353 if (col1 == true && A == true && _no_shooters == 1) {
ikenna1 36:c25417f0d150 354 _health.shooterh_update(1,5);
ikenna1 35:3341f2bd0408 355 pad.tone(500,0.05);
ikenna1 35:3341f2bd0408 356 wait(0.05);
ikenna1 35:3341f2bd0408 357 }
ikenna1 35:3341f2bd0408 358 }
ikenna1 35:3341f2bd0408 359 if(ship_ypos > _shooter2_pos.y + 6) {
ikenna1 35:3341f2bd0408 360 col2 = check_collision1(_shooter2_pos.x,9,ship_xpos + 2,3);
ikenna1 38:4571537238ed 361 if (col2 == true && A == true && _no_shooters == 2) {
ikenna1 36:c25417f0d150 362 _health.shooterh_update(2,5);
ikenna1 35:3341f2bd0408 363 pad.tone(500,0.05);
ikenna1 35:3341f2bd0408 364 wait(0.05);
ikenna1 35:3341f2bd0408 365 }
ikenna1 35:3341f2bd0408 366 }
ikenna1 35:3341f2bd0408 367 if(ship_ypos > _shooter3_pos.y + 6) {
ikenna1 35:3341f2bd0408 368 col3 = check_collision1(_shooter3_pos.x,9,ship_xpos + 2,3);
ikenna1 38:4571537238ed 369 if (col3 == true && A == true && _no_shooters == 3) {
ikenna1 36:c25417f0d150 370 _health.shooterh_update(3,5);
ikenna1 35:3341f2bd0408 371 pad.tone(500,0.05);
ikenna1 35:3341f2bd0408 372 wait(0.05);
ikenna1 35:3341f2bd0408 373 }
ikenna1 35:3341f2bd0408 374 }
ikenna1 36:c25417f0d150 375 }
ikenna1 36:c25417f0d150 376 void RosenEngine::check_health()
ikenna1 36:c25417f0d150 377 {
ikenna1 36:c25417f0d150 378 int seeker_health = _health.get_seekerh();
ikenna1 36:c25417f0d150 379 int shooter1_health = _health.get_shooterh(1);
ikenna1 36:c25417f0d150 380 int shooter2_health = _health.get_shooterh(2);
ikenna1 36:c25417f0d150 381 int shooter3_health = _health.get_shooterh(3);
ikenna1 36:c25417f0d150 382
ikenna1 36:c25417f0d150 383 if(seeker_health == 0){
ikenna1 36:c25417f0d150 384 _enemy.reset_seeker();
ikenna1 36:c25417f0d150 385 _health.reset_seekerh();
ikenna1 36:c25417f0d150 386 }
ikenna1 36:c25417f0d150 387 if(shooter1_health == 0){
ikenna1 36:c25417f0d150 388 _enemy.reset_shooter(1);
ikenna1 36:c25417f0d150 389 _health.reset_shooterh(1);
ikenna1 36:c25417f0d150 390 }
ikenna1 36:c25417f0d150 391 if(shooter2_health == 0){
ikenna1 36:c25417f0d150 392 _enemy.reset_shooter(2);
ikenna1 36:c25417f0d150 393 _health.reset_shooterh(2);
ikenna1 36:c25417f0d150 394 }
ikenna1 36:c25417f0d150 395 if(shooter3_health == 0){
ikenna1 36:c25417f0d150 396 _enemy.reset_shooter(3);
ikenna1 36:c25417f0d150 397 _health.reset_shooterh(3);
ikenna1 36:c25417f0d150 398 }
ikenna1 36:c25417f0d150 399
ikenna1 36:c25417f0d150 400 Vector2D hp = _health.get_hp();
ikenna1 36:c25417f0d150 401 if(hp.x <= 0){
ikenna1 38:4571537238ed 402 // printf("player deaad\n");
ikenna1 36:c25417f0d150 403 _dead = true;
ikenna1 36:c25417f0d150 404 }
ikenna1 37:8d8c8cce0bc7 405 }
ikenna1 37:8d8c8cce0bc7 406 int RosenEngine::rand_no()
ikenna1 37:8d8c8cce0bc7 407 {
ikenna1 37:8d8c8cce0bc7 408 srand(time(NULL));
ikenna1 37:8d8c8cce0bc7 409 int rand_no = (rand() %45) + 1;
ikenna1 38:4571537238ed 410 // printf("random no = %d\n",rand_no);
ikenna1 37:8d8c8cce0bc7 411 return rand_no;
ikenna1 38:4571537238ed 412 }
ikenna1 38:4571537238ed 413 float RosenEngine::timer(int fps)
ikenna1 38:4571537238ed 414 {
ikenna1 38:4571537238ed 415 _times_run = _times_run + 1;
ikenna1 38:4571537238ed 416 float time_frame = 1.0f/fps;
ikenna1 38:4571537238ed 417 float time_elapsed = _times_run * time_frame;
ikenna1 38:4571537238ed 418 // printf("time elapsed = %f,time frame = %f, _times_run = %d\n",time_elapsed,time_frame,_times_run);
ikenna1 38:4571537238ed 419 return time_elapsed;
ikenna1 38:4571537238ed 420 }
ikenna1 38:4571537238ed 421 void RosenEngine::score(int points)
ikenna1 38:4571537238ed 422 {
ikenna1 38:4571537238ed 423 _score = _score + points;
ikenna1 38:4571537238ed 424 }
ikenna1 38:4571537238ed 425 bool RosenEngine::dead()
ikenna1 38:4571537238ed 426 {
ikenna1 38:4571537238ed 427 return _dead;
ikenna1 38:4571537238ed 428 }
ikenna1 38:4571537238ed 429
ikenna1 38:4571537238ed 430 void RosenEngine::scaling(float time_elapsed)
ikenna1 38:4571537238ed 431 {
ikenna1 38:4571537238ed 432 if(time_elapsed > 10){
ikenna1 38:4571537238ed 433 _no_shooters = _no_shooters + 1;
ikenna1 38:4571537238ed 434 _enemy.sh_scaling(time_elapsed);
ikenna1 38:4571537238ed 435 }
ikenna1 38:4571537238ed 436 if(_no_shooters > 3){
ikenna1 38:4571537238ed 437 _no_shooters = 3;
ikenna1 38:4571537238ed 438 }
ikenna1 38:4571537238ed 439 _enemy.set_noshooters(_no_shooters);
ikenna1 38:4571537238ed 440
ikenna1 38:4571537238ed 441 }
ikenna1 38:4571537238ed 442 void RosenEngine::game_over(N5110 &lcd)
ikenna1 38:4571537238ed 443 {
ikenna1 38:4571537238ed 444 lcd.clear();
ikenna1 38:4571537238ed 445 lcd.printString("Game Over ",2,2);
ikenna1 38:4571537238ed 446 lcd.printString("Try dodging next time ",2,3);
ikenna1 18:2cc6898de6b2 447 }