public override void _Process(float delta) { base.Translate(positionDifference * speed * delta); base.Rotate(rotationSpeed * delta); if (HitCoolDownTimer > 0.0f) { HitCoolDownTimer -= delta; } else { if ((Area.GetOverlappingAreas().Count) > 0 && (DamageToTake > 0)) { Hit(DamageToTake, NodeGuid.ToString()); } } if (HitAnimationTimer > 0.0f) { var sprite = this.GetNode <AnimatedSprite>("Sprite"); sprite.SelfModulate = new Color(0.5f - HitAnimationTimer, 0.5f - HitAnimationTimer, 0.5f - HitAnimationTimer); HitAnimationTimer -= delta; } else { HitAnimationTimer = 0.0f; var sprite = this.GetNode <AnimatedSprite>("Sprite"); sprite.SelfModulate = new Color(1, 1, 1); } }
public override void Hit(int damage, string guid) { if (guid == NodeGuid.ToString()) { if (HitCoolDownTimer <= 0.0f) { Health -= damage; var hud = this.GetParent().GetNode <HUD>("HUD"); hud.SetBossHealthBarPercent(((float)Health) / ((float)TotalHealth)); Phase = MovementPhase.Hit; if (Health > 0) { HitAnimationTimer = 0.2f; HitCoolDownTimer = 0.5f; DamageToTake = damage; this.GetNode <AudioStreamPlayer2D>("HitSound").Play(); } else { var explosion = (PackedScene)ResourceLoader.Load("res://Components/Explosion.tscn"); Node2D explosionInstance = (Node2D)explosion.Instance(); var position = this.GlobalPosition; explosionInstance.Position = position; this.GetParent().AddChild(explosionInstance); var coin = (PackedScene)ResourceLoader.Load("res://Components/Coin.tscn"); Coin coinInstance = (Coin)coin.Instance(); coinInstance.Position = position; if (Rnd.NextDouble() < 0.90) { coinInstance.SetValue(1); hud.AddCoin(1); } else { coinInstance.SetValue(5); hud.AddCoin(5); } this.GetParent().AddChild(coinInstance); EmitSignal(nameof(BossDefeated)); CallDeferred("free"); } } } }
public override void _Process(float delta) { var newPoint = PointOnCircle(radius, currentAngle, playerPosition); LookAt(PointOnCircle(radius, currentAngle - 10, playerPosition)); Translate((newPoint - oldPosition)); currentAngle += speed * delta; radius -= shrinkSpeed * delta; shrinkSpeed += delta; speed += delta; oldPosition = newPoint; if (HitCoolDownTimer > 0.0f) { HitCoolDownTimer -= delta; } else { if ((Area.GetOverlappingAreas().Count) > 0 && (DamageToTake > 0)) { Hit(DamageToTake, NodeGuid.ToString()); } } if (HitAnimationTimer > 0.0f) { var sprite = this.GetNode <AnimatedSprite>("Sprite"); sprite.SelfModulate = new Color(0.5f - HitAnimationTimer, 0.5f - HitAnimationTimer, 0.5f - HitAnimationTimer); HitAnimationTimer -= delta; } else { HitAnimationTimer = 0.0f; var sprite = this.GetNode <AnimatedSprite>("Sprite"); sprite.SelfModulate = new Color(1, 1, 1); } }