Добавлен босс
This commit is contained in:
parent
b01a092fdb
commit
66558fb1e3
12 changed files with 360 additions and 9 deletions
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue