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:
- 7:04a7826ff7e4
- Parent:
- 6:d560ecc21ae6
- Child:
- 8:0b9a824c75fe
diff -r d560ecc21ae6 -r 04a7826ff7e4 Eng.cpp --- a/Eng.cpp Sun May 17 14:04:03 2020 +0000 +++ b/Eng.cpp Sun May 17 17:05:13 2020 +0000 @@ -14,6 +14,7 @@ //N5110 lcd; Aim aim; Heston heston; +Pup pup; void Eng::init() @@ -21,6 +22,10 @@ aim.init(); heston.init(); + pup.init(); + pupon = 0; + _tok = 0; + flag = true; } @@ -34,6 +39,18 @@ wait(0.1); check_hit(pad); } + + int c_score = heston.checkscore(); + if (c_score%5 == 0 && flag == false){ + flag = true; + powerup(lcd, pad); + } + if (c_score%5 == 1){ + flag = false; + } + + heston.checkstrike(); + heston.update(pad); aim.update(pad); @@ -44,12 +61,16 @@ { heston.draw(lcd); aim.draw(lcd, 0); + if (pupon == 1){ + pup.draw(lcd, 0); + } } void Eng::check_hit(Gamepad &pad) { Vector2D aim_pos = aim.get_pos(); Vector2D h1_pos = heston.get_pos(); + Vector2D pup_pos = pup.get_pos(); if ( (aim_pos.y >= h1_pos.y) && //top @@ -58,6 +79,43 @@ (aim_pos.x <= h1_pos.x + 11) //right ) { heston.hit(pad); + } + if ( + (pupon == 1) && + (aim_pos.y >= pup_pos.y) && //top + (aim_pos.y <= pup_pos.y + 8) && //bottom + (aim_pos.x >= pup_pos.x) && //left + (aim_pos.x <= pup_pos.x + 8) //right + ) { + pupon = 0; + heston.set_speed(0); + pad.led(2,1); + pad.led(5,1); + wait(0.2); + pad.leds_off(); + } + else { + heston.miss(pad); + } } +void Eng::powerup(N5110 &lcd, Gamepad &pad) +{ + Vector2D aim_pos = aim.get_pos(); + int x = aim_pos.x; + int y = aim_pos.y; + pup.position(x, y); + pupon = 1; + + } + +void Eng::tik() +{ + _tok = _tok + 1; + int rem = _tok%50; + if (rem == 0){ + heston.set_speed(1); + } +} +