Exemplo n.º 1
0
void Game::resetGame()
{ 
  objects->clear();
  objects->spawnTerrain(terrain);
  objects->spawnWater(water);
  
  // Create plane  
  unsigned int planeID = objects->spawnPlane(Vector3
    (0.0f,terrain->getHeight(0.0f,0.0f) + 10.0f,0.0f));
  m_tetherCamera->setTargetObject(planeID);

  // Load silos
  objects->spawnSilo(LocationOnterrain(-30.0f, 10.0f, 100.0f));
  objects->spawnSilo(LocationOnterrain(-10.0f, 10.0f, 100.0f));
  objects->spawnSilo(LocationOnterrain(10.0f, 10.0f, 100.0f));
  objects->spawnSilo(LocationOnterrain(30.0f, 10.0f, 100.0f));

  // Load windmill
  unsigned int windmillID = objects->spawnWindmill(LocationOnterrain(60.0f, 0.0f, 100.0f));
  
  // Load crows
  static const int numCrows = 20;
  for(int i = 0; i < numCrows; ++i)
  {
    // Distibute evenly over a hollow cylinder around the windmill
    
    GameObject *windmill = objects->getObjectPointer(windmillID);
    const Vector3 &windmillPos = windmill->getPosition();
    Vector3 boxSize = windmill->getBoundingBox().size();
    float minDist = sqrt(boxSize.x * boxSize.x + boxSize.z - boxSize.z); // At least the windmill's maximum diameter away from the windmill
    float maxDist = 175.0f; // Maximum distance; season to taste
    float radius = Random.getFloat(minDist, maxDist);
    float angle = Random.getFloat(0,k2Pi);
    float height = windmillPos.y + boxSize.y * Random.getFloat(1.5, 2.0f) + 10.0f; // Randomize crow height to somewhat above the windmill
    Vector3 crowPos(cos(angle) * radius + windmillPos.x, height, sin(angle) * radius + windmillPos.z);
    float crowSpeed = Random.getFloat(0.8f,2.5f);
    // One speedy crow, one slow crow
    if(i == numCrows - 2)
      crowSpeed = 6.0f;
    else if(i == numCrows - 1)
      crowSpeed = 0.5;
    
    //crowSpeed = 0.0;
    objects->spawnCrow(crowPos, windmillPos, crowSpeed, Random.getBool());
  }

  // Set the tether camera
  m_tetherCamera->minDist = 10.0f;
  m_tetherCamera->maxDist = 20.0f;
  m_tetherCamera->fov;
  m_tetherCamera->reset();
  m_tetherCamera->process(0.0f);
  m_currentCam = m_tetherCamera;   // select tether camera as the current camera
}
Exemplo n.º 2
0
/// Game Initiate.
/// Initiates all game logic.  This is called after the game engine is 
/// initiated.
/// \return True on success.  False on failure (application will terminate).
bool Game::initiate()
{   
	// Setup program
  float farClippingPlane = 2000.0f;

  // Set far clipping plane
  gRenderer.setNearFarClippingPlanes(1.0f,farClippingPlane);

  objects = new Ned3DObjectManager();
  objects->setNumberOfDeadFrames(2);
  m_tetherCamera = new TetherCamera(objects);
	
  // Create terrain
  terrain = new Terrain(8,"terrain.xml"); //powers of two for terrain size
  
  // Load models
  objects->setModelManager(gModelManager);
  gModelManager.importXml("models.xml");
  
  // set fog
  gRenderer.setFogEnable(true);
  gRenderer.setFogDistance(farClippingPlane - 1000.0f,farClippingPlane);
  gRenderer.setFogColor(MAKE_ARGB(0,60,180,254));

  // set lights
  gRenderer.setAmbientLightColor(MAKE_ARGB(255,100,100,100));
  gRenderer.setDirectionalLightColor(0XFFFFFFFF);
  Vector3 dir = Vector3(5.0f,-5.0f, 6.0f);
  dir.normalize();
  gRenderer.setDirectionalLightVector(dir);
  	
  // Create water now that we know what camera to use  
  float fov = degToRad(gGame.m_currentCam->fov);
  water = new Water(fov, farClippingPlane, "water.xml");
  
  // set the camera's y position so it is above the terrain
  m_currentCam->cameraPos.y = 200.0f;

  // Start placing objects into our world
  objects->clear();
  objects->spawnTerrain(terrain);
  objects->spawnWater(water);
  
  // Create plane  
  unsigned int planeID = objects->spawnPlane(Vector3
    (0.0f,terrain->getHeight(0.0f,0.0f) + 10.0f,0.0f));

  // Load silos
  objects->spawnSilo(LocationOnterrain(-30.0f, 10.0f, 100.0f));
  objects->spawnSilo(LocationOnterrain(-10.0f, 10.0f, 100.0f));
  objects->spawnSilo(LocationOnterrain(10.0f, 10.0f, 100.0f));
  objects->spawnSilo(LocationOnterrain(30.0f, 10.0f, 100.0f));

  // Load windmill
  unsigned int windmillID = objects->spawnWindmill(LocationOnterrain(60.0f, 0.0f, 100.0f));
  
  // Load crows
  static const int numCrows = 20;
  for(int i = 0; i < numCrows; ++i)
  {
    // Distibute evenly over a hollow cylinder around the windmill

    GameObject *windmill = objects->getObjectPointer(windmillID);
    const Vector3 &windmillPos = windmill->getPosition();
    Vector3 boxSize = windmill->getBoundingBox().size();
    float minDist = sqrt(boxSize.x * boxSize.x + boxSize.z - boxSize.z); // At least the windmill's maximum diameter away from the windmill
    float maxDist = 175.0f; // Maximum distance; season to taste
    float radius = Random.getFloat(minDist, maxDist);
    float angle = Random.getFloat(0,k2Pi);
    float height = windmillPos.y + boxSize.y * Random.getFloat(1.5, 2.0f) + 10.0f; // Randomize crow height to somewhat above the windmill
    Vector3 crowPos(cos(angle) * radius + windmillPos.x, height, sin(angle) * radius + windmillPos.z);
    float crowSpeed = Random.getFloat(0.8f,2.5f);
    // One speedy crow, one slow crow
    if(i == numCrows - 2)
      crowSpeed = 6.0f;
    else if(i == numCrows - 1)
      crowSpeed = 0.5;
    
    objects->spawnCrow(crowPos, windmillPos, crowSpeed, Random.getBool());
  }
  
  gConsole.addFunction("camerafollow","",consoleSetFollowCamera);
  gConsole.addFunction("cameratarget","s",consoleSetCameraTarget);

  // Set the tether camera
  m_tetherCamera->minDist = 10.0f;
  m_tetherCamera->maxDist = 20.0f;
  m_tetherCamera->fov;
  m_currentCam = m_tetherCamera;   // select tether camera as the current camera
  m_tetherCamera->setTargetObject(planeID);
  m_tetherCamera->reset();
  m_tetherCamera->process(0.0f);

  // Load console command comments from XML that are specific to NED3D
  gConsole.loadCommentsFromXml("nedConsoleDoc.xml");

	return true;
}
void StatePlaying::resetGame()
{ 
  m_objects->clear();
  m_objects->spawnTerrain(terrain);
  m_objects->spawnWater(water);
  
  // Create plane  
  unsigned int planeID = m_objects->spawnPlane(Vector3
    (0.0f,terrain->getHeight(0.0f,0.0f) + 10.0f,0.0f));
  m_tetherCamera->setTargetObject(planeID);

  // Load silos
  m_objects->spawnSilo(LocationOnterrain(-30.0f, 10.0f, 100.0f));
  m_objects->spawnSilo(LocationOnterrain(-10.0f, 10.0f, 100.0f));
  m_objects->spawnSilo(LocationOnterrain(10.0f, 10.0f, 100.0f));
  m_objects->spawnSilo(LocationOnterrain(30.0f, 10.0f, 100.0f));

  // Load windmill
  unsigned int windmillID = m_objects->spawnWindmill(LocationOnterrain(60.0f, 0.0f, 100.0f));
  
  // Load crows
  static const int numCrows = 20;
  for(int i = 0; i < numCrows; ++i)
  {
    // Distibute evenly over a hollow cylinder around the windmill
    
    GameObject *windmill = m_objects->getObjectPointer(windmillID);
    const Vector3 &windmillPos = windmill->getPosition();
    Vector3 boxSize = windmill->getBoundingBox().size();
    float minDist = sqrt(boxSize.x * boxSize.x + boxSize.z - boxSize.z); // At least the windmill's maximum diameter away from the windmill
    float maxDist = 175.0f; // Maximum distance; season to taste
    float radius = Random.getFloat(minDist, maxDist);
    float angle = Random.getFloat(0,k2Pi);
    float height = windmillPos.y + boxSize.y * Random.getFloat(1.5, 2.0f) + 10.0f; // Randomize crow height to somewhat above the windmill
    Vector3 crowPos(cos(angle) * radius + windmillPos.x, height, sin(angle) * radius + windmillPos.z);
    float crowSpeed = Random.getFloat(0.8f,2.5f);
    // One speedy crow, one slow crow
    if(i == numCrows - 2)
      crowSpeed = 6.0f;
    else if(i == numCrows - 1)
      crowSpeed = 0.5;
    
    //crowSpeed = 0.0;
    m_objects->spawnCrow(crowPos, windmillPos, crowSpeed, Random.getBool());
  }

  // reset camera following crow variables
  m_planeCrashed = false;
  m_timeSinceCrashed = 0.0f;
  m_crowID = -1;

  // Set the tether camera
  m_tetherCamera->minDist = 10.0f;
  m_tetherCamera->maxDist = 20.0f;
  m_tetherCamera->fov;
  m_tetherCamera->reset();
  m_tetherCamera->process(0.0f);
  gGame.m_currentCam = m_tetherCamera;   // select tether camera as the current camera
  
  // kill all active particle effects
  gParticle.killAll();

  // release our endgame sound, and stop all currently playing sounds
  gSoundManager.releaseInstance(m_failedSound,m_failedInstance);
  m_failedInstance = SoundManager::NOINSTANCE;
  gSoundManager.stop();
}