PageRenderTime 45ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/src/GameLogics/EnemyShip.cpp

https://bitbucket.org/maartenvandenheuvel/tyrian
C++ | 74 lines | 55 code | 13 blank | 6 comment | 9 complexity | 81f43172067cd99c673f2520bc47707d MD5 | raw file
  1. /*
  2. * EnemyShip.cpp
  3. *
  4. * Created on: Jan 29, 2012
  5. * Author: maarten
  6. */
  7. #include "EnemyShip.h"
  8. #include "PlayerBullet.h"
  9. #include "EnemyBullet.h"
  10. #include "PlayerShip.h"
  11. #include "World.h"
  12. #include "Factory.h"
  13. using namespace Tyrian;
  14. EnemyShip::EnemyShip( double x, double y, double s, Coord* loc, int h, double f, int d )
  15. : Ship( x, y, s, loc, h, f, d)
  16. {}
  17. void EnemyShip::Move( unsigned long frameDelay )
  18. {
  19. Coord* temp = new Coord();
  20. temp->SetY( temp->GetY() - (this->GetSpeed()*(frameDelay/TICKSPERSECOND)) );
  21. if ( this->lastShot > this->fireDelay)
  22. {
  23. this->GetWorld()->AddToList(this->GetFactory()->CreateEnemyBullet( *this->GetCoord(), this->damage ));
  24. this->lastShot = 0;
  25. }
  26. this->lastShot += frameDelay;
  27. *this->GetCoord() += *temp;
  28. }
  29. bool EnemyShip::CollidesWith(Entity* src)
  30. {
  31. if ( dynamic_cast<EnemyBullet*> (src) != 0)
  32. {
  33. return false;
  34. }
  35. if( dynamic_cast<PlayerBullet*> (src) != 0)
  36. {
  37. PlayerBullet* ptr = dynamic_cast<PlayerBullet*> (src);
  38. int tempHealth = ptr->GetHealth();
  39. ptr->SetHealth( ptr->GetHealth() - this->GetHealth() );
  40. this->SetHealth( this->GetHealth() - tempHealth);
  41. if ( this->GetHealth() <= 0 )
  42. {
  43. return true;
  44. }
  45. }
  46. if( dynamic_cast<PlayerShip*> (src) != 0)
  47. {
  48. PlayerShip* ptr = dynamic_cast<PlayerShip*> (src);
  49. int tempHealth = ptr->GetHealth();
  50. ptr->SetHealth( ptr->GetHealth() - this->GetHealth() );
  51. this->SetHealth( this->GetHealth() - tempHealth);
  52. if ( this->GetHealth() <= 0 )
  53. {
  54. return true;
  55. }
  56. }
  57. return false;
  58. }
  59. EnemyShip::~EnemyShip()
  60. {
  61. }