Bladeren bron

Besseres plazieren neuer asteroiden

Kolja Strohm 5 jaren geleden
bovenliggende
commit
7349d35518
2 gewijzigde bestanden met toevoegingen van 23 en 11 verwijderingen
  1. 21 11
      Asteroids/Data.cpp
  2. 2 0
      Asteroids/Ship.cpp

+ 21 - 11
Asteroids/Data.cpp

@@ -71,21 +71,31 @@ Asteroid *GameData::createNewAsteroid()
     Vec2< float > speed( (float)cos( sw ), (float)sin( sw ) );
     speed *= (float)( rGen->rand() * 40 );
     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 );
-    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( ( ship->getPosition() - Vertex( (float)world->getWorldInfo().size.x, 0 ) - pos ).getLength() > world->getWorldInfo().size.getLength() / 3 &&
+        ( ship->getPosition() + Vertex( (float)world->getWorldInfo().size.x, 0 ) - pos ).getLength() > world->getWorldInfo().size.getLength() / 3 &&
+        ( ship->getPosition() - Vertex( 0, (float)world->getWorldInfo().size.y ) - pos ).getLength() > world->getWorldInfo().size.getLength() / 3 &&
+        ( ship->getPosition() + Vertex( 0, (float)world->getWorldInfo().size.y ) - pos ).getLength() > world->getWorldInfo().size.getLength() / 3 &&
+        ( ship->getPosition() - Vertex( (float)world->getWorldInfo().size.x, (float)world->getWorldInfo().size.y ) - pos ).getLength() > world->getWorldInfo().size.getLength() / 3 &&
+        ( ship->getPosition() + Vertex( (float)world->getWorldInfo().size.x, (float)world->getWorldInfo().size.y ) - pos ).getLength() > world->getWorldInfo().size.getLength() / 3 &&
+        ( ship->getPosition() + Vertex( (float)world->getWorldInfo().size.x, -(float)world->getWorldInfo().size.y ) - pos ).getLength() > world->getWorldInfo().size.getLength() / 3 &&
+        ( ship->getPosition() + Vertex( -(float)world->getWorldInfo().size.x, (float)world->getWorldInfo().size.y ) - pos ).getLength() > world->getWorldInfo().size.getLength() / 3 &&
+        ( ship->getPosition() - pos ).getLength() > world->getWorldInfo().size.getLength() / 3 )
     {
-        if( ast->istModelInnen( asteroid->z( i ) ) )
+        if( speed.x < 0 )
+            pos.x = (float)( breite + 200 );
+        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++ )
         {
-            ast->release();
-            return 0;
+            if( ast->istModelInnen( asteroid->z( i ) ) )
+            {
+                ast->release();
+                return 0;
+            }
         }
+        return ast;
     }
-    return ast;
+    return 0;
 }
 
 // nicht constant

+ 2 - 0
Asteroids/Ship.cpp

@@ -116,6 +116,8 @@ bool Ship::tick( const WeltInfo &info, double zeit )
     {
         impuls( getWorldPos(stR), getWorldDir(kR) * (float)zeit * 10 );
     }
+    speed /= 1.01f;
+    rSpeed /= 1.01f;
     return __super::tick( info, zeit );
 }