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:
- 9:2836fc3d9ede
- Parent:
- 8:0b9a824c75fe
- Child:
- 10:6c574b8524df
--- a/Eng.cpp Sun May 17 19:44:26 2020 +0000 +++ b/Eng.cpp Mon May 18 12:41:06 2020 +0000 @@ -15,6 +15,7 @@ Aim aim; Heston heston; Pup pup; +Spikes spikes; void Eng::init() @@ -23,9 +24,11 @@ aim.init(); heston.init(); pup.init(); + spikes.init(); pupon = 0; _tok = 0; flag = true; + spike_f =false; } @@ -54,8 +57,13 @@ heston.update(pad); aim.update(pad); - - + + if (spike_f == true){ + //spikes.update(); + _s1.update(); + _s2.update(); + check_s_hit(); + } } void Eng::draw(N5110 &lcd) @@ -65,7 +73,11 @@ if (pupon == 1){ pup.draw(lcd, 0); } - print_score(lcd); + if (spike_f == true){ + _s1.draw(lcd); + _s2.draw(lcd); + } + //print_score(lcd); } void Eng::check_hit(Gamepad &pad) @@ -76,9 +88,9 @@ if ( (aim_pos.y >= h1_pos.y) && //top - (aim_pos.y <= h1_pos.y + 12) && //bottom + (aim_pos.y <= h1_pos.y + 11) && //bottom (aim_pos.x >= h1_pos.x) && //left - (aim_pos.x <= h1_pos.x + 11) //right + (aim_pos.x <= h1_pos.x + 10) //right ) { heston.hit(pad); } @@ -108,8 +120,6 @@ int y = aim_pos.y; pup.position(x, y); pupon = 1; - - } void Eng::tik() @@ -118,6 +128,9 @@ int rem = _tok%50; if (rem == 0){ heston.set_speed(1); + spike_f = true; + _s1.position(1); + _s2.position(2); } } @@ -130,4 +143,29 @@ 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 -} +} + +void Eng::check_s_hit(){ + Vector2D s1_pos = _s1.get_pos(); + Vector2D s2_pos = _s2.get_pos(); + Vector2D aim_pos = aim.get_pos(); + + if ( + (aim_pos.y >= s1_pos.y) && //top + (aim_pos.y <= s1_pos.y + 4) && //bottom + (aim_pos.x >= s1_pos.x) && //left + (aim_pos.x <= s1_pos.x + 4) //right + ) { + spike_f = false; + } + if ( + (aim_pos.y >= s2_pos.y) && //top + (aim_pos.y <= s2_pos.y + 4) && //bottom + (aim_pos.x >= s2_pos.x) && //left + (aim_pos.x <= s2_pos.x + 4) //right + ) { + spike_f = false; + } + + +}