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
SpaceEngine/SpaceEngine.cpp
- Committer:
- fy14lkaa
- Date:
- 2019-05-08
- Revision:
- 133:eed60548d170
- Parent:
- 127:8bd8cf136f19
- Child:
- 136:58f393968aa3
File content as of revision 133:eed60548d170:
#include"SpaceEngine.h"
SpaceEngine::SpaceEngine()
{
}
SpaceEngine::~SpaceEngine()
{
}
void SpaceEngine::init(int x_spaceship,int y_spaceship, int x_bullet, int y_bullet,int fired_bullet, int x_alien,int y_alien, int speed_alien, int speed_bullet, int speed_spaceship)
{
_x_spaceship=x_spaceship;
_y_spaceship=y_spaceship;
_x_bullet=x_bullet;
_y_bullet=y_bullet;
_fired_bullet= fired_bullet;
_x_alien= x_alien;
_y_alien= y_alien;
_speed_alien= speed_alien;
//_velocity_x= velocity_x;
//_velocity_y=velocity_y;
_speed_bullet=speed_bullet;
_speed_spaceship=speed_spaceship;
_bullet.init(_x_bullet, _y_bullet, speed_bullet,fired_bullet);
_alien.init (_x_alien, _y_alien,_speed_alien);
_spaceship.init( _x_spaceship, _y_spaceship, _speed_spaceship);
_alien_killed = 0;
}
void SpaceEngine::read_input(Gamepad &pad)
{
_d = pad.get_direction();
_mag = pad.get_mag();
}
void SpaceEngine::draw(N5110 &lcd)
{
_bullet.draw(lcd);
//if(!_killed){_alien.draw(lcd);}
if (_alien.isAlive() == true) {
_alien.draw(lcd);
} else { // alien is dead
int y_pos = (rand() % 30) + 10; // random number 10 to 39
_alien.init(70,y_pos,1);
wait(0.2);
}
_spaceship.draw(lcd);
lcd.printString("alien_killed",0,0);
char kills[14];
sprintf(kills,"%2d",_alien_killed);
lcd.printString(kills,70,0);
//wait(0.1);
// _alien.init(70,0,1);
// _spaceman.draw(lcd);
}
void SpaceEngine::update(Gamepad &pad)
{
_bullet.update(_d,_mag);
_alien.update(_d,_mag);
_spaceship.update(_d,_mag);
_check_space_collision(pad);
_y_alien = _alien.get_pos_y();
_x_alien = _alien.get_pos_x();
_y_bullet = _bullet.get_pos_y();
_x_bullet = _bullet.get_pos_x();
if(_d==E) {
_fired_bullet=1;
//_x_bullet=11;
//_y_bullet=y;
_bullet.set_pos(_spaceship.get_pos_x()+33, _spaceship.get_pos_y());
//_alien.set_pos(_bullet.get_pos_x()+50,_bullet.get_pos_y());
}
}
//else if(_d==W) {
// _fired_bullet=0;
//}
/* if( _x_bullet>_x_alien && _y_bullet >_y_alien) {
_x_alien =85;
_y_alien= _y_alien +2;
}*/
/*
_y_alien = alien.getposition_y
_x_alien =85;
if( _y_alien<0) {
_y_alien= _y_alien +2;
}
if (_y_alien> 48){
_y_alien= _y_alien -2;
}
_y_alien = alien.setposition_y
}*/
///////////////////////////////////////
/* _y_alien = _alien.get_pos_y
_x_alien =85;
if( _y_alien<0) {
_y_alien= _y_alien +2;
}
_y_alien = _alien.set_pos;
else if (_y_alien> 48){
_y_alien= _y_alien -2;
} */
void SpaceEngine::_check_space_collision(Gamepad &pad)
{
//if((_x_alien)<=( _x_bullet)&& (_y_alien)<=(_y_bullet )){ _killed = true;}
if(_x_bullet >= 65 && _x_bullet <= 68 && _y_bullet >= _y_alien-5 && _y_bullet <= _y_alien+15) {
_alien.setAlive(false);
_alien_killed++;
}
// _x_alien =1000;
// _y_alien= 1000;
// lcd.drawSprite(1000,1000,32,32,(int*)alien2);
//s} //if(x_bullet>=x_alien && y_bullet >=y_alien && y_bullet <=y_alien+10)
}