Ejemplo n.º 1
0
    public void Teleport()
    {
        var bs = Area.GetOverlappingBodies();
        var a  = new Node2D[bs.Count];

        bs.CopyTo(a, 0);
        a = a.Where(b => b is Knight).ToArray();
        if (a.Any())
        {
            var p = new List <Vector2> {
                Start, Start + new Vector2(20, 0), Start + new Vector2(-20, 0)
            };
            p.RemoveAll(t => t.DistanceTo(GlobalPosition) < 2);
            var r = new Random();
            GlobalPosition = p[r.Next(0, 2)];
            Sprite.FlipH   = a.First().GlobalPosition < GlobalPosition;
        }
        else
        {
            Sprite.FlipH   = true;
            GlobalPosition = Start;
        }
    }