70 lines
1.7 KiB
C#
70 lines
1.7 KiB
C#
using Godot;
|
|
using System;
|
|
|
|
public partial class Commander : Sprite2D
|
|
{
|
|
[Signal]
|
|
public delegate void DeathEventHandler(Commander THIS);
|
|
[Signal]
|
|
public delegate void ActionsUpEventHandler();
|
|
public int _health = 10, _actionsMax = 1, _actions;
|
|
public PackedScene _attackScene = GD.Load<PackedScene>("res://Attack.tscn");
|
|
public Attack _attack;
|
|
public PlayerController _playerController;
|
|
|
|
public override void _Process(double delta)
|
|
{
|
|
base._Process(delta);
|
|
if (_attack != null)
|
|
{
|
|
if (_attack.Position.Y > GetViewportRect().Size.Y + 50)
|
|
{
|
|
_attack.QueueFree();
|
|
_attack = null;
|
|
if (_actions <= 0)
|
|
{
|
|
EmitSignal(SignalName.ActionsUp);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public void AttackEnteredBucket()
|
|
{
|
|
_actions += (_actions + 1) > _actionsMax ? 0 : 1;
|
|
}
|
|
|
|
public void LoadAttack(Vector2 OFFSET)
|
|
{
|
|
if (_attack == null)
|
|
{
|
|
_attack = _attackScene.Instantiate<Attack>();
|
|
_attack.Position = OFFSET;
|
|
_attack._commanderOwner = this;
|
|
_attack.GravityScale = 0;
|
|
_attack.BucketEntered += AttackEnteredBucket;
|
|
AddChild(_attack);
|
|
}
|
|
}
|
|
|
|
public void TakeDamage(int DAMAGE, Enemy ATTACKER)
|
|
{
|
|
_health -= DAMAGE;
|
|
if (_health <= 0)
|
|
{
|
|
EmitSignal(SignalName.Death, this);
|
|
}
|
|
}
|
|
|
|
public void ShootCurrentAttack(Vector2 FORCE){
|
|
|
|
_attack.Shoot(FORCE);
|
|
_actions--;
|
|
}
|
|
|
|
public void UnloadAttack()
|
|
{
|
|
_attack.QueueFree();
|
|
}
|
|
}
|