本文整理汇总了C++中NodeManager::addNode方法的典型用法代码示例。如果您正苦于以下问题:C++ NodeManager::addNode方法的具体用法?C++ NodeManager::addNode怎么用?C++ NodeManager::addNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NodeManager
的用法示例。
在下文中一共展示了NodeManager::addNode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main (int argc, char * const argv[]) {
GameObjectManager* objectManager = GameObjectManager::getInstance();
NodeManager *nodeManager = NodeManager::getInstance();
{
Node *node;
for (int y = 0; y <= 14; y++) {
for (int x = 0; x <= 19; x++) {
node = new Node(x * 32, y * 32);
nodeManager->addNode(node);
}
}
}
Hill* hill1 = new Hill(StrainYellow, nodeManager->getEmptyRandomNode());
Hill* hill2 = new Hill(StrainRed, nodeManager->getEmptyRandomNode());
Hill* hill3 = new Hill(StrainBlue, nodeManager->getEmptyRandomNode());
objectManager->add(hill1);
objectManager->add(hill2);
objectManager->add(hill3);
Ants ants;
Strain antStrains[4] = { StrainYellow, StrainRed, StrainBlue, StrainRed };
for (int i = 0; i < 4; i++) {
Ant* ant = new Ant(antStrains[i], nodeManager->getEmptyRandomNode());
objectManager->add(ant);
ants.push_back(ant);
}
for (int i = 0; i < 10; i++) {
Spice *spice = new Spice(nodeManager->getEmptyRandomNode());
objectManager->addSpice(spice);
}
sf::RenderWindow App(sf::VideoMode(640, 480), "Ants");
App.SetFramerateLimit(60);
while (App.IsOpened())
{
sf::Event Event;
while (App.GetEvent(Event))
{
if (Event.Type == sf::Event::Closed)
App.Close();
if (Event.Type == sf::Event::MouseButtonPressed) {
const sf::Input& Input = App.GetInput();
cout << "Mouse cursor position: " << Input.GetMouseX()
<< "/" << Input.GetMouseY() << endl;
sf::Vector2f mouse(Input.GetMouseX(), Input.GetMouseY());
bool shiftDown = Input.IsKeyDown(sf::Key::LShift) ||
Input.IsKeyDown(sf::Key::RShift);
// cycle all gameobjects
// if position matches mouse input -> select
// if nothing matches -> deselect all
GameObjects allObjects = objectManager->getObjects();
GameObjects::iterator i = allObjects.begin();
for (; i < allObjects.end(); i++) {
GameObject* object = *i;
sf::Vector2f left_upper = object->getSprite()->GetPosition();
sf::Vector2f right_lower = left_upper;
// TODO: clean up with new vector2f class
left_upper.x -= 16;
left_upper.y -= 16;
right_lower.x += PIXELS_PER_NODE/2;
right_lower.y += PIXELS_PER_NODE/2;
if (left_upper.x <= mouse.x && right_lower.x >= mouse.x &&
left_upper.y <= mouse.y && right_lower.y >= mouse.y) {
object->setSelectionStatus(true);
} else if (!shiftDown) {
object->setSelectionStatus(false);
}
}
}
}
App.Clear();
// trigger updates
objectManager->trigger();
//display nodes
Nodes nodes = nodeManager->getNodes();
Nodes::iterator n = nodes.begin();
for (; n < nodes.end(); n++) {
App.Draw(*(*n)->getSprite());
}
// update ants
Ants::iterator a = ants.begin();
for(; a < ants.end(); a++) {
(*a)->handleCurrentAction(App.GetFrameTime());
}
// display game objects
GameObjects objects = objectManager->getObjects();
GameObjects::iterator i = objects.begin();
for (; i < objects.end(); i++) {
//.........这里部分代码省略.........