1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- #include "Asteroid.h"
- #include <Text.h>
- #include <Globals.h>
- #include <TastaturEreignis.h>
- #include "Schuss.h"
- #include <iostream>
- #include <Textur2D.h>
- #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;
- }
|