Exemplo n.º 1
0
 public bool CollidedWithIce()
 {
     if (details != null){
         details = null;
         return true;
     }
     return false;
 }
Exemplo n.º 2
0
        private void UpdatePlayer(float elapsedTimeSeconds)
        {
            Vector2 previousPosition = player.GetPosition();

            player.Update(elapsedTimeSeconds);

            Vector2 newPosition = player.GetPosition();

            Vector2 speed = player.GetSpeed();

            if (didCollide(newPosition))
            {
                details = GetCollisionDetails(previousPosition, newPosition, speed);

                player.SetNewPosition(details.positionAfterCollision);
            }
        }
Exemplo n.º 3
0
        private CollisionDetails GetCollisionDetails(Vector2 previousPosition, Vector2 newPosition, Vector2 speed)
        {
            CollisionDetails ret = new CollisionDetails(speed, previousPosition);

            Vector2 xPosition = new Vector2(newPosition.X, previousPosition.Y);
            Vector2 yPosition = new Vector2(previousPosition.X, newPosition.Y);

            if (didCollide(xPosition) == false)
            {
                return MoveRightOrLeft(speed, ret);
            }
            else if (didCollide(yPosition) == false)
            {
                return MoveUpOrDown(speed, ret, yPosition);
            }
            else
            {
                return Stop(ret, speed);
            }
        }
Exemplo n.º 4
0
        private static CollisionDetails Stop(CollisionDetails ret, Vector2 speed)
        {
            ret.speedAfterCollision = new Vector2(0, 0);

            return ret;
        }
Exemplo n.º 5
0
        private static CollisionDetails MoveUpOrDown(Vector2 speed, CollisionDetails ret, Vector2 yPosition)
        {
            ret.positionAfterCollision = yPosition;

            return ret;
        }
Exemplo n.º 6
0
        private static CollisionDetails MoveRightOrLeft(Vector2 speed, CollisionDetails ret)
        {
            ret.speedAfterCollision = SetSpeedX(speed);

            return ret;
        }