Laser.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include "Laser.h"
  2. #include "Karte.h"
  3. // Inhalt der Laser Klasse aus Laser.h
  4. // Konstruktor
  5. Laser::Laser( int id, Vec2< double > pos, Vec2< double > speed, int sNum, double intensity )
  6. {
  7. this->id = id;
  8. this->pos = pos;
  9. this->speed = speed;
  10. this->sNum = sNum;
  11. this->intensity = intensity;
  12. ref = 1;
  13. }
  14. // nicht constant
  15. void Laser::tick( double tickVal, Karte *zMap )
  16. {
  17. pos += speed * tickVal;
  18. Vec2< int > gr = zMap->getSize();
  19. if( pos.x < 0 )
  20. pos.x += gr.x;
  21. if( pos.y < 0 )
  22. pos.y += gr.y;
  23. if( pos.x >= gr.x )
  24. pos.x -= gr.x;
  25. if( pos.y >= gr.y )
  26. pos.y -= gr.y;
  27. intensity -= tickVal * 2;
  28. }
  29. // constant
  30. int Laser::getId() const
  31. {
  32. return id;
  33. }
  34. int Laser::getSpieler() const
  35. {
  36. return sNum;
  37. }
  38. Vec2< double > Laser::getPos() const
  39. {
  40. return pos;
  41. }
  42. Vec2< double > Laser::getSpeed() const
  43. {
  44. return speed;
  45. }
  46. double Laser::getIntensity() const
  47. {
  48. return intensity;
  49. }
  50. // Reference Counting
  51. Laser *Laser::getThis()
  52. {
  53. ref++;
  54. return this;
  55. }
  56. Laser *Laser::release()
  57. {
  58. ref--;
  59. if( !ref )
  60. delete this;
  61. return 0;
  62. }