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: GameEngine/GameEngine.cpp
- Revision:
- 8:13cef7cb872e
- Parent:
- 7:06c86ec1f19d
- Child:
- 9:e70179ff61c5
--- a/GameEngine/GameEngine.cpp Tue Apr 24 10:17:39 2018 +0000
+++ b/GameEngine/GameEngine.cpp Tue Apr 24 11:17:43 2018 +0000
@@ -13,7 +13,9 @@
void GameEngine::init()
{
_rocket.init();
- _asteroid.init(2);
+ _asteroid1.init(2);
+ _asteroid2.init(3);
+ _asteroid3.init(4);
}
void GameEngine::read_input(Gamepad &pad)
@@ -26,7 +28,9 @@
{
// draw the game elements in the LCD
_rocket.draw(lcd);
- _asteroid.draw(lcd);
+ _asteroid1.draw(lcd);
+ _asteroid2.draw(lcd);
+ _asteroid3.draw(lcd);
//print_scores(lcd);
print_scores1(lcd);
@@ -37,18 +41,23 @@
check_goal(pad);
_rocket.update(_d,_mag, lcd);
- _asteroid.update();
+ _asteroid1.update();
+ _asteroid2.update();
+ _asteroid3.update();
+
}
void GameEngine::check_goal(Gamepad &pad)
{
- Vector2D _asteroid_pos = _asteroid.get_pos() ;
-
+ Vector2D _asteroid1_pos = _asteroid1.get_pos() ;
+ Vector2D _asteroid2_pos = _asteroid2.get_pos() ;
+ Vector2D _asteroid3_pos = _asteroid3.get_pos() ;
+
Vector2D _rocket_pos = _rocket.get_pos();
- if (_rocket_pos.x+11 >=_asteroid_pos.x && _rocket_pos.x+9 <_asteroid_pos.x ) {//size //sprint width //float/////////////speed
- if( _asteroid_pos.y >= _rocket_pos.y && _asteroid_pos.y <= _rocket_pos.y+7 || _asteroid_pos.y+7 >= _rocket_pos.y && _asteroid_pos.y+7 <= _rocket_pos.y+7 ) {
+ if (_rocket_pos.x+11 >=_asteroid1_pos.x && _rocket_pos.x+9 <_asteroid1_pos.x ) {//size //sprint width //float/////////////speed
+ if( _asteroid1_pos.y >= _rocket_pos.y && _asteroid1_pos.y <= _rocket_pos.y+7 || _asteroid1_pos.y+7 >= _rocket_pos.y && _asteroid1_pos.y+7 <= _rocket_pos.y+7 ) {
_rocket.add_score();
pad.tone(1500.0,0.5);
pad.leds_on();
@@ -56,7 +65,30 @@
pad.leds_off();
}
}
+
+ if (_rocket_pos.x+11 >=_asteroid2_pos.x && _rocket_pos.x+9 <_asteroid2_pos.x ) {//size //sprint width //float/////////////speed
+ if( _asteroid2_pos.y >= _rocket_pos.y && _asteroid2_pos.y <= _rocket_pos.y+7 || _asteroid2_pos.y+7 >= _rocket_pos.y && _asteroid2_pos.y+7 <= _rocket_pos.y+7 ) {
+ _rocket.add_score();
+ pad.tone(1500.0,0.5);
+ pad.leds_on();
+ wait(0.5);
+ pad.leds_off();
+ }
+ }
+
+ if (_rocket_pos.x+11 >=_asteroid3_pos.x && _rocket_pos.x+7 <_asteroid3_pos.x ) {//size //sprint width //float/////////////speed
+ if( _asteroid3_pos.y >= _rocket_pos.y && _asteroid3_pos.y <= _rocket_pos.y+7 || _asteroid3_pos.y+7 >= _rocket_pos.y && _asteroid3_pos.y+7 <= _rocket_pos.y+7 ) {
+ _rocket.add_score();
+ pad.tone(1500.0,0.5);
+ pad.leds_on();
+ wait(0.5);
+ pad.leds_off();
+ }
+ }
+
}
+
+
//////////////////////////////////////////////////////////////////
void GameEngine::print_scores(N5110 &lcd) //this function is not used now
{