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.
MazeEngine/MazeEngine.cpp@25:28c57be06933, 2018-05-08 (annotated)
- Committer:
- ahmedhedait
- Date:
- Tue May 08 14:20:24 2018 +0000
- Revision:
- 25:28c57be06933
- Parent:
- 23:6733f8b9c321
I have re-adjusted my last comments so the code to be completed.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ahmedhedait | 17:68d4b4095d80 | 1 | #include "MazeEngine.h" |
ahmedhedait | 17:68d4b4095d80 | 2 | // nothing doing in the constructor and destructor |
ahmedhedait | 17:68d4b4095d80 | 3 | MazeEngine::MazeEngine() |
ahmedhedait | 17:68d4b4095d80 | 4 | { |
ahmedhedait | 17:68d4b4095d80 | 5 | |
ahmedhedait | 17:68d4b4095d80 | 6 | } |
ahmedhedait | 17:68d4b4095d80 | 7 | |
ahmedhedait | 17:68d4b4095d80 | 8 | MazeEngine::~MazeEngine() |
ahmedhedait | 17:68d4b4095d80 | 9 | { |
ahmedhedait | 17:68d4b4095d80 | 10 | |
ahmedhedait | 19:c6ebd1394bda | 11 | } |
ahmedhedait | 19:c6ebd1394bda | 12 | |
ahmedhedait | 19:c6ebd1394bda | 13 | void MazeEngine::init() |
ahmedhedait | 19:c6ebd1394bda | 14 | { |
ahmedhedait | 20:041affa5e242 | 15 | _ball.init(); |
ahmedhedait | 19:c6ebd1394bda | 16 | } |
ahmedhedait | 19:c6ebd1394bda | 17 | |
ahmedhedait | 19:c6ebd1394bda | 18 | void MazeEngine::read_input(Gamepad &pad) |
ahmedhedait | 19:c6ebd1394bda | 19 | { |
ahmedhedait | 20:041affa5e242 | 20 | _dir = pad.get_direction(); |
ahmedhedait | 22:745b4d352183 | 21 | // printf("direction %i\n", _dir); |
ahmedhedait | 20:041affa5e242 | 22 | } |
ahmedhedait | 20:041affa5e242 | 23 | |
ahmedhedait | 20:041affa5e242 | 24 | void MazeEngine::update(Gamepad &pad) |
ahmedhedait | 20:041affa5e242 | 25 | { |
ahmedhedait | 22:745b4d352183 | 26 | _ball.check_wall_collision(pad); |
ahmedhedait | 20:041affa5e242 | 27 | _ball.update(_dir); |
ahmedhedait | 21:bcc84d5cb068 | 28 | check_goal(pad); |
ahmedhedait | 19:c6ebd1394bda | 29 | } |
ahmedhedait | 19:c6ebd1394bda | 30 | |
ahmedhedait | 19:c6ebd1394bda | 31 | void MazeEngine::draw(N5110 &lcd) |
ahmedhedait | 19:c6ebd1394bda | 32 | { |
ahmedhedait | 25:28c57be06933 | 33 | // DRAW THE ELEMENTS OF MAZE. |
ahmedhedait | 19:c6ebd1394bda | 34 | _maze.draw(lcd); |
ahmedhedait | 20:041affa5e242 | 35 | |
ahmedhedait | 25:28c57be06933 | 36 | // BALL DRAWING |
ahmedhedait | 20:041affa5e242 | 37 | _ball.draw(lcd); |
ahmedhedait | 22:745b4d352183 | 38 | |
ahmedhedait | 25:28c57be06933 | 39 | /* 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 |
ahmedhedait | 25:28c57be06933 | 40 | TELL THE USER THE GAME IS FINISHED. */ |
ahmedhedait | 21:bcc84d5cb068 | 41 | if (ball_pos.x > 83 & ball_pos.y == 27) { |
ahmedhedait | 21:bcc84d5cb068 | 42 | print_win(lcd); |
ahmedhedait | 21:bcc84d5cb068 | 43 | } |
ahmedhedait | 21:bcc84d5cb068 | 44 | } |
ahmedhedait | 21:bcc84d5cb068 | 45 | |
ahmedhedait | 25:28c57be06933 | 46 | // CHECK IF THE GOAL IS MET, AND GIVE THE USER ABILITY TO RESTART THE GAME AGAIN. |
ahmedhedait | 21:bcc84d5cb068 | 47 | void MazeEngine::check_goal(Gamepad &pad) |
ahmedhedait | 21:bcc84d5cb068 | 48 | { |
ahmedhedait | 21:bcc84d5cb068 | 49 | ball_pos = _ball.get_pos(); |
ahmedhedait | 23:6733f8b9c321 | 50 | if(ball_pos.x > 83 & ball_pos.y == 27) { |
ahmedhedait | 23:6733f8b9c321 | 51 | if(pad.check_event(Gamepad::START_PRESSED) == true) { |
ahmedhedait | 23:6733f8b9c321 | 52 | init(); |
ahmedhedait | 23:6733f8b9c321 | 53 | } |
ahmedhedait | 23:6733f8b9c321 | 54 | } |
ahmedhedait | 21:bcc84d5cb068 | 55 | } |
ahmedhedait | 21:bcc84d5cb068 | 56 | |
ahmedhedait | 25:28c57be06933 | 57 | // CHECK IF THE GOAL IS MET, AND PRINT OUT TO THE LCD SCREEN. |
ahmedhedait | 21:bcc84d5cb068 | 58 | void MazeEngine::print_win(N5110 &lcd) |
ahmedhedait | 21:bcc84d5cb068 | 59 | { |
ahmedhedait | 21:bcc84d5cb068 | 60 | lcd.clear(); |
ahmedhedait | 25:28c57be06933 | 61 | lcd.printString(" WELL DONE! ",3,2); |
ahmedhedait | 23:6733f8b9c321 | 62 | lcd.printString(" Press Start ",0,4); |
ahmedhedait | 17:68d4b4095d80 | 63 | } |