Exemplo n.º 1
0
	BOOST_FOREACH(Asteroid& Asteroid, m_asteroids) {
		b2Body* body = Asteroid.GetBody();
		b2World* world = body->GetWorld();
		world->DestroyBody(body);
	}
Exemplo n.º 2
0
void MainScene::CreateAsteroids()
{
   Vec2 center(0,0);
   
   const string names[] =
   {
      "Asteroid_01",
      "Asteroid_02",
      "Asteroid_03",
      "Asteroid_04",
      "Asteroid_05",
      "Asteroid_06",
      "Asteroid_07",
      //       "Asteroid_08",
   };
   
   const int MAX_NAMES = sizeof(names)/sizeof(names[0]);
   
   typedef struct
   {
      float32 radius;
      uint32 asteroids;
   } RING_DATA_T;
   
   RING_DATA_T ringData[] =
   {
      {1, 1},
      {9, 3},
      {17, 7},
      {25, 13},
      {35, 20},
   };
   
   const int MAX_RINGS = sizeof(ringData)/sizeof(ringData[0]);
   
   float32 angleRads = 0;
   uint32 nameIdx = 0;
   
   
   for(int ring = 0; ring < MAX_RINGS; ring++)
   {
      // Inner ring asteroids
      float32 targetRadius = ringData[ring].radius;
      uint32 asteroids = ringData[ring].asteroids;
      
      for(int idx = 0; idx < asteroids; idx++)
      {
         Vec2 offset =  Vec2::FromPolar(targetRadius, angleRads);
         Vec2 position = center + offset;
         Asteroid* asteroid = new Asteroid();
         asteroid->Create(*_world,
                          names[nameIdx%MAX_NAMES],
                          position,
                          9.0 + RanNumGen::RandFloat(-1.0, 1.0));
         
         asteroid->GetBody()->SetDebugDraw(false);
         
         EntityManager::Instance().Register(asteroid);
         _asteroids.push_back(asteroid);
         
         
         // All asteroids have a distance joint to the anchor
         // Now create the joint.
         b2RopeJointDef jointDef;
         jointDef.bodyA = _anchor;
         jointDef.bodyB = asteroid->GetBody();
         jointDef.maxLength = b2Distance(jointDef.bodyA->GetPosition(), jointDef.bodyB->GetPosition());
         jointDef.collideConnected = true;
         _world->CreateJoint(&jointDef);
         
         nameIdx++;
         angleRads += (2*M_PI)/asteroids + RanNumGen::RandFloat(-M_PI/(12*asteroids), M_PI/(12*asteroids));
      }
   }
   
   
   for(int idx = 0;idx < _asteroids.size(); idx++)
   {
      _asteroidLayer->AddSprite(_asteroids[idx]->GetSprite());
      EntityScheduler::Instance().Register(_asteroids[idx]);
      // Give it at least one update to start.
      _asteroids[idx]->Update();
   }
}