public override void _PhysicsProcess(float delta) { if (KnockBackTimer.TimeLeft == 0) { var g = GetTree().GetNodesInGroup("Player"); Node2D[] p = new Node2D[g.Count]; g.CopyTo(p, 0); p = p.Where(n => PatrolArea.GetOverlappingBodies().Contains(n) && (n as Knight).Health > 0).ToArray(); if (p.Any()) { if (p.FirstOrDefault().GlobalPosition.DistanceTo(GlobalPosition) > 10 && (p.FirstOrDefault() as Knight).Health != 0) { Move(p.FirstOrDefault().GlobalPosition < GlobalPosition ? -1 : 1); } else { Move(0); } } else { if (GlobalPosition.DistanceTo(SpawnPos) > 2) { Move(SpawnPos.x > GlobalPosition.x ? 1 : -1); } else { Move(0); } } p = p.Where(n => n.GlobalPosition.DistanceTo(GlobalPosition) < 10).ToArray(); if (p.Any() && IsOnFloor() && CanAttack && !Attacking && Health > 0) { Attack(); } } else { Move(FlyR ? 1 : -1); } ProcessGravity(delta); }
public void AttackTimeout() { Attacking = false; var g = GetTree().GetNodesInGroup("Player"); Node2D[] p = new Node2D[g.Count]; g.CopyTo(p, 0); p = p.Where(n => AttackHitbox.GetOverlappingBodies().Contains(n)).ToArray(); if (p.Any()) { foreach (var e in p) { (e as Knight).Hurt(); } } }
public override void _Process(float delta) { var g = GetTree().GetNodesInGroup("Player"); Node2D[] p = new Node2D[g.Count]; g.CopyTo(p, 0); p = p.Where(n => (n as Knight).Health > 0).ToArray(); p = p.Where(n => n.GlobalPosition.DistanceTo(GlobalPosition) < 40).ToArray(); if (p.Any() && AttackCooldown.TimeLeft == 0 && Health > 0) { var k = p.FirstOrDefault(); Sprite.FlipH = k.GlobalPosition < GlobalPosition; AttackCooldown.Start(3f); ShootTimer.Start(1.5f); Animation.Play("A"); } }
public override void _Process(float delta) { if (Health <= 0) { return; } var bs = Area.GetOverlappingBodies(); var a = new Node2D[bs.Count]; bs.CopyTo(a, 0); a = a.Where(b => b is Knight).ToArray(); if (TeleportCooldown.TimeLeft == 0) { if (a.Any()) { TeleportMove.Start(1f); TeleportCooldown.Start(4f); Animation.Play("Teleport"); AttackCooldown.Start(1.6f); } else if (GlobalPosition != Start) { TeleportMove.Start(1f); TeleportCooldown.Start(4f); Animation.Play("Teleport"); AttackCooldown.Start(1.6f); } } else { if (AttackCooldown.TimeLeft == 0) { TeleportCooldown.Start(3f); AttackCooldown.Start(3f); Animation.Play("Attack"); FireballTimer.Start(1f); } } }
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; } }