#include "Asteroid.h" #include #include #include #include "Schuss.h" #include #include #include "Schuss.h" // Inhalt der Asteroid Klasse aus Asteroid.h // Konstruktor Asteroid::Asteroid( Model2DData *data, Bild *textur, Vertex p, Vertex s, float rS, float r, float gr, char num ) : Model2DObject() { setModel( data ); setDrehung( r ); setSize( gr ); if( textur ) { Textur2D *text = new Textur2D(); text->setTexturZ( textur ); setTextur( text ); } setPosition( p ); setSpeed( s ); setDrehungSpeed( rSpeed ); id = num; } // Destruktor Asteroid::~Asteroid() {} // nicht constant bool Asteroid::istGetroffen( Schuss *zSchuss, Polygon2D &a, Polygon2D &b, Punkt &pa, Punkt &pb, RandomGenerator *zRand ) { if( getMasse() < 40 * 40 ) return 0; if( istPunktInnen( zSchuss->getPosition() ) ) { if( zModel()->split( getObjectPos( zSchuss->getPosition() - zSchuss->getSpeed() ), getObjectDir( zSchuss->getSpeed() ) * 0.1f, "", a, b, pa, pb, [ zRand ]() { return zRand->rand(); } ) ) { impuls( zSchuss->getPosition() - zSchuss->getSpeed(), zSchuss->getSpeed() * 0.05f ); return 1; } } return 0; } bool Asteroid::tick( const WeltInfo &info, double time ) { if( getMasse() < 40 * 40 ) { setSize( getSize() - (float)time * 3 ); if( getSize() < 0 ) setSize( 0 ); } return __super::tick( info, time ); } // constant void Asteroid::save( Datei *zD ) const { zD->schreibe( (char*)&id, 1 ); zD->schreibe( (char*)&position.x, 4 ); zD->schreibe( (char*)&position.y, 4 ); zD->schreibe( (char*)&speed.x, 4 ); zD->schreibe( (char*)&speed.y, 4 ); zD->schreibe( (char*)&rSpeed, 4 ); float r = getDrehung(); zD->schreibe( (char*)&r, 4 ); float gr = getSize(); zD->schreibe( (char*)&gr, 4 ); } char Asteroid::getId() const { return id; } int Asteroid::getScore() const { if( getMasse() < 40 * 40 ) return 1; return 0; }