本文整理汇总了C#中Microsoft.Xna.Framework.Rectangle.TouchRight方法的典型用法代码示例。如果您正苦于以下问题:C# Rectangle.TouchRight方法的具体用法?C# Rectangle.TouchRight怎么用?C# Rectangle.TouchRight使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Xna.Framework.Rectangle
的用法示例。
在下文中一共展示了Rectangle.TouchRight方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Collision
public void Collision(Rectangle newRectangle, int xOffset, int yOffset, Camera camera)
{
Vector2 position = camera.getVisualCoords(player.getPosition());
Rectangle rectangle = new Rectangle((int)position.X, (int)position.Y, 32, 32);
if (rectangle.TouchTop(newRectangle))
{
position.Y = newRectangle.Y - rectangle.Height;
player.TouchingFloor = true;
player.CanJump = true;
player.CanJumpAgain = true;
}
if (rectangle.TouchLeft(newRectangle))
{
position.X = newRectangle.X - rectangle.Width;
player.speed.X = -0.05f;
}
if (rectangle.TouchRight(newRectangle))
{
position.X = newRectangle.X + newRectangle.Width;
player.speed.X = 0.05f;
}
if (rectangle.TouchBottom(newRectangle))
{
player.speed.Y = 0.5f;
}
if (position.X < 0)
{
position.X = 0 + rectangle.Width;
player.speed.X = 0.05f;
}
if (position.X > xOffset - rectangle.Width)
{
position.X = xOffset - rectangle.Width;
player.speed.X = -0.05f;
}
// If player falls, set IsAlive to false. Use this later to fix game over etc.
if (position.Y > yOffset - rectangle.Height)
{
player.IsAlive = false;
position.Y = yOffset - rectangle.Height;
Console.WriteLine("Player alive: " + player.IsAlive);
}
// If player leaves top of a rectangle.
if(position.X > newRectangle.X + newRectangle.Width)
{
player.TouchingFloor = false;
player.CanJump = false;
}
}