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


C++ NodeManager::getNodes方法代码示例

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


在下文中一共展示了NodeManager::getNodes方法的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++) {
//.........这里部分代码省略.........
开发者ID:macromate,项目名称:Ants,代码行数:101,代码来源:main.cpp


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