ELEC2645 (2018/19) / Mbed 2 deprecated el17aio

Dependencies:   mbed

Committer:
ikenna1
Date:
Mon May 06 16:49:53 2019 +0000
Revision:
39:7824f9080f59
Parent:
38:4571537238ed
Child:
40:90c7a893d513
Add Lore, enemy scaling, multiple seekers. improves shooter movement.; the new class lore will be used to print most of the text for the game.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ikenna1 3:f9cd1a38d5c6 1 #include "RosenEngine.h"
ikenna1 39:7824f9080f59 2
ikenna1 23:0301effce801 3 DigitalIn A(PTB9);
ikenna1 3:f9cd1a38d5c6 4
ikenna1 2:66a4e5d7a7cd 5 // Constructor
ikenna1 2:66a4e5d7a7cd 6 RosenEngine::RosenEngine()
ikenna1 2:66a4e5d7a7cd 7 {
ikenna1 2:66a4e5d7a7cd 8
ikenna1 2:66a4e5d7a7cd 9 }
ikenna1 2:66a4e5d7a7cd 10 // Destructor
ikenna1 2:66a4e5d7a7cd 11 RosenEngine::~RosenEngine()
ikenna1 2:66a4e5d7a7cd 12 {
ikenna1 2:66a4e5d7a7cd 13
ikenna1 2:66a4e5d7a7cd 14 }
ikenna1 3:f9cd1a38d5c6 15
ikenna1 4:740e14ebbc97 16
ikenna1 9:241a1a7d8527 17 void RosenEngine::init(int ship_width,int ship_height,int ship_speed,int ship_xpos,int ship_ypos)
ikenna1 2:66a4e5d7a7cd 18 {
ikenna1 4:740e14ebbc97 19 // initialise the game parameters
ikenna1 9:241a1a7d8527 20 _ship.init(ship_width,ship_height,ship_speed,ship_xpos,ship_ypos);
ikenna1 15:009ccc07bb57 21 // place seeker above the ship
ikenna1 39:7824f9080f59 22 _no_shooters = 0;
ikenna1 39:7824f9080f59 23 _no_seekers = 0;
ikenna1 39:7824f9080f59 24 _enemy.init(_no_shooters,_no_seekers);
ikenna1 9:241a1a7d8527 25 _menu.init(16);
ikenna1 21:628fb703188f 26 _health.init(_shipno);
ikenna1 38:4571537238ed 27 _times_run = 0;
ikenna1 38:4571537238ed 28 _score = 0;
ikenna1 38:4571537238ed 29 _dead = false;
ikenna1 39:7824f9080f59 30 _intro = false;
ikenna1 39:7824f9080f59 31 _wait_time = 10.25;
ikenna1 13:e114d362186d 32
ikenna1 3:f9cd1a38d5c6 33 }
ikenna1 27:f99249e727fd 34 void RosenEngine::reset()
ikenna1 27:f99249e727fd 35 {
ikenna1 39:7824f9080f59 36 _enemy.init(_no_shooters,_no_seekers);
ikenna1 27:f99249e727fd 37 _health.init(_shipno);
ikenna1 39:7824f9080f59 38 _wait_time = 10.25;
ikenna1 38:4571537238ed 39 _times_run = 0;
ikenna1 38:4571537238ed 40 _score = 0;
ikenna1 39:7824f9080f59 41 _no_shooters = 0;
ikenna1 38:4571537238ed 42 _dead = false;
ikenna1 39:7824f9080f59 43 _no_seekers = 0;
ikenna1 27:f99249e727fd 44 }
ikenna1 4:740e14ebbc97 45
ikenna1 5:bb6edc5b5be3 46 void RosenEngine::read_input(Gamepad &pad)
ikenna1 4:740e14ebbc97 47 {
ikenna1 4:740e14ebbc97 48 Vector2D mapped_coord = pad.get_coord();
ikenna1 8:87a845b8575e 49 _xjoystick = mapped_coord.x;
ikenna1 8:87a845b8575e 50 _yjoystick = mapped_coord.y;
ikenna1 9:241a1a7d8527 51 _d = pad.get_direction();
ikenna1 35:3341f2bd0408 52 wait(0.1);
ikenna1 14:88ca5b1a111a 53 // printf("_xjoystick ,_yjoystick = %f , %f\n",_xjoystick, _yjoystick);
ikenna1 4:740e14ebbc97 54 }
ikenna1 4:740e14ebbc97 55
ikenna1 14:88ca5b1a111a 56 void RosenEngine::draw(N5110 &lcd, Gamepad &pad)
ikenna1 7:ed5870cfb3e0 57 {
ikenna1 31:c7bd3ed16840 58 lcd.drawRect(0,0,78,48,FILL_TRANSPARENT);
ikenna1 27:f99249e727fd 59 _health.draw_health(lcd,_shipno);
ikenna1 18:2cc6898de6b2 60 _health.draw_shields(lcd);
ikenna1 15:009ccc07bb57 61 _enemy.draw_seeker(lcd);
ikenna1 34:6d0786582d81 62 _enemy.draw_shooter(lcd);
ikenna1 34:6d0786582d81 63 _enemy.draw_shw(lcd,pad);
ikenna1 21:628fb703188f 64 if(_shipno == 0) {
ikenna1 14:88ca5b1a111a 65 _ship.set_dimensions(9,6);
ikenna1 26:a53d41adf40b 66 _ship.draw_ship(lcd,_shipno);
ikenna1 23:0301effce801 67 _weapons.draw(lcd,pad,_shipno);
ikenna1 13:e114d362186d 68 }
ikenna1 21:628fb703188f 69 if(_shipno == 1) {
ikenna1 14:88ca5b1a111a 70 _ship.set_dimensions(7,10);
ikenna1 26:a53d41adf40b 71 _ship.draw_ship(lcd,_shipno);
ikenna1 26:a53d41adf40b 72 _weapons.draw(lcd,pad,_shipno);
ikenna1 26:a53d41adf40b 73 }
ikenna1 26:a53d41adf40b 74 if(_shipno == 2) {
ikenna1 26:a53d41adf40b 75 _ship.set_dimensions(7,10);
ikenna1 26:a53d41adf40b 76 _ship.draw_ship(lcd,_shipno);
ikenna1 23:0301effce801 77 _weapons.draw(lcd,pad,_shipno);
ikenna1 13:e114d362186d 78 }
ikenna1 38:4571537238ed 79 if(_dead == true){
ikenna1 38:4571537238ed 80 game_over(lcd);
ikenna1 38:4571537238ed 81 }
ikenna1 39:7824f9080f59 82 disp_points(lcd);
ikenna1 11:73cd744ffa80 83 }
ikenna1 7:ed5870cfb3e0 84
ikenna1 7:ed5870cfb3e0 85 void RosenEngine::update(Gamepad &pad)
ikenna1 7:ed5870cfb3e0 86 {
ikenna1 35:3341f2bd0408 87 _enemy.update_seeker(ship_xpos, ship_ypos);
ikenna1 30:711d722f3cef 88 _enemy.update_shooter(ship_xpos, ship_ypos);
ikenna1 35:3341f2bd0408 89 //printf("update_shooter\n");
ikenna1 32:098fbc1222cd 90 _enemy.update_shw();
ikenna1 21:628fb703188f 91 if(_shipno == 0) {
ikenna1 14:88ca5b1a111a 92 _ship.update_ship(_xjoystick,_yjoystick);
ikenna1 14:88ca5b1a111a 93 _weapons.update();
ikenna1 35:3341f2bd0408 94 kestrelw_seeker_collision(pad);
ikenna1 14:88ca5b1a111a 95 }
ikenna1 35:3341f2bd0408 96 //printf("if shipno == 0\n");
ikenna1 23:0301effce801 97 if(_shipno == 1 && A == false) {
ikenna1 14:88ca5b1a111a 98 _ship.update_ship(_xjoystick,_yjoystick);
ikenna1 14:88ca5b1a111a 99 _weapons.update();
ikenna1 14:88ca5b1a111a 100 }
ikenna1 35:3341f2bd0408 101 //printf("if shipno == 1\n");
ikenna1 27:f99249e727fd 102 if(_shipno == 2) {
ikenna1 27:f99249e727fd 103 _ship.update_ship(_xjoystick,_yjoystick);
ikenna1 27:f99249e727fd 104 _weapons.update();
ikenna1 27:f99249e727fd 105 }
ikenna1 35:3341f2bd0408 106 // test();
ikenna1 35:3341f2bd0408 107 shooter_ship_collision(pad);
ikenna1 35:3341f2bd0408 108 seeker_ship_collision(pad);
ikenna1 35:3341f2bd0408 109 shooterw_ship_collision(pad);
ikenna1 35:3341f2bd0408 110 imperionw_seeker_collision(pad);
ikenna1 35:3341f2bd0408 111 kestrelw_shooter_collision(pad);
ikenna1 35:3341f2bd0408 112 imperionw_shooter_collision(pad);
ikenna1 36:c25417f0d150 113 check_health();
ikenna1 37:8d8c8cce0bc7 114 rand_no();
ikenna1 38:4571537238ed 115 scaling(timer(12));
ikenna1 38:4571537238ed 116
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 39:7824f9080f59 123
ikenna1 39:7824f9080f59 124 _seeker1_pos = _enemy.get_seekerpos(1);
ikenna1 39:7824f9080f59 125 _seeker2_pos = _enemy.get_seekerpos(2);
ikenna1 39:7824f9080f59 126 _seeker3_pos = _enemy.get_seekerpos(3);
ikenna1 35:3341f2bd0408 127
ikenna1 37:8d8c8cce0bc7 128 _shooter1_pos = _enemy.get_shooterpos(1);
ikenna1 37:8d8c8cce0bc7 129 _shooter2_pos = _enemy.get_shooterpos(2);
ikenna1 37:8d8c8cce0bc7 130 _shooter3_pos = _enemy.get_shooterpos(3);
ikenna1 35:3341f2bd0408 131
ikenna1 9:241a1a7d8527 132 _weapons.init(ship_xpos, ship_ypos, ship_width);
ikenna1 13:e114d362186d 133 _ycursor = _menu.get_ycursor();
ikenna1 25:faba9eb44514 134
ikenna1 25:faba9eb44514 135 if(_shipno == 0) {
ikenna1 25:faba9eb44514 136 ship_width = 9;
ikenna1 25:faba9eb44514 137 ship_height = 6;
ikenna1 25:faba9eb44514 138 }
ikenna1 25:faba9eb44514 139 if(_shipno == 1) {
ikenna1 25:faba9eb44514 140 ship_width = 7;
ikenna1 25:faba9eb44514 141 ship_height = 10;
ikenna1 25:faba9eb44514 142 }
ikenna1 9:241a1a7d8527 143 }
ikenna1 9:241a1a7d8527 144 void RosenEngine::title(N5110 &lcd)
ikenna1 9:241a1a7d8527 145 {
ikenna1 30:711d722f3cef 146 _menu.title(lcd,_shipno);
ikenna1 10:c33d7593a275 147 _menu.update(_d);
ikenna1 10:c33d7593a275 148 }
ikenna1 13:e114d362186d 149 int RosenEngine::get_ycursor()
ikenna1 10:c33d7593a275 150 {
ikenna1 13:e114d362186d 151 _ycursor = _menu.get_ycursor();
ikenna1 10:c33d7593a275 152 return _ycursor;
ikenna1 12:47578eb9ea73 153 }
ikenna1 21:628fb703188f 154 int RosenEngine::get_shipno()
ikenna1 13:e114d362186d 155 {
ikenna1 21:628fb703188f 156 _shipno = _menu.get_xcursor();
ikenna1 21:628fb703188f 157 return _shipno;
ikenna1 13:e114d362186d 158 }
ikenna1 12:47578eb9ea73 159 void RosenEngine::ship_select(N5110 &lcd)
ikenna1 12:47578eb9ea73 160 {
ikenna1 12:47578eb9ea73 161 _menu.update(_d);
ikenna1 12:47578eb9ea73 162 _menu.disp_ships(lcd);
ikenna1 17:e65a9f981834 163 }
ikenna1 35:3341f2bd0408 164 bool RosenEngine::check_collision(int xpos1, int ypos1,int width1,int height1,int xpos2, int ypos2,int width2,int height2)
ikenna1 35:3341f2bd0408 165 {
ikenna1 35:3341f2bd0408 166 // Create arrays of all positions with appropriate height and length
ikenna1 35:3341f2bd0408 167 int xpos1_array[width1];
ikenna1 35:3341f2bd0408 168 int ypos1_array[height1];
ikenna1 35:3341f2bd0408 169 int xpos2_array[width2];
ikenna1 35:3341f2bd0408 170 int ypos2_array[height2];
ikenna1 35:3341f2bd0408 171 bool xcol = false;
ikenna1 35:3341f2bd0408 172 bool ycol = false;
ikenna1 35:3341f2bd0408 173 bool col = false;
ikenna1 35:3341f2bd0408 174 //printf("variables declared\n");
ikenna1 35:3341f2bd0408 175 // Loop through both height and width to get a 2D aray of the sprites position
ikenna1 35:3341f2bd0408 176 for(int cx = 0; cx<width1; cx=cx+1) {
ikenna1 35:3341f2bd0408 177 xpos1_array[cx]= xpos1 + cx;
ikenna1 35:3341f2bd0408 178 for(int nx = 0; nx<width2; nx=nx+1) {
ikenna1 35:3341f2bd0408 179 xpos2_array[nx]= xpos2 + nx;
ikenna1 35:3341f2bd0408 180 if(xpos2_array[nx] == xpos1_array[cx]) {
ikenna1 35:3341f2bd0408 181 xcol = true;
ikenna1 35:3341f2bd0408 182 }
ikenna1 35:3341f2bd0408 183 // printf("xarray = %d,x2array = %d,xcol = %d\n",xpos2_array[nx],xpos1_array[cx],xcol);
ikenna1 35:3341f2bd0408 184 }
ikenna1 35:3341f2bd0408 185 }
ikenna1 35:3341f2bd0408 186 //printf("first loop done\n");
ikenna1 35:3341f2bd0408 187 for(int cy = 0; cy<height1; cy=cy+1) {
ikenna1 35:3341f2bd0408 188 ypos1_array[cy]= ypos1 + cy;
ikenna1 35:3341f2bd0408 189 for(int ny = 0; ny<height2; ny=ny+1) {
ikenna1 35:3341f2bd0408 190 ypos2_array[ny]= ypos2 + ny;
ikenna1 35:3341f2bd0408 191 if(ypos2_array[ny] == ypos1_array[cy]) {
ikenna1 35:3341f2bd0408 192 ycol = true;
ikenna1 35:3341f2bd0408 193 }
ikenna1 35:3341f2bd0408 194 // printf("yarray = %d,y2array = %d,ycol = %d\n",ypos2_array[ny],ypos1_array[cy],ycol);
ikenna1 35:3341f2bd0408 195 }
ikenna1 35:3341f2bd0408 196 }
ikenna1 35:3341f2bd0408 197 //printf("second loop done\n");
ikenna1 35:3341f2bd0408 198 // if both the hight and width position values are equal a collision has occured
ikenna1 35:3341f2bd0408 199 col = (xcol & ycol);
ikenna1 35:3341f2bd0408 200 //printf("col gotten, col = %d\n",col);
ikenna1 35:3341f2bd0408 201 return col;
ikenna1 35:3341f2bd0408 202 }
ikenna1 35:3341f2bd0408 203 bool RosenEngine::check_collision1(int xpos1,int width1,int xpos2,int width2)
ikenna1 35:3341f2bd0408 204 {
ikenna1 35:3341f2bd0408 205 // Create arrays of all positions with appropriate height and length
ikenna1 35:3341f2bd0408 206 int xpos1_array[width1];
ikenna1 35:3341f2bd0408 207 int xpos2_array[width2];
ikenna1 35:3341f2bd0408 208 bool xcol = false;
ikenna1 35:3341f2bd0408 209
ikenna1 35:3341f2bd0408 210 for(int cx = 0; cx<width1; cx=cx+1) {
ikenna1 35:3341f2bd0408 211 xpos1_array[cx]= xpos1 + cx;
ikenna1 35:3341f2bd0408 212 for(int nx = 0; nx<width2; nx=nx+1) {
ikenna1 35:3341f2bd0408 213 xpos2_array[nx]= xpos2 + nx;
ikenna1 35:3341f2bd0408 214 if(xpos2_array[nx] == xpos1_array[cx]) {
ikenna1 35:3341f2bd0408 215 xcol = true;
ikenna1 35:3341f2bd0408 216 }
ikenna1 35:3341f2bd0408 217 // printf("xarray = %d,x2array = %d,xcol = %d\n",xpos2_array[nx],xpos1_array[cx],xcol);
ikenna1 35:3341f2bd0408 218 }
ikenna1 35:3341f2bd0408 219 }
ikenna1 35:3341f2bd0408 220 return xcol;
ikenna1 35:3341f2bd0408 221 }
ikenna1 35:3341f2bd0408 222
ikenna1 35:3341f2bd0408 223 void RosenEngine::test()
ikenna1 35:3341f2bd0408 224 {
ikenna1 35:3341f2bd0408 225 bool test;
ikenna1 35:3341f2bd0408 226 test = check_collision(5,5,5,5,5,5,5,5);
ikenna1 35:3341f2bd0408 227 if (test == false) {
ikenna1 35:3341f2bd0408 228 printf("fail\n");
ikenna1 35:3341f2bd0408 229 } else {
ikenna1 35:3341f2bd0408 230 printf("pass\n");
ikenna1 35:3341f2bd0408 231 }
ikenna1 35:3341f2bd0408 232 test = check_collision(0,0,1,1,24,24,1,1);
ikenna1 35:3341f2bd0408 233 if (test == true) {
ikenna1 35:3341f2bd0408 234 printf("fail\n");
ikenna1 35:3341f2bd0408 235 } else {
ikenna1 35:3341f2bd0408 236 printf("pass\n");
ikenna1 35:3341f2bd0408 237 }
ikenna1 35:3341f2bd0408 238 }
ikenna1 35:3341f2bd0408 239 // make function resemble test
ikenna1 35:3341f2bd0408 240
ikenna1 35:3341f2bd0408 241 void RosenEngine::seeker_ship_collision(Gamepad &pad)
ikenna1 35:3341f2bd0408 242 {
ikenna1 39:7824f9080f59 243 bool col1,col2,col3;
ikenna1 39:7824f9080f59 244
ikenna1 39:7824f9080f59 245 col1 = check_collision(ship_xpos,ship_ypos,9,6,_seeker1_pos.x, _seeker1_pos.y,10,7);
ikenna1 39:7824f9080f59 246 col2 = check_collision(ship_xpos,ship_ypos,9,6,_seeker2_pos.x, _seeker2_pos.y,10,7);
ikenna1 39:7824f9080f59 247 col3 = check_collision(ship_xpos,ship_ypos,9,6,_seeker3_pos.x, _seeker3_pos.y,10,7);
ikenna1 39:7824f9080f59 248 int sel = 0;
ikenna1 39:7824f9080f59 249
ikenna1 39:7824f9080f59 250 if (col1 == true && _no_seekers >= 1) {
ikenna1 39:7824f9080f59 251 sel = 1;
ikenna1 39:7824f9080f59 252 }
ikenna1 39:7824f9080f59 253 if (col2 == true && _no_seekers >= 2) {
ikenna1 39:7824f9080f59 254 sel = 2;
ikenna1 39:7824f9080f59 255 }
ikenna1 39:7824f9080f59 256 if (col3 == true && _no_seekers >= 3) {
ikenna1 39:7824f9080f59 257 sel = 3;
ikenna1 39:7824f9080f59 258 }
ikenna1 39:7824f9080f59 259 // printf("col1 = %d, col2 = %d, col3 = %d, no_seekers = %d\n",col1,col2,col3,_no_seekers);
ikenna1 39:7824f9080f59 260 if(sel != 0){
ikenna1 39:7824f9080f59 261 _health.update(5,pad);
ikenna1 39:7824f9080f59 262 _health.seekerh_update(sel,10);
ikenna1 35:3341f2bd0408 263 pad.tone(500,0.05);
ikenna1 35:3341f2bd0408 264 wait(0.05);
ikenna1 35:3341f2bd0408 265 }
ikenna1 35:3341f2bd0408 266 }
ikenna1 35:3341f2bd0408 267 void RosenEngine::shooter_ship_collision(Gamepad &pad)
ikenna1 35:3341f2bd0408 268 {
ikenna1 39:7824f9080f59 269 bool col1,col2,col3;
ikenna1 39:7824f9080f59 270 int sel = 0;
ikenna1 39:7824f9080f59 271 col1 = check_collision(ship_xpos,ship_ypos,9,6,_shooter1_pos.x, _shooter1_pos.y,10,7);
ikenna1 39:7824f9080f59 272 col2 = check_collision(ship_xpos,ship_ypos,9,6,_shooter2_pos.x, _shooter2_pos.y,10,7);
ikenna1 39:7824f9080f59 273 col3 = check_collision(ship_xpos,ship_ypos,9,6,_shooter3_pos.x, _shooter3_pos.y,10,7);
ikenna1 35:3341f2bd0408 274
ikenna1 39:7824f9080f59 275 if(col1 == true && _no_shooters >= 1) {
ikenna1 39:7824f9080f59 276 sel = 1;
ikenna1 39:7824f9080f59 277 }
ikenna1 39:7824f9080f59 278 if(col2 == true && _no_shooters >= 2) {
ikenna1 39:7824f9080f59 279 sel = 2;
ikenna1 39:7824f9080f59 280 }
ikenna1 39:7824f9080f59 281 if(col3 == true && _no_shooters >= 3) {
ikenna1 39:7824f9080f59 282 sel = 3;
ikenna1 39:7824f9080f59 283 }
ikenna1 39:7824f9080f59 284 if(sel != 0){
ikenna1 35:3341f2bd0408 285 _health.update(1,pad);
ikenna1 39:7824f9080f59 286 _health.shooterh_update(sel,10);
ikenna1 35:3341f2bd0408 287 pad.tone(500,0.05);
ikenna1 39:7824f9080f59 288 wait(0.05);
ikenna1 35:3341f2bd0408 289 }
ikenna1 35:3341f2bd0408 290 }
ikenna1 35:3341f2bd0408 291 void RosenEngine::shooterw_ship_collision(Gamepad &pad)
ikenna1 35:3341f2bd0408 292 {
ikenna1 37:8d8c8cce0bc7 293 Vector2D _shooterw1_pos = _enemy.get_shwpos(1);
ikenna1 37:8d8c8cce0bc7 294 Vector2D _shooterw2_pos = _enemy.get_shwpos(2);
ikenna1 37:8d8c8cce0bc7 295 Vector2D _shooterw3_pos = _enemy.get_shwpos(3);
ikenna1 35:3341f2bd0408 296
ikenna1 39:7824f9080f59 297 bool col1,col2,col3;
ikenna1 39:7824f9080f59 298 int sel = 0;
ikenna1 39:7824f9080f59 299 col1 = check_collision(ship_xpos,ship_ypos,9,6,_shooterw1_pos.x, _shooterw1_pos.y,2,2);
ikenna1 39:7824f9080f59 300 col2 = check_collision(ship_xpos,ship_ypos,9,6,_shooterw2_pos.x, _shooterw2_pos.y,2,2);
ikenna1 39:7824f9080f59 301 col3 = check_collision(ship_xpos,ship_ypos,9,6,_shooterw3_pos.x, _shooterw3_pos.y,2,2);
ikenna1 35:3341f2bd0408 302
ikenna1 39:7824f9080f59 303 if(col1 == true && _no_shooters >= 1) {
ikenna1 39:7824f9080f59 304 sel = 1;
ikenna1 39:7824f9080f59 305 }
ikenna1 39:7824f9080f59 306 if(col2 == true && _no_shooters >= 2) {
ikenna1 39:7824f9080f59 307 sel = 2;
ikenna1 39:7824f9080f59 308 }
ikenna1 39:7824f9080f59 309 if(col3 == true && _no_shooters >= 3) {
ikenna1 39:7824f9080f59 310 sel = 3;
ikenna1 39:7824f9080f59 311 }
ikenna1 39:7824f9080f59 312 if(sel != 0){
ikenna1 35:3341f2bd0408 313 _health.update(1,pad);
ikenna1 35:3341f2bd0408 314 pad.tone(500,0.05);
ikenna1 39:7824f9080f59 315 wait(0.05);
ikenna1 35:3341f2bd0408 316 }
ikenna1 35:3341f2bd0408 317 }
ikenna1 35:3341f2bd0408 318 void RosenEngine::kestrelw_seeker_collision(Gamepad &pad)
ikenna1 35:3341f2bd0408 319 {
ikenna1 39:7824f9080f59 320 bool col1, col2, col3;
ikenna1 39:7824f9080f59 321 int sel = 0;
ikenna1 35:3341f2bd0408 322 Vector2D missle_pos = _weapons.get_pos(_shipno);
ikenna1 39:7824f9080f59 323 col1 = check_collision(_seeker1_pos.x,_seeker1_pos.y,9,6,missle_pos.x,missle_pos.y,1,1);
ikenna1 39:7824f9080f59 324 col2 = check_collision(_seeker2_pos.x,_seeker2_pos.y,9,6,missle_pos.x,missle_pos.y,1,1);
ikenna1 39:7824f9080f59 325 col3 = check_collision(_seeker3_pos.x,_seeker3_pos.y,9,6,missle_pos.x,missle_pos.y,1,1);
ikenna1 39:7824f9080f59 326 if (col1 == true && _no_seekers >= 1) {
ikenna1 39:7824f9080f59 327 sel = 1;
ikenna1 39:7824f9080f59 328 }
ikenna1 39:7824f9080f59 329 if (col2 == true && _no_seekers >= 2) {
ikenna1 39:7824f9080f59 330 sel = 2;
ikenna1 39:7824f9080f59 331 }
ikenna1 39:7824f9080f59 332 if (col3 == true && _no_seekers >= 3) {
ikenna1 39:7824f9080f59 333 sel = 3;
ikenna1 39:7824f9080f59 334 }
ikenna1 39:7824f9080f59 335 if(sel != 0){
ikenna1 35:3341f2bd0408 336 pad.tone(500,0.05);
ikenna1 39:7824f9080f59 337 _health.seekerh_update(sel,5);
ikenna1 35:3341f2bd0408 338 wait(0.05);
ikenna1 35:3341f2bd0408 339 }
ikenna1 35:3341f2bd0408 340 }
ikenna1 35:3341f2bd0408 341 void RosenEngine::imperionw_seeker_collision(Gamepad &pad)
ikenna1 35:3341f2bd0408 342 {
ikenna1 39:7824f9080f59 343 bool col1,col2,col3;
ikenna1 39:7824f9080f59 344 int sel = 0;
ikenna1 39:7824f9080f59 345 if(ship_ypos > _seeker1_pos.y + 6) {
ikenna1 39:7824f9080f59 346 col1 = check_collision1(_seeker1_pos.x,9,ship_xpos + 2,3);
ikenna1 39:7824f9080f59 347 if (col1 == true && A == true && _no_seekers >= 1) {
ikenna1 39:7824f9080f59 348 sel = 1;
ikenna1 35:3341f2bd0408 349 }
ikenna1 35:3341f2bd0408 350 }
ikenna1 39:7824f9080f59 351 if(ship_ypos > _seeker2_pos.y + 6) {
ikenna1 39:7824f9080f59 352 col2 = check_collision1(_seeker2_pos.x,9,ship_xpos + 2,3);
ikenna1 39:7824f9080f59 353 if (col2 == true && A == true && _no_seekers >= 2) {
ikenna1 39:7824f9080f59 354 sel = 2;
ikenna1 39:7824f9080f59 355 }
ikenna1 39:7824f9080f59 356 }
ikenna1 39:7824f9080f59 357 if(ship_ypos > _seeker1_pos.y + 6) {
ikenna1 39:7824f9080f59 358 col3 = check_collision1(_seeker3_pos.x,9,ship_xpos + 2,3);
ikenna1 39:7824f9080f59 359 if (col3 == true && A == true && _no_seekers >= 3) {
ikenna1 39:7824f9080f59 360 sel = 3;
ikenna1 39:7824f9080f59 361 }
ikenna1 39:7824f9080f59 362 }
ikenna1 39:7824f9080f59 363 if(sel != 0){
ikenna1 39:7824f9080f59 364 _health.seekerh_update(sel,10);
ikenna1 39:7824f9080f59 365 pad.tone(500,0.05);
ikenna1 39:7824f9080f59 366 wait(0.05);
ikenna1 39:7824f9080f59 367 }
ikenna1 35:3341f2bd0408 368 }
ikenna1 35:3341f2bd0408 369 void RosenEngine::kestrelw_shooter_collision(Gamepad &pad)
ikenna1 35:3341f2bd0408 370 {
ikenna1 35:3341f2bd0408 371 Vector2D missle_pos = _weapons.get_pos(_shipno);
ikenna1 35:3341f2bd0408 372 bool col1, col2, col3;
ikenna1 39:7824f9080f59 373 int sel = 0;
ikenna1 35:3341f2bd0408 374 col1 = check_collision(_shooter1_pos.x,_shooter1_pos.y,9,6,missle_pos.x,missle_pos.y,1,1);
ikenna1 35:3341f2bd0408 375 col2 = check_collision(_shooter2_pos.x,_shooter2_pos.y,9,6,missle_pos.x,missle_pos.y,1,1);
ikenna1 35:3341f2bd0408 376 col3 = check_collision(_shooter3_pos.x,_shooter3_pos.y,9,6,missle_pos.x,missle_pos.y,1,1);
ikenna1 39:7824f9080f59 377 if (col1 == true && _no_shooters >= 1) {
ikenna1 39:7824f9080f59 378 sel = 1;
ikenna1 39:7824f9080f59 379 }
ikenna1 39:7824f9080f59 380 if (col2 == true && _no_shooters >= 2) {
ikenna1 39:7824f9080f59 381 sel = 2;
ikenna1 35:3341f2bd0408 382 }
ikenna1 39:7824f9080f59 383 if (col3 == true && _no_shooters >= 3) {
ikenna1 39:7824f9080f59 384 sel = 3;
ikenna1 39:7824f9080f59 385 }
ikenna1 39:7824f9080f59 386 // printf("col1 = %d,col2 = %d,col3 = %d, no_shooters = %d\n",col1,col2,col3,_no_shooters);
ikenna1 39:7824f9080f59 387 if(sel != 0){
ikenna1 35:3341f2bd0408 388 pad.tone(500,0.05);
ikenna1 39:7824f9080f59 389 _health.shooterh_update(sel,5);
ikenna1 35:3341f2bd0408 390 wait(0.05);
ikenna1 35:3341f2bd0408 391 }
ikenna1 35:3341f2bd0408 392 }
ikenna1 35:3341f2bd0408 393 void RosenEngine::imperionw_shooter_collision(Gamepad &pad)
ikenna1 35:3341f2bd0408 394 {
ikenna1 39:7824f9080f59 395 bool col1,col2,col3;
ikenna1 39:7824f9080f59 396 int sel = 0;
ikenna1 35:3341f2bd0408 397 if(ship_ypos > _shooter1_pos.y + 6) {
ikenna1 35:3341f2bd0408 398 col1 = check_collision1(_shooter1_pos.x,9,ship_xpos + 2,3);
ikenna1 39:7824f9080f59 399 if (col1 == true && A == true && _no_shooters >= 1) {
ikenna1 39:7824f9080f59 400 sel = 1;
ikenna1 35:3341f2bd0408 401 }
ikenna1 35:3341f2bd0408 402 }
ikenna1 35:3341f2bd0408 403 if(ship_ypos > _shooter2_pos.y + 6) {
ikenna1 35:3341f2bd0408 404 col2 = check_collision1(_shooter2_pos.x,9,ship_xpos + 2,3);
ikenna1 39:7824f9080f59 405 if (col2 == true && A == true && _no_shooters >= 2) {
ikenna1 39:7824f9080f59 406 sel = 2;
ikenna1 35:3341f2bd0408 407 }
ikenna1 35:3341f2bd0408 408 }
ikenna1 35:3341f2bd0408 409 if(ship_ypos > _shooter3_pos.y + 6) {
ikenna1 35:3341f2bd0408 410 col3 = check_collision1(_shooter3_pos.x,9,ship_xpos + 2,3);
ikenna1 39:7824f9080f59 411 if (col3 == true && A == true && _no_shooters >= 3) {
ikenna1 39:7824f9080f59 412 sel = 3;
ikenna1 35:3341f2bd0408 413 }
ikenna1 35:3341f2bd0408 414 }
ikenna1 39:7824f9080f59 415 if(sel != 0){
ikenna1 39:7824f9080f59 416 _health.shooterh_update(sel,10);
ikenna1 39:7824f9080f59 417 pad.tone(500,0.05);
ikenna1 39:7824f9080f59 418 wait(0.05);
ikenna1 39:7824f9080f59 419 }
ikenna1 36:c25417f0d150 420 }
ikenna1 39:7824f9080f59 421 void RosenEngine::check_health(){
ikenna1 39:7824f9080f59 422 check_se_health();
ikenna1 39:7824f9080f59 423 check_sh_health();
ikenna1 36:c25417f0d150 424
ikenna1 36:c25417f0d150 425 Vector2D hp = _health.get_hp();
ikenna1 36:c25417f0d150 426 if(hp.x <= 0){
ikenna1 38:4571537238ed 427 // printf("player deaad\n");
ikenna1 36:c25417f0d150 428 _dead = true;
ikenna1 36:c25417f0d150 429 }
ikenna1 39:7824f9080f59 430
ikenna1 39:7824f9080f59 431 }
ikenna1 39:7824f9080f59 432 void RosenEngine::check_se_health()
ikenna1 39:7824f9080f59 433 {
ikenna1 39:7824f9080f59 434 int sel = 0;
ikenna1 39:7824f9080f59 435 int seeker1_health = _health.get_seekerh(1);
ikenna1 39:7824f9080f59 436 int seeker2_health = _health.get_seekerh(2);
ikenna1 39:7824f9080f59 437 int seeker3_health = _health.get_seekerh(3);
ikenna1 39:7824f9080f59 438 // printf("seeker1_h = %d, seeker2_h = %d, seeker3_h = %d\n",seeker1_health,seeker2_health,seeker3_health);
ikenna1 39:7824f9080f59 439 if(seeker1_health == 0){
ikenna1 39:7824f9080f59 440 sel = 1;
ikenna1 39:7824f9080f59 441 }
ikenna1 39:7824f9080f59 442 if(seeker2_health == 0){
ikenna1 39:7824f9080f59 443 sel = 2;
ikenna1 39:7824f9080f59 444 }
ikenna1 39:7824f9080f59 445 if(seeker3_health == 0){
ikenna1 39:7824f9080f59 446 sel = 3;
ikenna1 39:7824f9080f59 447 }
ikenna1 39:7824f9080f59 448 if(sel != 0){
ikenna1 39:7824f9080f59 449 _enemy.reset_seeker(sel);
ikenna1 39:7824f9080f59 450 _health.reset_seekerh(sel);
ikenna1 39:7824f9080f59 451 _score = _score + 10;
ikenna1 39:7824f9080f59 452 }
ikenna1 39:7824f9080f59 453 }
ikenna1 39:7824f9080f59 454 void RosenEngine::check_sh_health()
ikenna1 39:7824f9080f59 455 {
ikenna1 39:7824f9080f59 456 int sel = 0;
ikenna1 39:7824f9080f59 457 int shooter1_health = _health.get_shooterh(1);
ikenna1 39:7824f9080f59 458 int shooter2_health = _health.get_shooterh(2);
ikenna1 39:7824f9080f59 459 int shooter3_health = _health.get_shooterh(3);
ikenna1 39:7824f9080f59 460
ikenna1 39:7824f9080f59 461 if(shooter1_health == 0){
ikenna1 39:7824f9080f59 462 sel = 1;
ikenna1 39:7824f9080f59 463 }
ikenna1 39:7824f9080f59 464 if(shooter2_health == 0){
ikenna1 39:7824f9080f59 465 sel = 2;
ikenna1 39:7824f9080f59 466 }
ikenna1 39:7824f9080f59 467 if(shooter3_health == 0){
ikenna1 39:7824f9080f59 468 sel = 3;
ikenna1 39:7824f9080f59 469 }
ikenna1 39:7824f9080f59 470 if(sel != 0){
ikenna1 39:7824f9080f59 471 _enemy.reset_shooter(sel);
ikenna1 39:7824f9080f59 472 _health.reset_shooterh(sel);
ikenna1 39:7824f9080f59 473 _score = _score + 20;
ikenna1 39:7824f9080f59 474 }
ikenna1 37:8d8c8cce0bc7 475 }
ikenna1 37:8d8c8cce0bc7 476 int RosenEngine::rand_no()
ikenna1 37:8d8c8cce0bc7 477 {
ikenna1 37:8d8c8cce0bc7 478 srand(time(NULL));
ikenna1 37:8d8c8cce0bc7 479 int rand_no = (rand() %45) + 1;
ikenna1 38:4571537238ed 480 // printf("random no = %d\n",rand_no);
ikenna1 37:8d8c8cce0bc7 481 return rand_no;
ikenna1 38:4571537238ed 482 }
ikenna1 38:4571537238ed 483 float RosenEngine::timer(int fps)
ikenna1 38:4571537238ed 484 {
ikenna1 38:4571537238ed 485 _times_run = _times_run + 1;
ikenna1 38:4571537238ed 486 float time_frame = 1.0f/fps;
ikenna1 38:4571537238ed 487 float time_elapsed = _times_run * time_frame;
ikenna1 38:4571537238ed 488 // printf("time elapsed = %f,time frame = %f, _times_run = %d\n",time_elapsed,time_frame,_times_run);
ikenna1 38:4571537238ed 489 return time_elapsed;
ikenna1 38:4571537238ed 490 }
ikenna1 38:4571537238ed 491 void RosenEngine::score(int points)
ikenna1 38:4571537238ed 492 {
ikenna1 38:4571537238ed 493 _score = _score + points;
ikenna1 38:4571537238ed 494 }
ikenna1 38:4571537238ed 495 bool RosenEngine::dead()
ikenna1 38:4571537238ed 496 {
ikenna1 38:4571537238ed 497 return _dead;
ikenna1 38:4571537238ed 498 }
ikenna1 38:4571537238ed 499
ikenna1 38:4571537238ed 500 void RosenEngine::scaling(float time_elapsed)
ikenna1 38:4571537238ed 501 {
ikenna1 39:7824f9080f59 502 if(time_elapsed == _wait_time){
ikenna1 38:4571537238ed 503 _no_shooters = _no_shooters + 1;
ikenna1 39:7824f9080f59 504 // _no_seekers = _no_seekers + 1;
ikenna1 38:4571537238ed 505 _enemy.sh_scaling(time_elapsed);
ikenna1 39:7824f9080f59 506 _wait_time = _wait_time + 10.00;
ikenna1 38:4571537238ed 507 }
ikenna1 38:4571537238ed 508 if(_no_shooters > 3){
ikenna1 38:4571537238ed 509 _no_shooters = 3;
ikenna1 39:7824f9080f59 510 }
ikenna1 39:7824f9080f59 511 if(_no_seekers > 3){
ikenna1 39:7824f9080f59 512 _no_seekers = 3;
ikenna1 39:7824f9080f59 513 }
ikenna1 38:4571537238ed 514 _enemy.set_noshooters(_no_shooters);
ikenna1 39:7824f9080f59 515 _enemy.set_noseekers(_no_seekers);
ikenna1 39:7824f9080f59 516 // printf("time_elapsed = %f, no_shooters = %d, wait_time = %f\n",time_elapsed,_no_shooters,_wait_time);
ikenna1 38:4571537238ed 517 }
ikenna1 38:4571537238ed 518 void RosenEngine::game_over(N5110 &lcd)
ikenna1 38:4571537238ed 519 {
ikenna1 39:7824f9080f59 520 /*
ikenna1 38:4571537238ed 521 lcd.clear();
ikenna1 39:7824f9080f59 522 lcd.refresh();
ikenna1 38:4571537238ed 523 lcd.printString("Game Over ",2,2);
ikenna1 39:7824f9080f59 524 lcd.printString("Try dodging ",2,3);
ikenna1 39:7824f9080f59 525 lcd.printString("next time",2,4);
ikenna1 39:7824f9080f59 526 lcd.refresh();
ikenna1 39:7824f9080f59 527 wait(2);
ikenna1 39:7824f9080f59 528 */
ikenna1 39:7824f9080f59 529 _lore.display(lcd);
ikenna1 39:7824f9080f59 530 }
ikenna1 39:7824f9080f59 531 void RosenEngine::intro(N5110 &lcd)
ikenna1 39:7824f9080f59 532 {
ikenna1 39:7824f9080f59 533 if(_intro == false){
ikenna1 39:7824f9080f59 534 lcd.clear();
ikenna1 39:7824f9080f59 535 lcd.refresh();
ikenna1 39:7824f9080f59 536 lcd.printString("You are tasked",2,0);
ikenna1 39:7824f9080f59 537 lcd.printString("with holding",2,1);
ikenna1 39:7824f9080f59 538 lcd.printString(" the line ",2,2);
ikenna1 39:7824f9080f59 539 lcd.printString(" from an ",2,3);
ikenna1 39:7824f9080f59 540 lcd.printString("invading army ",2,4);
ikenna1 39:7824f9080f59 541 lcd.refresh();
ikenna1 39:7824f9080f59 542 wait(2);
ikenna1 39:7824f9080f59 543 lcd.clear();
ikenna1 39:7824f9080f59 544 lcd.refresh();
ikenna1 39:7824f9080f59 545 lcd.printString(" as an ",2,0);
ikenna1 39:7824f9080f59 546 lcd.printString(" expendable ",2,1);
ikenna1 39:7824f9080f59 547 lcd.printString(" asset, ",2,2);
ikenna1 39:7824f9080f59 548 lcd.printString("you are not ",2,3);
ikenna1 39:7824f9080f59 549 lcd.printString("expected to",2,4);
ikenna1 39:7824f9080f59 550 lcd.printString(" survive ",2,5);
ikenna1 39:7824f9080f59 551 lcd.refresh();
ikenna1 39:7824f9080f59 552 wait(2);
ikenna1 39:7824f9080f59 553
ikenna1 39:7824f9080f59 554 }
ikenna1 39:7824f9080f59 555 _intro = true;
ikenna1 39:7824f9080f59 556 }
ikenna1 39:7824f9080f59 557 void RosenEngine::disp_points(N5110 &lcd)
ikenna1 39:7824f9080f59 558 {
ikenna1 39:7824f9080f59 559 char buffer[10];
ikenna1 39:7824f9080f59 560 sprintf(buffer,"%d",_score);
ikenna1 39:7824f9080f59 561 lcd.printString(buffer,2,0);
ikenna1 39:7824f9080f59 562 }