本文整理汇总了C++中TerrainTile::getTerrainType方法的典型用法代码示例。如果您正苦于以下问题:C++ TerrainTile::getTerrainType方法的具体用法?C++ TerrainTile::getTerrainType怎么用?C++ TerrainTile::getTerrainType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TerrainTile
的用法示例。
在下文中一共展示了TerrainTile::getTerrainType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: turnlyUpdate
void World::turnlyUpdate(){
boost::random::uniform_int_distribution<int> dist(1, 100);
incrementElapsedTurns();
getCurrentTime().increment();
//The weather will tend to change every ~8 hours, or 480 minutes.
//Ideally, something like this:
//1 hour (60) -> 4%
//2 hours (120) -> 6%
//3 hours (180) -> 8%
//4 hours (240) -> 12.5%
//5 hours (300) -> 16%
//6 hours (360) -> 24%
//7 hours (420) -> 30%
//8 hours (480) -> 40%
for(auto& effect : weatherEffects){
effect.second += minutesPerTurn;
}
auto effect = std::begin(weatherEffects);
while(effect != std::end(weatherEffects)){
int removeEffect{dist(masterManager.randomEngine)};
//For instance, if the effect has been there for 240 minutes, it will have an
//40% chance of being removed. There is a hard cap of 80%.
int totalChance = effect->second / 15;
if(totalChance > 50){
totalChance = 50;
}
if(removeEffect <= totalChance){
effect = weatherEffects.erase(effect);
}
else{
effect++;
}
}
int hourlyChance = 20;
int turnlyChance = hourlyChance / (60/minutesPerTurn);
int randomRoll{dist(masterManager.randomEngine)};
if (randomRoll <= turnlyChance){
addWeather();
}
////////////////////////////////////////////////////////////////////////////////
//////////////////MUD CREATION AND REMOVAL//////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//Firstly, depending on whether the rain is heavy or light, there will be a varying
//amount of mud formations per turn.
bool rain{false};
int minimumMudFormations{0};
for(auto& effect : weatherEffects){
if(effect.first == World::Weather::HEAVY_RAIN){
rain = true;
minimumMudFormations = 4;
break;
}
else if(effect.first == World::Weather::LIGHT_RAIN){
rain = true;
minimumMudFormations = 2;
break;
}
}
//A random tile on the map that we call the origin is converted to mud (if possible).
if(rain){
for (int i{0}; i < minimumMudFormations; ++i){
boost::random::uniform_int_distribution<int> randomIndexDist(0, getDimensions().x * getDimensions().y);
int randomIndex{randomIndexDist(masterManager.randomEngine)};
sf::Vector2i originPosition{cartesianPosAtIndex(randomIndex)};
TerrainTile* origin = terrainAtCartesianPos(originPosition);
bool originConvertedToMud{false};
if(origin->getTerrainType() == TerrainTile::TerrainType::MEADOW){
toggleMud(origin);
originConvertedToMud = true;
}
if(!originConvertedToMud){
break;
//.........这里部分代码省略.........
示例2: getInput
void GameState_Setup::getInput(){
sf::Event event;
while (game->mWindow.pollEvent(event)){
switch (event.type){
case sf::Event::MouseMoved:
game->mousePos.x = event.mouseMove.x;
game->mousePos.y = event.mouseMove.y;
break;
case sf::Event::Resized:
handleResize();
break;
case sf::Event::MouseButtonPressed:
if (event.mouseButton.button == sf::Mouse::Middle){
middleButtonHeld = true;
middleButtonCoords = {event.mouseButton.x, event.mouseButton.y};
}
else if (event.mouseButton.button == sf::Mouse::Left && drawUI){
//If no menu item was selectedSpawnableUnit, select it
if (selectedSpawnableUnit == nullptr){
sf::Vector2f worldCoords{game->mWindow.mapPixelToCoords(game->mousePos, *game->currentView)};
sf::Vector2f uiCoords{game->mWindow.mapPixelToCoords(game->mousePos, setupUI.uiView)};
std::vector<SpawnableUnit> current{game->currentPlayer->getSpawnableUnits()};
for (size_t i{0}; i < current.size(); ++i){
if (uiCoords.x > current[i].left() && uiCoords.x < current[i].right()
&&
uiCoords.y > current[i].top() && uiCoords.y < current[i].bottom()){
selectedSpawnableUnit = std::move(std::unique_ptr<SpawnableUnit>(new SpawnableUnit(current[i])));
break;
}
}
if (uiCoords.x >= setupUI.getButton().left() && uiCoords.x <= setupUI.getButton().right()
&&
uiCoords.y >= setupUI.getButton().top() && uiCoords.y <= setupUI.getButton().bottom()){
//As long as the player has at least one non-general unit
if (game->currentPlayer->getDeploymentPoints() <= game->currentPlayer->getMaxDeploymentPoints() - 1){
game->currentPlayer->setReady(true);
}
}
if(selectedSpawnableUnit == nullptr){
middleButtonHeld = true;
middleButtonCoords = {event.mouseButton.x, event.mouseButton.y};
}
}
//Spawn a unit on the tile:
else{
sf::Vector2i mouseCoords{event.mouseButton.x, event.mouseButton.y};
sf::Vector2i worldCoords{game->mWindow.mapPixelToCoords(mouseCoords, *game->currentView)};
TerrainTile* terrain = game->mWorld->terrainAtPixelPos(worldCoords);
if (terrain != nullptr){
if(terrain->getTerrainType() != TerrainTile::TerrainType::WATER){
game->currentPlayer->spawnUnit(selectedSpawnableUnit->unitID, worldCoords);
}
}
selectedSpawnableUnit = nullptr;
break;
}
}
else if (event.mouseButton.button == sf::Mouse::Right && drawUI){
//Deselect the currently selectedSpawnableUnit icon:
if (selectedSpawnableUnit != nullptr){
selectedSpawnableUnit = nullptr;
break;
}
//Delete a unit from a tile:
else{
sf::Vector2i mouseCoords{event.mouseButton.x, event.mouseButton.y};
sf::Vector2i worldCoords{game->mWindow.mapPixelToCoords(mouseCoords, *game->currentView)};
auto removed = game->currentPlayer->removeUnit(worldCoords);
//.........这里部分代码省略.........