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
Diff: RosenEngine/RosenEngine.cpp
- Revision:
- 32:098fbc1222cd
- Parent:
- 31:c7bd3ed16840
- Child:
- 33:7a814c874c57
diff -r c7bd3ed16840 -r 098fbc1222cd RosenEngine/RosenEngine.cpp --- a/RosenEngine/RosenEngine.cpp Sat Apr 20 03:52:22 2019 +0000 +++ b/RosenEngine/RosenEngine.cpp Sat Apr 20 09:05:10 2019 +0000 @@ -44,6 +44,7 @@ _health.draw_shields(lcd); _enemy.draw_seeker(lcd); _enemy.draw_shooter(lcd,3); + _enemy.draw_shw(lcd,pad,3); if(_shipno == 0) { _ship.set_dimensions(9,6); _ship.draw_ship(lcd,_shipno); @@ -65,6 +66,7 @@ { _enemy.update_seeker(ship_xpos, ship_ypos); _enemy.update_shooter(ship_xpos, ship_ypos); + _enemy.update_shw(); if(_shipno == 0) { _ship.update_ship(_xjoystick,_yjoystick); _weapons.update(); @@ -77,8 +79,11 @@ _ship.update_ship(_xjoystick,_yjoystick); _weapons.update(); } - // _menu.update(_d); - + if(shooter_weapon_collision(3) == true){ + _health.update(1,pad); + pad.tone(500,0.05); + wait(0.05); + } if(enemy_ship_collision() == true) { _health.update(1,pad); _enemy.reset_seeker(); @@ -260,6 +265,64 @@ return false; } } +bool RosenEngine::shooter_weapon_collision(int sh_no) +{ + Vector2D shw1_pos = _enemy.get_sh1pos(); + Vector2D shw2_pos = _enemy.get_sh2pos(); + Vector2D shw3_pos = _enemy.get_sh3pos(); + + bool shw1xcol = false; + bool shw1ycol = false; + bool shw2xcol = false; + bool shw2ycol = false; + bool shw3xcol = false; + bool shw3ycol = false; + + int ship_x[9]; + int ship_y[6]; + + for(int cx = 0; cx<=9; cx=cx+1) { + ship_x[cx] = ship_xpos + cx; + if(ship_x[cx] == shw1_pos.x){ + shw1xcol = true; + } + if(ship_x[cx] == shw2_pos.x){ + shw2xcol = true; + } + if(ship_x[cx] == shw3_pos.x){ + shw3xcol = true; + } + } + for(int cy = 0; cy<=6; cy=cy+1) { + ship_y[cy] = (ship_ypos ) + cy ; + if(ship_y[cy] == shw1_pos.y){ + shw1ycol = true; + } + if(ship_y[cy] == shw2_pos.y){ + shw2ycol = true; + } + if(ship_y[cy] == shw3_pos.y){ + shw3ycol = true; + } + } + if(sh_no == 1){ + shw2xcol = false; + shw2ycol = false; + shw3xcol = false; + shw3ycol = false; + } + if(sh_no == 2){ + shw3xcol = false; + shw3ycol = false; + } + + if(shw1xcol && shw1ycol == true || shw2xcol && shw2ycol == true || shw3xcol && shw3ycol == true){ + return true; + } + else{ + return false; + } +} void RosenEngine::score(int points){ _score = _score + points; } \ No newline at end of file