Files
hotdesking/Gameplay/Manager.cs

126 lines
3.0 KiB
C#

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<Cell> _moves = new();
public Manager _opponent;
public List<Worker> _workers = new();
public Node _workerNode;
public Worker _hoveredWorker, _selectedWorker, _heldWorker;
// public List<Tchotchke> _tchotckes = new();
public override void _Ready()
{
_workerNode = GetNode("Workers");
_healthMax = _health;
SetSprite("res://art/ness.png");
// _managerPanel = GetNode<ManagerPanel>("Panel");
_desk = GetNode<Desk>("Desk");
_desk.Setup(15, 20, 50);
_cell = _desk.GetCellFromAddress(1, 1);
// _movements.Insert(0, _deskPosition);
_image = GetNode<Sprite2D>("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();
}
public void AddWorker(Worker NEWWORKER)
{
Worker newWorker = NEWWORKER ?? Globals.Instance._workerScene.Instantiate<Worker>();
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 ChangeHealth(int CHANGE)
{
_health += CHANGE;
_health = Math.Min(_health, _healthMax);
if (_health < 0)
{
_dead = true;
_health = 0;
}
GetNode<ManagerPanel>("Panel").SetValue(_health);
}
public void SetSprite(string PATH)
{
_imagePath = PATH;
}
}