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: PongEngine/PongEngine.cpp
- Revision:
- 6:7f79f320b827
- Parent:
- 4:6bd488b5b31a
- Child:
- 7:ef162a6232ca
--- a/PongEngine/PongEngine.cpp Fri Apr 19 12:41:22 2019 +0000
+++ b/PongEngine/PongEngine.cpp Sat Apr 20 19:25:28 2019 +0000
@@ -25,15 +25,12 @@
_p1.init(_p1y,_paddle_height,_paddle_width);
_ball.init(_ball_size,_speed);
- _grid1.init(3,GAP+1,WIDTH_BRICK,HEIGHT_BRICK); // need to figure out how to make a list of these
- _grid2.init(13,GAP+1,WIDTH_BRICK,HEIGHT_BRICK);
- _grid3.init(23,GAP+1,WIDTH_BRICK,HEIGHT_BRICK);
- _grid4.init(33,GAP+1,WIDTH_BRICK,HEIGHT_BRICK);
- _grid5.init(43,GAP+1,WIDTH_BRICK,HEIGHT_BRICK);
- _grid6.init(53,GAP+1,WIDTH_BRICK,HEIGHT_BRICK);
- _grid7.init(63,GAP+1,WIDTH_BRICK,HEIGHT_BRICK);
- _grid8.init(73,GAP+1,WIDTH_BRICK,HEIGHT_BRICK);
- _grid9.init(83,GAP+1,WIDTH_BRICK,HEIGHT_BRICK);
+ _brick1.init(3,GAP+1,HEIGHT_BRICK,WIDTH_BRICK); // need to figure out how to make a list of these
+ _brick2.init(16,GAP+1,HEIGHT_BRICK,WIDTH_BRICK);
+ _brick3.init(29,GAP+1,HEIGHT_BRICK,WIDTH_BRICK);
+ _brick4.init(42,GAP+1,HEIGHT_BRICK,WIDTH_BRICK);
+ _brick5.init(55,GAP+1,HEIGHT_BRICK,WIDTH_BRICK);
+ _brick6.init(68,GAP+1,HEIGHT_BRICK,WIDTH_BRICK);
}
void PongEngine::read_input(Gamepad &pad)
@@ -55,22 +52,20 @@
// ball
_ball.draw(lcd);
- _grid1.draw(lcd);
- _grid2.draw(lcd);
- _grid3.draw(lcd);
- _grid4.draw(lcd);
- _grid5.draw(lcd);
- _grid6.draw(lcd);
- _grid7.draw(lcd);
- _grid8.draw(lcd);
- _grid9.draw(lcd);
+ _brick1.draw(lcd);
+ _brick2.draw(lcd);
+ _brick3.draw(lcd);
+ _brick4.draw(lcd);
+ _brick5.draw(lcd);
+ _brick6.draw(lcd);
+
// for(int i = GAP+1; i <= WIDTH; i+= WIDTH_BRICK + 1){
// for(int j = GAP+1; j <= (HEIGHT_BRICK + 1)*3; j+= HEIGHT_BRICK + 1){
-// Vector3d grid[i][j]= _grid.init(i, j,WIDTH_BRICK,HEIGHT_BRICK);
+// Vector3d grid[i][j]= _brick.init(i, j,WIDTH_BRICK,HEIGHT_BRICK);
// }
// }
}
@@ -159,17 +154,17 @@
Vector2D ball_velocity = _ball.get_velocity();
// check p1 first
- Vector2D _grid1_pos = _grid1.get_pos();
+ Vector2D _brick1_pos = _brick1.get_pos();
// see if ball has hit the paddle by checking for overlaps
if (
- (ball_pos.x >= _grid1_pos.x) && //left
- (ball_pos.x <= _grid1_pos.x + WIDTH_BRICK) && //right
- (ball_pos.y >= _grid1_pos.y) && //bottom
- (ball_pos.y <= _grid1_pos.y + HEIGHT_BRICK) //top
+ (ball_pos.x >= _brick1_pos.x) && //left
+ (ball_pos.x <= _brick1_pos.x + WIDTH_BRICK) && //right
+ (ball_pos.y >= _brick1_pos.y) && //bottom
+ (ball_pos.y <= _brick1_pos.y + HEIGHT_BRICK) //top
) { // edit this so that if it hits the middle, reflect, else change angle depending on how far off centre (add angle to ball)
// if it has, fix position and reflect x velocity
- ball_pos.y = _grid1_pos.y;
+ ball_pos.y = _brick1_pos.y;
ball_velocity.y = -ball_velocity.y;
// audio feedback
pad.tone(1000.0,0.1);
@@ -178,7 +173,7 @@
// write new attributes
_ball.set_velocity(ball_velocity);
_ball.set_pos(ball_pos);
- _grid1.hit();
+ _brick1.hit();
}
void PongEngine::check_goal(Gamepad &pad)