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: BreakoutEngine/BreakoutEngine.cpp
- Revision:
- 92:2e6d88e44f56
- Parent:
- 91:c01a736fb0d9
- Child:
- 93:18f81996ea89
--- a/BreakoutEngine/BreakoutEngine.cpp Mon May 06 22:57:04 2019 +0000
+++ b/BreakoutEngine/BreakoutEngine.cpp Mon May 06 23:03:22 2019 +0000
@@ -150,16 +150,6 @@
}
-void BreakoutEngine::inc_index()
-{
- _index ++;
-}
-
-void BreakoutEngine::reset_index()
-{
- _index = 0;
-}
-
void BreakoutEngine::draw(N5110 &lcd)
{
// draw the elements in the LCD buffer
@@ -304,13 +294,13 @@
Vector2D ball_pos = _ball.get_pos();
Vector2D ball_velocity = _ball.get_velocity();
- // check p1 first
- Vector2D p1_pos = _paddle.get_pos();
+ // check paddle first
+ Vector2D paddle_pos = _paddle.get_pos();
// see if ball has hit the paddle by checking for overlaps
if (
- (ball_pos.x >= p1_pos.x) && //left
- (ball_pos.x <= p1_pos.x + _paddle_width) && //right
+ (ball_pos.x >= paddle_pos.x) && //left
+ (ball_pos.x <= paddle_pos.x + _paddle_width) && //right
(ball_pos.y >= _paddley) && //bottom
(ball_pos.y <= _paddley + _paddle_height) //top
) { // edit this so that if it hits the middle, reflect, else change angle depending on how far off centre (add angle to ball)
@@ -319,20 +309,20 @@
ball_pos.y = _paddley + _paddle_height - 1;
ball_velocity.y = -ball_velocity.y;
-// if (ball_pos.x == p1_pos.x + PADDLE_WIDTH/2) { // check ballxpos in relation to paddle xpos. translate the distance from the centre to an angle between 30 and 60 degrees in that direction
+// if (ball_pos.x == paddle_pos.x + PADDLE_WIDTH/2) { // check ballxpos in relation to paddle xpos. translate the distance from the centre to an angle between 30 and 60 degrees in that direction
// ball_pos.y = _paddley + _paddle_height - 1;
// ball_velocity.y = -ball_velocity.y;
// }
-// else if (ball_pos.x <= p1_pos.x + PADDLE_WIDTH/2) {
-// float ang = 40*(((p1_pos.x + PADDLE_WIDTH/2)-ball_pos.x)/(PADDLE_WIDTH/2 - p1_pos.x)) + 30; //converts the distance from the centre to an angle between 30 and 60
+// else if (ball_pos.x <= paddle_pos.x + PADDLE_WIDTH/2) {
+// float ang = 40*(((paddle_pos.x + PADDLE_WIDTH/2)-ball_pos.x)/(PADDLE_WIDTH/2 - paddle_pos.x)) + 30; //converts the distance from the centre to an angle between 30 and 60
// if (ball_velocity.x > 0) {
// ball_velocity.x = -ball_velocity.x;
// }
// ball_pos.y = _paddley + _paddle_heigh - 1;
// ball_velocity.y = -tan(ang);
// }
-// else if (ball_pos.x >= p1_pos.x + PADDLE_WIDTH/2) {
-// float ang = 40*(((p1_pos.x + PADDLE_WIDTH/2)-ball_pos.x)/(PADDLE_WIDTH/2 - p1_pos.x)) + 30; //converts the distance from the centre to an angle between 30 and 60
+// else if (ball_pos.x >= paddle_pos.x + PADDLE_WIDTH/2) {
+// float ang = 40*(((paddle_pos.x + PADDLE_WIDTH/2)-ball_pos.x)/(PADDLE_WIDTH/2 - paddle_pos.x)) + 30; //converts the distance from the centre to an angle between 30 and 60
// if (ball_velocity.x < 0) {
// ball_velocity.x = -ball_velocity.x;
// }
@@ -372,7 +362,7 @@
//delete _brick11;
if(it_R-> hit() == true) {
it_R -> set_posx(-100);
- one_less();
+ dec_num_left();
}
}
}
@@ -384,7 +374,7 @@
void BreakoutEngine::check_laser_collisions(Gamepad &pad)
{
// read current ball attributes
- // check p1 first
+ // check paddle first
for (it_L = listofLasers.begin(); it_L != listofLasers.end(); ++it_L) {
for (it_R = listofBricks.begin(); it_R != listofBricks.end(); ++it_R) {
if (
@@ -399,7 +389,7 @@
pad.tone(1000.0,0.1);
if(it_R-> hit() == true) {
it_R -> set_posx(-100);
- one_less();
+ dec_num_left();
}
}
}
@@ -409,7 +399,7 @@
bool BreakoutEngine::check_loss(Gamepad &pad)
{
Vector2D ball_pos = _ball.get_pos();
- // P1 has scored
+ // paddle has scored
if (ball_pos.y > HEIGHT) {
_paddle.lose_life();
//lose_screen(); // go to loss screen then initialise again
@@ -449,7 +439,7 @@
{
return _number_left;
}
-void BreakoutEngine::one_less()
+void BreakoutEngine::dec_num_left()
{
_number_left -= 1;
}
@@ -469,3 +459,11 @@
{
_multiplier = 0;
}
+void BreakoutEngine::inc_index()
+{
+ _index ++;
+}
+void BreakoutEngine::reset_index()
+{
+ _index = 0;
+}