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:
- 16:106c27d03402
- Parent:
- 15:658f1216ee84
--- a/GameEngine/GameEngine.cpp Mon May 07 13:29:49 2018 +0000
+++ b/GameEngine/GameEngine.cpp Mon May 07 18:27:42 2018 +0000
@@ -13,8 +13,8 @@
void GameEngine::init()
{
- //initialise game objects rocket and 3 asteroids with diffrent speeds
- _rocket.init();
+ //initialise game objects Spaceship and 3 asteroids with diffrent speeds
+ _Spaceship.init();
_asteroid1.init(2);
_asteroid2.init(3);
_asteroid3.init(4);
@@ -33,7 +33,7 @@
void GameEngine::draw(N5110 &lcd)
{
// draw the game elements in the LCD
- _rocket.draw(lcd);
+ _Spaceship.draw(lcd);
_asteroid1.draw(lcd);
_asteroid2.draw(lcd);
_asteroid3.draw(lcd);
@@ -55,7 +55,7 @@
check_collision3(pad);
//updating the display
- _rocket.update(_d,_mag);
+ _Spaceship.update(_d,_mag);
_asteroid1.update();
_asteroid2.update();
_asteroid3.update();
@@ -68,15 +68,15 @@
void GameEngine::check_collision1(Gamepad &pad)
{
Vector2D _asteroid1_pos = _asteroid1.get_pos() ;
- Vector2D _rocket_pos = _rocket.get_pos();
+ Vector2D _Spaceship_pos = _Spaceship.get_pos();
// check if the collision occers with Asteroid 1
- if ((_rocket_pos.x+10 >=_asteroid1_pos.x) &&( _rocket_pos.x+8 <_asteroid1_pos.x )) {
+ if ((_Spaceship_pos.x+10 >=_asteroid1_pos.x) &&( _Spaceship_pos.x+8 <_asteroid1_pos.x )) {
- if( ( _asteroid1_pos.y >= _rocket_pos.y) && ( _asteroid1_pos.y <= _rocket_pos.y+7) ||
- (_asteroid1_pos.y+6 >= _rocket_pos.y) &&(_asteroid1_pos.y+6 <= _rocket_pos.y+7 )) {
+ if( ( _asteroid1_pos.y >= _Spaceship_pos.y) && ( _asteroid1_pos.y <= _Spaceship_pos.y+7) ||
+ (_asteroid1_pos.y+6 >= _Spaceship_pos.y) &&(_asteroid1_pos.y+6 <= _Spaceship_pos.y+7 )) {
- _rocket.add_collisions();
+ _Spaceship.add_collisions();
pad.tone(1500.0,0.5); //tone
pad.leds_on(); //LEDs flashing
wait(0.5);
@@ -92,15 +92,15 @@
{
Vector2D _asteroid2_pos = _asteroid2.get_pos();
- Vector2D _rocket_pos = _rocket.get_pos();
+ Vector2D _Spaceship_pos = _Spaceship.get_pos();
// check if the collision occers with Asteroid 2
- if ((_rocket_pos.x+10 >=_asteroid2_pos.x) && (_rocket_pos.x+8 <_asteroid2_pos.x )) {
+ if ((_Spaceship_pos.x+10 >=_asteroid2_pos.x) && (_Spaceship_pos.x+8 <_asteroid2_pos.x )) {
- if( (_asteroid2_pos.y >= _rocket_pos.y) && ( _asteroid2_pos.y <= _rocket_pos.y+7) ||
- (_asteroid2_pos.y+6 >= _rocket_pos.y) &&( _asteroid2_pos.y+6 <= _rocket_pos.y+7 )) {
+ if( (_asteroid2_pos.y >= _Spaceship_pos.y) && ( _asteroid2_pos.y <= _Spaceship_pos.y+7) ||
+ (_asteroid2_pos.y+6 >= _Spaceship_pos.y) &&( _asteroid2_pos.y+6 <= _Spaceship_pos.y+7 )) {
- _rocket.add_collisions();
+ _Spaceship.add_collisions();
pad.tone(1500.0,0.5); //tone
pad.leds_on(); //LEDs flashing
wait(0.5);
@@ -116,15 +116,15 @@
{
Vector2D _asteroid3_pos = _asteroid3.get_pos();
- Vector2D _rocket_pos = _rocket.get_pos();
+ Vector2D _Spaceship_pos = _Spaceship.get_pos();
// check if the collision occers with Asteroid 3
- if ((_rocket_pos.x+10 >= _asteroid3_pos.x) &&( _rocket_pos.x+6 < _asteroid3_pos.x )) {
+ if ((_Spaceship_pos.x+10 >= _asteroid3_pos.x) &&( _Spaceship_pos.x+6 < _asteroid3_pos.x )) {
- if( (_asteroid3_pos.y >= _rocket_pos.y) &&( _asteroid3_pos.y <= _rocket_pos.y+7) ||
- ( _asteroid3_pos.y+6 >= _rocket_pos.y) &&(_asteroid3_pos.y+6 <= _rocket_pos.y+7 )) {
+ if( (_asteroid3_pos.y >= _Spaceship_pos.y) &&( _asteroid3_pos.y <= _Spaceship_pos.y+7) ||
+ ( _asteroid3_pos.y+6 >= _Spaceship_pos.y) &&(_asteroid3_pos.y+6 <= _Spaceship_pos.y+7 )) {
- _rocket.add_collisions();
+ _Spaceship.add_collisions();
pad.tone(1500.0,0.5); //tone
pad.leds_on(); //LEDs flashing
wait(0.5);
@@ -138,18 +138,18 @@
void GameEngine::draw_hearts(N5110 &lcd)
{
- // get collision from Rocket class
- int _rocket_collisions= _rocket.get_collisions();
+ // get collision from Spaceship class
+ int _Spaceship_collisions= _Spaceship.get_collisions();
// reduce the hearts with each collision till the third collision the game ends
- if (_rocket_collisions==0) {
- _rocket.drawFullHearts(lcd);
+ if (_Spaceship_collisions==0) {
+ _Spaceship.drawFullHearts(lcd);
- } else if (_rocket_collisions ==1) {
- _rocket.drawTwoHearts(lcd);
+ } else if (_Spaceship_collisions ==1) {
+ _Spaceship.drawTwoHearts(lcd);
- } else if (_rocket_collisions == 2) {
- _rocket.drawOneHeart(lcd);
+ } else if (_Spaceship_collisions == 2) {
+ _Spaceship.drawOneHeart(lcd);
} else {
gameOver=1;