本文整理汇总了C#中ICollidable.getVelocity方法的典型用法代码示例。如果您正苦于以下问题:C# ICollidable.getVelocity方法的具体用法?C# ICollidable.getVelocity怎么用?C# ICollidable.getVelocity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICollidable
的用法示例。
在下文中一共展示了ICollidable.getVelocity方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: collisionOccured
public bool collisionOccured(ICollidable collideObject)
{
bool collisionOccured = false;
bool isObjectPlayer = collideObject is Player;
Vector3 playerPosition = Vector3.Zero;
bool[] deactivateKeys = new bool[4];
Player player = null;
if (isObjectPlayer) {
player = (Player)collideObject;
playerPosition = player.getPositionVector();
for (int i = 0; i < 4; i++)
deactivateKeys[i] = false;
}
List<BoundingSphere> bs = collideObject.getBoundingSpheres();
foreach (BoundingSphere sphere in bs) {
if (!collisionOccured) {
if (_leftBox.Intersects(sphere)) {
Vector2 bounceVelocity = collideObject.getVelocity();
if(bounceVelocity.X > 0)
bounceVelocity.X *= -1;
collideObject.bounce(bounceVelocity);
if (isObjectPlayer)
deactivateKeys[(int)KeyboardKey.LEFT] = true;
collisionOccured = true;
}
if (_rightBox.Intersects(sphere)) {
Vector2 bounceVelocity = collideObject.getVelocity();
if(bounceVelocity.X < 0)
bounceVelocity.X *= -1;
collideObject.bounce(bounceVelocity);
if (isObjectPlayer)
deactivateKeys[(int)KeyboardKey.RIGHT] = true;
collisionOccured = true;
}
if (_backBox.Intersects(sphere)) {
Vector2 bounceVelocity = collideObject.getVelocity();
if(bounceVelocity.Y < 0)
bounceVelocity.Y *= -1;
collideObject.bounce(bounceVelocity);
if (isObjectPlayer)
deactivateKeys[(int)KeyboardKey.UP] = true;
collisionOccured = true;
}
if (_frontBox.Intersects(sphere)) {
Vector2 bounceVelocity = collideObject.getVelocity();
if(bounceVelocity.Y > 0)
bounceVelocity.Y *= -1;
collideObject.bounce(bounceVelocity);
if (isObjectPlayer)
deactivateKeys[(int)KeyboardKey.DOWN] = true;
collisionOccured = true;
}
if (isObjectPlayer)
player.deactivateKeys(deactivateKeys);
}
}
return collisionOccured;
}