|
@@ -12,131 +12,223 @@
|
|
|
|
|
|
Ship::Ship( Model2DData *data, Textur2D *zFlammenM, Textur2D *zFlammenL, Textur2D *zFlammenR, Bild *textur, Vec2< float > p, Vec2< float > s, float r )
|
|
|
{
|
|
|
- ship = new Model2D();
|
|
|
- ship->setStyle( Model2D::Style::Sichtbar | Model2D::Style::Textur );
|
|
|
+ for( auto i = data->polygons->getArray(); i.set; i++ )
|
|
|
+ {
|
|
|
+ if( i.var.name->istGleich( "engine_l" ) )
|
|
|
+ {
|
|
|
+ stL = *i.var.schwerpunkt;
|
|
|
+ Vertex l, r;
|
|
|
+ for( int j = 0; j < 4; j++ )
|
|
|
+ {
|
|
|
+ if( i.var.tKordinaten->get( j ).y == 1.f )
|
|
|
+ {
|
|
|
+ if( i.var.tKordinaten->get( j ).x == 0.f )
|
|
|
+ l = i.var.vertex->get( j );
|
|
|
+ if( i.var.tKordinaten->get( j ).x == 1.f )
|
|
|
+ r = i.var.vertex->get( j );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ kL = ( ( l + ( r - l ) * 0.5 ) - stL );
|
|
|
+ }
|
|
|
+ if( i.var.name->istGleich( "engine_r" ) )
|
|
|
+ {
|
|
|
+ stR = *i.var.schwerpunkt;
|
|
|
+ Vertex l, r;
|
|
|
+ for( int j = 0; j < 4; j++ )
|
|
|
+ {
|
|
|
+ if( i.var.tKordinaten->get( j ).y == 1.f )
|
|
|
+ {
|
|
|
+ if( i.var.tKordinaten->get( j ).x == 0.f )
|
|
|
+ l = i.var.vertex->get( j );
|
|
|
+ if( i.var.tKordinaten->get( j ).x == 1.f )
|
|
|
+ r = i.var.vertex->get( j );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ kR = ( ( l + ( r - l ) * 0.5 ) - stR );
|
|
|
+ }
|
|
|
+ if( i.var.name->istGleich( "engine_m" ) )
|
|
|
+ {
|
|
|
+ stM = *i.var.schwerpunkt;
|
|
|
+ Vertex l, r;
|
|
|
+ for( int j = 0; j < 4; j++ )
|
|
|
+ {
|
|
|
+ if( i.var.tKordinaten->get( j ).y == 1.f )
|
|
|
+ {
|
|
|
+ if( i.var.tKordinaten->get( j ).x == 0.f )
|
|
|
+ l = i.var.vertex->get( j );
|
|
|
+ if( i.var.tKordinaten->get( j ).x == 1.f )
|
|
|
+ r = i.var.vertex->get( j );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ kM = ( ( l + ( r - l ) * 0.5 ) - stM );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ rSpeed = 0;
|
|
|
+ ship = new Model2D();
|
|
|
+ ship->setStyle( Model2D::Style::Sichtbar | Model2D::Style::Textur | Model2D::Style::Alpha );
|
|
|
ship->setModel( data );
|
|
|
+ ship->setFarbe( 0x00000000 );
|
|
|
Textur2D *txt = new Textur2D();
|
|
|
txt->setTexturZ( textur );
|
|
|
- ship->setTextur( txt, "ship" );
|
|
|
+ ship->setTextur( txt, "ship" );
|
|
|
ship->setTextur( zFlammenL->getThis(), "engine_l" );
|
|
|
ship->setTextur( zFlammenR->getThis(), "engine_r" );
|
|
|
ship->setTextur( zFlammenM->getThis(), "engine_m" );
|
|
|
- ship->setDrehung( r );
|
|
|
- pos = p;
|
|
|
- speed = s;
|
|
|
- ref = 1;
|
|
|
+ ship->setDrehung( r );
|
|
|
+ pos = p;
|
|
|
+ speed = s;
|
|
|
+ ref = 1;
|
|
|
}
|
|
|
|
|
|
|
|
|
Ship::~Ship()
|
|
|
{
|
|
|
- ship->release();
|
|
|
+ ship->release();
|
|
|
}
|
|
|
|
|
|
+#define sgn( x ) x < 0 ? -1 : 1
|
|
|
+
|
|
|
|
|
|
bool Ship::tick( double zeit, int breite, int höhe, char tastenStände )
|
|
|
{
|
|
|
- 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 )
|
|
|
+ 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 )
|
|
|
- {
|
|
|
- speed.x += (float)( 4.2 * cos( ship->getDrehung() ) ) * (float)zeit * 30;
|
|
|
- speed.y += (float)( 4.2 * sin( ship->getDrehung() ) ) * (float)zeit * 30;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- float movementAngle = atan2( speed.y, speed.x );
|
|
|
- if( speed.x != 0 )
|
|
|
- speed.x += 1.2f * cos( movementAngle + (float)PI ) * (float)zeit * 30;
|
|
|
- if( speed.y != 0 )
|
|
|
- speed.y += 1.2f * sin( movementAngle + (float)PI ) * (float)zeit * 30;
|
|
|
- if( speed.x < 6.f && speed.x > -6.f )
|
|
|
- speed.x = 0;
|
|
|
- if( speed.y < 6.f && speed.y > -6.f )
|
|
|
- speed.y = 0;
|
|
|
- }
|
|
|
- if( ( tastenStände | 8 ) != tastenStände )
|
|
|
- {
|
|
|
- if( ( tastenStände | 2 ) == tastenStände )
|
|
|
- ship->addDrehung( (float)zeit * 2 );
|
|
|
- if( ( tastenStände | 4 ) == tastenStände )
|
|
|
- ship->addDrehung( (float)-zeit * 2 );
|
|
|
- }
|
|
|
- if( speed.x || speed.y )
|
|
|
- {
|
|
|
- pos += speed * (float)zeit;
|
|
|
- ship->setPosition( pos );
|
|
|
- }
|
|
|
- return ship->tick( zeit );
|
|
|
+ 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 )
|
|
|
+ {
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ if( ( tastenStände | 4 ) == 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ if( speed.x || speed.y )
|
|
|
+ {
|
|
|
+ pos += speed * (float)zeit;
|
|
|
+ ship->setPosition( pos );
|
|
|
+ }
|
|
|
+ return ship->tick( zeit );
|
|
|
}
|
|
|
|
|
|
void Ship::render( Bild &zRObj )
|
|
|
{
|
|
|
- ship->render( zRObj );
|
|
|
+ ship->render( zRObj );
|
|
|
}
|
|
|
|
|
|
|
|
|
void Ship::save( Datei *zD ) const
|
|
|
{
|
|
|
- zD->schreibe( (char*)&pos.x, 4 );
|
|
|
- zD->schreibe( (char*)&pos.y, 4 );
|
|
|
- zD->schreibe( (char*)&speed.x, 4 );
|
|
|
- zD->schreibe( (char*)&speed.y, 4 );
|
|
|
- float r = ship->getDrehung();
|
|
|
- zD->schreibe( (char*)&r, 4 );
|
|
|
+ zD->schreibe( (char*)&pos.x, 4 );
|
|
|
+ zD->schreibe( (char*)&pos.y, 4 );
|
|
|
+ zD->schreibe( (char*)&speed.x, 4 );
|
|
|
+ zD->schreibe( (char*)&speed.y, 4 );
|
|
|
+ float r = ship->getDrehung();
|
|
|
+ zD->schreibe( (char*)&r, 4 );
|
|
|
}
|
|
|
|
|
|
Schuss *Ship::getSchuss() const
|
|
|
{
|
|
|
- return new Schuss( pos, Vec2<float>( cos( ship->getDrehung() ), sin( ship->getDrehung() ) ) * 200 );
|
|
|
+ return new Schuss( pos, Vec2<float>( cos( ship->getDrehung() ), sin( ship->getDrehung() ) ) * 200 );
|
|
|
}
|
|
|
|
|
|
bool Ship::istTod( Asteroid *zA ) const
|
|
|
{
|
|
|
- return ship->istModelInnen( zA->zModel() );
|
|
|
+ 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 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;
|
|
|
+ return (Punkt)pos;
|
|
|
}
|
|
|
|
|
|
|
|
|
Ship *Ship::getThis()
|
|
|
{
|
|
|
- ref++;
|
|
|
- return this;
|
|
|
+ ref++;
|
|
|
+ return this;
|
|
|
}
|
|
|
|
|
|
Ship *Ship::release()
|
|
|
{
|
|
|
- ref--;
|
|
|
- if( !ref )
|
|
|
- delete this;
|
|
|
- return 0;
|
|
|
+ ref--;
|
|
|
+ if( !ref )
|
|
|
+ delete this;
|
|
|
+ return 0;
|
|
|
}
|