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:
- 8:1c0bc1a08153
- Parent:
- 7:4c19433600c8
- Child:
- 9:0efc8d7cdcf7
diff -r 4c19433600c8 -r 1c0bc1a08153 Engine.cpp --- a/Engine.cpp Thu Apr 06 09:38:06 2017 +0000 +++ b/Engine.cpp Sun Apr 09 12:46:39 2017 +0000 @@ -8,6 +8,8 @@ { } +int collisions = 0; + void Engine::init(int friendly_width,int friendly_height,int ship_size,int speed,N5110 &lcd, Gamepad &pad) { _friendly_width = friendly_width; @@ -37,6 +39,7 @@ lcd.drawLine(0,39,84,39,1); _friendly.draw(lcd); _stats.draw_health(lcd); + _stats.check_health(lcd, collisions); } void Engine::ships_gen(N5110 &lcd) @@ -53,6 +56,7 @@ { check_pass(pad); check_death(lcd, pad); + //_stats.check_health(lcd); } void Engine::update(N5110 &lcd, Gamepad &pad) @@ -142,6 +146,7 @@ ) { pad.tone(800.0,0.1); + //collisions = collisions + 1; dead = true; } } @@ -159,6 +164,7 @@ ) { pad.tone(800.0,0.1); + collisions = collisions + 1; } } @@ -175,6 +181,7 @@ ) { pad.tone(800.0,0.1); + collisions = collisions + 1; } } @@ -191,6 +198,7 @@ ) { pad.tone(800.0,0.1); + collisions = collisions + 1; } } @@ -207,6 +215,7 @@ ) { pad.tone(800.0,0.1); + collisions = collisions + 1; } } @@ -223,8 +232,10 @@ ) { pad.tone(800.0,0.1); + collisions = collisions + 1; } } + void Engine::check_death(N5110 &lcd, Gamepad &pad) { check_death1(lcd, pad); @@ -233,4 +244,20 @@ check_death4(lcd, pad); check_death5(lcd, pad); check_death6(lcd, pad); + game_over(lcd, pad); +} + +void Engine::game_over(N5110 &lcd, Gamepad &pad) +{ + if (collisions >= 6) { + lcd.drawRect(0,0,84,48,FILL_WHITE); + lcd.printString(" You Lose! ",0,1); + lcd.printString(" Press Start! ",0,4); + lcd.refresh(); + while (pad.check_event(Gamepad::START_PRESSED) == false) { + wait(0.1); + } + init(_friendly_width, _friendly_height, _ship_size, _speed, lcd, pad); + collisions = 0; + } } \ No newline at end of file