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.
Dependencies: mbed
Diff: Eng.cpp
- Revision:
- 8:0b9a824c75fe
- Parent:
- 7:04a7826ff7e4
- Child:
- 9:2836fc3d9ede
--- a/Eng.cpp Sun May 17 17:05:13 2020 +0000 +++ b/Eng.cpp Sun May 17 19:44:26 2020 +0000 @@ -31,13 +31,13 @@ } //void Eng::read_input(Gamepad &pad); -void Eng::update(Gamepad &pad, bool fire, N5110 &lcd) +void Eng::update(Gamepad &pad, int fire, N5110 &lcd) { - if (fire == 1){ + int shot = fire; + if (shot == 1){ aim.draw(lcd, fire); lcd.refresh(); - wait(0.1); - check_hit(pad); + check_hit(pad); } int c_score = heston.checkscore(); @@ -49,7 +49,8 @@ flag = false; } - heston.checkstrike(); + int strikes = heston.checkstrike(); + heston.update(pad); aim.update(pad); @@ -64,6 +65,7 @@ if (pupon == 1){ pup.draw(lcd, 0); } + print_score(lcd); } void Eng::check_hit(Gamepad &pad) @@ -80,7 +82,7 @@ ) { heston.hit(pad); } - if ( + else if ( (pupon == 1) && (aim_pos.y >= pup_pos.y) && //top (aim_pos.y <= pup_pos.y + 8) && //bottom @@ -91,12 +93,12 @@ heston.set_speed(0); pad.led(2,1); pad.led(5,1); - wait(0.2); - pad.leds_off(); } else { heston.miss(pad); } +wait(0.4); +pad.leds_off(); } void Eng::powerup(N5110 &lcd, Gamepad &pad) @@ -118,4 +120,14 @@ heston.set_speed(1); } } - + +void Eng::print_score(N5110 &lcd) +{ + // get scores from paddles + int g_score = heston.checkstrike(); + + // print to LCD i + char buffer1[14]; + sprintf(buffer1,"%2d",g_score); + lcd.printString(buffer1,1,1); // font is 8 wide, so leave 4 pixel gape from middle assuming two digits +}