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: MazeEngine/MazeEngine.cpp
- Revision:
- 21:bcc84d5cb068
- Parent:
- 20:041affa5e242
- Child:
- 22:745b4d352183
diff -r 041affa5e242 -r bcc84d5cb068 MazeEngine/MazeEngine.cpp --- a/MazeEngine/MazeEngine.cpp Tue May 08 11:57:19 2018 +0000 +++ b/MazeEngine/MazeEngine.cpp Tue May 08 12:20:04 2018 +0000 @@ -23,6 +23,7 @@ void MazeEngine::update(Gamepad &pad) { _ball.update(_dir); + check_goal(pad); } void MazeEngine::draw(N5110 &lcd) @@ -33,4 +34,30 @@ // ball _ball.draw(lcd); + + // HERE IS A SIMPLE CODE THAT WHEN THE BALL PASS THROUGH THE OPENING THEN THE SCREEN SHOULD BE CLEARED IN WHICH BRAVO IS PRINTED TO + // TELL THE USER THE GAME IS FINISHED. + if (ball_pos.x > 83 & ball_pos.y == 27) { + print_win(lcd); + } +} + +void MazeEngine::check_goal(Gamepad &pad) +{ + ball_pos = _ball.get_pos(); + // WHEN THE BALL REACHES THE Y-AXIS NEEDED WHICH IS 27, THEN THE JOYSTICK FREELY MOVE THE BALL RIGHT THROUGH THE OPENING OF THE SMAZE WALL, + // HOWEVER, IF THE BALL IS NOT EQUAL TO THE Y-AXIS NEEDED, THEN THE BALL MUST BE RESTRICTED TO MOVING SO THAT IT DOES NOT PASS THE WALLS. + if (ball_pos.y == 27) { + if (ball_pos.x > WIDTH) { + ball_pos.x = WIDTH; + } + } else if (ball_pos.x > 80) { + ball_pos.x = 80; + } +} + +void MazeEngine::print_win(N5110 &lcd) +{ + lcd.clear(); + lcd.printString(" Bravo! ",12,2); } \ No newline at end of file