Friday, 15 August 2025 23:08:08
This commit is contained in:
@@ -1,44 +1,190 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
|
||||
public partial class Worker : Node2D
|
||||
public partial class Worker : RigidBody2D
|
||||
{
|
||||
[Signal]
|
||||
public delegate void DamageOverflowEventHandler(int OVERFLOW);
|
||||
public bool _dead = false, _hovered = false;
|
||||
public int _health = 5, _healthMax;
|
||||
|
||||
public bool _dead = false, _hovered = false, _held = false, _placed = false, _selected = false, _primed = false, _moving = false;
|
||||
public int _health, _healthMax, _aptitude, _agility, _ardor, _accumen, _awareness, _appeal, _id;
|
||||
public float _rotationalForce = 0;
|
||||
public Vector2 _force = Vector2.Zero;
|
||||
public Node _collisionTarget;
|
||||
public Sprite2D _image;
|
||||
public Manager _manager;
|
||||
public List<Effect> _effects = new();
|
||||
public override void _Ready()
|
||||
{
|
||||
_health = 10;
|
||||
_aptitude = 5;
|
||||
_agility = 5;
|
||||
_ardor = 5;
|
||||
_accumen = 5;
|
||||
_awareness = 5;
|
||||
_appeal = 5;
|
||||
|
||||
_healthMax = _health;
|
||||
_image = GetNode<Sprite2D>("Sprite2D");
|
||||
}
|
||||
|
||||
public virtual void ChangeDefense(int CHANGE)
|
||||
public override void _Process(double DELTA_)
|
||||
{
|
||||
_health += CHANGE;
|
||||
_health = Math.Min(_health, _healthMax);
|
||||
if (_health < 0)
|
||||
if (!_moving)
|
||||
{
|
||||
EmitSignal(SignalName.DamageOverflow, _health);
|
||||
_health = 0;
|
||||
if (!_placed)
|
||||
{
|
||||
if (!_held)
|
||||
{
|
||||
if (_hovered)
|
||||
{
|
||||
if (Input.IsActionJustPressed("left_click"))
|
||||
{
|
||||
Hold();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_selected)
|
||||
{
|
||||
Vector2 mousePosition = GetGlobalMousePosition();
|
||||
LookAt(mousePosition);
|
||||
if (Input.IsActionJustReleased("left_click"))
|
||||
{
|
||||
_selected = false;
|
||||
_force = (GlobalPosition - mousePosition) * 100;
|
||||
_rotationalForce = 5f;
|
||||
_primed = true;
|
||||
}
|
||||
}
|
||||
else if (_hovered)
|
||||
{
|
||||
if (Input.IsActionJustPressed("left_click"))
|
||||
{
|
||||
_selected = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Vector2 towardCenter = (Globals.Instance._screenCenter - GlobalPosition).Normalized();
|
||||
// ApplyCentralForce(towardCenter * 100);
|
||||
_image.Rotate(_rotationalForce);
|
||||
_rotationalForce -= 0.5f / 60;
|
||||
if (_rotationalForce <= 0f)
|
||||
{
|
||||
Stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetSprite(string PATH)
|
||||
public override void _PhysicsProcess(double DELTA_)
|
||||
{
|
||||
GetNode<Sprite2D>("Image").Texture = GD.Load<Texture2D>(PATH);
|
||||
if (_held)
|
||||
{
|
||||
GlobalPosition = GetGlobalMousePosition();
|
||||
if (Input.IsActionJustReleased("left_click"))
|
||||
{
|
||||
Transform2D newTransform = GlobalTransform;
|
||||
newTransform.Origin = Position;
|
||||
GlobalTransform = newTransform;
|
||||
Drop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ChangeHealth(int CHANGE, Node CHANGEMAKER)
|
||||
{
|
||||
if (_health <= 0 && CHANGE < 0)
|
||||
{
|
||||
// knock the piece off the board and out for the round!
|
||||
// process on knockout
|
||||
}
|
||||
_health += CHANGE;
|
||||
if (_health <= 0)
|
||||
{
|
||||
_dead = true;
|
||||
_health = 0;
|
||||
TriggerSpecificEffects(Effect.Trigger.Death);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void Drop()
|
||||
{
|
||||
if (_held)
|
||||
{
|
||||
_held = false;
|
||||
_placed = true;
|
||||
Freeze = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void Hold()
|
||||
{
|
||||
if (_held)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Freeze = true;
|
||||
_held = true;
|
||||
}
|
||||
|
||||
public void Launch()
|
||||
{
|
||||
GravityScale = 1.0f;
|
||||
_moving = true;
|
||||
ApplyCentralForce(_force);
|
||||
_force = Vector2.Zero;
|
||||
_primed = false;
|
||||
TriggerSpecificEffects(Effect.Trigger.Launch);
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
GravityScale = 0.0f;
|
||||
Sleeping = true;
|
||||
_moving = false;
|
||||
_rotationalForce = 0f;
|
||||
TriggerSpecificEffects(Effect.Trigger.Stop);
|
||||
}
|
||||
|
||||
public void TriggerSpecificEffects(Effect.Trigger TRIGGER)
|
||||
{
|
||||
List<Effect> triggeredEffects = _effects.Where(e => e._trigger.IndexOf(TRIGGER) > -1).ToList();
|
||||
for (int i = 0; i < triggeredEffects.Count; i++)
|
||||
{
|
||||
triggeredEffects[i].TriggerEffect();
|
||||
}
|
||||
}
|
||||
|
||||
// PRIVATE METHODS
|
||||
private void OnMouseEntered()
|
||||
{
|
||||
_hovered = true;
|
||||
}
|
||||
|
||||
private void OnMouseExited()
|
||||
{
|
||||
_hovered = false;
|
||||
}
|
||||
|
||||
private void OnBodyEntered(Node NODE)
|
||||
{
|
||||
if (NODE is Worker)
|
||||
{
|
||||
_collisionTarget = NODE;
|
||||
TriggerSpecificEffects(Effect.Trigger.Stop);
|
||||
|
||||
_rotationalForce *= 0.8f;
|
||||
Vector2 rotatedForce = LinearVelocity.Rotated(((Worker)NODE)._rotationalForce);
|
||||
|
||||
ApplyCentralForce(rotatedForce);
|
||||
_collisionTarget = null;
|
||||
}
|
||||
}
|
||||
|
||||
// Processes
|
||||
// public virtual void ProcessOnCollision(Ball TARGET)
|
||||
// {
|
||||
// Worker TARGETWORKER = TARGET.GetParent<Worker>();
|
||||
// if (_launched)
|
||||
// {
|
||||
// TARGETWORKER.ChangeDefense(-3);
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user