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: Classic_Engine/ClassicEngine.cpp
- Revision:
- 31:c95f1b1d6423
- Parent:
- 29:42651f87522b
- Child:
- 32:eff573ad8e42
--- a/Classic_Engine/ClassicEngine.cpp Sat Apr 27 13:07:25 2019 +0000 +++ b/Classic_Engine/ClassicEngine.cpp Sat Apr 27 18:57:06 2019 +0000 @@ -7,6 +7,7 @@ } void ClassicEngine::init(Ball &ball, Map &map){ + _frames = 0; _ball_coord.x = 42; _ball_coord.y = 24; _map_coord.x = 47; @@ -19,9 +20,59 @@ map.read_input(accelerometer, ball); map.update(); ball.set_position(_ball_coord); + _frames++; + _map_coord = map.get_map_display(); + _abs_ball_pos.x = _ball_coord.x + _map_coord.x; + _abs_ball_pos.y = _ball_coord.y + _map_coord.y; } void ClassicEngine::classic_draw(N5110 &lcd, Map &map, Ball &ball){ map.draw(lcd); ball.draw(lcd); } + +bool ClassicEngine::finished(){ + bool finished = false; + if(_abs_ball_pos.x == 402 && //these are the range of coords the ball + _abs_ball_pos.y > 101 && //can have as it crosses the finish line + _abs_ball_pos.y < 141 ){ + finished = true; + } + else{ finished = false; } + return finished; +} + +void ClassicEngine::mode_complete(N5110 &lcd, Gamepad &gamepad, int fps){ + while(!(gamepad.check_event(gamepad.A_PRESSED))){ + float time_taken = _frames / fps; + char buffer[6]; + sprintf(buffer, "%4.f", time_taken); + lcd.clear(); + lcd.printString("You win!", 18, 1); + lcd.printString("Your time:", 12, 3); + lcd.printString(buffer, 18,4); + lcd.printChar('s',54,4); + lcd.printString("(A = back)", 24, 5); + lcd.refresh(); + wait(0.2); + } +} + +bool ClassicEngine::mode_failed(N5110 &lcd, Gamepad &gamepad, Ball &ball, Map &map){ + bool back_to_start_menu = false; + while(1){ + wait(0.2); + lcd.clear(); + lcd.printString("You lose!", 15, 1); + lcd.printString("Back = A", 18, 3); + lcd.printString("Replay = B", 12, 4); + lcd.refresh(); + if(gamepad.check_event(gamepad.A_PRESSED)){ + back_to_start_menu = true; + break; } + if(gamepad.check_event(gamepad.B_PRESSED)){ + back_to_start_menu = false; + break; } + } + return back_to_start_menu; +} \ No newline at end of file