Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
RosenEngine/RosenEngine.cpp@40:90c7a893d513, 2019-05-07 (annotated)
- Committer:
- ikenna1
- Date:
- Tue May 07 10:01:34 2019 +0000
- Revision:
- 40:90c7a893d513
- Parent:
- 39:7824f9080f59
- Child:
- 41:e1fa36c0492e
Add Orion ship weapons ; Gives a weapon that tracks the movements of enemy ship to the Orion
Who changed what in which revision?
User | Revision | Line number | New 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 | 39:7824f9080f59 | 21 | _no_shooters = 0; |
ikenna1 | 39:7824f9080f59 | 22 | _no_seekers = 0; |
ikenna1 | 39:7824f9080f59 | 23 | _enemy.init(_no_shooters,_no_seekers); |
ikenna1 | 9:241a1a7d8527 | 24 | _menu.init(16); |
ikenna1 | 21:628fb703188f | 25 | _health.init(_shipno); |
ikenna1 | 38:4571537238ed | 26 | _times_run = 0; |
ikenna1 | 38:4571537238ed | 27 | _score = 0; |
ikenna1 | 38:4571537238ed | 28 | _dead = false; |
ikenna1 | 39:7824f9080f59 | 29 | _intro = false; |
ikenna1 | 39:7824f9080f59 | 30 | _wait_time = 10.25; |
ikenna1 | 13:e114d362186d | 31 | |
ikenna1 | 3:f9cd1a38d5c6 | 32 | } |
ikenna1 | 27:f99249e727fd | 33 | void RosenEngine::reset() |
ikenna1 | 27:f99249e727fd | 34 | { |
ikenna1 | 39:7824f9080f59 | 35 | _enemy.init(_no_shooters,_no_seekers); |
ikenna1 | 27:f99249e727fd | 36 | _health.init(_shipno); |
ikenna1 | 39:7824f9080f59 | 37 | _wait_time = 10.25; |
ikenna1 | 38:4571537238ed | 38 | _times_run = 0; |
ikenna1 | 38:4571537238ed | 39 | _score = 0; |
ikenna1 | 39:7824f9080f59 | 40 | _no_shooters = 0; |
ikenna1 | 38:4571537238ed | 41 | _dead = false; |
ikenna1 | 39:7824f9080f59 | 42 | _no_seekers = 0; |
ikenna1 | 27:f99249e727fd | 43 | } |
ikenna1 | 4:740e14ebbc97 | 44 | |
ikenna1 | 5:bb6edc5b5be3 | 45 | void RosenEngine::read_input(Gamepad &pad) |
ikenna1 | 4:740e14ebbc97 | 46 | { |
ikenna1 | 4:740e14ebbc97 | 47 | Vector2D mapped_coord = pad.get_coord(); |
ikenna1 | 8:87a845b8575e | 48 | _xjoystick = mapped_coord.x; |
ikenna1 | 8:87a845b8575e | 49 | _yjoystick = mapped_coord.y; |
ikenna1 | 9:241a1a7d8527 | 50 | _d = pad.get_direction(); |
ikenna1 | 35:3341f2bd0408 | 51 | wait(0.1); |
ikenna1 | 14:88ca5b1a111a | 52 | // printf("_xjoystick ,_yjoystick = %f , %f\n",_xjoystick, _yjoystick); |
ikenna1 | 4:740e14ebbc97 | 53 | } |
ikenna1 | 4:740e14ebbc97 | 54 | |
ikenna1 | 14:88ca5b1a111a | 55 | void RosenEngine::draw(N5110 &lcd, Gamepad &pad) |
ikenna1 | 7:ed5870cfb3e0 | 56 | { |
ikenna1 | 31:c7bd3ed16840 | 57 | lcd.drawRect(0,0,78,48,FILL_TRANSPARENT); |
ikenna1 | 27:f99249e727fd | 58 | _health.draw_health(lcd,_shipno); |
ikenna1 | 18:2cc6898de6b2 | 59 | _health.draw_shields(lcd); |
ikenna1 | 15:009ccc07bb57 | 60 | _enemy.draw_seeker(lcd); |
ikenna1 | 34:6d0786582d81 | 61 | _enemy.draw_shooter(lcd); |
ikenna1 | 34:6d0786582d81 | 62 | _enemy.draw_shw(lcd,pad); |
ikenna1 | 40:90c7a893d513 | 63 | Vector2D inde = find_closest1(); |
ikenna1 | 40:90c7a893d513 | 64 | int index = inde.x; |
ikenna1 | 40:90c7a893d513 | 65 | Vector2D closest = find_closest2(index); |
ikenna1 | 21:628fb703188f | 66 | if(_shipno == 0) { |
ikenna1 | 14:88ca5b1a111a | 67 | _ship.set_dimensions(9,6); |
ikenna1 | 26:a53d41adf40b | 68 | _ship.draw_ship(lcd,_shipno); |
ikenna1 | 40:90c7a893d513 | 69 | _weapons.draw(lcd,pad,_shipno,closest); |
ikenna1 | 13:e114d362186d | 70 | } |
ikenna1 | 21:628fb703188f | 71 | if(_shipno == 1) { |
ikenna1 | 14:88ca5b1a111a | 72 | _ship.set_dimensions(7,10); |
ikenna1 | 26:a53d41adf40b | 73 | _ship.draw_ship(lcd,_shipno); |
ikenna1 | 40:90c7a893d513 | 74 | _weapons.draw(lcd,pad,_shipno,closest); |
ikenna1 | 26:a53d41adf40b | 75 | } |
ikenna1 | 26:a53d41adf40b | 76 | if(_shipno == 2) { |
ikenna1 | 26:a53d41adf40b | 77 | _ship.set_dimensions(7,10); |
ikenna1 | 26:a53d41adf40b | 78 | _ship.draw_ship(lcd,_shipno); |
ikenna1 | 40:90c7a893d513 | 79 | _weapons.draw(lcd,pad,_shipno,closest); |
ikenna1 | 13:e114d362186d | 80 | } |
ikenna1 | 40:90c7a893d513 | 81 | if(_dead == true) { |
ikenna1 | 40:90c7a893d513 | 82 | game_over(lcd); |
ikenna1 | 38:4571537238ed | 83 | } |
ikenna1 | 39:7824f9080f59 | 84 | disp_points(lcd); |
ikenna1 | 11:73cd744ffa80 | 85 | } |
ikenna1 | 7:ed5870cfb3e0 | 86 | |
ikenna1 | 7:ed5870cfb3e0 | 87 | void RosenEngine::update(Gamepad &pad) |
ikenna1 | 7:ed5870cfb3e0 | 88 | { |
ikenna1 | 35:3341f2bd0408 | 89 | _enemy.update_seeker(ship_xpos, ship_ypos); |
ikenna1 | 30:711d722f3cef | 90 | _enemy.update_shooter(ship_xpos, ship_ypos); |
ikenna1 | 35:3341f2bd0408 | 91 | //printf("update_shooter\n"); |
ikenna1 | 32:098fbc1222cd | 92 | _enemy.update_shw(); |
ikenna1 | 21:628fb703188f | 93 | if(_shipno == 0) { |
ikenna1 | 14:88ca5b1a111a | 94 | _ship.update_ship(_xjoystick,_yjoystick); |
ikenna1 | 14:88ca5b1a111a | 95 | _weapons.update(); |
ikenna1 | 35:3341f2bd0408 | 96 | kestrelw_seeker_collision(pad); |
ikenna1 | 14:88ca5b1a111a | 97 | } |
ikenna1 | 35:3341f2bd0408 | 98 | //printf("if shipno == 0\n"); |
ikenna1 | 23:0301effce801 | 99 | if(_shipno == 1 && A == false) { |
ikenna1 | 14:88ca5b1a111a | 100 | _ship.update_ship(_xjoystick,_yjoystick); |
ikenna1 | 14:88ca5b1a111a | 101 | _weapons.update(); |
ikenna1 | 14:88ca5b1a111a | 102 | } |
ikenna1 | 35:3341f2bd0408 | 103 | //printf("if shipno == 1\n"); |
ikenna1 | 27:f99249e727fd | 104 | if(_shipno == 2) { |
ikenna1 | 27:f99249e727fd | 105 | _ship.update_ship(_xjoystick,_yjoystick); |
ikenna1 | 27:f99249e727fd | 106 | _weapons.update(); |
ikenna1 | 27:f99249e727fd | 107 | } |
ikenna1 | 35:3341f2bd0408 | 108 | // test(); |
ikenna1 | 35:3341f2bd0408 | 109 | shooter_ship_collision(pad); |
ikenna1 | 35:3341f2bd0408 | 110 | seeker_ship_collision(pad); |
ikenna1 | 35:3341f2bd0408 | 111 | shooterw_ship_collision(pad); |
ikenna1 | 35:3341f2bd0408 | 112 | imperionw_seeker_collision(pad); |
ikenna1 | 35:3341f2bd0408 | 113 | kestrelw_shooter_collision(pad); |
ikenna1 | 35:3341f2bd0408 | 114 | imperionw_shooter_collision(pad); |
ikenna1 | 40:90c7a893d513 | 115 | orionw_collision(pad); |
ikenna1 | 36:c25417f0d150 | 116 | check_health(); |
ikenna1 | 37:8d8c8cce0bc7 | 117 | rand_no(); |
ikenna1 | 38:4571537238ed | 118 | scaling(timer(12)); |
ikenna1 | 40:90c7a893d513 | 119 | |
ikenna1 | 7:ed5870cfb3e0 | 120 | } |
ikenna1 | 9:241a1a7d8527 | 121 | void RosenEngine::get_pos() |
ikenna1 | 9:241a1a7d8527 | 122 | { |
ikenna1 | 9:241a1a7d8527 | 123 | Vector2D ship_pos = _ship.get_pos(); |
ikenna1 | 9:241a1a7d8527 | 124 | ship_xpos = ship_pos.x; |
ikenna1 | 9:241a1a7d8527 | 125 | ship_ypos = ship_pos.y; |
ikenna1 | 40:90c7a893d513 | 126 | |
ikenna1 | 39:7824f9080f59 | 127 | _seeker1_pos = _enemy.get_seekerpos(1); |
ikenna1 | 39:7824f9080f59 | 128 | _seeker2_pos = _enemy.get_seekerpos(2); |
ikenna1 | 39:7824f9080f59 | 129 | _seeker3_pos = _enemy.get_seekerpos(3); |
ikenna1 | 35:3341f2bd0408 | 130 | |
ikenna1 | 37:8d8c8cce0bc7 | 131 | _shooter1_pos = _enemy.get_shooterpos(1); |
ikenna1 | 37:8d8c8cce0bc7 | 132 | _shooter2_pos = _enemy.get_shooterpos(2); |
ikenna1 | 37:8d8c8cce0bc7 | 133 | _shooter3_pos = _enemy.get_shooterpos(3); |
ikenna1 | 35:3341f2bd0408 | 134 | |
ikenna1 | 9:241a1a7d8527 | 135 | _weapons.init(ship_xpos, ship_ypos, ship_width); |
ikenna1 | 13:e114d362186d | 136 | _ycursor = _menu.get_ycursor(); |
ikenna1 | 25:faba9eb44514 | 137 | |
ikenna1 | 25:faba9eb44514 | 138 | if(_shipno == 0) { |
ikenna1 | 25:faba9eb44514 | 139 | ship_width = 9; |
ikenna1 | 25:faba9eb44514 | 140 | ship_height = 6; |
ikenna1 | 25:faba9eb44514 | 141 | } |
ikenna1 | 25:faba9eb44514 | 142 | if(_shipno == 1) { |
ikenna1 | 25:faba9eb44514 | 143 | ship_width = 7; |
ikenna1 | 25:faba9eb44514 | 144 | ship_height = 10; |
ikenna1 | 25:faba9eb44514 | 145 | } |
ikenna1 | 9:241a1a7d8527 | 146 | } |
ikenna1 | 9:241a1a7d8527 | 147 | void RosenEngine::title(N5110 &lcd) |
ikenna1 | 9:241a1a7d8527 | 148 | { |
ikenna1 | 30:711d722f3cef | 149 | _menu.title(lcd,_shipno); |
ikenna1 | 10:c33d7593a275 | 150 | _menu.update(_d); |
ikenna1 | 10:c33d7593a275 | 151 | } |
ikenna1 | 13:e114d362186d | 152 | int RosenEngine::get_ycursor() |
ikenna1 | 10:c33d7593a275 | 153 | { |
ikenna1 | 13:e114d362186d | 154 | _ycursor = _menu.get_ycursor(); |
ikenna1 | 10:c33d7593a275 | 155 | return _ycursor; |
ikenna1 | 12:47578eb9ea73 | 156 | } |
ikenna1 | 21:628fb703188f | 157 | int RosenEngine::get_shipno() |
ikenna1 | 13:e114d362186d | 158 | { |
ikenna1 | 21:628fb703188f | 159 | _shipno = _menu.get_xcursor(); |
ikenna1 | 21:628fb703188f | 160 | return _shipno; |
ikenna1 | 13:e114d362186d | 161 | } |
ikenna1 | 12:47578eb9ea73 | 162 | void RosenEngine::ship_select(N5110 &lcd) |
ikenna1 | 12:47578eb9ea73 | 163 | { |
ikenna1 | 12:47578eb9ea73 | 164 | _menu.update(_d); |
ikenna1 | 12:47578eb9ea73 | 165 | _menu.disp_ships(lcd); |
ikenna1 | 17:e65a9f981834 | 166 | } |
ikenna1 | 35:3341f2bd0408 | 167 | bool RosenEngine::check_collision(int xpos1, int ypos1,int width1,int height1,int xpos2, int ypos2,int width2,int height2) |
ikenna1 | 35:3341f2bd0408 | 168 | { |
ikenna1 | 35:3341f2bd0408 | 169 | // Create arrays of all positions with appropriate height and length |
ikenna1 | 35:3341f2bd0408 | 170 | int xpos1_array[width1]; |
ikenna1 | 35:3341f2bd0408 | 171 | int ypos1_array[height1]; |
ikenna1 | 35:3341f2bd0408 | 172 | int xpos2_array[width2]; |
ikenna1 | 35:3341f2bd0408 | 173 | int ypos2_array[height2]; |
ikenna1 | 35:3341f2bd0408 | 174 | bool xcol = false; |
ikenna1 | 35:3341f2bd0408 | 175 | bool ycol = false; |
ikenna1 | 35:3341f2bd0408 | 176 | bool col = false; |
ikenna1 | 35:3341f2bd0408 | 177 | //printf("variables declared\n"); |
ikenna1 | 35:3341f2bd0408 | 178 | // Loop through both height and width to get a 2D aray of the sprites position |
ikenna1 | 35:3341f2bd0408 | 179 | for(int cx = 0; cx<width1; cx=cx+1) { |
ikenna1 | 35:3341f2bd0408 | 180 | xpos1_array[cx]= xpos1 + cx; |
ikenna1 | 35:3341f2bd0408 | 181 | for(int nx = 0; nx<width2; nx=nx+1) { |
ikenna1 | 35:3341f2bd0408 | 182 | xpos2_array[nx]= xpos2 + nx; |
ikenna1 | 35:3341f2bd0408 | 183 | if(xpos2_array[nx] == xpos1_array[cx]) { |
ikenna1 | 35:3341f2bd0408 | 184 | xcol = true; |
ikenna1 | 35:3341f2bd0408 | 185 | } |
ikenna1 | 35:3341f2bd0408 | 186 | // printf("xarray = %d,x2array = %d,xcol = %d\n",xpos2_array[nx],xpos1_array[cx],xcol); |
ikenna1 | 35:3341f2bd0408 | 187 | } |
ikenna1 | 35:3341f2bd0408 | 188 | } |
ikenna1 | 35:3341f2bd0408 | 189 | //printf("first loop done\n"); |
ikenna1 | 35:3341f2bd0408 | 190 | for(int cy = 0; cy<height1; cy=cy+1) { |
ikenna1 | 35:3341f2bd0408 | 191 | ypos1_array[cy]= ypos1 + cy; |
ikenna1 | 35:3341f2bd0408 | 192 | for(int ny = 0; ny<height2; ny=ny+1) { |
ikenna1 | 35:3341f2bd0408 | 193 | ypos2_array[ny]= ypos2 + ny; |
ikenna1 | 35:3341f2bd0408 | 194 | if(ypos2_array[ny] == ypos1_array[cy]) { |
ikenna1 | 35:3341f2bd0408 | 195 | ycol = true; |
ikenna1 | 35:3341f2bd0408 | 196 | } |
ikenna1 | 35:3341f2bd0408 | 197 | // printf("yarray = %d,y2array = %d,ycol = %d\n",ypos2_array[ny],ypos1_array[cy],ycol); |
ikenna1 | 35:3341f2bd0408 | 198 | } |
ikenna1 | 35:3341f2bd0408 | 199 | } |
ikenna1 | 35:3341f2bd0408 | 200 | //printf("second loop done\n"); |
ikenna1 | 35:3341f2bd0408 | 201 | // if both the hight and width position values are equal a collision has occured |
ikenna1 | 35:3341f2bd0408 | 202 | col = (xcol & ycol); |
ikenna1 | 35:3341f2bd0408 | 203 | //printf("col gotten, col = %d\n",col); |
ikenna1 | 35:3341f2bd0408 | 204 | return col; |
ikenna1 | 35:3341f2bd0408 | 205 | } |
ikenna1 | 35:3341f2bd0408 | 206 | bool RosenEngine::check_collision1(int xpos1,int width1,int xpos2,int width2) |
ikenna1 | 35:3341f2bd0408 | 207 | { |
ikenna1 | 35:3341f2bd0408 | 208 | // Create arrays of all positions with appropriate height and length |
ikenna1 | 35:3341f2bd0408 | 209 | int xpos1_array[width1]; |
ikenna1 | 35:3341f2bd0408 | 210 | int xpos2_array[width2]; |
ikenna1 | 35:3341f2bd0408 | 211 | bool xcol = false; |
ikenna1 | 35:3341f2bd0408 | 212 | |
ikenna1 | 35:3341f2bd0408 | 213 | for(int cx = 0; cx<width1; cx=cx+1) { |
ikenna1 | 35:3341f2bd0408 | 214 | xpos1_array[cx]= xpos1 + cx; |
ikenna1 | 35:3341f2bd0408 | 215 | for(int nx = 0; nx<width2; nx=nx+1) { |
ikenna1 | 35:3341f2bd0408 | 216 | xpos2_array[nx]= xpos2 + nx; |
ikenna1 | 35:3341f2bd0408 | 217 | if(xpos2_array[nx] == xpos1_array[cx]) { |
ikenna1 | 35:3341f2bd0408 | 218 | xcol = true; |
ikenna1 | 35:3341f2bd0408 | 219 | } |
ikenna1 | 35:3341f2bd0408 | 220 | // printf("xarray = %d,x2array = %d,xcol = %d\n",xpos2_array[nx],xpos1_array[cx],xcol); |
ikenna1 | 35:3341f2bd0408 | 221 | } |
ikenna1 | 35:3341f2bd0408 | 222 | } |
ikenna1 | 35:3341f2bd0408 | 223 | return xcol; |
ikenna1 | 35:3341f2bd0408 | 224 | } |
ikenna1 | 35:3341f2bd0408 | 225 | |
ikenna1 | 35:3341f2bd0408 | 226 | void RosenEngine::test() |
ikenna1 | 35:3341f2bd0408 | 227 | { |
ikenna1 | 35:3341f2bd0408 | 228 | bool test; |
ikenna1 | 35:3341f2bd0408 | 229 | test = check_collision(5,5,5,5,5,5,5,5); |
ikenna1 | 35:3341f2bd0408 | 230 | if (test == false) { |
ikenna1 | 35:3341f2bd0408 | 231 | printf("fail\n"); |
ikenna1 | 35:3341f2bd0408 | 232 | } else { |
ikenna1 | 35:3341f2bd0408 | 233 | printf("pass\n"); |
ikenna1 | 35:3341f2bd0408 | 234 | } |
ikenna1 | 35:3341f2bd0408 | 235 | test = check_collision(0,0,1,1,24,24,1,1); |
ikenna1 | 35:3341f2bd0408 | 236 | if (test == true) { |
ikenna1 | 35:3341f2bd0408 | 237 | printf("fail\n"); |
ikenna1 | 35:3341f2bd0408 | 238 | } else { |
ikenna1 | 35:3341f2bd0408 | 239 | printf("pass\n"); |
ikenna1 | 35:3341f2bd0408 | 240 | } |
ikenna1 | 35:3341f2bd0408 | 241 | } |
ikenna1 | 35:3341f2bd0408 | 242 | // make function resemble test |
ikenna1 | 35:3341f2bd0408 | 243 | |
ikenna1 | 35:3341f2bd0408 | 244 | void RosenEngine::seeker_ship_collision(Gamepad &pad) |
ikenna1 | 35:3341f2bd0408 | 245 | { |
ikenna1 | 39:7824f9080f59 | 246 | bool col1,col2,col3; |
ikenna1 | 40:90c7a893d513 | 247 | |
ikenna1 | 39:7824f9080f59 | 248 | col1 = check_collision(ship_xpos,ship_ypos,9,6,_seeker1_pos.x, _seeker1_pos.y,10,7); |
ikenna1 | 39:7824f9080f59 | 249 | col2 = check_collision(ship_xpos,ship_ypos,9,6,_seeker2_pos.x, _seeker2_pos.y,10,7); |
ikenna1 | 39:7824f9080f59 | 250 | col3 = check_collision(ship_xpos,ship_ypos,9,6,_seeker3_pos.x, _seeker3_pos.y,10,7); |
ikenna1 | 39:7824f9080f59 | 251 | int sel = 0; |
ikenna1 | 40:90c7a893d513 | 252 | |
ikenna1 | 39:7824f9080f59 | 253 | if (col1 == true && _no_seekers >= 1) { |
ikenna1 | 39:7824f9080f59 | 254 | sel = 1; |
ikenna1 | 39:7824f9080f59 | 255 | } |
ikenna1 | 39:7824f9080f59 | 256 | if (col2 == true && _no_seekers >= 2) { |
ikenna1 | 39:7824f9080f59 | 257 | sel = 2; |
ikenna1 | 39:7824f9080f59 | 258 | } |
ikenna1 | 39:7824f9080f59 | 259 | if (col3 == true && _no_seekers >= 3) { |
ikenna1 | 39:7824f9080f59 | 260 | sel = 3; |
ikenna1 | 39:7824f9080f59 | 261 | } |
ikenna1 | 39:7824f9080f59 | 262 | // printf("col1 = %d, col2 = %d, col3 = %d, no_seekers = %d\n",col1,col2,col3,_no_seekers); |
ikenna1 | 40:90c7a893d513 | 263 | if(sel != 0) { |
ikenna1 | 39:7824f9080f59 | 264 | _health.update(5,pad); |
ikenna1 | 39:7824f9080f59 | 265 | _health.seekerh_update(sel,10); |
ikenna1 | 35:3341f2bd0408 | 266 | pad.tone(500,0.05); |
ikenna1 | 35:3341f2bd0408 | 267 | wait(0.05); |
ikenna1 | 35:3341f2bd0408 | 268 | } |
ikenna1 | 35:3341f2bd0408 | 269 | } |
ikenna1 | 35:3341f2bd0408 | 270 | void RosenEngine::shooter_ship_collision(Gamepad &pad) |
ikenna1 | 35:3341f2bd0408 | 271 | { |
ikenna1 | 39:7824f9080f59 | 272 | bool col1,col2,col3; |
ikenna1 | 39:7824f9080f59 | 273 | int sel = 0; |
ikenna1 | 39:7824f9080f59 | 274 | col1 = check_collision(ship_xpos,ship_ypos,9,6,_shooter1_pos.x, _shooter1_pos.y,10,7); |
ikenna1 | 39:7824f9080f59 | 275 | col2 = check_collision(ship_xpos,ship_ypos,9,6,_shooter2_pos.x, _shooter2_pos.y,10,7); |
ikenna1 | 39:7824f9080f59 | 276 | col3 = check_collision(ship_xpos,ship_ypos,9,6,_shooter3_pos.x, _shooter3_pos.y,10,7); |
ikenna1 | 35:3341f2bd0408 | 277 | |
ikenna1 | 39:7824f9080f59 | 278 | if(col1 == true && _no_shooters >= 1) { |
ikenna1 | 39:7824f9080f59 | 279 | sel = 1; |
ikenna1 | 39:7824f9080f59 | 280 | } |
ikenna1 | 39:7824f9080f59 | 281 | if(col2 == true && _no_shooters >= 2) { |
ikenna1 | 39:7824f9080f59 | 282 | sel = 2; |
ikenna1 | 39:7824f9080f59 | 283 | } |
ikenna1 | 39:7824f9080f59 | 284 | if(col3 == true && _no_shooters >= 3) { |
ikenna1 | 39:7824f9080f59 | 285 | sel = 3; |
ikenna1 | 39:7824f9080f59 | 286 | } |
ikenna1 | 40:90c7a893d513 | 287 | if(sel != 0) { |
ikenna1 | 35:3341f2bd0408 | 288 | _health.update(1,pad); |
ikenna1 | 39:7824f9080f59 | 289 | _health.shooterh_update(sel,10); |
ikenna1 | 35:3341f2bd0408 | 290 | pad.tone(500,0.05); |
ikenna1 | 40:90c7a893d513 | 291 | wait(0.05); |
ikenna1 | 35:3341f2bd0408 | 292 | } |
ikenna1 | 35:3341f2bd0408 | 293 | } |
ikenna1 | 35:3341f2bd0408 | 294 | void RosenEngine::shooterw_ship_collision(Gamepad &pad) |
ikenna1 | 35:3341f2bd0408 | 295 | { |
ikenna1 | 37:8d8c8cce0bc7 | 296 | Vector2D _shooterw1_pos = _enemy.get_shwpos(1); |
ikenna1 | 37:8d8c8cce0bc7 | 297 | Vector2D _shooterw2_pos = _enemy.get_shwpos(2); |
ikenna1 | 37:8d8c8cce0bc7 | 298 | Vector2D _shooterw3_pos = _enemy.get_shwpos(3); |
ikenna1 | 35:3341f2bd0408 | 299 | |
ikenna1 | 39:7824f9080f59 | 300 | bool col1,col2,col3; |
ikenna1 | 39:7824f9080f59 | 301 | int sel = 0; |
ikenna1 | 39:7824f9080f59 | 302 | col1 = check_collision(ship_xpos,ship_ypos,9,6,_shooterw1_pos.x, _shooterw1_pos.y,2,2); |
ikenna1 | 39:7824f9080f59 | 303 | col2 = check_collision(ship_xpos,ship_ypos,9,6,_shooterw2_pos.x, _shooterw2_pos.y,2,2); |
ikenna1 | 39:7824f9080f59 | 304 | col3 = check_collision(ship_xpos,ship_ypos,9,6,_shooterw3_pos.x, _shooterw3_pos.y,2,2); |
ikenna1 | 35:3341f2bd0408 | 305 | |
ikenna1 | 39:7824f9080f59 | 306 | if(col1 == true && _no_shooters >= 1) { |
ikenna1 | 39:7824f9080f59 | 307 | sel = 1; |
ikenna1 | 39:7824f9080f59 | 308 | } |
ikenna1 | 39:7824f9080f59 | 309 | if(col2 == true && _no_shooters >= 2) { |
ikenna1 | 39:7824f9080f59 | 310 | sel = 2; |
ikenna1 | 39:7824f9080f59 | 311 | } |
ikenna1 | 39:7824f9080f59 | 312 | if(col3 == true && _no_shooters >= 3) { |
ikenna1 | 39:7824f9080f59 | 313 | sel = 3; |
ikenna1 | 39:7824f9080f59 | 314 | } |
ikenna1 | 40:90c7a893d513 | 315 | if(sel != 0) { |
ikenna1 | 35:3341f2bd0408 | 316 | _health.update(1,pad); |
ikenna1 | 35:3341f2bd0408 | 317 | pad.tone(500,0.05); |
ikenna1 | 40:90c7a893d513 | 318 | wait(0.05); |
ikenna1 | 35:3341f2bd0408 | 319 | } |
ikenna1 | 35:3341f2bd0408 | 320 | } |
ikenna1 | 35:3341f2bd0408 | 321 | void RosenEngine::kestrelw_seeker_collision(Gamepad &pad) |
ikenna1 | 35:3341f2bd0408 | 322 | { |
ikenna1 | 39:7824f9080f59 | 323 | bool col1, col2, col3; |
ikenna1 | 39:7824f9080f59 | 324 | int sel = 0; |
ikenna1 | 35:3341f2bd0408 | 325 | Vector2D missle_pos = _weapons.get_pos(_shipno); |
ikenna1 | 39:7824f9080f59 | 326 | col1 = check_collision(_seeker1_pos.x,_seeker1_pos.y,9,6,missle_pos.x,missle_pos.y,1,1); |
ikenna1 | 39:7824f9080f59 | 327 | col2 = check_collision(_seeker2_pos.x,_seeker2_pos.y,9,6,missle_pos.x,missle_pos.y,1,1); |
ikenna1 | 39:7824f9080f59 | 328 | col3 = check_collision(_seeker3_pos.x,_seeker3_pos.y,9,6,missle_pos.x,missle_pos.y,1,1); |
ikenna1 | 39:7824f9080f59 | 329 | if (col1 == true && _no_seekers >= 1) { |
ikenna1 | 39:7824f9080f59 | 330 | sel = 1; |
ikenna1 | 39:7824f9080f59 | 331 | } |
ikenna1 | 39:7824f9080f59 | 332 | if (col2 == true && _no_seekers >= 2) { |
ikenna1 | 39:7824f9080f59 | 333 | sel = 2; |
ikenna1 | 39:7824f9080f59 | 334 | } |
ikenna1 | 39:7824f9080f59 | 335 | if (col3 == true && _no_seekers >= 3) { |
ikenna1 | 39:7824f9080f59 | 336 | sel = 3; |
ikenna1 | 39:7824f9080f59 | 337 | } |
ikenna1 | 40:90c7a893d513 | 338 | if(sel != 0) { |
ikenna1 | 35:3341f2bd0408 | 339 | pad.tone(500,0.05); |
ikenna1 | 39:7824f9080f59 | 340 | _health.seekerh_update(sel,5); |
ikenna1 | 35:3341f2bd0408 | 341 | wait(0.05); |
ikenna1 | 35:3341f2bd0408 | 342 | } |
ikenna1 | 35:3341f2bd0408 | 343 | } |
ikenna1 | 35:3341f2bd0408 | 344 | void RosenEngine::imperionw_seeker_collision(Gamepad &pad) |
ikenna1 | 35:3341f2bd0408 | 345 | { |
ikenna1 | 39:7824f9080f59 | 346 | bool col1,col2,col3; |
ikenna1 | 39:7824f9080f59 | 347 | int sel = 0; |
ikenna1 | 40:90c7a893d513 | 348 | if(_shipno == 1){ |
ikenna1 | 39:7824f9080f59 | 349 | if(ship_ypos > _seeker1_pos.y + 6) { |
ikenna1 | 39:7824f9080f59 | 350 | col1 = check_collision1(_seeker1_pos.x,9,ship_xpos + 2,3); |
ikenna1 | 39:7824f9080f59 | 351 | if (col1 == true && A == true && _no_seekers >= 1) { |
ikenna1 | 40:90c7a893d513 | 352 | sel = 1; |
ikenna1 | 35:3341f2bd0408 | 353 | } |
ikenna1 | 35:3341f2bd0408 | 354 | } |
ikenna1 | 39:7824f9080f59 | 355 | if(ship_ypos > _seeker2_pos.y + 6) { |
ikenna1 | 39:7824f9080f59 | 356 | col2 = check_collision1(_seeker2_pos.x,9,ship_xpos + 2,3); |
ikenna1 | 39:7824f9080f59 | 357 | if (col2 == true && A == true && _no_seekers >= 2) { |
ikenna1 | 39:7824f9080f59 | 358 | sel = 2; |
ikenna1 | 39:7824f9080f59 | 359 | } |
ikenna1 | 39:7824f9080f59 | 360 | } |
ikenna1 | 39:7824f9080f59 | 361 | if(ship_ypos > _seeker1_pos.y + 6) { |
ikenna1 | 39:7824f9080f59 | 362 | col3 = check_collision1(_seeker3_pos.x,9,ship_xpos + 2,3); |
ikenna1 | 39:7824f9080f59 | 363 | if (col3 == true && A == true && _no_seekers >= 3) { |
ikenna1 | 39:7824f9080f59 | 364 | sel = 3; |
ikenna1 | 39:7824f9080f59 | 365 | } |
ikenna1 | 39:7824f9080f59 | 366 | } |
ikenna1 | 40:90c7a893d513 | 367 | } |
ikenna1 | 40:90c7a893d513 | 368 | if(sel != 0) { |
ikenna1 | 39:7824f9080f59 | 369 | _health.seekerh_update(sel,10); |
ikenna1 | 39:7824f9080f59 | 370 | pad.tone(500,0.05); |
ikenna1 | 39:7824f9080f59 | 371 | wait(0.05); |
ikenna1 | 39:7824f9080f59 | 372 | } |
ikenna1 | 35:3341f2bd0408 | 373 | } |
ikenna1 | 35:3341f2bd0408 | 374 | void RosenEngine::kestrelw_shooter_collision(Gamepad &pad) |
ikenna1 | 35:3341f2bd0408 | 375 | { |
ikenna1 | 35:3341f2bd0408 | 376 | Vector2D missle_pos = _weapons.get_pos(_shipno); |
ikenna1 | 35:3341f2bd0408 | 377 | bool col1, col2, col3; |
ikenna1 | 39:7824f9080f59 | 378 | int sel = 0; |
ikenna1 | 35:3341f2bd0408 | 379 | col1 = check_collision(_shooter1_pos.x,_shooter1_pos.y,9,6,missle_pos.x,missle_pos.y,1,1); |
ikenna1 | 35:3341f2bd0408 | 380 | col2 = check_collision(_shooter2_pos.x,_shooter2_pos.y,9,6,missle_pos.x,missle_pos.y,1,1); |
ikenna1 | 35:3341f2bd0408 | 381 | col3 = check_collision(_shooter3_pos.x,_shooter3_pos.y,9,6,missle_pos.x,missle_pos.y,1,1); |
ikenna1 | 39:7824f9080f59 | 382 | if (col1 == true && _no_shooters >= 1) { |
ikenna1 | 39:7824f9080f59 | 383 | sel = 1; |
ikenna1 | 39:7824f9080f59 | 384 | } |
ikenna1 | 39:7824f9080f59 | 385 | if (col2 == true && _no_shooters >= 2) { |
ikenna1 | 39:7824f9080f59 | 386 | sel = 2; |
ikenna1 | 35:3341f2bd0408 | 387 | } |
ikenna1 | 39:7824f9080f59 | 388 | if (col3 == true && _no_shooters >= 3) { |
ikenna1 | 39:7824f9080f59 | 389 | sel = 3; |
ikenna1 | 39:7824f9080f59 | 390 | } |
ikenna1 | 40:90c7a893d513 | 391 | // printf("col1 = %d,col2 = %d,col3 = %d, no_shooters = %d\n",col1,col2,col3,_no_shooters); |
ikenna1 | 40:90c7a893d513 | 392 | if(sel != 0) { |
ikenna1 | 35:3341f2bd0408 | 393 | pad.tone(500,0.05); |
ikenna1 | 39:7824f9080f59 | 394 | _health.shooterh_update(sel,5); |
ikenna1 | 35:3341f2bd0408 | 395 | wait(0.05); |
ikenna1 | 35:3341f2bd0408 | 396 | } |
ikenna1 | 35:3341f2bd0408 | 397 | } |
ikenna1 | 35:3341f2bd0408 | 398 | void RosenEngine::imperionw_shooter_collision(Gamepad &pad) |
ikenna1 | 35:3341f2bd0408 | 399 | { |
ikenna1 | 39:7824f9080f59 | 400 | bool col1,col2,col3; |
ikenna1 | 39:7824f9080f59 | 401 | int sel = 0; |
ikenna1 | 40:90c7a893d513 | 402 | if(_shipno == 1) { |
ikenna1 | 40:90c7a893d513 | 403 | if(ship_ypos > _shooter1_pos.y + 6) { |
ikenna1 | 40:90c7a893d513 | 404 | col1 = check_collision1(_shooter1_pos.x,9,ship_xpos + 2,3); |
ikenna1 | 40:90c7a893d513 | 405 | if (col1 == true && A == true && _no_shooters >= 1) { |
ikenna1 | 40:90c7a893d513 | 406 | sel = 1; |
ikenna1 | 40:90c7a893d513 | 407 | } |
ikenna1 | 40:90c7a893d513 | 408 | } |
ikenna1 | 40:90c7a893d513 | 409 | if(ship_ypos > _shooter2_pos.y + 6) { |
ikenna1 | 40:90c7a893d513 | 410 | col2 = check_collision1(_shooter2_pos.x,9,ship_xpos + 2,3); |
ikenna1 | 40:90c7a893d513 | 411 | if (col2 == true && A == true && _no_shooters >= 2) { |
ikenna1 | 40:90c7a893d513 | 412 | sel = 2; |
ikenna1 | 40:90c7a893d513 | 413 | } |
ikenna1 | 40:90c7a893d513 | 414 | } |
ikenna1 | 40:90c7a893d513 | 415 | if(ship_ypos > _shooter3_pos.y + 6) { |
ikenna1 | 40:90c7a893d513 | 416 | col3 = check_collision1(_shooter3_pos.x,9,ship_xpos + 2,3); |
ikenna1 | 40:90c7a893d513 | 417 | if (col3 == true && A == true && _no_shooters >= 3) { |
ikenna1 | 40:90c7a893d513 | 418 | sel = 3; |
ikenna1 | 40:90c7a893d513 | 419 | } |
ikenna1 | 35:3341f2bd0408 | 420 | } |
ikenna1 | 35:3341f2bd0408 | 421 | } |
ikenna1 | 40:90c7a893d513 | 422 | if(sel != 0) { |
ikenna1 | 39:7824f9080f59 | 423 | _health.shooterh_update(sel,10); |
ikenna1 | 39:7824f9080f59 | 424 | pad.tone(500,0.05); |
ikenna1 | 39:7824f9080f59 | 425 | wait(0.05); |
ikenna1 | 39:7824f9080f59 | 426 | } |
ikenna1 | 36:c25417f0d150 | 427 | } |
ikenna1 | 40:90c7a893d513 | 428 | void RosenEngine::orionw_collision(Gamepad &pad) |
ikenna1 | 40:90c7a893d513 | 429 | { |
ikenna1 | 40:90c7a893d513 | 430 | |
ikenna1 | 40:90c7a893d513 | 431 | Vector2D inde = find_closest1(); |
ikenna1 | 40:90c7a893d513 | 432 | int index1 = inde.x; |
ikenna1 | 40:90c7a893d513 | 433 | int index2 = inde.x - 3; |
ikenna1 | 40:90c7a893d513 | 434 | int distance = inde.y; |
ikenna1 | 40:90c7a893d513 | 435 | |
ikenna1 | 40:90c7a893d513 | 436 | // enemy 0,1 and 2 are shooters |
ikenna1 | 40:90c7a893d513 | 437 | if(_no_shooters >= index1 && A == true && distance < 15){ |
ikenna1 | 40:90c7a893d513 | 438 | _health.shooterh_update(index1,10); |
ikenna1 | 40:90c7a893d513 | 439 | pad.tone(500,0.05); |
ikenna1 | 40:90c7a893d513 | 440 | wait(0.05); |
ikenna1 | 40:90c7a893d513 | 441 | } |
ikenna1 | 40:90c7a893d513 | 442 | if(_no_seekers >= index2 && A == true && distance < 15){ |
ikenna1 | 40:90c7a893d513 | 443 | _health.seekerh_update(index2,10); |
ikenna1 | 40:90c7a893d513 | 444 | pad.tone(500,0.05); |
ikenna1 | 40:90c7a893d513 | 445 | wait(0.05); |
ikenna1 | 40:90c7a893d513 | 446 | } |
ikenna1 | 40:90c7a893d513 | 447 | |
ikenna1 | 40:90c7a893d513 | 448 | |
ikenna1 | 40:90c7a893d513 | 449 | } |
ikenna1 | 40:90c7a893d513 | 450 | void RosenEngine::check_health() |
ikenna1 | 40:90c7a893d513 | 451 | { |
ikenna1 | 39:7824f9080f59 | 452 | check_se_health(); |
ikenna1 | 39:7824f9080f59 | 453 | check_sh_health(); |
ikenna1 | 40:90c7a893d513 | 454 | |
ikenna1 | 36:c25417f0d150 | 455 | Vector2D hp = _health.get_hp(); |
ikenna1 | 40:90c7a893d513 | 456 | if(hp.x <= 0) { |
ikenna1 | 38:4571537238ed | 457 | // printf("player deaad\n"); |
ikenna1 | 36:c25417f0d150 | 458 | _dead = true; |
ikenna1 | 40:90c7a893d513 | 459 | } |
ikenna1 | 40:90c7a893d513 | 460 | |
ikenna1 | 39:7824f9080f59 | 461 | } |
ikenna1 | 39:7824f9080f59 | 462 | void RosenEngine::check_se_health() |
ikenna1 | 39:7824f9080f59 | 463 | { |
ikenna1 | 39:7824f9080f59 | 464 | int sel = 0; |
ikenna1 | 39:7824f9080f59 | 465 | int seeker1_health = _health.get_seekerh(1); |
ikenna1 | 39:7824f9080f59 | 466 | int seeker2_health = _health.get_seekerh(2); |
ikenna1 | 39:7824f9080f59 | 467 | int seeker3_health = _health.get_seekerh(3); |
ikenna1 | 39:7824f9080f59 | 468 | // printf("seeker1_h = %d, seeker2_h = %d, seeker3_h = %d\n",seeker1_health,seeker2_health,seeker3_health); |
ikenna1 | 40:90c7a893d513 | 469 | if(seeker1_health == 0) { |
ikenna1 | 39:7824f9080f59 | 470 | sel = 1; |
ikenna1 | 39:7824f9080f59 | 471 | } |
ikenna1 | 40:90c7a893d513 | 472 | if(seeker2_health == 0) { |
ikenna1 | 39:7824f9080f59 | 473 | sel = 2; |
ikenna1 | 39:7824f9080f59 | 474 | } |
ikenna1 | 40:90c7a893d513 | 475 | if(seeker3_health == 0) { |
ikenna1 | 39:7824f9080f59 | 476 | sel = 3; |
ikenna1 | 39:7824f9080f59 | 477 | } |
ikenna1 | 40:90c7a893d513 | 478 | if(sel != 0) { |
ikenna1 | 39:7824f9080f59 | 479 | _enemy.reset_seeker(sel); |
ikenna1 | 39:7824f9080f59 | 480 | _health.reset_seekerh(sel); |
ikenna1 | 39:7824f9080f59 | 481 | _score = _score + 10; |
ikenna1 | 39:7824f9080f59 | 482 | } |
ikenna1 | 39:7824f9080f59 | 483 | } |
ikenna1 | 39:7824f9080f59 | 484 | void RosenEngine::check_sh_health() |
ikenna1 | 39:7824f9080f59 | 485 | { |
ikenna1 | 39:7824f9080f59 | 486 | int sel = 0; |
ikenna1 | 39:7824f9080f59 | 487 | int shooter1_health = _health.get_shooterh(1); |
ikenna1 | 39:7824f9080f59 | 488 | int shooter2_health = _health.get_shooterh(2); |
ikenna1 | 39:7824f9080f59 | 489 | int shooter3_health = _health.get_shooterh(3); |
ikenna1 | 40:90c7a893d513 | 490 | |
ikenna1 | 40:90c7a893d513 | 491 | if(shooter1_health == 0) { |
ikenna1 | 39:7824f9080f59 | 492 | sel = 1; |
ikenna1 | 39:7824f9080f59 | 493 | } |
ikenna1 | 40:90c7a893d513 | 494 | if(shooter2_health == 0) { |
ikenna1 | 39:7824f9080f59 | 495 | sel = 2; |
ikenna1 | 39:7824f9080f59 | 496 | } |
ikenna1 | 40:90c7a893d513 | 497 | if(shooter3_health == 0) { |
ikenna1 | 39:7824f9080f59 | 498 | sel = 3; |
ikenna1 | 39:7824f9080f59 | 499 | } |
ikenna1 | 40:90c7a893d513 | 500 | if(sel != 0) { |
ikenna1 | 39:7824f9080f59 | 501 | _enemy.reset_shooter(sel); |
ikenna1 | 39:7824f9080f59 | 502 | _health.reset_shooterh(sel); |
ikenna1 | 39:7824f9080f59 | 503 | _score = _score + 20; |
ikenna1 | 39:7824f9080f59 | 504 | } |
ikenna1 | 37:8d8c8cce0bc7 | 505 | } |
ikenna1 | 37:8d8c8cce0bc7 | 506 | int RosenEngine::rand_no() |
ikenna1 | 37:8d8c8cce0bc7 | 507 | { |
ikenna1 | 37:8d8c8cce0bc7 | 508 | srand(time(NULL)); |
ikenna1 | 37:8d8c8cce0bc7 | 509 | int rand_no = (rand() %45) + 1; |
ikenna1 | 38:4571537238ed | 510 | // printf("random no = %d\n",rand_no); |
ikenna1 | 37:8d8c8cce0bc7 | 511 | return rand_no; |
ikenna1 | 38:4571537238ed | 512 | } |
ikenna1 | 38:4571537238ed | 513 | float RosenEngine::timer(int fps) |
ikenna1 | 38:4571537238ed | 514 | { |
ikenna1 | 38:4571537238ed | 515 | _times_run = _times_run + 1; |
ikenna1 | 38:4571537238ed | 516 | float time_frame = 1.0f/fps; |
ikenna1 | 40:90c7a893d513 | 517 | float time_elapsed = _times_run * time_frame; |
ikenna1 | 38:4571537238ed | 518 | // printf("time elapsed = %f,time frame = %f, _times_run = %d\n",time_elapsed,time_frame,_times_run); |
ikenna1 | 38:4571537238ed | 519 | return time_elapsed; |
ikenna1 | 38:4571537238ed | 520 | } |
ikenna1 | 38:4571537238ed | 521 | void RosenEngine::score(int points) |
ikenna1 | 38:4571537238ed | 522 | { |
ikenna1 | 38:4571537238ed | 523 | _score = _score + points; |
ikenna1 | 38:4571537238ed | 524 | } |
ikenna1 | 38:4571537238ed | 525 | bool RosenEngine::dead() |
ikenna1 | 38:4571537238ed | 526 | { |
ikenna1 | 38:4571537238ed | 527 | return _dead; |
ikenna1 | 38:4571537238ed | 528 | } |
ikenna1 | 38:4571537238ed | 529 | |
ikenna1 | 38:4571537238ed | 530 | void RosenEngine::scaling(float time_elapsed) |
ikenna1 | 38:4571537238ed | 531 | { |
ikenna1 | 40:90c7a893d513 | 532 | if(time_elapsed == _wait_time) { |
ikenna1 | 38:4571537238ed | 533 | _no_shooters = _no_shooters + 1; |
ikenna1 | 40:90c7a893d513 | 534 | _no_seekers = _no_seekers + 1; |
ikenna1 | 38:4571537238ed | 535 | _enemy.sh_scaling(time_elapsed); |
ikenna1 | 39:7824f9080f59 | 536 | _wait_time = _wait_time + 10.00; |
ikenna1 | 38:4571537238ed | 537 | } |
ikenna1 | 40:90c7a893d513 | 538 | if(_no_shooters > 3) { |
ikenna1 | 38:4571537238ed | 539 | _no_shooters = 3; |
ikenna1 | 39:7824f9080f59 | 540 | } |
ikenna1 | 40:90c7a893d513 | 541 | if(_no_seekers > 3) { |
ikenna1 | 39:7824f9080f59 | 542 | _no_seekers = 3; |
ikenna1 | 39:7824f9080f59 | 543 | } |
ikenna1 | 38:4571537238ed | 544 | _enemy.set_noshooters(_no_shooters); |
ikenna1 | 39:7824f9080f59 | 545 | _enemy.set_noseekers(_no_seekers); |
ikenna1 | 39:7824f9080f59 | 546 | // printf("time_elapsed = %f, no_shooters = %d, wait_time = %f\n",time_elapsed,_no_shooters,_wait_time); |
ikenna1 | 38:4571537238ed | 547 | } |
ikenna1 | 38:4571537238ed | 548 | void RosenEngine::game_over(N5110 &lcd) |
ikenna1 | 38:4571537238ed | 549 | { |
ikenna1 | 39:7824f9080f59 | 550 | /* |
ikenna1 | 38:4571537238ed | 551 | lcd.clear(); |
ikenna1 | 39:7824f9080f59 | 552 | lcd.refresh(); |
ikenna1 | 38:4571537238ed | 553 | lcd.printString("Game Over ",2,2); |
ikenna1 | 39:7824f9080f59 | 554 | lcd.printString("Try dodging ",2,3); |
ikenna1 | 39:7824f9080f59 | 555 | lcd.printString("next time",2,4); |
ikenna1 | 39:7824f9080f59 | 556 | lcd.refresh(); |
ikenna1 | 39:7824f9080f59 | 557 | wait(2); |
ikenna1 | 39:7824f9080f59 | 558 | */ |
ikenna1 | 39:7824f9080f59 | 559 | _lore.display(lcd); |
ikenna1 | 39:7824f9080f59 | 560 | } |
ikenna1 | 39:7824f9080f59 | 561 | void RosenEngine::intro(N5110 &lcd) |
ikenna1 | 39:7824f9080f59 | 562 | { |
ikenna1 | 40:90c7a893d513 | 563 | if(_intro == false) { |
ikenna1 | 40:90c7a893d513 | 564 | lcd.clear(); |
ikenna1 | 40:90c7a893d513 | 565 | lcd.refresh(); |
ikenna1 | 40:90c7a893d513 | 566 | lcd.printString("You're tasked",2,0); |
ikenna1 | 40:90c7a893d513 | 567 | lcd.printString(" with holding",2,1); |
ikenna1 | 40:90c7a893d513 | 568 | lcd.printString(" the line ",2,2); |
ikenna1 | 40:90c7a893d513 | 569 | lcd.printString(" from an ",2,3); |
ikenna1 | 40:90c7a893d513 | 570 | lcd.printString("invading army ",2,4); |
ikenna1 | 40:90c7a893d513 | 571 | lcd.refresh(); |
ikenna1 | 40:90c7a893d513 | 572 | wait(2); |
ikenna1 | 40:90c7a893d513 | 573 | lcd.clear(); |
ikenna1 | 40:90c7a893d513 | 574 | lcd.refresh(); |
ikenna1 | 40:90c7a893d513 | 575 | lcd.printString(" as an ",2,0); |
ikenna1 | 40:90c7a893d513 | 576 | lcd.printString(" expendable ",2,1); |
ikenna1 | 40:90c7a893d513 | 577 | lcd.printString(" asset, ",2,2); |
ikenna1 | 40:90c7a893d513 | 578 | lcd.printString(" you are not ",2,3); |
ikenna1 | 40:90c7a893d513 | 579 | lcd.printString(" expected to",2,4); |
ikenna1 | 40:90c7a893d513 | 580 | lcd.printString(" survive ",2,5); |
ikenna1 | 40:90c7a893d513 | 581 | lcd.refresh(); |
ikenna1 | 40:90c7a893d513 | 582 | wait(2); |
ikenna1 | 40:90c7a893d513 | 583 | |
ikenna1 | 39:7824f9080f59 | 584 | } |
ikenna1 | 39:7824f9080f59 | 585 | _intro = true; |
ikenna1 | 39:7824f9080f59 | 586 | } |
ikenna1 | 39:7824f9080f59 | 587 | void RosenEngine::disp_points(N5110 &lcd) |
ikenna1 | 39:7824f9080f59 | 588 | { |
ikenna1 | 39:7824f9080f59 | 589 | char buffer[10]; |
ikenna1 | 39:7824f9080f59 | 590 | sprintf(buffer,"%d",_score); |
ikenna1 | 39:7824f9080f59 | 591 | lcd.printString(buffer,2,0); |
ikenna1 | 39:7824f9080f59 | 592 | } |
ikenna1 | 40:90c7a893d513 | 593 | Vector2D RosenEngine::get_enemynum() |
ikenna1 | 40:90c7a893d513 | 594 | { |
ikenna1 | 40:90c7a893d513 | 595 | return{_no_shooters,_no_seekers}; |
ikenna1 | 40:90c7a893d513 | 596 | |
ikenna1 | 40:90c7a893d513 | 597 | } |
ikenna1 | 40:90c7a893d513 | 598 | int RosenEngine::range(int x1, int y1, float x2, float y2) |
ikenna1 | 40:90c7a893d513 | 599 | { |
ikenna1 | 40:90c7a893d513 | 600 | float rangex = (abs(x1 - x2)); |
ikenna1 | 40:90c7a893d513 | 601 | float rangey = (abs(y1 - y2)); |
ikenna1 | 40:90c7a893d513 | 602 | int distance = floor((rangex+rangey)/2); |
ikenna1 | 40:90c7a893d513 | 603 | // printf("distance = %d\n",distance); |
ikenna1 | 40:90c7a893d513 | 604 | return distance; |
ikenna1 | 40:90c7a893d513 | 605 | } |
ikenna1 | 40:90c7a893d513 | 606 | Vector2D RosenEngine::find_closest1() |
ikenna1 | 40:90c7a893d513 | 607 | { |
ikenna1 | 40:90c7a893d513 | 608 | // get the distance for all enemies |
ikenna1 | 40:90c7a893d513 | 609 | int sh1 = range(ship_xpos,ship_ypos,_shooter1_pos.x,_shooter1_pos.y); |
ikenna1 | 40:90c7a893d513 | 610 | int sh2 = range(ship_xpos,ship_ypos,_shooter2_pos.x,_shooter2_pos.y); |
ikenna1 | 40:90c7a893d513 | 611 | int sh3 = range(ship_xpos,ship_ypos,_shooter3_pos.x,_shooter3_pos.y); |
ikenna1 | 40:90c7a893d513 | 612 | int se1 = range(ship_xpos,ship_ypos,_seeker1_pos.x,_seeker1_pos.y); |
ikenna1 | 40:90c7a893d513 | 613 | int se2 = range(ship_xpos,ship_ypos,_seeker2_pos.x,_seeker2_pos.y); |
ikenna1 | 40:90c7a893d513 | 614 | int se3 = range(ship_xpos,ship_ypos,_seeker3_pos.x,_seeker3_pos.y); |
ikenna1 | 40:90c7a893d513 | 615 | |
ikenna1 | 40:90c7a893d513 | 616 | int close[6] = {sh1,sh2,sh3,se1,se2,se3}; |
ikenna1 | 40:90c7a893d513 | 617 | // find index of the smallest element |
ikenna1 | 40:90c7a893d513 | 618 | int index = 0; |
ikenna1 | 40:90c7a893d513 | 619 | int smallest = close[0]; |
ikenna1 | 40:90c7a893d513 | 620 | for(int i=0; i<6; i=i+1) { |
ikenna1 | 40:90c7a893d513 | 621 | if(smallest>close[i]) { |
ikenna1 | 40:90c7a893d513 | 622 | smallest=close[i]; |
ikenna1 | 40:90c7a893d513 | 623 | index = i; |
ikenna1 | 40:90c7a893d513 | 624 | } |
ikenna1 | 40:90c7a893d513 | 625 | } |
ikenna1 | 40:90c7a893d513 | 626 | return {(index + 1),smallest}; |
ikenna1 | 40:90c7a893d513 | 627 | } |
ikenna1 | 40:90c7a893d513 | 628 | Vector2D RosenEngine::find_closest2(int index) |
ikenna1 | 40:90c7a893d513 | 629 | { |
ikenna1 | 40:90c7a893d513 | 630 | // printf("index = %d, _no_shooters = %d, _no_seekers = %d\n",index,_no_shooters,_no_seekers); |
ikenna1 | 40:90c7a893d513 | 631 | // return the position of the closest enemy |
ikenna1 | 40:90c7a893d513 | 632 | if(index == 1 && _no_shooters >= 1) { |
ikenna1 | 40:90c7a893d513 | 633 | return {_shooter1_pos.x,_shooter1_pos.y}; |
ikenna1 | 40:90c7a893d513 | 634 | } |
ikenna1 | 40:90c7a893d513 | 635 | if(index == 2 && _no_shooters >= 2) { |
ikenna1 | 40:90c7a893d513 | 636 | return {_shooter2_pos.x,_shooter2_pos.y}; |
ikenna1 | 40:90c7a893d513 | 637 | } |
ikenna1 | 40:90c7a893d513 | 638 | if(index == 3 && _no_shooters >= 3) { |
ikenna1 | 40:90c7a893d513 | 639 | return {_shooter3_pos.x,_shooter3_pos.y}; |
ikenna1 | 40:90c7a893d513 | 640 | } |
ikenna1 | 40:90c7a893d513 | 641 | if(index == 4 && _no_seekers >= 1 ) { |
ikenna1 | 40:90c7a893d513 | 642 | return {_seeker1_pos.x,_seeker1_pos.y}; |
ikenna1 | 40:90c7a893d513 | 643 | } |
ikenna1 | 40:90c7a893d513 | 644 | if(index == 5 && _no_seekers >= 2) { |
ikenna1 | 40:90c7a893d513 | 645 | return {_seeker2_pos.x,_seeker2_pos.y}; |
ikenna1 | 40:90c7a893d513 | 646 | } |
ikenna1 | 40:90c7a893d513 | 647 | if(index == 6 && _no_seekers >= 3) { |
ikenna1 | 40:90c7a893d513 | 648 | return {_seeker3_pos.x,_seeker3_pos.y}; |
ikenna1 | 40:90c7a893d513 | 649 | } |
ikenna1 | 40:90c7a893d513 | 650 | |
ikenna1 | 40:90c7a893d513 | 651 | } |