Laser.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #include "Laser.h"
  2. #include "../Karte/Karte.h"
  3. #include "../Spieler/Spieler.h"
  4. #include "../Define.h"
  5. // Inhalt der Laser Klasse aus Laser.h
  6. // Konstruktor
  7. Laser::Laser( int id, Vertex pos, Vertex speed, int sNum, double intensität, int tf )
  8. : Object2D()
  9. {
  10. this->id = id;
  11. setPosition( pos );
  12. setSpeed( speed );
  13. this->sNum = sNum;
  14. this->intensität = intensität;
  15. this->startIntensität = intensität;
  16. this->tf = tf;
  17. setCollision( 0 );
  18. save();
  19. }
  20. // privat
  21. char Laser::getOutCode( Punkt& p, Bild &zrObj ) const
  22. {
  23. char ret = 0;
  24. if( p.x < 0 )
  25. ret |= 1;
  26. else if( p.x >= zrObj.getDrawGr().x )
  27. ret |= 2;
  28. if( p.y < 0 )
  29. ret |= 4;
  30. else if( p.y >= zrObj.getDrawGr().y )
  31. ret |= 8;
  32. return ret;
  33. }
  34. // nicht constant
  35. Rect2< float > Laser::getBoundingBox() const
  36. {
  37. Rect2< float > r = Rect2< float >();
  38. r.topLeft.x = -abs( getSpeed().x );
  39. r.topLeft.y = -abs( getSpeed().y );
  40. r.bottomRight.x = abs( getSpeed().x );
  41. r.bottomRight.y = abs( getSpeed().y );
  42. r.topLeft = getWorldPos( r.topLeft );
  43. r.bottomRight = getWorldPos( r.bottomRight );
  44. return r;
  45. }
  46. bool Laser::tick( const WeltInfo &info, double tv )
  47. {
  48. __super::tick( info, tv );
  49. intensität -= tv * 2;
  50. return 1;
  51. }
  52. void Laser::render( Mat3< float > &kamMat, Bild &zRObj, const char *kamName )
  53. {
  54. int fa = (int)( ( intensität / startIntensität ) * 255 );
  55. int f = ( ( fa << 24 ) & 0xFF000000 ) | ( tf & 0xFFFFFF );
  56. Mat3< float > mat = kamMat * getObjectMatrix();
  57. Punkt a = (Punkt)( mat * Vertex( 0, 0 ) );
  58. Punkt b = (Punkt)( mat * ( getSpeed() / getSpeed().getLength() * 10 ) );
  59. zRObj.drawLinieBorderedAlpha( a, b, f, 0xFFFFFFFF );
  60. }
  61. void Laser::save()
  62. {
  63. last.pos = getPosition();
  64. last.speed = getSpeed();
  65. last.intensity = intensität;
  66. }
  67. void Laser::load()
  68. {
  69. intensität = last.intensity;
  70. setPosition( last.pos );
  71. setSpeed( last.speed );
  72. }
  73. // constant
  74. int Laser::getId() const
  75. {
  76. return id;
  77. }
  78. int Laser::getSpieler() const
  79. {
  80. return sNum;
  81. }
  82. double Laser::getIntensität( Vertex targetSpeed ) const
  83. {
  84. return intensität * ( ( speed - targetSpeed ).getLength() / 200 );
  85. }
  86. // Reference Counting
  87. Laser *Laser::getThis()
  88. {
  89. ref++;
  90. return this;
  91. }
  92. Laser *Laser::release()
  93. {
  94. ref--;
  95. if( !ref )
  96. delete this;
  97. return 0;
  98. }