Добавлен босс
This commit is contained in:
parent
b01a092fdb
commit
66558fb1e3
12 changed files with 360 additions and 9 deletions
|
@ -12,4 +12,6 @@ public static class Constants
|
|||
public const float MaxFlashlightEnergy = 100;
|
||||
public const float FlashlightEnergyPerCharge = 40;
|
||||
public const float FlashlightDischargeModifier = 10;
|
||||
|
||||
public const float BossInjureTimeout = 0.5f;
|
||||
}
|
||||
|
|
68
scripts/enemies/Boss.cs
Normal file
68
scripts/enemies/Boss.cs
Normal file
|
@ -0,0 +1,68 @@
|
|||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class Boss : CharacterBody2D
|
||||
{
|
||||
[Signal]
|
||||
public delegate void KilledEventHandler();
|
||||
|
||||
[Export] public int MaxHp = 6;
|
||||
|
||||
public enum State
|
||||
{
|
||||
Default,
|
||||
Injured
|
||||
}
|
||||
|
||||
private AnimatedSprite2D _sprite;
|
||||
private State _state = State.Default;
|
||||
private int _currentHp;
|
||||
private float _injureTimeout = Constants.BossInjureTimeout;
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
{
|
||||
_sprite = (AnimatedSprite2D)FindChild("AnimatedSprite2D");
|
||||
_currentHp = MaxHp;
|
||||
}
|
||||
|
||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
}
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
_injureTimeout -= (float)delta;
|
||||
switch (_state)
|
||||
{
|
||||
case State.Default:
|
||||
_sprite.Play("default");
|
||||
break;
|
||||
case State.Injured:
|
||||
_sprite.Play("injured");
|
||||
if (_injureTimeout < 0)
|
||||
{
|
||||
_state = State.Default;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (_currentHp <= 0)
|
||||
{
|
||||
EmitSignal(SignalName.Killed);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void _OnAttack(Node2D body)
|
||||
{
|
||||
if (body is LivingArmor armor)
|
||||
{
|
||||
_currentHp -= 1;
|
||||
_state = State.Injured;
|
||||
_injureTimeout = Constants.BossInjureTimeout;
|
||||
armor.Kill(this);
|
||||
if (_currentHp <= 0)
|
||||
GD.Print($"{this.Name} was killed.");
|
||||
}
|
||||
}
|
||||
}
|
81
scripts/enemies/Claw.cs
Normal file
81
scripts/enemies/Claw.cs
Normal file
|
@ -0,0 +1,81 @@
|
|||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class Claw : CharacterBody2D
|
||||
{
|
||||
[Export] public float MovingSpeed = 32f;
|
||||
public enum State
|
||||
{
|
||||
Moving,
|
||||
Prepare,
|
||||
Attack
|
||||
}
|
||||
|
||||
private State _state = State.Moving;
|
||||
private float _stateTimeout = 0;
|
||||
private bool _isPlayerNearBy = false;
|
||||
private AnimatedSprite2D _sprite;
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
{
|
||||
_sprite = (AnimatedSprite2D)FindChild("AnimatedSprite2D");
|
||||
}
|
||||
|
||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
}
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
_stateTimeout -= (float)delta;
|
||||
switch (_state)
|
||||
{
|
||||
case State.Moving:
|
||||
var direction = (Player.Instance.Position - Position).Normalized();
|
||||
Velocity = direction * MovingSpeed;
|
||||
_sprite.FlipH = Velocity.X < 0.001f;
|
||||
_sprite.Play("default");
|
||||
MoveAndSlide();
|
||||
break;
|
||||
case State.Prepare:
|
||||
_sprite.Play("prepare");
|
||||
if (_stateTimeout < 0)
|
||||
{
|
||||
_state = State.Attack;
|
||||
_stateTimeout = 0.25f;
|
||||
}
|
||||
break;
|
||||
case State.Attack:
|
||||
_sprite.Play("attack");
|
||||
if (_stateTimeout < 0)
|
||||
{
|
||||
_state = State.Moving;
|
||||
if (_isPlayerNearBy)
|
||||
Player.Instance.Kill(this);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void _OnEntered(Node2D body)
|
||||
{
|
||||
if (body is Player)
|
||||
{
|
||||
_state = State.Prepare;
|
||||
_isPlayerNearBy = true;
|
||||
_stateTimeout = 0.5f;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void _OnExited(Node2D body)
|
||||
{
|
||||
_isPlayerNearBy = false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -161,10 +161,14 @@ public partial class LivingArmor : CharacterBody2D
|
|||
foreach (var body in _bodiesInSight)
|
||||
{
|
||||
var distance = (body.Position - Position).Length();
|
||||
GD.Print($"{body.Name}");
|
||||
switch (body)
|
||||
{
|
||||
case Boss boss:
|
||||
_target = boss;
|
||||
break;
|
||||
case Wretched wretched:
|
||||
if (_target is Boss)
|
||||
continue;
|
||||
if (targetDistance < 0 || targetDistance > distance)
|
||||
{
|
||||
targetDistance = distance;
|
||||
|
@ -172,12 +176,8 @@ public partial class LivingArmor : CharacterBody2D
|
|||
}
|
||||
break;
|
||||
case Player player:
|
||||
|
||||
if (_target is Wretched)
|
||||
{
|
||||
if (_target is Wretched or Boss)
|
||||
continue;
|
||||
}
|
||||
|
||||
_target = player;
|
||||
break;
|
||||
}
|
||||
|
@ -227,16 +227,16 @@ public partial class LivingArmor : CharacterBody2D
|
|||
|
||||
private void _OnBodyEntered(Node2D body)
|
||||
{
|
||||
if (body is not Wretched and not Player)
|
||||
if (body is not Wretched and not Player and not Boss)
|
||||
return;
|
||||
|
||||
GD.Print($"{body.Name} Entered");
|
||||
_bodiesInSight.Add(body);
|
||||
}
|
||||
|
||||
|
||||
private void _OnBodyExited(Node2D body)
|
||||
{
|
||||
if (body is not Wretched and not Player)
|
||||
if (body is not Wretched and not Player and not Boss)
|
||||
return;
|
||||
if (body == _target)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue