本文整理汇总了C++中WorldObject::GetSpriteInstance方法的典型用法代码示例。如果您正苦于以下问题:C++ WorldObject::GetSpriteInstance方法的具体用法?C++ WorldObject::GetSpriteInstance怎么用?C++ WorldObject::GetSpriteInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WorldObject
的用法示例。
在下文中一共展示了WorldObject::GetSpriteInstance方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MoveShips
void Sim::MoveShips()
{
for (int i = 0; i < ARRAYSIZE(mPlayers); ++i)
{
for (int j = 0; j < mPlayers[i].NumShips(); ++j)
{
if (mPlayers[i].GetShipHasTarget(j))
{
WorldObject* ship = mPlayers[i].GetShip(j);
V2 target = mPlayers[i].GetShipTarget(j);
V2 direction = (target - ship->pos).Normalize();
V2 delta = direction * F32(.35f);
V2 mappos = ToMap(ship->pos + delta);
ship->GetSpriteInstance()->SetAnimation(MapDeltaToBoatAnimation(delta));
if (mMap.Flags(mappos) & Map::Flag_Water)
{
ship->pos += delta;
if ((ship->pos - target).LengthSq() < 2)
{
mPlayers[i].SetShipHasTarget(j, false);
}
}
}
}
}
}
示例2: MoveWarBoats
void Sim::MoveWarBoats()
{
for (int i = 0; i < ARRAYSIZE(mPlayers); ++i)
{
if (mPlayers[i].IsAtWar())
{
WorldObject* wo = mPlayers[i].GetWarBoat();
V2 target = ToWorld(WarPath[mPlayers[i].mWarBoatTargetMoveIndex]);
V2 direction = (target - wo->pos).Normalize();
V2 delta = direction * F32(.2f);
V2 mappos = ToMap(wo->pos + delta);
wo->GetSpriteInstance()->SetAnimation(MapDeltaToBoatAnimation(delta));
wo->pos += delta;
if ((wo->pos - target).LengthSq() < 2)
{
mPlayers[i].mWarBoatTargetMoveIndex += mPlayers[i].mWarBoatTargetMoveIndexDelta;
if (mPlayers[i].mWarBoatTargetMoveIndex < 0 || mPlayers[i].mWarBoatTargetMoveIndex >= ARRAYSIZE(WarPath))
{
Play(Sound_War);
wo->Hide();
// attacker_pop / (attacker_pop + defender_pop) % chance of destroying up to N buildings
// cost is that attacker's population doesn't grow while boat is travelling
// todo; perhaps some tech related thing? stealing a tech? un-researching a tech?
int other = i ^ 1;
F32 chance = F32(mPlayers[i].GetPopulation()) / F32(mPlayers[i].GetPopulation() + mPlayers[other].GetPopulation());
if (mPlayers[other].GetHaveTechnology(Tech_Metal_Work))
{
chance -= F32(.1f);
}
int numBuildings = 6;
if (mPlayers[i].GetHaveTechnology(Tech_War_Boats)) numBuildings *= 2;
for (int i = 0; i < numBuildings; ++i)
{
if (mRand.Getf() < chance)
{
V2 location;
if (FindRandomBuilding(other, location))
{
mBuildings.Destroy(location);
}
}
}
}
}
}
}
}