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 92:2e6d88e44f56, committed 2019-05-06
- Comitter:
- jamesheavey
- Date:
- Mon May 06 23:03:22 2019 +0000
- Parent:
- 91:c01a736fb0d9
- Child:
- 93:18f81996ea89
- Commit message:
- cp
Changed in this revision
--- 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;
+}
--- a/BreakoutEngine/BreakoutEngine.h Mon May 06 22:57:04 2019 +0000
+++ b/BreakoutEngine/BreakoutEngine.h Mon May 06 23:03:22 2019 +0000
@@ -13,13 +13,13 @@
#include <iterator>
#define GAP_TOP 10
-#define GAP 2
+#define GAP 2
/* BreajoutEngine Class
@author James Heavey, University of Leeds
-@brief Controls the Breakout game
+@brief Controls the Breakout game
@date May 2019
-*/
+*/
class BreakoutEngine
{
@@ -45,7 +45,7 @@
int get_score();
void inc_mult();
void set_mult_zero();
-
+
private:
void check_wall_collisions(Gamepad &pad);
@@ -53,8 +53,8 @@
void check_brick_collisions(Gamepad &pad);
void check_laser_collisions(Gamepad &pad);
void print_scores(N5110 &lcd);
- void one_less();
-
+ void dec_num_left();
+
int _paddle_width;
int _paddle_height;
int _ball_size;
@@ -62,25 +62,25 @@
int _index;
int _multiplier;
double _cool_time;
-
+
int _paddley;
int _number_left;
int _prev_score;
int _score;
-
+
Direction _d;
float _mag;
-
+
Paddle _paddle;
-
+
Ball _ball;
-
+
std::list<Laser> listofLasers;
std::list<Laser>::iterator it_L;
-
+
std::list<Brick> listofBricks;
- std::list<Brick>::iterator it_R;
-
+ std::list<Brick>::iterator it_R;
+
Brick _brick11;
Brick _brick12;
Brick _brick13;
@@ -99,7 +99,7 @@
Brick _brick34;
Brick _brick35;
Brick _brick36;
-
+
Laser _laser1;
Laser _laser2;
Laser _laser3;