Explorar o código

neue 2D Funktionalität des Frameworks wird nun verwendet

Kolja Strohm %!s(int64=5) %!d(string=hai) anos
pai
achega
91f31ec5f0
Modificáronse 12 ficheiros con 190 adicións e 414 borrados
  1. 36 126
      Asteroids/Asteroid.cpp
  2. 3 21
      Asteroids/Asteroid.h
  3. 42 16
      Asteroids/Data.cpp
  4. 2 1
      Asteroids/Data.h
  5. 4 0
      Asteroids/Game.cpp
  6. 41 33
      Asteroids/Map.cpp
  7. 4 2
      Asteroids/Map.h
  8. 4 3
      Asteroids/Menü.cpp
  9. 15 43
      Asteroids/Schuss.cpp
  10. 3 13
      Asteroids/Schuss.h
  11. 32 142
      Asteroids/Ship.cpp
  12. 4 14
      Asteroids/Ship.h

+ 36 - 126
Asteroids/Asteroid.cpp

@@ -9,148 +9,73 @@
 
 // Inhalt der Asteroid Klasse aus Asteroid.h
 // Konstruktor
-Asteroid::Asteroid( Model2DData *data, Bild *textur, Vec2< float > p, Vec2< float > s, float rS, float r, float gr, char num )
+Asteroid::Asteroid( Model2DData *data, Bild *textur, Vertex p, Vertex s, float rS, float r, float gr, char num )
+    : Model2DObject()
 {
-    txt = 0;
-	asteroid = new Model2D();
-	asteroid->setStyle( Model2D::Style::Sichtbar | Model2D::Style::Textur );
-	asteroid->setModel( data );
-	asteroid->setDrehung( r );
-	asteroid->setSize( gr );
+	setModel( data );
+	setDrehung( r );
+	setSize( gr );
     if( textur )
-        setTextur( textur );
-	pos = p;
-	speed = s;
-	rSpeed = rS;
+    {
+        Textur2D *text = new Textur2D();
+        text->setTexturZ( textur );
+        setTextur( text );
+    }
+    setPosition( p );
+    setSpeed( s );
+    setDrehungSpeed( rSpeed );
 	id = num;
-	ref = 1;
 }
 
 // Destruktor
 Asteroid::~Asteroid()
-{
-    if( txt )
-        txt->release();
-	asteroid->release();
-}
+{}
 
 // nicht constant
-void Asteroid::setTextur( Bild *textur )
-{
-    if( txt )
-        txt->release();
-    txt = textur->getThis();
-    Textur2D *txt = new Textur2D();
-    txt->setTexturZ( textur );
-    asteroid->setTextur( txt->getThis() );
-}
-
-bool Asteroid::tick( double zeit, int breite, int höhe )
-{
-	Vertex minP = (Vertex)asteroid->zModel()->minP * asteroid->getSize() + asteroid->getPosition();
-	Vertex maxP = (Vertex)asteroid->zModel()->maxP * asteroid->getSize() + asteroid->getPosition();
-	if( maxP.x < 0 && speed.x < 0 )
-		pos.x += breite + asteroid->zModel()->maxP.x * asteroid->getSize();
-	if( maxP.y < 0 && speed.y < 0 )
-		pos.y += höhe + asteroid->zModel()->maxP.y * asteroid->getSize();
-	if( minP.x > breite && speed.x > 0 )
-		pos.x -= breite + asteroid->zModel()->maxP.x * asteroid->getSize();
-	if( minP.y > höhe && speed.y > 0 )
-		pos.y -= höhe + asteroid->zModel()->maxP.y * asteroid->getSize();
-	asteroid->setPosition( pos );
-	if( rSpeed )
-		asteroid->addDrehung( rSpeed * (float)zeit );
-    if( ( asteroid->zModel()->maxP - asteroid->zModel()->minP ).x < 50 || ( asteroid->zModel()->maxP - asteroid->zModel()->minP ).y < 50 )
-    {
-        asteroid->setSize( asteroid->getSize() - (float)zeit * 3 );
-        if( asteroid->getSize() < 0 )
-            asteroid->setSize( 0 );
-    }
-	if( speed.x || speed.y )
-	{
-		pos += speed * (float)zeit;
-		asteroid->setPosition( pos );
-	}
-	return asteroid->tick( zeit );
-}
-
-void Asteroid::render( Bild &zRObj )
-{
-	asteroid->render( zRObj );
-}
-
 bool Asteroid::istGetroffen( Schuss *zSchuss, Polygon2D &a, Polygon2D &b, Punkt &pa, Punkt &pb, RandomGenerator *zRand )
 {
-    if( ( asteroid->zModel()->maxP - asteroid->zModel()->minP ).x < 50 || ( asteroid->zModel()->maxP - asteroid->zModel()->minP ).y < 50 )
+    if( ( zModel()->maxP - zModel()->minP ).x < 50 || ( zModel()->maxP - zModel()->minP ).y < 50 )
         return 0;
-    Vertex sp( 0, 0);
-    float r = 0;
-    Vertex hp;
-	if( zSchuss->istInM2( *asteroid, sp, r, hp ) )
-	{
-        asteroid->zModel()->split( hp, sp.rotation( -asteroid->getDrehung() ) * 0.1f, "", a, b, pa, pb, [ zRand ]()
+    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();
-        } );
-        hp = ( hp * asteroid->getSize() ).rotation( asteroid->getDrehung() ) + asteroid->getPosition();
-        speed += sp * 0.1f;
-        rSpeed += r * 0.1f;
-        zSchuss->getPos();
-		return 1;
+        } ) )
+        {
+            impuls( zSchuss->getPosition() - zSchuss->getSpeed(), zSchuss->getSpeed() * 0.05f );
+            return 1;
+        }
 	}
 	return 0;
 }
 
-void Asteroid::setDead()
+bool Asteroid::tick( const WeltInfo &info, double time )
 {
-    asteroid->setSize( 0 );
+    if( ( zModel()->maxP - zModel()->minP ).x < 50 || ( zModel()->maxP - zModel()->minP ).y < 50 )
+    {
+        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*)&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 );
 	zD->schreibe( (char*)&rSpeed, 4 );
-	float r = asteroid->getDrehung();
+	float r = getDrehung();
 	zD->schreibe( (char*)&r, 4 );
-	float gr = asteroid->getSize();
+	float gr = getSize();
 	zD->schreibe( (char*)&gr, 4 );
 }
 
-bool Asteroid::amLeben() const
-{
-	return asteroid->getSize() != 0;
-}
-
-Model2D *Asteroid::zModel() const
-{
-	return asteroid;
-}
-
-Punkt Asteroid::getPos() const
-{
-	return (Punkt)pos;
-}
-
-Bild *Asteroid::getTextur() const
-{
-    return txt ? txt->getThis() : 0;
-}
-
-Vec2< float > Asteroid::getSpeed() const
-{
-    return speed;
-}
-
-float Asteroid::getRSpeed() const
-{
-    return rSpeed;
-}
-
 char Asteroid::getId() const
 {
     return id;
@@ -158,22 +83,7 @@ char Asteroid::getId() const
 
 int Asteroid::getScore() const
 {
-    if( ( asteroid->zModel()->maxP - asteroid->zModel()->minP ).x < 50 || ( asteroid->zModel()->maxP - asteroid->zModel()->minP ).y < 50 )
+    if( ( zModel()->maxP - zModel()->minP ).x < 50 || ( zModel()->maxP - zModel()->minP ).y < 50 )
         return 1;
     return 0;
-}
-
-// Refernece Counting
-Asteroid *Asteroid::getThis()
-{
-	ref++;
-	return this;
-}
-
-Asteroid *Asteroid::release()
-{
-	ref--;
-	if( !ref )
-		delete this;
-	return 0;
 }

+ 3 - 21
Asteroids/Asteroid.h

@@ -9,41 +9,23 @@ using namespace Framework;
 
 class Schuss;
 
-class Asteroid
+class Asteroid : public Model2DObject
 {
 private:
-	Model2D *asteroid;
-	Vec2< float > pos;
-	Vec2< float > speed;
-    Bild *txt;
-	float rSpeed;
 	char id;
-	int ref;
 
 public:
 	// Konstruktor
-	Asteroid( Model2DData *data, Bild *textur, Vec2< float > p, Vec2< float > s, float rS, float r = 0, float gr = 0, char num = 0 );
+	Asteroid( Model2DData *data, Bild *textur, Vertex p, Vertex s, float rS, float r = 0, float gr = 0, char num = 0 );
 	// Destruktor
 	~Asteroid();
 	// nicht constant
-    void setTextur( Bild *textur );
-	bool tick( double zeit, int breite, int höhe );
-	void render( Bild &zRObj );
 	bool istGetroffen( Schuss *zSchuss, Polygon2D &a, Polygon2D &b, Punkt &pa, Punkt &pb, RandomGenerator *zRand );
-    void setDead();
+    bool Asteroid::tick( const WeltInfo &info, double time ) override;
 	// constant
 	void save( Datei *zD ) const;
-	bool amLeben() const;
-	Model2D *zModel() const;
-	Punkt getPos() const;
-    Bild *getTextur() const;
-    Vec2< float > getSpeed() const;
-    float getRSpeed() const;
     char getId() const;
     int getScore() const;
-	// Refernece Counting
-	Asteroid *getThis();
-	Asteroid *release();
 };
 
 #endif

+ 42 - 16
Asteroids/Data.cpp

@@ -1,9 +1,12 @@
 #include "Data.h"
 #include <M2Datei.h>
+#include <Textur2D.h>
 
 // Konstructor
 GameData::GameData( const char *shipM2, const char *asteroidsM2 )
 {
+    world = new Welt2D();
+    //world->setAirResistance( 0.01f );
     schuss = new RCArray< Schuss >();
     ship = 0;
     asteroid = new RCArray< Asteroid >();
@@ -57,6 +60,7 @@ GameData::~GameData()
     delete[] sData;
     if( rGen )
         rGen->release();
+    world->release();
 }
 
 // private
@@ -66,10 +70,22 @@ Asteroid *GameData::createNewAsteroid()
     double sw = ( rGen->rand() * 360 ) / 180.0 * PI;
     Vec2< float > speed( (float)cos( sw ), (float)sin( sw ) );
     speed *= (float)( rGen->rand() * 40 );
-    Vec2< float > pos( -200.f, höhe / 2.f );
+    Vec2< float > pos( (float)rGen->rand() * breite, (float)rGen->rand() * höhe );
+    if( ( ship->getPosition() - pos ).getLengthSq() > world->getWorldInfo().size.getLengthSq() / 3 )
+        return 0;
     if( speed.x < 0 )
         pos.x = (float)( breite + 200 );
-    return new Asteroid( aData[ num ]->getThis(), 0, pos, speed, (float)( rGen->rand() * 100 ) / 75.f, (float)sw, aGröße / 1000.f, num );
+    Asteroid *ast = new Asteroid( aData[ num ]->getThis(), 0, pos, speed, (float)( rGen->rand() * 100 ) / 75.f, (float)sw, aGröße / 1000.f, num );
+    int aAnz = asteroid->getEintragAnzahl();
+    for( int i = 0; i < aAnz; i++ )
+    {
+        if( ast->istModelInnen( asteroid->z( i ) ) )
+        {
+            ast->release();
+            return 0;
+        }
+    }
+    return ast;
 }
 
 // nicht constant
@@ -82,7 +98,8 @@ void GameData::reset( Text *zOptionen )
     scoreCheck = score * 11197;
     tastenStände = 0;
     if( ship )
-        ship = ship->release();
+        ship = (Ship*)ship->release();
+    world->removeAll();
     schuss->leeren();
     asteroid->leeren();
     Text *tmp = zOptionen->getTeilText( zOptionen->positionVon( '=' ) + 1, zOptionen->positionVon( ',' ) );
@@ -114,6 +131,7 @@ void GameData::reset( Text *zOptionen )
         tmp->release();
     }
     ship = new Ship( sData[ shipN ]->getThis(), shipPos, shipSpeed, shipR );
+    world->addObject( ship );
 }
 
 bool GameData::tick( double tickVal )
@@ -136,33 +154,36 @@ bool GameData::tick( double tickVal )
         timer = mTimer / 1000.0;
         for( int i = 0; i < rGen->rand() * 1 + 1; i++ )
         {
-            asteroid->add( createNewAsteroid() );
+            Asteroid *newA = createNewAsteroid();
+            if( newA )
+            {
+                asteroid->add( newA );
+                world->addObject( newA->getThis() );
+            }
         }
     }
     // Update
+    ship->setTastenstände( tastenStände );
     int aAnz = asteroid->getEintragAnzahl();
-    for( int i = 0; i < aAnz; i++ )
-        asteroid->z( i )->tick( tickVal, breite, höhe );
     int sAnz = schuss->getEintragAnzahl();
-    for( int i = 0; i < sAnz; i++ )
-        schuss->z( i )->tick( tickVal );
-    ship->tick( tickVal, breite, höhe, tastenStände );
     for( int i = aAnz - 1; i >= 0; i-- )
     {
-        if( !asteroid->z( i )->amLeben() )
+        if( asteroid->z( i )->getSize() == 0 )
         {
             score += asteroid->z( i )->getScore();
             scoreCheck = score * 11197;
+            world->removeObject( asteroid->z( i ) );
             asteroid->remove( i );
             aAnz--;
         }
     }
     for( int i = sAnz - 1; i >= 0; i-- )
     {
-        Vec2< float > pos = schuss->z( i )->getPos();
+        Vec2< float > pos = schuss->z( i )->getPosition();
         if( pos.x < 0 || pos.y < 0 || pos.x > breite || pos.y > höhe )
         {
             sAnz--;
+            world->removeObject( schuss->z( i ) );
             schuss->remove( i );
         }
     }
@@ -183,28 +204,33 @@ bool GameData::tick( double tickVal )
                 npaA->add( ap );
                 Model2DData *npdA = new Model2DData();
                 npdA->erstelleModell( npaA );
-                float rot = asteroid->z( j )->zModel()->getDrehung();
+                float rot = asteroid->z( j )->getDrehung();
                 char id = asteroid->z( j )->getId();
                 if( id >= 0 )
                     id = -id - 1;
-                asteroid->add( new Asteroid( npdA, asteroid->z( j )->getTextur(), pa.rotation( rot ) + asteroid->z( j )->getPos(), asteroid->z( j )->getSpeed(), asteroid->z( j )->getRSpeed(), rot, asteroid->z( j )->zModel()->getSize(), id ) );
+                Asteroid *newA = new Asteroid( npdA, asteroid->z( j )->zTextur()->zTextur()->getThis(), pa.rotation( rot ) + asteroid->z( j )->getPosition(), asteroid->z( j )->getSpeed(), asteroid->z( j )->getDrehungSpeed(), rot, asteroid->z( j )->getSize(), id );
+                asteroid->add( newA );
+                world->addObject( newA->getThis() );
                 Array< Polygon2D > *npaB = new Array< Polygon2D >();
                 npaB->add( bp );
                 Model2DData *npdB = new Model2DData();
                 npdB->erstelleModell( npaB );
-                asteroid->add( new Asteroid( npdB, asteroid->z( j )->getTextur(), pb.rotation( rot ) + asteroid->z( j )->getPos(), asteroid->z( j )->getSpeed(), asteroid->z( j )->getRSpeed(), rot, asteroid->z( j )->zModel()->getSize(), id ) );
+                newA = new Asteroid( npdB, asteroid->z( j )->zTextur()->zTextur()->getThis(), pb.rotation( rot ) + asteroid->z( j )->getPosition(), asteroid->z( j )->getSpeed(), asteroid->z( j )->getDrehungSpeed(), rot, asteroid->z( j )->getSize(), id );
+                asteroid->add( newA );
+                world->addObject( newA->getThis() );
                 b = 1;
-                asteroid->z( j )->setDead();
+                asteroid->z( j )->setSize( 0 );
             }
         }
         if( b )
         {
+            world->removeObject( schuss->z( i ) );
             schuss->remove( i );
             sAnz--;
         }
     }
     for( int i = 0; i < aAnz && !beendet; i++ )
-        beendet |= ship->istTod( asteroid->z( i ) );
+        beendet |= ship->istModelInnen( asteroid->z( i ) );
     beendet |= ( score * 11197 != scoreCheck );
     if( score * 11197 != scoreCheck )
     {

+ 2 - 1
Asteroids/Data.h

@@ -8,6 +8,7 @@
 class GameData
 {
 protected:
+    Welt2D *world;
     RCArray< Schuss > *schuss;
     Ship *ship;
     RCArray< Asteroid > *asteroid;
@@ -36,7 +37,7 @@ public:
     // Konstructor
     GameData( const char *shipM2, const char *asteroidsM2 );
     // Destructor
-    ~GameData();
+    virtual ~GameData();
     // nicht constant
     virtual void reset( Text *zOptionen );
     virtual bool tick( double t );

+ 4 - 0
Asteroids/Game.cpp

@@ -82,6 +82,8 @@ void Game::render( Bild &zRObj )
 
 void Game::setSchriftZ( Schrift *schrift )
 {
+    if( this->schrift )
+        this->schrift->release();
 	this->schrift = schrift;
 	if( !menü && this->schrift && screen && client )
 		menü = new Menü( schrift, screen, client->getThis() );
@@ -89,6 +91,8 @@ void Game::setSchriftZ( Schrift *schrift )
 
 void Game::setBildschirmZ( Bildschirm *screen )
 {
+    if( this->screen )
+        this->screen->release();
 	this->screen = screen;
 	if( !menü && schrift && screen && client )
 		menü = new Menü( schrift, screen, client->getThis() );

+ 41 - 33
Asteroids/Map.cpp

@@ -17,6 +17,11 @@
 Map::Map( KSGClient::MinigameServerClient *klient )
     : GameData( "data/Minigames/Asteroids/models/ship.m2", "data/Minigames/Asteroids/models/asteroids.m2" )
 {
+    kamera = new Kamera2D();
+    kamera->setWelt( world->getThis(), 1 );
+    kamera->setSize( 800, 500 );
+    mapKamera = new Kamera2D();
+    mapKamera->setWelt( world->getThis(), 0 );
     this->klient = klient;
     aTextur = new Bild*[ 7 ]();
     sTextur = new Bild*[ 2 ]();
@@ -60,12 +65,12 @@ Map::Map( KSGClient::MinigameServerClient *klient )
         name.append( (char)( 'a' + i ) );
         sTextur[ i ] = td.laden( 0, new Text( (char*)( Text( name ) += ".png" ) ) );
     }
-    kam = new LRahmen();
-    kam->setFarbe( 0xFF777777 );
     map = new LRahmen();
     map->setFarbe( 0xFFFFFFFF );
     map->setPosition( 10, 10 );
     map->setSize( 200, 200 );
+    mapKamera->setPosition( 10, 10 );
+    mapKamera->setSize( 200, 200 );
 }
 
 // Destruktor
@@ -77,19 +82,27 @@ Map::~Map()
         sTextur[ i ]->release();
     delete[] aTextur;
     delete[] sTextur;
-    kam->release();
     map->release();
     if( klient )
         klient->release();
     flammenM->release();
     flammenL->release();
     flammenR->release();
+    if( kamera )
+        kamera->release();
+    if( mapKamera )
+        mapKamera->release();
 }
 
 Asteroid *Map::createNewAsteroid()
 {
     Asteroid *a = __super::createNewAsteroid();
-    a->setTextur( aTextur[ a->getId() ] );
+    if( a )
+    {
+        Textur2D *text = new Textur2D();
+        text->setTexturZ( aTextur[ a->getId() ]->getThis() );
+        a->setTextur( text );
+    }
     return a;
 }
 
@@ -100,6 +113,9 @@ void Map::reset( Text *zOptionen )
     flammenR->setAnimation( -1 );
     flammenM->setAnimation( -1 );
     __super::reset( zOptionen );
+    world->setSize( breite, höhe );
+    world->setSize( 1 );
+    world->setCircular( 1 );
     Text *tmp = zOptionen->getTeilText( zOptionen->positionVon( '=', 5 ) + 1, zOptionen->positionVon( ',', 5 ) );
     bool fortsetzen = (int)*tmp != 0;
     tmp->release();
@@ -209,7 +225,9 @@ void Map::reset( Text *zOptionen )
                 save->lese( (char*)&y, 4 );
                 save->lese( (char*)&xs, 4 );
                 save->lese( (char*)&ys, 4 );
-                schuss->add( new Schuss( Vec2< float >( x, y ), Vec2< float >( xs, ys ) ) );
+                Schuss *newS = new Schuss( Vec2< float >( x, y ), Vec2< float >( xs, ys ) );
+                schuss->add( newS );
+                world->addObject( newS->getThis() );
             }
         }
         save->close();
@@ -233,9 +251,7 @@ void Map::reset( Text *zOptionen )
 }
 
 void Map::doMausEreignis( MausEreignis &me )
-{
-
-}
+{}
 
 void Map::doTastaturEreignis( TastaturEreignis &te )
 {
@@ -313,7 +329,9 @@ void Map::doTastaturEreignis( TastaturEreignis &te )
             capture.schreibe( (char*)&gameTime, 8 );
             capture.schreibe( "\x10", 1 );
         }
-        schuss->add( ship->getSchuss() );
+        Schuss *newS = ship->getSchuss();
+        schuss->add( newS );
+        world->addObject( newS->getThis() );
     }
     cs.unlock();
 }
@@ -323,6 +341,7 @@ bool Map::tick( double t )
     if( beendet )
         return 0;
     bool ret = __super::tick( t );
+    ret |= kamera->tick( t );
     if( beendet && klient )
     {
         capture.close();
@@ -391,32 +410,21 @@ bool Map::tick( double t )
 void Map::render( Bild &zRObj )
 {
     cs.lock();
-    Punkt kamP = ship->getKamPos( breite, höhe );
-    zRObj.addScrollOffset( kamP.x, kamP.y );
-    int aAnz = asteroid->getEintragAnzahl();
-    for( int i = 0; i < aAnz; i++ )
-        asteroid->z( i )->render( zRObj );
-    int sAnz = schuss->getEintragAnzahl();
-    for( int i = 0; i < sAnz; i++ )
-        schuss->z( i )->render( zRObj );
-    ship->render( zRObj );
-    zRObj.addScrollOffset( -kamP.x, -kamP.y );
+    kamera->lookAtWorldPos( (int)ship->getPosition().x, (int)ship->getPosition().y );
+    kamera->render( zRObj );
     if( breite >= 800 || höhe >= 500 )
     { // Minimap
-        const Punkt &dOff = zRObj.getDrawOff();
+        zRObj.setAlpha( 50 );
+        if( breite > höhe )
+            mapKamera->setSize( 200, (int)( ( 200.0 / world->getWorldInfo().size.x ) * world->getWorldInfo().size.y ) );
+        else
+            mapKamera->setSize( (int)( ( 200.0 / world->getWorldInfo().size.y ) * world->getWorldInfo().size.x ), 200 );
+        mapKamera->lookAtWorldPos( world->getWorldInfo().size.x / 2, world->getWorldInfo().size.y / 2 );
+        mapKamera->lookAtWorldArea( world->getWorldInfo().size.x, world->getWorldInfo().size.y );
+        mapKamera->render( zRObj );
+        map->setSize( mapKamera->getBreite(), mapKamera->getHeight() );
         map->render( zRObj );
-        zRObj.setPixelDP( 10 + ( ship->getPos().x * 200 ) / breite + dOff.x, 10 + ( ship->getPos().y * 200 ) / höhe + dOff.y, 0xFF00FF00 );
-        for( int i = 0; i < aAnz; i++ )
-            zRObj.setPixelDP( 10 + ( asteroid->z( i )->getPos().x * 200 ) / breite + dOff.x, 10 + ( asteroid->z( i )->getPos().y * 200 ) / höhe + dOff.y, 0xFFFF0000 );
-        for( int i = 0; i < sAnz; i++ )
-            zRObj.setPixelDP( 10 + ( (int)schuss->z( i )->getPos().x * 200 ) / breite + dOff.x, 10 + ( (int)schuss->z( i )->getPos().y * 200 ) / höhe + dOff.y, 0xFF00FFFF );
-        kam->setPosition( 10 + ( 200 * kamP.x ) / breite, 10 + ( 200 * kamP.y ) / höhe );
-        kam->setSize( ( 200 * 800 ) / breite, ( 200 * 500 ) / höhe );
-        if( kam->getBreite() > 200 )
-            kam->setSize( 200, kam->getHeight() );
-        if( kam->getHeight() > 200 )
-            kam->setSize( kam->getBreite(), 200 );
-        kam->render( zRObj );
+        zRObj.releaseAlpha();
     }
     cs.unlock();
 }
@@ -445,7 +453,7 @@ void Map::speichern()
             {
                 name[ 0 ] = n;
                 if( asteroid->z( index++ )->getId() < 0 )
-                    sad.saveModel( asteroid->z( index - 1 )->zModel()->zModel(), name );
+                    sad.saveModel( asteroid->z( index - 1 )->zModel(), name );
                 else
                     n--;
             }

+ 4 - 2
Asteroids/Map.h

@@ -5,13 +5,15 @@
 #include <Textur2D.h>
 #include "Data.h"
 #include "KSGNetwork.h"
+#include <Kamera2D.h>
 
 using namespace Framework;
 
 class Map : public GameData
 {
 private:
-    LRahmen *kam;
+    Kamera2D *kamera;
+    Kamera2D *mapKamera;
     LRahmen *map;
     Datei capture;
     KSGClient::MinigameServerClient *klient;
@@ -24,7 +26,7 @@ private:
     Asteroid *createNewAsteroid() override;
 public:
     // Konstruktor
-    Map( KSGClient::MinigameServerClient *klient );
+    Map( KSGClient::MinigameServerClient *klientd );
     // Destruktor
     ~Map();
     // nicht constant

+ 4 - 3
Asteroids/Menü.cpp

@@ -204,11 +204,12 @@ void Men
 bool MenüSpiel::tick( double tickVal )
 {
     timePuffer += tickVal;
+    
     bool ret = beenden->tick( tickVal );
-    while( timePuffer >= 0.01 )
+    while( timePuffer >= 0.02 )
     {
-        ret |= map->tick( 0.01 );
-        timePuffer -= 0.01;
+        ret |= map->tick( 0.02 );
+        timePuffer -= 0.02;
     }
     if( map->istBeendet() )
         ret |= verloren->tick( tickVal );

+ 15 - 43
Asteroids/Schuss.cpp

@@ -3,62 +3,34 @@
 // Inhalt der Schuss Klasse aus Schuss.h
 // Konstruktor
 Schuss::Schuss( Vec2< float > pos, Vec2< float > speed )
+    : Object2D()
 {
-	this->pos = pos;
-	this->speed = speed;
+    setPosition( pos );
+    setSpeed( speed );
 	ref = 1;
 }
 
 // nicht constant
-bool Schuss::tick( double zeit )
+void Schuss::render( Mat3< float > &kamMat, Bild &zRObj )
 {
-	pos += speed * (float)zeit;
-	return 1;
-}
-
-void Schuss::render( Bild &zRObj )
-{
-	zRObj.drawLinie( (Punkt)pos, (Punkt)( pos - speed / 10 ), 0xFFFFFFFF );
+	zRObj.drawLinie( (Punkt)(kamMat * position), (Punkt)( kamMat * (position - speed / 10) ), 0xFFFFFFFF );
 }
 
 // constant
-bool Schuss::istInM2( const Model2D &mdl, Vertex &speed, float &rot, Vertex &hp ) const
-{
-    if( mdl.istPunktInnen( pos ) )
-    {
-        if( mdl.zModel()->calcHitPoint( ( ( pos - this->speed / 10 ) - mdl.getPosition() ).rotation( -mdl.getDrehung() ) / mdl.getSize(), Vertex( this->speed / 10 ).rotation( -mdl.getDrehung() ), "", hp, speed, rot ) )
-        {
-            speed = speed.rotation( mdl.getDrehung() );
-            return 1;
-        }
-    }
-    return 0;
+Rect2< float > Schuss::getBoundingBox() const
+{
+    auto rect = Rect2< float >();
+    rect.topLeft.x = min( position.x, ( position - this->speed / 10 ).x );
+    rect.topLeft.y = min( position.y, ( position - this->speed / 10 ).y );
+    rect.bottomRight.x = max( position.x, ( position - this->speed / 10 ).x );
+    rect.bottomRight.y = max( position.y, ( position - this->speed / 10 ).y );
+    return rect;
 }
 
 void Schuss::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 );
-}
-
-Vec2< float > Schuss::getPos() const
-{
-	return pos;
-}
-
-// Reference Counting
-Schuss *Schuss::getThis()
-{
-	ref++;
-	return this;
-}
-
-Schuss *Schuss::release()
-{
-	ref--;
-	if( !ref )
-		delete this;
-	return 0;
 }

+ 3 - 13
Asteroids/Schuss.h

@@ -7,26 +7,16 @@
 
 using namespace Framework;
 
-class Schuss
+class Schuss : public Object2D
 {
-private:
-	Vec2< float > pos;
-	Vec2< float > speed;
-	int ref;
-
 public:
 	// Konstruktor
 	Schuss( Vec2< float > pos, Vec2< float > speed );
 	// nicht constant
-	bool tick( double zeit );
-	void render( Bild &zRObj );
+	void render( Mat3< float > &kamMat, Bild &zRObj ) override;
 	// constant
-	bool istInM2( const Model2D &mdl, Vertex &speed, float &rot, Vertex &hp ) const;
+    Rect2< float > getBoundingBox() const override;
 	void save( Datei *zD ) const;
-	Vec2< float > getPos() const;
-	// Reference Counting
-	Schuss *getThis();
-	Schuss *release();
 };
 
 #endif

+ 32 - 142
Asteroids/Ship.cpp

@@ -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() );
 }

+ 4 - 14
Asteroids/Ship.h

@@ -9,20 +9,16 @@ using namespace Framework;
 class Schuss;
 class Asteroid;
 
-class Ship
+class Ship : public Model2DObject
 {
 private:
-	Model2D *ship;
-	Vec2< float > pos;
-	Vec2< float > speed;
     Vertex stL;
     Vertex kL;
     Vertex stR;
     Vertex kR;
     Vertex stM;
     Vertex kM;
-    float rSpeed;
-	int ref;
+    char tastenstände;
 
 public:
 	// Konstruktor
@@ -30,19 +26,13 @@ public:
 	// Destruktor
 	~Ship();
 	// nicht constant
+    void setTastenstände( char ts );
     void setTexture( Textur2D *zFlammenM, Textur2D *zFlammenL, Textur2D *zFlammenR, Bild *textur );
     void setPRS( Vec2< float > p, Vec2< float > s, float r, float rSpeed );
-	bool tick( double zeit, int breite, int höhe, char tastenStände );
-	void render( Bild &zRObj );
+	bool tick( const WeltInfo &info, double zeit );
 	// constant
 	void save( Datei *zD ) const;
 	Schuss *getSchuss() const;
-	bool istTod( Asteroid *zA ) const;
-	Punkt getKamPos( int breite, int höhe ) const;
-	Punkt getPos() const;
-	// Reference Counting
-	Ship *getThis();
-	Ship *release();
 };
 
 #endif