Asteroid.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include "Asteroid.h"
  2. Asteroid::Asteroid( int id, Vertex pos, Vertex speed, float rot, float rotS, Model2DData *data )
  3. : Model2DObject()
  4. {
  5. this->id = id;
  6. setPosition( pos );
  7. setSpeed( speed );
  8. setDrehung( rot );
  9. setDrehungSpeed( rotS );
  10. setModel( data );
  11. }
  12. bool Asteroid::tick( const WeltInfo &info, double zeit )
  13. {
  14. wInfo = info;
  15. return Model2DObject::tick( info, zeit );
  16. }
  17. Asteroid *Asteroid::istTreffer( Laser *zL, RandomGenerator *zRandG, int &asteroidId, Vertex &pos )
  18. {
  19. Vertex hp;
  20. for( int i = 0; i < 3; i++ )
  21. {
  22. for( int j = 0; j < 3; j++ )
  23. {
  24. pos = zL->getPosition() + Punkt( ( i - 1 ) * wInfo.size.x, ( j - 1 ) * wInfo.size.y );
  25. if( istPunktInnen( pos ) && calcHitPoint( pos - zL->getSpeed(), zL->getSpeed(), hp ) )
  26. {
  27. Polygon2D a, b;
  28. Punkt pa, pb;
  29. if( zModel()->split( getObjectPos( hp ), getObjectDir( zL->getSpeed() ) * 0.1f, ( char* )"", a, b, pa, pb, [ zRandG ]() -> double
  30. {
  31. return zRandG->rand();
  32. } ) )
  33. {
  34. impuls( pos - zL->getSpeed(), zL->getSpeed() * 0.05f );
  35. hp = ( hp * getSize() ).rotation( getDrehung() ) + getPosition();
  36. Vertex pav = ( (Vertex)pa ).rotation( getDrehung() ) + getPosition();
  37. Vertex pbv = ( (Vertex)pb ).rotation( getDrehung() ) + getPosition();
  38. Array< Polygon2D > *npaA = new Array< Polygon2D >();
  39. npaA->add( a );
  40. Model2DData *npdA = new Model2DData();
  41. npdA->erstelleModell( npaA );
  42. Array< Polygon2D > *npaB = new Array< Polygon2D >();
  43. npaB->add( b );
  44. Model2DData *npdB = new Model2DData();
  45. npdB->erstelleModell( npaB );
  46. Asteroid *astr = new Asteroid( asteroidId++, pav, getSpeed() * (float)zRandG->rand(), getDrehung(), getDrehungSpeed() * (float)zRandG->rand(), npdA );
  47. setSpeed( getSpeed() * (float)zRandG->rand() );
  48. setDrehungSpeed( getDrehungSpeed() * (float)zRandG->rand() );
  49. setModel( npdB );
  50. setPosition( pbv );
  51. return astr;
  52. }
  53. }
  54. }
  55. }
  56. return 0;
  57. }
  58. int Asteroid::getId() const
  59. {
  60. return id;
  61. }