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.
Revision 21:bcc84d5cb068, committed 2018-05-08
- Comitter:
- ahmedhedait
- Date:
- Tue May 08 12:20:04 2018 +0000
- Parent:
- 20:041affa5e242
- Child:
- 22:745b4d352183
- Commit message:
- implemented the code in which when the ball reach the goal, bravo is printed and maze disappears.
Changed in this revision
--- a/Ball/Ball.cpp Tue May 08 11:57:19 2018 +0000
+++ b/Ball/Ball.cpp Tue May 08 12:20:04 2018 +0000
@@ -52,4 +52,9 @@
_circx = 3;
}
+}
+
+Vector2D Ball::get_pos() {
+ Vector2D p = {_circx,_circy};
+ return p;
}
\ No newline at end of file
--- a/Ball/Ball.h Tue May 08 11:57:19 2018 +0000
+++ b/Ball/Ball.h Tue May 08 12:20:04 2018 +0000
@@ -15,6 +15,7 @@
void init();
void draw(N5110 &lcd);
void update(Direction dir);
+ Vector2D get_pos();
private:
--- 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
--- a/MazeEngine/MazeEngine.h Tue May 08 11:57:19 2018 +0000
+++ b/MazeEngine/MazeEngine.h Tue May 08 12:20:04 2018 +0000
@@ -13,17 +13,21 @@
MazeEngine();
~MazeEngine();
-
+
void init();
void read_input(Gamepad &pad);
void draw(N5110 &lcd);
void update(Gamepad &pad);
-
+
private:
+ void check_goal(Gamepad &pad);
+ void print_win(N5110 &lcd);
+
Maze _maze;
Direction _dir;
Ball _ball;
+ Vector2D ball_pos;
};
#endif
\ No newline at end of file
--- a/main.cpp Tue May 08 11:57:19 2018 +0000
+++ b/main.cpp Tue May 08 12:20:04 2018 +0000
@@ -39,8 +39,6 @@
// INTIALISING THE STARTING POSITION OF THE BALL IN SCREEN AND THE LETTERS.
- float circy = 5;
- float circx = 5;
int a;
int b;
int c;
@@ -188,23 +186,11 @@
}
}
- // 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 (circy == 27) {
- if (circx > WIDTH) {
- circx = WIDTH;
- }
- } else if (circx > 80) {
- circx = 80;
- }
+
- // 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 (circx > 83 & circy == 27) {
- lcd.clear();
- lcd.printString(" Bravo! ",12,2);
- }
+
+
wait(.035);
lcd.refresh();