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


C++ Tower::getId方法代码示例

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


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

示例1: main

int main() {
    srand(time(0));
    map<sf::Keyboard::Key, bool> keys;
    bool running = true;
    sf::RenderWindow window;
    Vec2i mouse;

    initializeGame();
    if(Game::map.size()==0)
        Game::map.push_back(vector<Game::TileType>(1, Game::TileType::EmptyTile));


    sf::IntRect towersPanel(sf::Vector2i(Game::map.size()*Game::pixelsPerSquare,100),
                            Game::towerManager->getDrawRectSize()),
                                 upgradesPanel(0,Game::map[0].size()*Game::pixelsPerSquare,
                                         towersPanel.left+towersPanel.width,200);


    window.create(sf::VideoMode(upgradesPanel.left+upgradesPanel.width,
                                upgradesPanel.top+upgradesPanel.height), "Tower Defense", sf::Style::Titlebar|sf::Style::Close);
    window.setFramerateLimit(60);


    glViewport(0, 0, window.getSize().x, window.getSize().y);
    glOrtho(0,window.getSize().x, window.getSize().y,0, 0,1);

    glEnable (GL_BLEND);
    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    bool paused = false;

    Tooltip* tooltip = nullptr;
    TowerType* placingTower = nullptr;

    while(running && window.isOpen()) {
        sf::Event ev;
        while(window.pollEvent(ev)) {
            switch(ev.type) {
            case sf::Event::Closed:
                running = false;
                break;
            case sf::Event::MouseMoved:
                mouse.x = ev.mouseMove.x;
                mouse.y = ev.mouseMove.y;
                break;
            case sf::Event::KeyPressed:
                keys[ev.key.code] = true;
                if(ev.key.code == sf::Keyboard::Space) {
                    paused = !paused;
                } else if(ev.key.code == sf::Keyboard::Return) {
                    Game::clearEnemies();
                    Game::clearEntities();
                    Game::clearTowers();
                    Game::life = 20;
                    Game::money = 1500;
                    Game::tickCount = 0;
                }
                break;
            case sf::Event::KeyReleased:
                keys[ev.key.code] = false;
                break;
            case sf::Event::MouseButtonPressed:
                SetFocus(window.getSystemHandle());
                if(ev.mouseButton.button == sf::Mouse::Left) {
                    Vec2i p = Vec2i(mouse.x,mouse.y)/Game::pixelsPerSquare;
                    if(Game::map.size()>p.x && p.x>=0
                            && Game::map[p.x].size()>p.y && p.y>=0) {
                        bool mustDeselect = true;
                        if(Game::map[p.x][p.y] == Game::TileType::EmptyTile) {
                            if(placingTower != nullptr && Game::money >= placingTower->cost) {
                                Game::money -= placingTower->cost;
                                Tower* t = placingTower->model->clone();
                                t->setPosition(p);
                                if(!Game::putTower(t))
                                    delete t;
                                else
                                    mustDeselect = false;
                            }
                        } else if(Game::map[p.x][p.y] == Game::TileType::TowerTile) {
                            Game::selectedTower = Game::getTower(Vec2i(mouse.x,mouse.y)/Game::pixelsPerSquare);
                            mustDeselect = false;
                        }
                        if(mustDeselect)
                            Game::selectedTower = nullptr;
                    }
                    placingTower = nullptr;
                } else if(ev.mouseButton.button == sf::Mouse::Right) {
                    Vec2i p = Vec2i(mouse.x,mouse.y)/Game::pixelsPerSquare;
                    if(Game::map[p.x][p.y] == Game::TileType::TowerTile) {
                        Tower* t = Game::removeTower(p);
                        if(t==nullptr) {
                            cout << "ERROR DELETING TOWER" << endl;
                        } else {
                            Game::money += Game::towerManager->getTowerCost(t->getId());
                            delete t;
                        }
                    }
                }
                break;
            default:
//.........这里部分代码省略.........
开发者ID:ivancea,项目名称:TowerDefense,代码行数:101,代码来源:main.cpp


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