本文整理汇总了C#中Collision.IsRight方法的典型用法代码示例。如果您正苦于以下问题:C# Collision.IsRight方法的具体用法?C# Collision.IsRight怎么用?C# Collision.IsRight使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Collision
的用法示例。
在下文中一共展示了Collision.IsRight方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnCollision
public virtual void OnCollision(Collision collision)
{
if (!collision.SecondObject.Collidable || !Parent.Collidable || !Parent.CanCollideWith(collision.SecondObject))
return;
VectorRectangle bounds = Parent.Bounds;
VectorRectangle lastFrame = Parent.LastFrameBounds;
Vector2 size = bounds.Size;
float vX, vY, aX, aY;
vX = vY = aX = aY = 1;
if (
(collision.IsBottom() || collision.IsTop())
&& !collision.IsLeft()
&& !collision.IsRight()
)
{
vY = -collision.SecondObject.Elasticity;
float newY;
if (collision.IsBottom())
{
newY = collision.SecondObject.Position.Y - size.Y;
}
else
{
newY = collision.SecondObject.Position.Y + collision.SecondObject.Size.Y;
}
Parent.Position = new Vector2(Parent.Position.X, newY);
}
if (
(collision.IsLeft() || collision.IsRight())
&& !collision.IsTop()
&& !collision.IsBottom()
)
{
vX = 0;
float newX;
if (collision.IsLeft())
{
newX = collision.SecondObject.Position.X + collision.SecondObject.Size.X;
}
else
{
newX = collision.SecondObject.Position.X - size.X;
}
Parent.Position = new Vector2(newX, Parent.Position.Y);
}
if (collision.TouchingSidesCount == 2)
{
float width = collision.Intersect.Width, height = collision.Intersect.Height;
if (lastFrame.IntersectsVertical(collision.SecondObject.Bounds) && !lastFrame.IntersectsHorizontal(collision.SecondObject.Bounds)) // TODO also previous frame
{
height = 0;
vX = 0;
collision.OnStopColliding(Collision.Side.Top);
collision.OnStopColliding(Collision.Side.Bottom);
Console.WriteLine("Stopping horizontal");
}
else if (lastFrame.IntersectsHorizontal(collision.SecondObject.Bounds))
{
width = 0;
vY = 0;
collision.OnStopColliding(Collision.Side.Left);
collision.OnStopColliding(Collision.Side.Right);
Console.WriteLine("Stopping vertical");
}
else
{
Parent.OnDecollision(collision.SecondObject);
}
if (collision.IsRight())
width *= -1;
if (collision.IsBottom())
height *= -1;
Parent.Position += new Vector2(width, height);
}
Parent.Velocity *= new Vector2(vX, vY);
Parent.Acceleration *= new Vector2(aX, aY);
//TODO: Make _parent.Velocity.Y equal to Zero when value drops below sertain value to decrease hovering
//above the platform he is standing on.
if (Parent.Velocity.Y < 0 && Parent.Velocity.Y > -6)
Parent.Velocity = new Vector2(Parent.Velocity.X, 0);
//END OF TODO
//Console.WriteLine("Collision");
}