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.
Dependencies: mbed FATFileSystem
Diff: Ball/Ball.cpp
- Revision:
- 9:bc34f2243e43
- Parent:
- 8:d410856c6d04
- Child:
- 10:9f54a6366e94
diff -r d410856c6d04 -r bc34f2243e43 Ball/Ball.cpp
--- a/Ball/Ball.cpp Thu Apr 18 10:42:42 2019 +0000
+++ b/Ball/Ball.cpp Sat Apr 20 10:42:17 2019 +0000
@@ -16,14 +16,14 @@
//public methods
-void Ball::init(float x, float y) //ball starts stationary in x and y positions given
+void Ball::init(Coord start_pos) //ball starts new level stationary in x and y positions given
{
- _x_pos = x;
- _y_pos = y;
+ _x_pos = start_pos.x;
+ _y_pos = start_pos.y;
_x_vel = 0.0f;
_y_vel = 0.0f;
+ _total_shot_count = _total_shot_count + _shot_count;
_shot_count = 0;
-
}
void Ball::drawBall(N5110 &lcd)
@@ -40,8 +40,8 @@
void Ball::drawPower(N5110 &lcd, float mag)
{
- lcd.drawRect(0,0,36,6,FILL_TRANSPARENT);
- lcd.drawRect(0,0,36*mag,6,FILL_BLACK);
+ lcd.drawRect(0,10,36,6,FILL_TRANSPARENT);
+ lcd.drawRect(0,10,36*mag,6,FILL_BLACK);
}
@@ -87,13 +87,32 @@
return shot_count;
}
-void Ball::set_vel(float x_vel, float y_vel)
+int Ball::get_total_shot_count()
{
- _x_vel = x_vel;
- _y_vel = y_vel;
+ int total_shot_count = _total_shot_count;
+ return total_shot_count;
+}
+
+void Ball::set_total_shot_count(int total_shot_count)
+{
+ int _total_shot_count = total_shot_count;
}
-void Ball::check_wall_bounce(Course map[], int size) //uses information from course struct to check if ball bounces against any of the walls
+bool Ball::check_hole(Coord hole) //returns true when ball is hit in hole and next level begins
+{
+ if(_x_pos > hole.x - 1 && _x_pos < hole.x + 2 && _y_pos > hole.y - 1 && _y_pos < hole.y + 2) {
+ _x_vel = 0; //stop ball moving
+ _y_vel = 0;
+ _x_pos = hole.x;
+ _y_pos = hole.y;
+ return true; //causes next level process to begin
+ }
+ else {
+ return false;
+ }
+}
+
+void Ball::check_wall_bounce(WallMap map[], int size) //uses information from WallMap array for each level to check for bounces
{
for(int i = 0; i < size; i ++) {