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.
Fork of fy15raf by
GameEngine/GameEngine.cpp
- Committer:
- RehamFaqehi
- Date:
- 2018-04-20
- Revision:
- 6:7b733b2a6cf6
- Parent:
- 5:b230e79d36d6
- Child:
- 7:06c86ec1f19d
File content as of revision 6:7b733b2a6cf6:
#include "GameEngine.h"
GameEngine::GameEngine()
{
}
GameEngine::~GameEngine()
{
}
void GameEngine::init()
{
_rocket.init();
_asteroid.init(2);
}
void GameEngine::read_input(Gamepad &pad)
{
_d = pad.get_direction();
_mag = pad.get_mag();
}
void GameEngine::draw(N5110 &lcd)
{
// draw the game elements in the LCD
_rocket.draw(lcd);
_asteroid.draw(lcd);
print_scores(lcd);
}
void GameEngine::update(Gamepad &pad, N5110 &lcd)
{
check_goal(pad);
_rocket.update(_d,_mag, lcd);
_asteroid.update();
}
void GameEngine::check_goal(Gamepad &pad)
{
Vector2D _asteroid_pos = _asteroid.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 ){
_rocket.add_score();
pad.tone(1500.0,0.5);
pad.leds_on();
wait(0.5);
pad.leds_off();
}
}
}
//////////////////////////////////////////////////////////////////
void GameEngine::print_scores(N5110 &lcd)
{
// get the number of hits
int _rocket_score = _rocket.get_score();
// print to LCD i
char buffer1[11];
sprintf(buffer1,"hits:%2d",_rocket_score);
lcd.printString(buffer1,WIDTH/2 - 20, 1);
}
