|
@@ -11,6 +11,7 @@
|
|
|
// Inhalt der Ship Klasse aus Ship.h
|
|
|
// Konstruktor
|
|
|
Ship::Ship( Model2DData *data, Vec2< float > p, Vec2< float > s, float r )
|
|
|
+ : Model2DObject()
|
|
|
{
|
|
|
for( auto i = data->polygons->getArray(); i.set; i++ )
|
|
|
{
|
|
@@ -64,21 +65,16 @@ Ship::Ship( Model2DData *data, Vec2< float > p, Vec2< float > s, float r )
|
|
|
}
|
|
|
}
|
|
|
rSpeed = 0;
|
|
|
- ship = new Model2D();
|
|
|
- ship->setStyle( Model2D::Style::Sichtbar | Model2D::Style::Textur | Model2D::Style::Alpha );
|
|
|
- ship->setModel( data );
|
|
|
- ship->setFarbe( 0x00000000 );
|
|
|
- ship->setDrehung( r );
|
|
|
- pos = p;
|
|
|
- speed = s;
|
|
|
- ref = 1;
|
|
|
+ setModel( data );
|
|
|
+ setDrehung( r );
|
|
|
+ setPosition( p );
|
|
|
+ setSpeed( s );
|
|
|
+ tastenstände = 0;
|
|
|
}
|
|
|
|
|
|
// Destruktor
|
|
|
Ship::~Ship()
|
|
|
-{
|
|
|
- ship->release();
|
|
|
-}
|
|
|
+{}
|
|
|
|
|
|
#define sgn( x ) x < 0 ? -1 : 1
|
|
|
|
|
@@ -87,161 +83,55 @@ void Ship::setTexture( Textur2D *zFlammenM, Textur2D *zFlammenL, Textur2D *zFlam
|
|
|
{
|
|
|
Textur2D *txt = new Textur2D();
|
|
|
txt->setTexturZ( textur );
|
|
|
- ship->setTextur( txt, "ship" );
|
|
|
- ship->setTextur( zFlammenL->getThis(), "engine_l" );
|
|
|
- ship->setTextur( zFlammenR->getThis(), "engine_r" );
|
|
|
- ship->setTextur( zFlammenM->getThis(), "engine_m" );
|
|
|
+ setTextur( txt, "ship" );
|
|
|
+ setTextur( zFlammenL->getThis(), "engine_l" );
|
|
|
+ setTextur( zFlammenR->getThis(), "engine_r" );
|
|
|
+ setTextur( zFlammenM->getThis(), "engine_m" );
|
|
|
}
|
|
|
|
|
|
void Ship::setPRS( Vec2< float > p, Vec2< float > s, float r, float rSpeed )
|
|
|
{
|
|
|
- this->rSpeed = rSpeed;
|
|
|
- ship->setDrehung( r );
|
|
|
- pos = p;
|
|
|
- speed = s;
|
|
|
+ setDrehung( r );
|
|
|
+ setPosition( p );
|
|
|
+ setSpeed( s );
|
|
|
+ setDrehungSpeed( rSpeed );
|
|
|
}
|
|
|
|
|
|
-bool Ship::tick( double zeit, int breite, int höhe, char tastenStände )
|
|
|
+void Ship::setTastenstände( char ts )
|
|
|
{
|
|
|
- Vertex minP = (Vertex)ship->zModel()->minP * ship->getSize() + ship->getPosition();
|
|
|
- Vertex maxP = (Vertex)ship->zModel()->maxP * ship->getSize() + ship->getPosition();
|
|
|
- if( maxP.x < 0 && speed.x < 0 )
|
|
|
- pos.x += breite + ship->zModel()->maxP.x * ship->getSize();
|
|
|
- if( maxP.y < 0 && speed.y < 0 )
|
|
|
- pos.y += höhe + ship->zModel()->maxP.y * ship->getSize();
|
|
|
- if( minP.x > breite && speed.x > 0 )
|
|
|
- pos.x -= breite + ship->zModel()->maxP.x * ship->getSize();
|
|
|
- if( minP.y > höhe && speed.y > 0 )
|
|
|
- pos.y -= höhe + ship->zModel()->maxP.y * ship->getSize();
|
|
|
- ship->setPosition( pos );
|
|
|
- if( ( tastenStände | 1 ) == tastenStände )
|
|
|
- {
|
|
|
- Vertex hp;
|
|
|
- Vertex mv;
|
|
|
- float r;
|
|
|
- if( ship->zModel()->calcHitPoint( stM, kM, "ship", hp, mv, r ) )
|
|
|
- {
|
|
|
- rSpeed += r * (float)zeit;
|
|
|
- speed += mv.rotation( ship->getDrehung() ) * (float)zeit;
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- float movementAngle = atan2( speed.y, speed.x );
|
|
|
- int ix = sgn( speed.x ), iy = sgn( speed.y );
|
|
|
- if( speed.x != 0 )
|
|
|
- speed.x += 1.2f * cos( movementAngle + (float)PI ) * (float)zeit * 10;
|
|
|
- if( speed.y != 0 )
|
|
|
- speed.y += 1.2f * sin( movementAngle + (float)PI ) * (float)zeit * 10;
|
|
|
- if( ix * sgn( speed.x ) < 0 )
|
|
|
- speed.x = 0;
|
|
|
- if( iy * sgn( speed.y ) < 0 )
|
|
|
- speed.y = 0;
|
|
|
- if( rSpeed > 0 )
|
|
|
- {
|
|
|
- rSpeed -= (float)zeit;
|
|
|
- if( rSpeed < 0 )
|
|
|
- rSpeed = 0;
|
|
|
- }
|
|
|
- if( rSpeed < 0 )
|
|
|
- {
|
|
|
- rSpeed += (float)zeit;
|
|
|
- if( rSpeed > 0 )
|
|
|
- rSpeed = 0;
|
|
|
- }
|
|
|
- }
|
|
|
- ship->addDrehung( (float)zeit * rSpeed );
|
|
|
- if( ( tastenStände | 2 ) == tastenStände )
|
|
|
+ tastenstände = ts;
|
|
|
+}
|
|
|
+
|
|
|
+bool Ship::tick( const WeltInfo &info, double zeit )
|
|
|
+{
|
|
|
+ if( ( tastenstände | 1 ) == tastenstände )
|
|
|
{
|
|
|
- Vertex hp;
|
|
|
- Vertex mv;
|
|
|
- float r;
|
|
|
- if( ship->zModel()->calcHitPoint( stL, kL, "ship", hp, mv, r ) )
|
|
|
- {
|
|
|
- rSpeed += r * (float)zeit;
|
|
|
- speed += mv.rotation( ship->getDrehung() ) * (float)zeit;
|
|
|
- }
|
|
|
- //ship->addDrehung( (float)zeit * 2 );
|
|
|
+ impuls( getWorldPos(stM), getWorldDir(kM) * (float)zeit * 10 );
|
|
|
}
|
|
|
- if( ( tastenStände | 4 ) == tastenStände )
|
|
|
+ if( ( tastenstände | 2 ) == tastenstände )
|
|
|
{
|
|
|
- Vertex hp;
|
|
|
- Vertex mv;
|
|
|
- float r;
|
|
|
- if( ship->zModel()->calcHitPoint( stR, kR, "ship", hp, mv, r ) )
|
|
|
- {
|
|
|
- rSpeed += r * (float)zeit;
|
|
|
- speed += mv.rotation( ship->getDrehung() ) * (float)zeit;
|
|
|
- }
|
|
|
- //ship->addDrehung( (float)-zeit * 2 );
|
|
|
+ impuls( getWorldPos(stL), getWorldDir(kL) * (float)zeit * 10 );
|
|
|
}
|
|
|
- if( speed.x || speed.y )
|
|
|
+ if( ( tastenstände | 4 ) == tastenstände )
|
|
|
{
|
|
|
- pos += speed * (float)zeit;
|
|
|
- ship->setPosition( pos );
|
|
|
+ impuls( getWorldPos(stR), getWorldDir(kR) * (float)zeit * 10 );
|
|
|
}
|
|
|
- return ship->tick( zeit );
|
|
|
-}
|
|
|
-
|
|
|
-void Ship::render( Bild &zRObj )
|
|
|
-{
|
|
|
- ship->render( zRObj );
|
|
|
+ return __super::tick( info, zeit );
|
|
|
}
|
|
|
|
|
|
// constant
|
|
|
void Ship::save( Datei *zD ) const
|
|
|
{
|
|
|
- zD->schreibe( (char*)&pos.x, 4 );
|
|
|
- zD->schreibe( (char*)&pos.y, 4 );
|
|
|
+ zD->schreibe( (char*)&position.x, 4 );
|
|
|
+ zD->schreibe( (char*)&position.y, 4 );
|
|
|
zD->schreibe( (char*)&speed.x, 4 );
|
|
|
zD->schreibe( (char*)&speed.y, 4 );
|
|
|
- float r = ship->getDrehung();
|
|
|
+ float r = getDrehung();
|
|
|
zD->schreibe( (char*)&r, 4 );
|
|
|
zD->schreibe( (char*)&rSpeed, 4 );
|
|
|
}
|
|
|
|
|
|
Schuss *Ship::getSchuss() const
|
|
|
{
|
|
|
- return new Schuss( pos, Vec2<float>( cos( ship->getDrehung() ), sin( ship->getDrehung() ) ) * 200 );
|
|
|
-}
|
|
|
-
|
|
|
-bool Ship::istTod( Asteroid *zA ) const
|
|
|
-{
|
|
|
- return ship->istModelInnen( zA->zModel() );
|
|
|
-}
|
|
|
-
|
|
|
-Punkt Ship::getKamPos( int breite, int höhe ) const
|
|
|
-{
|
|
|
- Punkt ret;
|
|
|
- ret.x = (int)pos.x - 400;
|
|
|
- ret.y = (int)pos.y - 250;
|
|
|
- if( ret.x < 0 )
|
|
|
- ret.x = 0;
|
|
|
- if( ret.y < 0 )
|
|
|
- ret.y = 0;
|
|
|
- if( ret.x > breite - 800 )
|
|
|
- ret.x = breite - 800;
|
|
|
- if( ret.y > höhe - 500 )
|
|
|
- ret.y = höhe - 500;
|
|
|
- return ret;
|
|
|
-}
|
|
|
-
|
|
|
-Punkt Ship::getPos() const
|
|
|
-{
|
|
|
- return (Punkt)pos;
|
|
|
-}
|
|
|
-
|
|
|
-// Reference Counting
|
|
|
-Ship *Ship::getThis()
|
|
|
-{
|
|
|
- ref++;
|
|
|
- return this;
|
|
|
-}
|
|
|
-
|
|
|
-Ship *Ship::release()
|
|
|
-{
|
|
|
- ref--;
|
|
|
- if( !ref )
|
|
|
- delete this;
|
|
|
- return 0;
|
|
|
+ return new Schuss( position, Vec2<float>( cos( getDrehung() ), sin( getDrehung() ) ) * 200 + getSpeed() );
|
|
|
}
|