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


C++ WorldObject::GetSpriteInstance方法代码示例

本文整理汇总了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);
					}
				}
			}
		}
	}
}
开发者ID:sgraham,项目名称:twinisles,代码行数:26,代码来源:sim.cpp

示例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);
							}
						}
					}
				}
			}
		}
	}
}
开发者ID:sgraham,项目名称:twinisles,代码行数:48,代码来源:sim.cpp


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