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.
Diff: Engine.cpp
- Revision:
- 5:88886c1bd2c1
- Parent:
- 4:e84724dcad49
- Child:
- 6:cae24a40ab34
--- a/Engine.cpp Tue Mar 21 09:33:12 2017 +0000 +++ b/Engine.cpp Sat Apr 01 11:44:22 2017 +0000 @@ -61,10 +61,9 @@ _ship5.draw(lcd); } -void Engine::update(Gamepad &pad) +void Engine::update(N5110 &lcd, Gamepad &pad) { check_pass(pad); - check_death(pad); _friendly.update(_d,_mag); _ship1.update(); @@ -73,6 +72,7 @@ _ship4.update(); _ship5.update(); + check_death(lcd, pad); } void Engine::check_pass(Gamepad &pad) @@ -108,24 +108,96 @@ } } -void Engine::check_death(Gamepad &pad) +void Engine::death(Gamepad &pad) +{ + +} + +void Engine::check_death1(N5110 &lcd, Gamepad &pad) { Vector2D friendly_pos = _friendly.get_pos(); Vector2D ship1_pos = _ship1.get_pos(); + + if ( + (friendly_pos.y >= ship1_pos.y-5) && // change 5 to friendly size and 6 to ship size + (friendly_pos.y <= ship1_pos.y+5) && + (friendly_pos.x+6 >= ship1_pos.x) && + (friendly_pos.x+6 <= ship1_pos.x+5) + ) { - // overlap check - if ((ship1_pos.y == friendly_pos.y) && - (ship1_pos.x == friendly_pos.x) || - (ship2_pos.y == friendly_pos.y) && - (ship2_pos.x == friendly_pos.x) || - (ship3_pos.y == friendly_pos.y) && - (ship3_pos.x == friendly_pos.x) || - (ship4_pos.y == friendly_pos.y) && - (ship4_pos.x == friendly_pos.x) || - (ship5_pos.y == friendly_pos.y) && - (ship5_pos.x == friendly_pos.x)) { - - pad.tone(1000.0,0.1); + pad.tone(800.0,0.1); + } +} + +void Engine::check_death2(N5110 &lcd, Gamepad &pad) +{ + Vector2D friendly_pos = _friendly.get_pos(); + Vector2D ship2_pos = _ship2.get_pos(); + + if ( + (friendly_pos.y >= ship2_pos.y-5) && // change 5 to friendly size and 6 to ship size + (friendly_pos.y <= ship2_pos.y+5) && + (friendly_pos.x+6 >= ship2_pos.x) && + (friendly_pos.x+6 <= ship2_pos.x+5) + ) { + + pad.tone(800.0,0.1); + } +} + +void Engine::check_death3(N5110 &lcd, Gamepad &pad) +{ + Vector2D friendly_pos = _friendly.get_pos(); + Vector2D ship3_pos = _ship3.get_pos(); + + if ( + (friendly_pos.y >= ship3_pos.y-5) && // change 5 to friendly size and 6 to ship size + (friendly_pos.y <= ship3_pos.y+5) && + (friendly_pos.x+6 >= ship3_pos.x) && + (friendly_pos.x+6 <= ship3_pos.x+5) + ) { + + pad.tone(800.0,0.1); } +} + +void Engine::check_death4(N5110 &lcd, Gamepad &pad) +{ + Vector2D friendly_pos = _friendly.get_pos(); + Vector2D ship4_pos = _ship4.get_pos(); + if ( + (friendly_pos.y >= ship4_pos.y-5) && // change 5 to friendly size and 6 to ship size + (friendly_pos.y <= ship4_pos.y+5) && + (friendly_pos.x+6 >= ship4_pos.x) && + (friendly_pos.x+6 <= ship4_pos.x+5) + ) { + + pad.tone(800.0,0.1); + } +} + +void Engine::check_death5(N5110 &lcd, Gamepad &pad) +{ + Vector2D friendly_pos = _friendly.get_pos(); + Vector2D ship5_pos = _ship5.get_pos(); + + if ( + (friendly_pos.y >= ship5_pos.y-5) && // change 5 to friendly size and 6 to ship size + (friendly_pos.y <= ship5_pos.y+5) && + (friendly_pos.x+6 >= ship5_pos.x) && + (friendly_pos.x+6 <= ship5_pos.x+5) + ) { + + pad.tone(800.0,0.1); + } +} + +void Engine::check_death(N5110 &lcd, Gamepad &pad) +{ + check_death1(lcd, pad); + check_death2(lcd, pad); + check_death3(lcd, pad); + check_death4(lcd, pad); + check_death5(lcd, pad); } \ No newline at end of file