using Godot; using System; using System.Collections.Generic; using System.Linq; /// TODO alter code to player vs computer to account for differing logic public partial class Manager : Node2D { public bool _dead, _ready, _moving; public int _ballsMoving = 0, _health = 10, _healthMax, _speed = 5; public string _imagePath; public CollisionShape2D _startArea; public ManagerPanel _managerPanel = null; public Sprite2D _image; public Desk _desk = null; public Cell _cell; public List _moves = new(); public Manager _opponent; public List _workers = new(); public Node _workerNode; public Worker _hoveredWorker, _selectedWorker, _heldWorker; // public List _tchotckes = new(); public override void _Ready() { _workerNode = GetNode("Workers"); _healthMax = _health; SetSprite("res://art/ness.png"); // _managerPanel = GetNode("Panel"); _desk = GetNode("Desk"); _desk.Setup(15, 20); _cell = _desk.GetCellFromAddress(1, 1); // _movements.Insert(0, _deskPosition); _image = GetNode("Image"); _image.GlobalPosition = _cell.GlobalPosition; // _managerPanel.SetManager(this); for (int i = 0; i < Globals.Instance._random.Next(3, 6); i++) { AddWorker(null); } } public override void _Process(double DELTA_) { ChainMovement(); ChainSelection(); } public void AddWorker(Worker NEWWORKER) { Worker newWorker = NEWWORKER ?? Globals.Instance._workerScene.Instantiate(); newWorker._cell = _desk.GetCellFromAddress(1, 1); newWorker.Position = newWorker._cell.GlobalPosition; newWorker._manager = this; _workers.Add(newWorker); _workerNode.AddChild(newWorker); // newWorker.SetHovered += SetHoveredWorker; } public void ChainMovement() { Vector2 direction = Vector2.Zero; if (Input.IsActionJustPressed("move_up")) { direction = Vector2.Up; } else if (Input.IsActionJustPressed("move_down")) { direction = Vector2.Down; } else if (Input.IsActionJustPressed("move_left")) { direction = Vector2.Left; } else if (Input.IsActionJustPressed("move_right")) { direction = Vector2.Right; } if (direction != Vector2.Zero) { GD.Print(_cell._row + (int)direction.Y, _cell._column + (int)direction.X); Cell newCell = _desk.GetCellFromAddress(_cell._row + (int)direction.Y, _cell._column + (int)direction.X); if (newCell != null) { GD.Print(_cell._row, _cell._column); if (_moves.Count > 0) { for (int i = 0; i < _workers.Count && i < _moves.Count; i++) { _workers[i]._cell = _moves[i]; _workers[i].GlobalPosition = _workers[i]._cell.GlobalPosition; } } _cell = newCell; _moves.Insert(0, newCell); _image.GlobalPosition = _cell.GlobalPosition; } } } public void ChainSelection() { // if (_heldWorker != null) // { // _heldWorker.GlobalPosition = GetGlobalMousePosition(); // if (_hoveredWorker != null && _heldWorker != _hoveredWorker) // { // SwapPositions(_heldWorker, _hoveredWorker); // _hoveredWorker._hovered = false; // _hoveredWorker = null; // } // if (Input.IsActionJustReleased("left_click")) // { // _heldWorker.GlobalPosition = _desk.GetPositionFromAddress((int)_heldWorker._deskPosition.Y, (int)_heldWorker._deskPosition.X); // _heldWorker._held = false; // _heldWorker = null; // _hoveredWorker._hovered = false; // _hoveredWorker = null; // } // } // else // { // if (_selectedWorker != null) // { // if (Input.IsActionPressed("left_click") && (GetGlobalMousePosition() - _selectedWorker._chainPosition).Length() > 5) // { // _heldWorker = _selectedWorker; // _heldWorker._held = true; // _heldWorker._selected = false; // _selectedWorker = null; // } // } // if (_hoveredWorker != null) // { // if (Input.IsActionJustPressed("left_click")) // { // _selectedWorker = _hoveredWorker; // _selectedWorker._selected = true; // _selectedWorker._hovered = false; // _hoveredWorker = null; // } // } // } } public void ChangeHealth(int CHANGE) { _health += CHANGE; _health = Math.Min(_health, _healthMax); if (_health < 0) { _dead = true; _health = 0; } GetNode("Panel").SetValue(_health); } public void SetSprite(string PATH) { _imagePath = PATH; } // public void Start() // { // _workers[0].GlobalPosition = _desk.GetPositionFromAddress(1, 1); // } private void SetHoveredWorker(Worker HOVEREDWORKER) { if (HOVEREDWORKER._hovered) { _hoveredWorker = HOVEREDWORKER; } else { _hoveredWorker = null; } } }