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:
- 40:ac53905346fb
- Parent:
- 39:a9bb03bef107
- Child:
- 41:fe383cbb51b2
--- a/BreakoutEngine/BreakoutEngine.cpp Thu Apr 25 21:08:34 2019 +0000
+++ b/BreakoutEngine/BreakoutEngine.cpp Fri Apr 26 07:07:42 2019 +0000
@@ -23,32 +23,32 @@
_index = 0;
// y position on screen - WIDTH is defined in N5110.h
- _p1y = HEIGHT - GAP;
+ _p1y = HEIGHT - GAP - 1;
// puts paddles and ball in middle
_p1.init(_p1y,_paddle_height,_paddle_width);
_ball.init(_ball_size,_speed);
- _brick11.init(3,GAP+1,BRICK_HEIGHT,BRICK_WIDTH); // need to figure out how to make a list of these
- _brick12.init(16,GAP+1,BRICK_HEIGHT,BRICK_WIDTH);
- _brick13.init(29,GAP+1,BRICK_HEIGHT,BRICK_WIDTH);
- _brick14.init(42,GAP+1,BRICK_HEIGHT,BRICK_WIDTH);
- _brick15.init(55,GAP+1,BRICK_HEIGHT,BRICK_WIDTH);
- _brick16.init(68,GAP+1,BRICK_HEIGHT,BRICK_WIDTH);
+ _brick11.init(3,GAP_TOP+1,BRICK_HEIGHT,BRICK_WIDTH); // need to figure out how to make a list of these
+ _brick12.init(16,GAP_TOP+1,BRICK_HEIGHT,BRICK_WIDTH);
+ _brick13.init(29,GAP_TOP+1,BRICK_HEIGHT,BRICK_WIDTH);
+ _brick14.init(42,GAP_TOP+1,BRICK_HEIGHT,BRICK_WIDTH);
+ _brick15.init(55,GAP_TOP+1,BRICK_HEIGHT,BRICK_WIDTH);
+ _brick16.init(68,GAP_TOP+1,BRICK_HEIGHT,BRICK_WIDTH);
- _brick21.init(3,GAP+BRICK_HEIGHT+2,BRICK_HEIGHT,BRICK_WIDTH); // need to figure out how to make a list of these
- _brick22.init(16,GAP+BRICK_HEIGHT+2,BRICK_HEIGHT,BRICK_WIDTH);
- _brick23.init(29,GAP+BRICK_HEIGHT+2,BRICK_HEIGHT,BRICK_WIDTH);
- _brick24.init(42,GAP+BRICK_HEIGHT+2,BRICK_HEIGHT,BRICK_WIDTH);
- _brick25.init(55,GAP+BRICK_HEIGHT+2,BRICK_HEIGHT,BRICK_WIDTH);
- _brick26.init(68,GAP+BRICK_HEIGHT+2,BRICK_HEIGHT,BRICK_WIDTH);
+ _brick21.init(3,GAP_TOP+BRICK_HEIGHT+2,BRICK_HEIGHT,BRICK_WIDTH); // need to figure out how to make a list of these
+ _brick22.init(16,GAP_TOP+BRICK_HEIGHT+2,BRICK_HEIGHT,BRICK_WIDTH);
+ _brick23.init(29,GAP_TOP+BRICK_HEIGHT+2,BRICK_HEIGHT,BRICK_WIDTH);
+ _brick24.init(42,GAP_TOP+BRICK_HEIGHT+2,BRICK_HEIGHT,BRICK_WIDTH);
+ _brick25.init(55,GAP_TOP+BRICK_HEIGHT+2,BRICK_HEIGHT,BRICK_WIDTH);
+ _brick26.init(68,GAP_TOP+BRICK_HEIGHT+2,BRICK_HEIGHT,BRICK_WIDTH);
- _brick31.init(3,GAP+1+((BRICK_HEIGHT+1)*2),BRICK_HEIGHT,BRICK_WIDTH); // need to figure out how to make a list of these
- _brick32.init(16,GAP+1+((BRICK_HEIGHT+1)*2),BRICK_HEIGHT,BRICK_WIDTH);
- _brick33.init(29,GAP+1+((BRICK_HEIGHT+1)*2),BRICK_HEIGHT,BRICK_WIDTH);
- _brick34.init(42,GAP+1+((BRICK_HEIGHT+1)*2),BRICK_HEIGHT,BRICK_WIDTH);
- _brick35.init(55,GAP+1+((BRICK_HEIGHT+1)*2),BRICK_HEIGHT,BRICK_WIDTH);
- _brick36.init(68,GAP+1+((BRICK_HEIGHT+1)*2),BRICK_HEIGHT,BRICK_WIDTH);
+ _brick31.init(3,GAP_TOP+1+((BRICK_HEIGHT+1)*2),BRICK_HEIGHT,BRICK_WIDTH); // need to figure out how to make a list of these
+ _brick32.init(16,GAP_TOP+1+((BRICK_HEIGHT+1)*2),BRICK_HEIGHT,BRICK_WIDTH);
+ _brick33.init(29,GAP_TOP+1+((BRICK_HEIGHT+1)*2),BRICK_HEIGHT,BRICK_WIDTH);
+ _brick34.init(42,GAP_TOP+1+((BRICK_HEIGHT+1)*2),BRICK_HEIGHT,BRICK_WIDTH);
+ _brick35.init(55,GAP_TOP+1+((BRICK_HEIGHT+1)*2),BRICK_HEIGHT,BRICK_WIDTH);
+ _brick36.init(68,GAP_TOP+1+((BRICK_HEIGHT+1)*2),BRICK_HEIGHT,BRICK_WIDTH);
listofBricks.push_back(_brick11); //maybe be able yo iterate through and this.draw(), maybe useful if i figure out how to delete objects aswell
listofBricks.push_back(_brick12);
@@ -128,9 +128,9 @@
{
// draw the elements in the LCD buffer
// pitch
- lcd.drawRect(0,0,WIDTH,HEIGHT,FILL_TRANSPARENT);
+ lcd.drawRect(0,GAP_TOP - 2,WIDTH,HEIGHT - GAP_TOP + 2,FILL_TRANSPARENT);
//score
- //print_scores(lcd);
+ print_scores(lcd);
// paddles
_p1.draw(lcd);
// ball
@@ -223,8 +223,8 @@
Vector2D ball_pos = _ball.get_pos();
Vector2D ball_velocity = _ball.get_velocity();
- if (ball_pos.y <= 1) { // 1 due to 1 pixel boundary
- ball_pos.y = 1; // bounce off ceiling without going off screen
+ if (ball_pos.y <= GAP_TOP - 1) { // 1 due to 1 pixel boundary
+ ball_pos.y = GAP_TOP - 1; // bounce off ceiling without going off screen
ball_velocity.y = -ball_velocity.y;
// audio feedback
pad.tone(750.0,0.1);
@@ -379,12 +379,13 @@
void BreakoutEngine::print_scores(N5110 &lcd) //maybe add to oneless
{
// get scores from paddles
- int p1_score = _p1.get_lives();
-
+ int p1_score = (18 - get_num_left())*100; //maybe add a previous score so the score carries over through victory screens. add hi score fix so restart restarts from 321
+ // also, add a multiplier of 2 for every contiue on victory
// print to LCD i
char buffer1[14];
sprintf(buffer1,"%2d",p1_score);
- lcd.printString(buffer1,WIDTH/2 -8,4); // font is 8 wide, so leave 4 pixel gape from middle assuming two digits
+ lcd.printString("SCORE: ",2 ,0);
+ lcd.printString(buffer1,WIDTH/2 -2,0); // font is 8 wide, so leave 4 pixel gape from middle assuming two digits
}
int BreakoutEngine::get_num_left(){