本文整理汇总了C++中EntityManager::getEntity方法的典型用法代码示例。如果您正苦于以下问题:C++ EntityManager::getEntity方法的具体用法?C++ EntityManager::getEntity怎么用?C++ EntityManager::getEntity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EntityManager
的用法示例。
在下文中一共展示了EntityManager::getEntity方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: updateFleeAI
void updateFleeAI(double dt, Entity<EntityManagerTypes...> &entity) {
auto &transform = entity.template getComponent<TransformComponent>();
auto &aiComponent = entity.template getComponent<EnemyAIComponent>();
auto &playerEntity = entityManagerRef->getEntity(aiComponent.playerId);
auto &playerTransform = playerEntity.template getComponent<TransformComponent>();
}
示例2: 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;
}
示例3: 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;
}
示例4: GIVEN
using namespace tetra;
using namespace tetra::meta;
using namespace tetra::framework;
SCENARIO( "Using an EntityManager to manage a set of entities",
"[EntityManager]" )
{
GIVEN( "An empty EntityManager" )
{
EntityManager entityManager{};
THEN( "We should be able to create a new Entity" )
{
auto id = entityManager.createEntity();
Entity& entity = entityManager.getEntity( id );
}
THEN( "Attempting to access an entity which does not exist "
"should throw an EntityDoesNotExistException" )
{
REQUIRE_THROWS_AS( entityManager.getEntity( 5 ),
EntityDoesNotExistException );
}
THEN( "We should be able to get a list of all existing entities "
"and access them" )
{
auto id1 = entityManager.createEntity();
auto id2 = entityManager.createEntity();
auto entityList = entityManager.getAllEntities();