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: Ball/Ball.cpp
- Revision:
- 25:28c57be06933
- Parent:
- 22:745b4d352183
--- a/Ball/Ball.cpp Tue May 08 13:39:31 2018 +0000 +++ b/Ball/Ball.cpp Tue May 08 14:20:24 2018 +0000 @@ -27,6 +27,7 @@ void Ball::update(Direction dir) { + // ADJUSTING THE SPEED OF THE BALL FOR THE 4 DIFFERENT DIRECTIONS. if (dir == N) { _circy -= _speed; } else if (dir == S) { @@ -39,7 +40,7 @@ _circx += _speed; } - // THIS CODE IS NEEDED TO MAKE SURE THAT THE BALL DOES NOT OFF THE DIMENSIONS OF THE LCD SCREEN. + // THIS CODE IS NEEDED TO MAKE SURE THAT THE BALL DOES NOT SURPASS THE DIMENSIONS OF THE LCD SCREEN. if (_circy < 3) { _circy = 3; } @@ -51,7 +52,6 @@ if (_circx < 3) { _circx = 3; } - } Vector2D Ball::get_pos() { @@ -61,7 +61,7 @@ void Ball::check_wall_collision(Gamepad &pad) { - // FOR LOOP TO STOP BALL FROM GOING THROUGH WALLS + // FOR LOOP TO STOP BALL FROM GOING THROUGH WALLS OF THE MAZE. for (int i = 0; i <= 12; i++) { //printf(" Stage %d\n", i); @@ -153,14 +153,17 @@ _d = 1; } - + // ADDED A PRINT FUNCTION TO DETECT IF COLLISION OCCURED BETWEEN BALL AND WALL OR NOT IN THE GIVEN DIMENSIONS. if ( (_circy >= _b - 2) && //top (_circy <= 1 + _b + _d) && //bottom (_circx >= _a - 2) && //left (_circx <= _a + _c + 1) //right ) { - printf("COLLISION"); + // printf("COLLISION"); + + /* CONDITIONS FOR THE 4 DIRECTIONS FOR EACH RECTANGLE NEEDS TO BE MET SO THAT THE BALL DOES NOT PASS + THE DIFFERENT WALLS OF THE MAZE. */ //left if (_circx <= _a - 2) { if(_circx >= _a - 3) { @@ -192,8 +195,9 @@ } - // 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. + /* GAVE THE AXIS NEEEDED FOR THE BALL TO GET OUT AND ONLY OUT OF THE OPENING OF THE MAZE. WEHN THE CONDITIONS ARE + NOT MEANT, THEN IT RESTRICTS THE BALL FROM MOVING OUTSIDE THE MAZE */ + if (_circy == 27) { if (_circx > WIDTH) { _circx = WIDTH;