Exemplo n.º 1
0
        public void MoveTo(Vector2f vector, float time)
        {
            if (racket.GetCanMove())
            {
                float distance = MathExt.VectorLength(vector, racket.GetCenter());

                Vector2f directionTemp = new Vector2f(speed * time * (vector.X - racket.GetCenter().X) / distance,
                                                      speed * time * (vector.Y - racket.GetCenter().Y) / distance);
                racket.gameObject.Position += directionTemp;
            }
        }
Exemplo n.º 2
0
        public void Move(Vector2f direction, Vector2u window, float time)
        {
            if (direction != new Vector2f(0, 0) && GetCanMove())
            {
                float    directionXAbs = Math.Abs(direction.X), directionYAbs = Math.Abs(direction.Y);
                Vector2f tempVector = new Vector2f(direction.X * (window.X + window.X / 2), direction.Y * (window.Y + window.Y / 2)); // window. /2 here is to make movement not smooth when ball is close to border
                float    distance   = MathExt.VectorLength(tempVector, GetCenter());

                Vector2f directionTemp = new Vector2f(speed * time * (tempVector.X - GetCenter().X *directionXAbs) / distance,
                                                      speed * time * (tempVector.Y - GetCenter().Y *directionYAbs) / distance);
                gameObject.Position += directionTemp;
                // directionXAbs and directionYAbs in the formule makes x or y 0 if it is 0.If vector is 0,1 ,then x for moving will be 0.
            }
        }