Exemple #1
0
 public void Teleport(Teleport teleport)
 {
     Teleport(teleport.Map, teleport.TeleportPosition, teleport.Direction);
 }
Exemple #2
0
        private void UpdateObject(MapObject obj, double timePassed)
        {
            int size = Global.TileSize;
            Vector2 currentPosition = obj.CurrentPosition;
            Vector2 destinationPosition = obj.DestinationPosition;
            Vector2 mapPosition = obj.MapPosition;
            double lerpTime = obj.LerpTime;

            currentPosition = mapPosition * size;
            
            // Calculate moving animation
            if (obj.IsMoving)
            {
                int x = (int)(currentPosition.X + (destinationPosition.X - currentPosition.X) * lerpTime);
                int y = (int)(currentPosition.Y + (destinationPosition.Y - currentPosition.Y) * lerpTime);
                currentPosition = new Vector2(x, y);
                lerpTime += timePassed * obj.AnimationSpeed;

                // Finished movement
                if (lerpTime >= 1)
                {
                    lerpTime = 0;
                    obj.IsMoving = false;
                    mapPosition = destinationPosition / size;
                    mustTeleport = currentMap.GetCollision(mapPosition) == 2;

                    if (mustTeleport)
                        teleportObject = (Teleport)currentMap.GetObject(mapPosition);
                }
            }

            obj.CurrentPosition = currentPosition;
            obj.DestinationPosition = destinationPosition;
            obj.MapPosition = mapPosition;
            obj.LerpTime = lerpTime;
        }