当前位置: 首页>>代码示例>>C++>>正文


C++ EntityManager::updateRender方法代码示例

本文整理汇总了C++中EntityManager::updateRender方法的典型用法代码示例。如果您正苦于以下问题:C++ EntityManager::updateRender方法的具体用法?C++ EntityManager::updateRender怎么用?C++ EntityManager::updateRender使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在EntityManager的用法示例。


在下文中一共展示了EntityManager::updateRender方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main


//.........这里部分代码省略.........
  sf::Font font;
  if (!font.loadFromFile(resourcePath() + "fonts/sansation.ttf"))
  	return EXIT_FAILURE;
  sf::Text text("Hello SFML", font, 50);
  text.setColor(sf::Color::Black);

  // Load a music to play
  sf::Music music;
  if (!music.openFromFile(resourcePath() + "music/fairy_road.ogg"))
  	return EXIT_FAILURE;

  
  sf::Clock frameTimer;
  sf::Time deltaTime;
    
  // Generates the World
  b2Vec2 gravity(0, -9.8);
  b2World* world = new b2World(gravity);
  
  GameContainer* gc = new GameContainer(window, world);
    
  
  EntityManager* em = new EntityManager();
  
  Entity* player = em->addEntity(new Entity(gc, "player"));
  player->setPosition(8, 0);
  player->addComponent(new BodyComponent(gc, 0.6f, 1.8f, true));
  player->addComponent(new WireboxRenderComponent("wirebox"));
  
  float windowRatio = (float)gc->getWindow()->getSize().y / (float)gc->getWindow()->getSize().x;
  Entity* camera = em->addEntity(new Entity(gc, "camera"));
  camera->setPosition(100, 10);
  camera->addComponent(new CameraComponent(gc, player, 30, 30*windowRatio));
  
  Entity* terrain = em->addEntity(new Entity(gc, "terrain"));
  terrain->setPosition(0, -10);
  terrain->addComponent(new WirechainRenderComponent(6));
  terrain->addComponent(new TerrainComponent(gc, "gameTerrain", 6));
  ((TerrainComponent*) terrain->getComponent("gameTerrain"))->addPoint(0, 5, 0);
  ((TerrainComponent*) terrain->getComponent("gameTerrain"))->addPoint(1, 20, 5);
  ((TerrainComponent*) terrain->getComponent("gameTerrain"))->addPoint(2, 30, -2);
  ((TerrainComponent*) terrain->getComponent("gameTerrain"))->addPoint(3, 50, 10);
  ((TerrainComponent*) terrain->getComponent("gameTerrain"))->addPoint(4, 80, 5);
  ((TerrainComponent*) terrain->getComponent("gameTerrain"))->addPoint(5, 100, 15);
  ((TerrainComponent*) terrain->getComponent("gameTerrain"))->generate();
  
  Entity* options = em->addEntity(new Entity(gc, "options"));
  options->addComponent(new OptionComponent("controls", "moveLeft", "A"));
  options->addComponent(new OptionComponent("controls", "moveLeft_alt", "arrow_left"));
  options->addComponent(new OptionComponent("controls", "moveRight", "D"));
  options->addComponent(new OptionComponent("controls", "moveRight_alt", "arrow_right"));
  
  
  
  
  //ControlManager::player(player);
  
  
  // Play the music
  music.play();
      

  // Start the game loop
  while (window->isOpen())
  {
  	// Process events
  	sf::Event event;
  	while (window->pollEvent(event))
  	{
  		// Close window : exit
  		if (event.type == sf::Event::Closed)
  			window->close();
          
  		// Escape pressed : exit
  		if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape)
  			window->close();
  	}
    
    currentFPS =  1000 / (gc->getDelta().asMicroseconds() / 1000.0f);

  	// Clear screen
  	gc->getWindow()->clear();
  	    
    em->updateRender();
    
    em->getNearbyEntities(em->getEntity("player"), 2);
    
    
    
    gc->getWorld()->Step(1/currentFPS,  8, 3);
    gc->getWindow()->setView(gc->view);
    
    // Update the window
  	gc->getWindow()->display();
    
    gc->setDelta(frameTimer.restart());
  }

	return EXIT_SUCCESS;
}
开发者ID:Goriar,项目名称:lazy-crab,代码行数:101,代码来源:main.cpp

示例2: main

int main (int argc, const char * argv[])
{  
  string gameName = "Lazy Crab";
  float currentFPS = 0;
  
  // Create the main window
  sf::VideoMode DesktopMode = sf::VideoMode::getDesktopMode();
  sf::RenderWindow* window = new sf::RenderWindow(sf::VideoMode(DesktopMode.width/2, DesktopMode.height/2,DesktopMode.bitsPerPixel), gameName);

  sf::Clock frameTimer;
    
  // Generates the World
  b2Vec2 gravity(0, -9.8);
  b2World* world = new b2World(gravity);
  
  GameContainer* gc = new GameContainer(window, world);
    
  
  EntityManager* em = new EntityManager();
  
  Entity* player = em->addEntity(new Entity(gc, "player"));
  player->setPosition(8, 30);
  player->addComponent(new BodyComponent(gc, 0.6f, 1.8f, true));
  player->addComponent(new WireboxRenderComponent("wirebox"));
  
  float windowRatio = (float)gc->getWindow()->getSize().y / (float)gc->getWindow()->getSize().x;
  Entity* camera = em->addEntity(new Entity(gc, "camera"));
  camera->setPosition(100, 10);
  camera->addComponent(new CameraComponent(gc, player, 30, 30*windowRatio));
  
  Entity* terrain = em->addEntity(new Entity(gc, "terrain"));
  
  terrain->setPosition(0, 0);
  terrain->addComponent(new WirechainRenderComponent(5));
  terrain->addComponent(new TerrainComponent(gc, "gameTerrain", 5));
  /*for(int i = 0; i != coords.size(); i++)
  {
    ((TerrainComponent*) terrain->getComponent("gameTerrain"))->addPoint(i, coords[i].x, coords[i].y);
  }*/
  ((TerrainComponent*) terrain->getComponent("gameTerrain"))->addPoint(0, 0, 5);
  ((TerrainComponent*) terrain->getComponent("gameTerrain"))->addPoint(1, 30, -2);
  ((TerrainComponent*) terrain->getComponent("gameTerrain"))->addPoint(2, 50, 10);
  ((TerrainComponent*) terrain->getComponent("gameTerrain"))->addPoint(3, 80, 5);
  ((TerrainComponent*) terrain->getComponent("gameTerrain"))->addPoint(4, 100, 15);
  ((TerrainComponent*) terrain->getComponent("gameTerrain"))->generate();

  
  Entity* options = em->addEntity(new Entity(gc, "options"));
  options->addComponent(new OptionComponent("controls", "moveLeft", "A"));
  options->addComponent(new OptionComponent("controls", "moveLeft_alt", "arrow_left"));
  options->addComponent(new OptionComponent("controls", "moveRight", "D"));
  options->addComponent(new OptionComponent("controls", "moveRight_alt", "arrow_right"));
  
  
  
  
  
  
  //ControlManager::player(player);
  
  // Start the game loop
  while (window->isOpen())
  {
  	// Process events
  	sf::Event event;
  	while (window->pollEvent(event))
  	{
  		// Close window : exit
  		if (event.type == sf::Event::Closed)
  			window->close();
          
  		// Escape pressed : exit
  		if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape)
  			window->close();
  	}
    
    currentFPS =  1000 / (gc->getDelta().asMicroseconds() / 1000.0f);

  	// Clear screen
  	gc->getWindow()->clear();
  	    
    em->updateRender();
    
    em->getNearbyEntities(em->getEntity("player"), 2);
    
    
    
    gc->getWorld()->Step(1/currentFPS,  8, 3);
    gc->getWindow()->setView(gc->view);
    
    // Update the window
  	gc->getWindow()->display();
    
    gc->setDelta(frameTimer.restart());
  }

	return EXIT_SUCCESS;
}
开发者ID:mungogames,项目名称:lazy-crab,代码行数:98,代码来源:main.cpp


注:本文中的EntityManager::updateRender方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。