87 lines
1.8 KiB
C#
87 lines
1.8 KiB
C#
using Godot;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
public partial class Worker : Node2D
|
|
{
|
|
[Signal]
|
|
public delegate void DamageOverflowEventHandler(int OVERFLOW);
|
|
public bool _dead = false, _available = false, _hovered = false, _selected = false, _launched = false, _placed = false, _potted = false, _isLead = false;
|
|
public int _defense = 5, _defenseMax = 5;
|
|
public CollisionShape2D _startArea;
|
|
public TempBall _tempBall;
|
|
public Ball _ball;
|
|
|
|
public static Worker _Create()
|
|
{
|
|
PackedScene scene = ResourceLoader.Load<PackedScene>("res://Gameplay/worker.tscn");
|
|
Worker newWorker = scene.Instantiate<Worker>();
|
|
return newWorker;
|
|
}
|
|
|
|
public override void _Ready()
|
|
{
|
|
_ball = GetNode<Ball>("Ball");
|
|
_tempBall = GetNode<TempBall>("TempBall");
|
|
|
|
RemoveChild(_ball);
|
|
RemoveChild(_tempBall);
|
|
}
|
|
|
|
public override void _Process(double delta)
|
|
{
|
|
_hovered = _ball._hovered || _tempBall._hovered;
|
|
}
|
|
|
|
public virtual void ChangeBallPosition(Vector2 NEWPOSITION)
|
|
{
|
|
RemoveChild(_ball);
|
|
_ball.Position = NEWPOSITION;
|
|
AddChild(_ball);
|
|
}
|
|
|
|
public virtual void ChangeDefense(int CHANGE)
|
|
{
|
|
_defense += CHANGE;
|
|
_defense = Math.Min(_defense, _defenseMax);
|
|
if (_defense < 0)
|
|
{
|
|
EmitSignal(SignalName.DamageOverflow, _defense);
|
|
if (!_isLead)
|
|
{
|
|
PotBall();
|
|
}
|
|
_defense = 0;
|
|
}
|
|
}
|
|
|
|
public void SetSprite(string PATH)
|
|
{
|
|
GetNode<Sprite2D>("Image").Texture = GD.Load<Texture2D>(PATH);
|
|
}
|
|
|
|
public void PlaceBall(Vector2 POSITION)
|
|
{
|
|
_ball.Position = POSITION;
|
|
AddChild(_ball);
|
|
}
|
|
|
|
public void PotBall()
|
|
{
|
|
_ball.Pot();
|
|
RemoveChild(_ball);
|
|
}
|
|
|
|
public void OnBallHit()
|
|
{
|
|
// if (!_launched)
|
|
// {
|
|
// return;
|
|
// }
|
|
// Ball target = (Ball)TARGET;
|
|
// target.ChangeDefense(-1);
|
|
// ChangeDefense(-6);
|
|
// GD.Print("Defense: " + _defense);
|
|
}
|
|
}
|