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:
- 10:9f445faa892c
- Parent:
- 9:f6f0f39538c7
- Child:
- 12:f714a9e8c55b
--- a/PongEngine/PongEngine.cpp Sun Apr 21 20:44:24 2019 +0000
+++ b/PongEngine/PongEngine.cpp Mon Apr 22 11:56:30 2019 +0000
@@ -89,6 +89,8 @@
// ball
_ball.draw(lcd);
+ print_scores(lcd);
+
_brick11.draw(lcd);
_brick12.draw(lcd);
_brick13.draw(lcd);
@@ -153,15 +155,47 @@
pad.leds_off();
}
- //else if (_p1.get_lives() == 1) {
+ else if (_p1.get_lives() == 1) {
+ //turn leftmost led on
+ pad.leds_off();
+ pad.led(1,1);
+ }
+
+ else if (_p1.get_lives() == 2) {
+ //turn leftmost led on
+ pad.leds_off();
+ pad.led(1,1);
+ pad.led(2,1);
+ }
+
+ else if (_p1.get_lives() == 3) {
//turn leftmost led on
- //}
+ pad.leds_off();
+ pad.led(1,1);
+ pad.led(2,1);
+ pad.led(3,1);
+ }
+
+ else if (_p1.get_lives() == 4) {
+ pad.leds_on();
+ pad.led(5,0);
+ pad.led(6,0);
+ }
+
+ else if (_p1.get_lives() == 5) {
+ pad.leds_on();
+ pad.led(6,0);
+ }
else if (_p1.get_lives() == 6) {
- pad.leds_off();
+ pad.leds_on();
}
}
+int PongEngine::get_lives() {
+ return _p1.get_lives();
+}
+
void PongEngine::check_wall_collision(Gamepad &pad)
{
// read current ball attributes
@@ -284,37 +318,36 @@
_ball.init(_ball_size,_speed);
pad.tone(1500.0,0.5);
- pad.leds_on();
- wait(0.5);
- pad.leds_off();
+ //flash_backlight(lcd);
}
}
-
-//void lives_leds(Gamepad &pad)
-//{
-// int lives = _p1.get_pos();
-// if (lives == 6) {
-// pad.leds_on();
-// }
-
- //if {lives == 5) {
- // 5leds on
- //}
-
-// if (lives == 0) {
-// pad.leds_off();
-// }
+//void flash_backlight (N5110 &lcd) {
+// lcd.setBrightness(0);
+// wait(0.1);
+// lcd.setBrightness(1);
+// wait(0.1);
+// lcd.setBrightness(0);
+// wait(0.1);
+// lcd.setBrightness(1);
+// wait(0.1);
+// lcd.setBrightness(0);
+// wait(0.1);
+// lcd.setBrightness(1);
+// wait(0.1);
+// lcd.setBrightness(0);
+// wait(0.1);
+// lcd.setBrightness(1);
//}
void PongEngine::print_scores(N5110 &lcd)
{
// get scores from paddles
- int p1_score = _p1.get_score();
+ int p1_score = _p1.get_lives();
// print to LCD i
char buffer1[14];
sprintf(buffer1,"%2d",p1_score);
- //lcd.printString(buffer1,WIDTH/2 - 20,1); // font is 8 wide, so leave 4 pixel gape from middle assuming two digits
+ lcd.printString(buffer1,WIDTH/2 -8,4); // font is 8 wide, so leave 4 pixel gape from middle assuming two digits
}
\ No newline at end of file