Ahmed Hedait / Mbed 2 deprecated el16ah

Dependencies:   mbed

Committer:
ahmedhedait
Date:
Tue May 08 13:13:20 2018 +0000
Revision:
23:6733f8b9c321
Parent:
22:745b4d352183
Child:
25:28c57be06933
Added a welcome screen and when the game finishes the user could press start to re-start the game.

Who changed what in which revision?

UserRevisionLine numberNew 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 19:c6ebd1394bda 33 // draw the elements in the LCD buffer
ahmedhedait 19:c6ebd1394bda 34 // maze
ahmedhedait 19:c6ebd1394bda 35 _maze.draw(lcd);
ahmedhedait 20:041affa5e242 36
ahmedhedait 20:041affa5e242 37 // ball
ahmedhedait 20:041affa5e242 38 _ball.draw(lcd);
ahmedhedait 22:745b4d352183 39
ahmedhedait 21:bcc84d5cb068 40 // 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 21:bcc84d5cb068 41 // TELL THE USER THE GAME IS FINISHED.
ahmedhedait 21:bcc84d5cb068 42 if (ball_pos.x > 83 & ball_pos.y == 27) {
ahmedhedait 21:bcc84d5cb068 43 print_win(lcd);
ahmedhedait 21:bcc84d5cb068 44 }
ahmedhedait 21:bcc84d5cb068 45 }
ahmedhedait 21:bcc84d5cb068 46
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 21:bcc84d5cb068 57 void MazeEngine::print_win(N5110 &lcd)
ahmedhedait 21:bcc84d5cb068 58 {
ahmedhedait 21:bcc84d5cb068 59 lcd.clear();
ahmedhedait 21:bcc84d5cb068 60 lcd.printString(" Bravo! ",12,2);
ahmedhedait 23:6733f8b9c321 61 lcd.printString(" Press Start ",0,4);
ahmedhedait 17:68d4b4095d80 62 }