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


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

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


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

示例1: initializeGame

void initializeGame() {
    vector< vector<bool> > tileMap;
    int n = MapManager::load(tileMap, Game::pixelsPerSquare, Game::enemiesRoute, "map.tdm");

    /// Always after initialize Game::pixelsPerSquare
    Game::towerManager = new BasicTowerManager();

    if(n==0) {
        Game::map.resize(tileMap.size(), vector<Game::TileType>(tileMap[0].size(), Game::TileType::EmptyTile));
        for(int i=0; i<tileMap.size(); i++)
            for(int j=0; j<tileMap[i].size(); j++)
                if(!tileMap[i][j])
                    Game::map[i][j] = Game::TileType::RoadTile;
    } else {
        cout << "Error loading map \"map.tdm\". Error: " << n << endl;
        cout << "Loading default map." << endl;

        Game::pixelsPerSquare = 50;
        Game::enemiesRoute.push_back(Vec2i(0,25));
        Game::enemiesRoute.push_back(Vec2i(475,25));
        Game::enemiesRoute.push_back(Vec2i(475,500));
        for(int i=0; i<10; i++)
            Game::map.push_back(vector<Game::TileType>(10, Game::TileType::EmptyTile));
        for(int i=0; i<10; i++) {
            Game::map[i][0] = Game::TileType::RoadTile;
            Game::map[9][i] = Game::TileType::RoadTile;
        }

        Tower* t = new SniperTower();
        t->setPosition(Vec2i(3,3));
        t->setPriority(Near);
        if(!Game::putTower(t))
            delete t;
        t = new SniperTower();
        t->setPosition(Vec2i(4,5));
        t->setPriority(Last);
        if(!Game::putTower(t))
            delete t;
        t = new SniperTower();
        t->setPosition(Vec2i(5,4));
        if(!Game::putTower(t))
            delete t;
    }

    Game::life = 20;
    Game::money = 1500;
    Game::tickCount = 0;
}
开发者ID:ivancea,项目名称:TowerDefense,代码行数:48,代码来源:main.cpp

示例2: initializeGameField

void Model::initializeGameField() {
	Base* base = new Base();
	_leftArmy->addUnit(base);
	base->setPosition(BW_Point(base->getPositionBW().x + base->getContentSize().getWidth() * 2, _fieldHeigth / 2));

	base = new Base();
	_rightArmy->addUnit(base);
	base->setPosition(BW_Point(base->getPositionBW().x - base->getContentSize().getWidth() * 2, _fieldHeigth / 2));
	base->setLookingTo(LEFT);

	float towerLeftX = _fieldWidth / 4; // 25%
	float towerRigthX = _fieldWidth - towerLeftX; // 75%

	Tower* tower = new Tower();
	_leftArmy->addUnit(tower);
	tower->setPosition(BW_Point(towerLeftX, _fieldHeigth / 2));

	tower = new Tower();
	_rightArmy->addUnit(tower);
	tower->setPosition(BW_Point(towerRigthX, _fieldHeigth / 2));
	tower->setLookingTo(LEFT);
    
    createMoveableUnit();
}
开发者ID:LiamJamesPku,项目名称:BaseWar,代码行数:24,代码来源:Model.cpp

示例3: addTower

void StartScene::addTower(Point pos, Tower::TowerType towerType)
{
    DataModel *m = DataModel::getModel();
    Tower *target = NULL ;
    Point towerLoc = this->tileCoordForPosition(pos);
    int tileGid = this->_background->tileGIDAt(towerLoc);
    Value props = this->_tileMap->propertiesForGID(tileGid);
    ValueMap map = props.asValueMap();
    int type_int = map.at("buildable").asInt();
    target = Tower::createWithType(towerType);
    if (target->price>m->currentMoney) {
        MessageBox("no enough money!","");
        return;
    }
    if (1 == type_int)
    {
//        std::string targetPos = "pos.x = "+std::to_string(towerLoc.x)+" pos.y = "+std::to_string(towerLoc.y);
//        log(targetPos.c_str());
        bool buildable = true;
        for (auto point = m->buildedPoints.equal_range(towerLoc.x); point.first!=point.second; ++point.first) {
            if (towerLoc.y==point.first->second) {
                buildable = false;
                break;
            }
        }
        if (buildable) {
            m->buildedPoints.insert(std::make_pair(towerLoc.x, towerLoc.y));
            target->setPosition(ccp((towerLoc.x * 32) + 16, this->_tileMap->getContentSize().height - (towerLoc.y * 32) - 16));
            this->addChild(target,1);
            target->setTag(1);
            m->currentMoney -= target->price;
            money->setText(to_string(m->currentMoney));
            m->towers.pushBack(target);
        }
    }
    else
    {
        log("Tile Not Buildable");
    }
}
开发者ID:hustjf,项目名称:ProtectTank,代码行数:40,代码来源:StartScene.cpp

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