本文整理汇总了C++中TilePtr::isEmpty方法的典型用法代码示例。如果您正苦于以下问题:C++ TilePtr::isEmpty方法的具体用法?C++ TilePtr::isEmpty怎么用?C++ TilePtr::isEmpty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TilePtr
的用法示例。
在下文中一共展示了TilePtr::isEmpty方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: updateWalkingTile
void Creature::updateWalkingTile()
{
// determine new walking tile
TilePtr newWalkingTile;
Rect virtualCreatureRect(Otc::TILE_PIXELS + (m_walkOffset.x - getDisplacementX()),
Otc::TILE_PIXELS + (m_walkOffset.y - getDisplacementY()),
Otc::TILE_PIXELS, Otc::TILE_PIXELS);
for(int xi = -1; xi <= 1 && !newWalkingTile; ++xi) {
for(int yi = -1; yi <= 1 && !newWalkingTile; ++yi) {
Rect virtualTileRect((xi+1)*Otc::TILE_PIXELS, (yi+1)*Otc::TILE_PIXELS, Otc::TILE_PIXELS, Otc::TILE_PIXELS);
// only render creatures where bottom right is inside tile rect
if(virtualTileRect.contains(virtualCreatureRect.bottomRight())) {
newWalkingTile = g_map.getOrCreateTile(m_position.translated(xi, yi, 0));
}
}
}
if(newWalkingTile != m_walkingTile) {
if(m_walkingTile)
m_walkingTile->removeWalkingCreature(static_self_cast<Creature>());
if(newWalkingTile) {
newWalkingTile->addWalkingCreature(static_self_cast<Creature>());
// recache visible tiles in map views
if(newWalkingTile->isEmpty())
g_map.notificateTileUpdate(newWalkingTile->getPosition());
}
m_walkingTile = newWalkingTile;
}
}
示例2: walk
bool Game::walk(Otc::Direction direction, bool dash)
{
if(!canPerformGameAction())
return false;
// must cancel follow before any new walk
if(isFollowing())
cancelFollow();
// must cancel auto walking, and wait next try
if(m_localPlayer->isAutoWalking() || m_localPlayer->isServerWalking()) {
m_protocolGame->sendStop();
if(m_localPlayer->isAutoWalking())
m_localPlayer->stopAutoWalk();
return false;
}
if(dash) {
if(m_localPlayer->isWalking() && m_dashTimer.ticksElapsed() < std::max<int>(m_localPlayer->getStepDuration(false, direction) - m_ping, 30))
return false;
}
else {
// check we can walk and add new walk event if false
if(!m_localPlayer->canWalk(direction)) {
if(m_lastWalkDir != direction) {
// must add a new walk event
float ticks = m_localPlayer->getStepTicksLeft();
if(ticks <= 0) { ticks = 1; }
if(m_walkEvent) {
m_walkEvent->cancel();
m_walkEvent = nullptr;
}
m_walkEvent = g_dispatcher.scheduleEvent([=] { walk(direction, false); }, ticks);
}
return false;
}
}
Position toPos = m_localPlayer->getPosition().translatedToDirection(direction);
TilePtr toTile = g_map.getTile(toPos);
// only do prewalks to walkable tiles (like grounds and not walls)
if(toTile && toTile->isWalkable()) {
m_localPlayer->preWalk(direction);
// check walk to another floor (e.g: when above 3 parcels)
} else {
// check if can walk to a lower floor
auto canChangeFloorDown = [&]() -> bool {
Position pos = toPos;
if(!pos.down())
return false;
TilePtr toTile = g_map.getTile(pos);
if(toTile && toTile->hasElevation(3))
return true;
return false;
};
// check if can walk to a higher floor
auto canChangeFloorUp = [&]() -> bool {
TilePtr fromTile = m_localPlayer->getTile();
if(!fromTile || !fromTile->hasElevation(3))
return false;
Position pos = toPos;
if(!pos.up())
return false;
TilePtr toTile = g_map.getTile(pos);
if(!toTile || !toTile->isWalkable())
return false;
return true;
};
if(canChangeFloorDown() || canChangeFloorUp() ||
(!toTile || toTile->isEmpty())) {
m_localPlayer->lockWalk();
} else
return false;
}
m_localPlayer->stopAutoWalk();
g_lua.callGlobalField("g_game", "onWalk", direction, dash);
forceWalk(direction);
if(dash)
m_dashTimer.restart();
m_lastWalkDir = direction;
return true;
}
示例3: dashWalk
bool Game::dashWalk(Otc::Direction direction)
{
if(!canPerformGameAction())
return false;
// must cancel follow before any new walk
if(isFollowing())
cancelFollow();
// must cancel auto walking
if(m_localPlayer->isAutoWalking()) {
m_protocolGame->sendStop();
m_localPlayer->stopAutoWalk();
}
if(m_localPlayer->isWalking() && m_dashTimer.ticksElapsed() < std::max<int>(m_localPlayer->getStepDuration(false, direction) - m_ping, 30))
return false;
Position toPos = m_localPlayer->getPosition().translatedToDirection(direction);
TilePtr toTile = g_map.getTile(toPos);
// only do prewalks to walkable tiles (like grounds and not walls)
if(toTile && toTile->isWalkable()) {
if(!m_localPlayer->isWalking() && m_localPlayer->getWalkTicksElapsed() >= m_localPlayer->getStepDuration() + 100)
m_localPlayer->preWalk(direction);
// check walk to another floor (e.g: when above 3 parcels)
} else {
// check if can walk to a lower floor
auto canChangeFloorDown = [&]() -> bool {
Position pos = toPos;
if(!pos.down())
return false;
TilePtr toTile = g_map.getTile(pos);
if(toTile && toTile->hasElevation(3))
return true;
return false;
};
// check if can walk to a higher floor
auto canChangeFloorUp = [&]() -> bool {
TilePtr fromTile = m_localPlayer->getTile();
if(!fromTile || !fromTile->hasElevation(3))
return false;
Position pos = toPos;
if(!pos.up())
return false;
TilePtr toTile = g_map.getTile(pos);
if(!toTile || !toTile->isWalkable())
return false;
return true;
};
if(canChangeFloorDown() || canChangeFloorUp() ||
(!toTile || toTile->isEmpty())) {
m_localPlayer->lockWalk();
} else
return false;
}
forceWalk(direction);
m_dashTimer.restart();
m_lastWalkDir = direction;
return true;
}