Răsfoiți Sursa

Schüssen können nun auch einen selbst treffen (man nimmt dadurch keinen schaden)

Kolja Strohm 5 ani în urmă
părinte
comite
223f7cf3e7
6 a modificat fișierele cu 37 adăugiri și 10 ștergeri
  1. 3 3
      Asteroids/Asteroid.cpp
  2. 2 0
      Asteroids/Asteroid.h
  3. 2 0
      Asteroids/Data.cpp
  4. 12 6
      Asteroids/Map.cpp
  5. 17 1
      Asteroids/Ship.cpp
  6. 1 0
      Asteroids/Ship.h

+ 3 - 3
Asteroids/Asteroid.cpp

@@ -34,7 +34,7 @@ Asteroid::~Asteroid()
 // nicht constant
 bool Asteroid::istGetroffen( Schuss *zSchuss, Polygon2D &a, Polygon2D &b, Punkt &pa, Punkt &pb, RandomGenerator *zRand )
 {
-    if( ( zModel()->maxP - zModel()->minP ).x < 50 || ( zModel()->maxP - zModel()->minP ).y < 50 )
+    if( getMasse() < 40 * 40 )
         return 0;
     if( istPunktInnen( zSchuss->getPosition() ) )
     {
@@ -52,7 +52,7 @@ bool Asteroid::istGetroffen( Schuss *zSchuss, Polygon2D &a, Polygon2D &b, Punkt
 
 bool Asteroid::tick( const WeltInfo &info, double time )
 {
-    if( ( zModel()->maxP - zModel()->minP ).x < 50 || ( zModel()->maxP - zModel()->minP ).y < 50 )
+    if( getMasse() < 40 * 40 )
     {
         setSize( getSize() - (float)time * 3 );
         if( getSize() < 0 )
@@ -83,7 +83,7 @@ char Asteroid::getId() const
 
 int Asteroid::getScore() const
 {
-    if( ( zModel()->maxP - zModel()->minP ).x < 50 || ( zModel()->maxP - zModel()->minP ).y < 50 )
+    if( getMasse() < 40 * 40 )
         return 1;
     return 0;
 }

+ 2 - 0
Asteroids/Asteroid.h

@@ -4,6 +4,8 @@
 #include <Model2D.h>
 #include <Datei.h>
 #include <Random.h>
+#include <Schrift.h>
+#include <Bild.h>
 
 using namespace Framework;
 

+ 2 - 0
Asteroids/Data.cpp

@@ -232,6 +232,8 @@ bool GameData::tick( double tickVal )
                 asteroid->z( j )->setSize( 0 );
             }
         }
+        if( !b )
+            b |= ship->istGetroffen( zs );
         if( b )
         {
             world->removeObject( schuss->z( i ) );

+ 12 - 6
Asteroids/Map.cpp

@@ -225,9 +225,12 @@ void Map::reset( Text *zOptionen )
                 save->lese( (char*)&y, 4 );
                 save->lese( (char*)&xs, 4 );
                 save->lese( (char*)&ys, 4 );
-                Schuss *newS = new Schuss( Vec2< float >( x, y ), Vec2< float >( xs, ys ) );
-                schuss->add( newS );
-                world->addObject( newS->getThis() );
+                if( schuss->getEintragAnzahl() > 100 )
+                {
+                    Schuss *newS = new Schuss( Vec2< float >( x, y ), Vec2< float >( xs, ys ) );
+                    schuss->add( newS );
+                    world->addObject( newS->getThis() );
+                }
             }
         }
         save->close();
@@ -329,9 +332,12 @@ void Map::doTastaturEreignis( TastaturEreignis &te )
             capture.schreibe( (char*)&gameTime, 8 );
             capture.schreibe( "\x10", 1 );
         }
-        Schuss *newS = ship->getSchuss();
-        schuss->add( newS );
-        world->addObject( newS->getThis() );
+        if( schuss->getEintragAnzahl() < 100 )
+        {
+            Schuss *newS = ship->getSchuss();
+            schuss->add( newS );
+            world->addObject( newS->getThis() );
+        }
     }
     cs.unlock();
 }

+ 17 - 1
Asteroids/Ship.cpp

@@ -79,6 +79,18 @@ Ship::~Ship()
 #define sgn( x ) x < 0 ? -1 : 1
 
 // nicht constant
+bool Ship::istGetroffen( Schuss *zSchuss )
+{
+    if( getMasse() < 40 * 40 )
+        return 0;
+    if( istPunktInnen( zSchuss->getPosition() ) )
+    {
+        impuls( zSchuss->getPosition() - zSchuss->getSpeed(), zSchuss->getSpeed() * 0.3f );
+        return 1;
+    }
+    return 0;
+}
+
 void Ship::setTexture( Textur2D *zFlammenM, Textur2D *zFlammenL, Textur2D *zFlammenR, Bild *textur )
 {
     Textur2D *txt = new Textur2D();
@@ -135,5 +147,9 @@ void Ship::save( Datei *zD ) const
 
 Schuss *Ship::getSchuss() const
 {
-    return new Schuss( position, Vec2<float>( cos( getDrehung() ), sin( getDrehung() ) ) * 200 + getSpeed() );
+    Vertex pos = position;
+    Vertex sp = Vec2<float>( cos( getDrehung() ), sin( getDrehung() ) ) * 200 + getSpeed();
+    while( istPunktInnen( pos ) )
+        pos += sp / 60.0f;
+    return new Schuss( pos, sp );
 }

+ 1 - 0
Asteroids/Ship.h

@@ -26,6 +26,7 @@ public:
 	// Destruktor
 	~Ship();
 	// nicht constant
+    bool istGetroffen( Schuss *zSchuss );
     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 );