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
GameEngine/GameEngine.cpp
- Committer:
- adat80
- Date:
- 2019-04-21
- Revision:
- 1:3916f272663e
- Child:
- 2:88019d96e1da
File content as of revision 1:3916f272663e:
#include "GameEngine.h"
GameEngine::GameEngine()
{
}
GameEngine::~GameEngine()
{
}
void GameEngine::init(int CrossHairsSpeed, int fps)
{
// initialise the game parameters
_fps = fps;
_levelNumber = 100;
_money = 0;
_crossHairs.init(CrossHairsSpeed);
srand(time(NULL));
_enemies = _level.init(_levelNumber);
}
void GameEngine::read_input(Gamepad &pad)
{
_angle = pad.get_angle();
_mag = pad.get_mag();
}
void GameEngine::draw(N5110 &lcd)
{
//draw wall
lcd.drawRect(0,28,10,20,FILL_TRANSPARENT);
lcd.drawLine(0,28,10,0,1); //back top of wall
lcd.drawLine(10,0,20,0,1); //side of wall
lcd.drawLine(10,28,20,0,1); //front top of wall
lcd.drawLine(10,48,20,20,1); //front bottom of wall
lcd.drawLine(20,20,20,0,1); //front side of wall
// draw the elements in the LCD buffer
/*
_enemy.draw(lcd);
_enemy2.draw(lcd);
*/
_crossHairs.draw(lcd);
for (int i=0; i < _levelNumber; i++) {
_enemies[i].draw(lcd);
}
}
void GameEngine::update(Gamepad &pad)
{
_level.update(_fps);
_crossHairs.update(_angle,_mag, _fps);
/*
_enemy.update();
_enemy2.update();
*/
for (int i=0; i < _levelNumber; i++) {
_enemies[i].update();
}
if ( pad.check_event(Gamepad::B_PRESSED) == true) {
fireShot(pad);
}
}
void GameEngine::fireShot(Gamepad &gpad)
{
Vector2D shotLoc = _crossHairs.get_pos();
for(int i = 0; i < _levelNumber; i++) {
Vector2D enemyLoc = _enemies[i].get_pos();
if (abs(enemyLoc.x - shotLoc.x) < 4) {
if (abs(enemyLoc.y - shotLoc.y) < 4) {
_enemies[i].set_alive(false);
}
}
}
}