Schuss.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include "Schuss.h"
  2. // Inhalt der Schuss Klasse aus Schuss.h
  3. // Konstruktor
  4. Schuss::Schuss( Vec2< float > pos, Vec2< float > speed )
  5. {
  6. this->pos = pos;
  7. this->speed = speed;
  8. ref = 1;
  9. }
  10. // nicht constant
  11. bool Schuss::tick( double zeit )
  12. {
  13. pos += speed * (float)zeit;
  14. return 1;
  15. }
  16. void Schuss::render( Bild &zRObj )
  17. {
  18. zRObj.drawLinie( (Punkt)pos, (Punkt)( pos - speed / 10 ), 0xFFFFFFFF );
  19. }
  20. // constant
  21. bool Schuss::istInM2( const Model2D &mdl, Vertex &speed, float &rot, Vertex &hp ) const
  22. {
  23. if( mdl.istPunktInnen( pos ) )
  24. {
  25. if( mdl.zModel()->calcHitPoint( ( ( pos - this->speed / 10 ) - mdl.getPosition() ).rotation( -mdl.getDrehung() ) / mdl.getSize(), Vertex( this->speed / 10 ).rotation( -mdl.getDrehung() ), "", hp, speed, rot ) )
  26. {
  27. speed = speed.rotation( mdl.getDrehung() );
  28. return 1;
  29. }
  30. }
  31. return 0;
  32. }
  33. void Schuss::save( Datei *zD ) const
  34. {
  35. zD->schreibe( (char*)&pos.x, 4 );
  36. zD->schreibe( (char*)&pos.y, 4 );
  37. zD->schreibe( (char*)&speed.x, 4 );
  38. zD->schreibe( (char*)&speed.y, 4 );
  39. }
  40. Vec2< float > Schuss::getPos() const
  41. {
  42. return pos;
  43. }
  44. // Reference Counting
  45. Schuss *Schuss::getThis()
  46. {
  47. ref++;
  48. return this;
  49. }
  50. Schuss *Schuss::release()
  51. {
  52. ref--;
  53. if( !ref )
  54. delete this;
  55. return 0;
  56. }