second commit
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class Enemy : StaticBody2D
|
||||
{
|
||||
[Signal]
|
||||
public delegate void TurnDoneEventHandler();
|
||||
public bool _toMove = false;
|
||||
public int _speed = 100, _reach = 200, _damage = 1, _health = 2;
|
||||
public float _movement = 0;
|
||||
public Player _player;
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
base._PhysicsProcess(delta);
|
||||
if (_toMove)
|
||||
{
|
||||
Vector2 moveVector = (_player.Position - Position) * (float)delta;
|
||||
if ((_movement += moveVector.Length()) <= _speed )
|
||||
{
|
||||
MoveAndCollide(moveVector);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((_player.Position - Position).Length() <= _reach)
|
||||
{
|
||||
Attack(_player);
|
||||
}
|
||||
_toMove = false;
|
||||
_movement = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Attack(Player PLAYER)
|
||||
{
|
||||
PLAYER.TakeDamage(_damage, this);
|
||||
QueueFree();
|
||||
}
|
||||
|
||||
public void TakeDamage(int DAMAGE, Player ATTACKER)
|
||||
{
|
||||
_health -= DAMAGE;
|
||||
GD.Print($"Taking {DAMAGE}, Health is now {_health}");
|
||||
if (_health <= 0)
|
||||
{
|
||||
QueueFree();
|
||||
}
|
||||
}
|
||||
|
||||
public void TakeTurn()
|
||||
{
|
||||
_toMove = true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user