Ahmed Hedait / Mbed 2 deprecated el16ah

Dependencies:   mbed

Committer:
ahmedhedait
Date:
Tue May 08 12:20:04 2018 +0000
Revision:
21:bcc84d5cb068
Parent:
20:041affa5e242
Child:
22:745b4d352183
implemented the code in which when the ball reach the goal, bravo is printed and maze disappears.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ahmedhedait 17:68d4b4095d80 1 #include "Ball.h"
ahmedhedait 17:68d4b4095d80 2
ahmedhedait 17:68d4b4095d80 3 // nothing doing in the constructor and destructor
ahmedhedait 17:68d4b4095d80 4 Ball::Ball()
ahmedhedait 17:68d4b4095d80 5 {
ahmedhedait 17:68d4b4095d80 6
ahmedhedait 17:68d4b4095d80 7 }
ahmedhedait 17:68d4b4095d80 8
ahmedhedait 17:68d4b4095d80 9 Ball::~Ball()
ahmedhedait 17:68d4b4095d80 10 {
ahmedhedait 17:68d4b4095d80 11
ahmedhedait 20:041affa5e242 12 }
ahmedhedait 20:041affa5e242 13
ahmedhedait 20:041affa5e242 14 void Ball::init()
ahmedhedait 20:041affa5e242 15 {
ahmedhedait 20:041affa5e242 16 _circy = 5;
ahmedhedait 20:041affa5e242 17 _circx = 5;
ahmedhedait 20:041affa5e242 18 _speed = 1;
ahmedhedait 20:041affa5e242 19
ahmedhedait 20:041affa5e242 20 }
ahmedhedait 20:041affa5e242 21
ahmedhedait 20:041affa5e242 22 void Ball::draw(N5110 &lcd)
ahmedhedait 20:041affa5e242 23 {
ahmedhedait 20:041affa5e242 24 // VERY SIMPLE CODE IN WHCIH I DREW THE BALL OF THE MAZE.
ahmedhedait 20:041affa5e242 25 lcd.drawCircle(_circx,_circy,2,FILL_BLACK);
ahmedhedait 20:041affa5e242 26 }
ahmedhedait 20:041affa5e242 27
ahmedhedait 20:041affa5e242 28 void Ball::update(Direction dir)
ahmedhedait 20:041affa5e242 29 {
ahmedhedait 20:041affa5e242 30 if (dir == N) {
ahmedhedait 20:041affa5e242 31 _circy -= _speed;
ahmedhedait 20:041affa5e242 32 } else if (dir == S) {
ahmedhedait 20:041affa5e242 33 _circy += _speed;
ahmedhedait 20:041affa5e242 34 }
ahmedhedait 20:041affa5e242 35
ahmedhedait 20:041affa5e242 36 if (dir == W) {
ahmedhedait 20:041affa5e242 37 _circx -= _speed;
ahmedhedait 20:041affa5e242 38 } else if (dir == E) {
ahmedhedait 20:041affa5e242 39 _circx += _speed;
ahmedhedait 20:041affa5e242 40 }
ahmedhedait 20:041affa5e242 41
ahmedhedait 20:041affa5e242 42 // THIS CODE IS NEEDED TO MAKE SURE THAT THE BALL DOES NOT OFF THE DIMENSIONS OF THE LCD SCREEN.
ahmedhedait 20:041affa5e242 43 if (_circy < 3) {
ahmedhedait 20:041affa5e242 44 _circy = 3;
ahmedhedait 20:041affa5e242 45 }
ahmedhedait 20:041affa5e242 46
ahmedhedait 20:041affa5e242 47 if (_circy > HEIGHT - 4) {
ahmedhedait 20:041affa5e242 48 _circy = HEIGHT - 4;
ahmedhedait 20:041affa5e242 49 }
ahmedhedait 20:041affa5e242 50
ahmedhedait 20:041affa5e242 51 if (_circx < 3) {
ahmedhedait 20:041affa5e242 52 _circx = 3;
ahmedhedait 20:041affa5e242 53 }
ahmedhedait 20:041affa5e242 54
ahmedhedait 21:bcc84d5cb068 55 }
ahmedhedait 21:bcc84d5cb068 56
ahmedhedait 21:bcc84d5cb068 57 Vector2D Ball::get_pos() {
ahmedhedait 21:bcc84d5cb068 58 Vector2D p = {_circx,_circy};
ahmedhedait 21:bcc84d5cb068 59 return p;
ahmedhedait 17:68d4b4095d80 60 }