DeadPlayer.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #include "DeadPlayer.h"
  2. #include "../Define.h"
  3. #include <Textur2D.h>
  4. #include <Bild.h>
  5. DeadPlayer::DeadPlayer( Model2DData *mda, Model2DData *mdb, Vertex posa, Vertex posb, Vertex speedA, Vertex speedB, float curRotA, float curRotB, float rotA, float rotB, Textur2D *zTextur )
  6. : Object2D()
  7. {
  8. m2a = new Model2DObject();
  9. m2a->setModel( mda );
  10. m2a->setPosition( posa );
  11. m2a->setTextur( dynamic_cast<Textur2D *>( zTextur->getThis() ) );
  12. m2a->setDrehung( curRotA );
  13. m2a->setSpeed( speedA );
  14. m2a->setDrehungSpeed( rotA );
  15. m2b = new Model2DObject();
  16. m2b->setModel( mdb );
  17. m2b->setPosition( posb );
  18. m2b->setTextur( dynamic_cast<Textur2D *>( zTextur->getThis() ) );
  19. m2b->setDrehung( curRotB );
  20. m2b->setSpeed( speedB );
  21. m2b->setDrehungSpeed( rotB );
  22. alpha = 255;
  23. setCollision( 0 );
  24. save();
  25. }
  26. DeadPlayer::~DeadPlayer()
  27. {
  28. m2a->release();
  29. m2b->release();
  30. }
  31. void DeadPlayer::render( Mat3< float > &kamMat, Bild &zRObj, const char *kamName )
  32. {
  33. zRObj.setAlpha( (unsigned char)alpha );
  34. m2a->render( kamMat, zRObj, kamName );
  35. m2b->render( kamMat, zRObj, kamName );
  36. zRObj.releaseAlpha();
  37. }
  38. bool DeadPlayer::tick( const WeltInfo &info, double zeit )
  39. {
  40. m2a->tick( info, zeit );
  41. m2b->tick( info, zeit );
  42. alpha -= zeit * 15;
  43. if( alpha < 0 )
  44. alpha = 0;
  45. return 1;
  46. }
  47. Rect2< float > DeadPlayer::getBoundingBox() const
  48. {
  49. Rect2< float > r1 = m2a->getBoundingBox();
  50. Rect2< float > r2 = m2b->getBoundingBox();
  51. Rect2< float > r;
  52. r.topLeft.x = min( r1.topLeft.x, r2.topLeft.x );
  53. r.topLeft.y = min( r1.topLeft.y, r2.topLeft.y );
  54. r.bottomRight.x = max( r1.bottomRight.x, r2.bottomRight.x );
  55. r.bottomRight.y = max( r1.bottomRight.y, r2.bottomRight.y );
  56. return r;
  57. }
  58. bool DeadPlayer::isFinished() const
  59. {
  60. return alpha == 0;
  61. }
  62. void DeadPlayer::save()
  63. {
  64. alt.alpha = alpha;
  65. alt.posA = m2a->getPosition();
  66. alt.speedA = m2a->getSpeed();
  67. alt.rotA = m2a->getDrehung();
  68. alt.rotSA = m2a->getDrehungSpeed();
  69. alt.posB = m2b->getPosition();
  70. alt.speedB = m2b->getSpeed();
  71. alt.rotB = m2b->getDrehung();
  72. alt.rotSB = m2b->getDrehungSpeed();
  73. }
  74. void DeadPlayer::load()
  75. {
  76. alpha = alt.alpha;
  77. m2a->setPosition( alt.posA );
  78. m2a->setSpeed( alt.speedA );
  79. m2a->setDrehung( alt.rotA );
  80. m2a->setDrehungSpeed( alt.rotSA );
  81. m2b->setPosition( alt.posB );
  82. m2b->setSpeed( alt.speedB );
  83. m2b->setDrehung( alt.rotB );
  84. m2b->setDrehungSpeed( alt.rotSB );
  85. }