Beispiel #1
0
        private static void Blink()
        {
            Player player = Player.Instance();

            float heading = player.GetDirection().GetHeading();

            float currentX = player.GetX();
            float currentY = player.GetY();

            float distance = 150.0f;

            CollisionBox       bounds      = UserInterface.ScrollTransformBounds;
            OrthographicCamera camera      = JustCombat.WorldCamera;
            Vector2            worldCoords = camera.ScreenToWorld(bounds.GetPosX(), bounds.GetPosY());

            float boundWest  = worldCoords.X;
            float boundNorth = worldCoords.Y;
            float boundEast  = boundWest + bounds.GetWidth();
            float boundSouth = boundNorth + bounds.GetHeight();

            float cameraDiffX = 0;
            float cameraDiffY = 0;

            // North
            if (heading == 0)
            {
                float newY = (currentY - distance);
                float diff = (boundNorth - (newY + player.GetHeight()));

                if (diff > 0)
                {
                    cameraDiffY = -(diff);
                }

                player.Teleport(currentX, newY);
                camera.Move(new Vector2(cameraDiffX, cameraDiffY));
            }

            // East
            if (heading == 90)
            {
                float newX = (currentX + distance);
                float diff = (newX - boundEast);

                if (diff > 0)
                {
                    cameraDiffX = diff;
                }

                player.Teleport(newX, currentY);
                camera.Move(new Vector2(cameraDiffX, cameraDiffY));
            }

            // South
            if (heading == 180)
            {
                float newY = (currentY + distance);
                float diff = (newY - boundSouth);

                if (diff > 0)
                {
                    cameraDiffY = diff;
                }

                player.Teleport(currentX, newY);
                camera.Move(new Vector2(cameraDiffX, cameraDiffY));
            }

            // West
            if (heading == 270)
            {
                float newX = (currentX - distance);
                float diff = (boundWest - (newX + player.GetWidth()));

                if (diff > 0)
                {
                    cameraDiffX = -(diff);
                }

                player.Teleport(newX, currentY);
                camera.Move(new Vector2(cameraDiffX, cameraDiffY));
            }

            JustCombat.TransformMatrix = camera.GetViewMatrix();
        }