本文整理汇总了C#中IPlayer.GetPosition方法的典型用法代码示例。如果您正苦于以下问题:C# IPlayer.GetPosition方法的具体用法?C# IPlayer.GetPosition怎么用?C# IPlayer.GetPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPlayer
的用法示例。
在下文中一共展示了IPlayer.GetPosition方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandleCollision
public void HandleCollision(IPlayer player)
{
int playerRadius = (player.GetPosition().Width) / 2;
// the center of the player's bounding circle
int x1 = player.GetPosition().X + (player.GetPosition().Width/2);
int y1 = player.GetPosition().Y + (player.GetPosition().Height/2);
// the center of the torch's bounding circle for the nimbus
int x2 = positionNimbus.X + (positionNimbus.Width/2);
int y2 = positionNimbus.Y + (positionNimbus.Height/2);
int dx = x1 - x2;
int dy = y1 - y2;
int distance = (int)Math.Sqrt((dx*dx) + (dy*dy));
if (distance < playerRadius + nimbusRadius && player.HiddenPercent > 0)
{
// if the player is hitting a torch his hidden percent drops
player.HiddenPercent -= 0.49f;
}
}
示例2: HandleVision
//if he sees the player, the player should die.
public void HandleVision(IPlayer player, IList<ITile> surroundingTiles)
{
//grab the position of the eyes(relative to guard) and make them relative to the map)
Vector2 mapEyePos = new Vector2(this.position.X + eyePos.X, this.position.Y + eyePos.Y);
//distance between the x and y position of the guards eyes and the middle of the player
float dX = mapEyePos.X - (player.GetPosition().X + (player.GetPosition().Width / 2));
float dY = mapEyePos.Y - (player.GetPosition().Y + (player.GetPosition().Height / 2));
float distance = (float)Math.Sqrt(Math.Pow(dX, 2) + Math.Pow(dY, 2));
float visibility = distance - ((1 - player.HiddenPercent) * LOSRadius);
// if the player is behind the guard we don't care
if ((facingDirection == Direction.left && player.GetPosition().Left <= mapEyePos.X) || (facingDirection == Direction.right && player.GetPosition().Right >= mapEyePos.X))
{
// is the player visible enough/close enough for the guard to be able to see
if (visibility <= 0 && isVisible(player.GetPosition(), surroundingTiles))
{
player.Kill();
}
}
}