/src/GameLogics/EnemyShip.cpp
C++ | 74 lines | 55 code | 13 blank | 6 comment | 9 complexity | 81f43172067cd99c673f2520bc47707d MD5 | raw file
- /*
- * EnemyShip.cpp
- *
- * Created on: Jan 29, 2012
- * Author: maarten
- */
- #include "EnemyShip.h"
- #include "PlayerBullet.h"
- #include "EnemyBullet.h"
- #include "PlayerShip.h"
- #include "World.h"
- #include "Factory.h"
- using namespace Tyrian;
- EnemyShip::EnemyShip( double x, double y, double s, Coord* loc, int h, double f, int d )
- : Ship( x, y, s, loc, h, f, d)
- {}
- void EnemyShip::Move( unsigned long frameDelay )
- {
- Coord* temp = new Coord();
- temp->SetY( temp->GetY() - (this->GetSpeed()*(frameDelay/TICKSPERSECOND)) );
- if ( this->lastShot > this->fireDelay)
- {
- this->GetWorld()->AddToList(this->GetFactory()->CreateEnemyBullet( *this->GetCoord(), this->damage ));
- this->lastShot = 0;
- }
- this->lastShot += frameDelay;
- *this->GetCoord() += *temp;
- }
- bool EnemyShip::CollidesWith(Entity* src)
- {
- if ( dynamic_cast<EnemyBullet*> (src) != 0)
- {
- return false;
- }
- if( dynamic_cast<PlayerBullet*> (src) != 0)
- {
- PlayerBullet* ptr = dynamic_cast<PlayerBullet*> (src);
- int tempHealth = ptr->GetHealth();
- ptr->SetHealth( ptr->GetHealth() - this->GetHealth() );
- this->SetHealth( this->GetHealth() - tempHealth);
- if ( this->GetHealth() <= 0 )
- {
- return true;
- }
- }
- if( dynamic_cast<PlayerShip*> (src) != 0)
- {
- PlayerShip* ptr = dynamic_cast<PlayerShip*> (src);
- int tempHealth = ptr->GetHealth();
- ptr->SetHealth( ptr->GetHealth() - this->GetHealth() );
- this->SetHealth( this->GetHealth() - tempHealth);
- if ( this->GetHealth() <= 0 )
- {
- return true;
- }
- }
- return false;
- }
- EnemyShip::~EnemyShip()
- {
- }