Files
hotdesking/Gameplay/Battle.cs
2025-08-02 03:51:34 -04:00

110 lines
2.2 KiB
C#

using Godot;
using System;
using System.Collections.Generic;
using System.Linq;
public partial class Battle : Node
{
public bool _current;
public Vector2 _startPosition = new Vector2(890, 340);
public Manager _turn;
public List<Sprite2D> _potted = new();
public List<Ball> _balls = new();
public Table _table;
public override void _Ready()
{
}
public override void _Process(double DELTA_)
{
CheckMovement();
}
public void CheckMovement()
{
bool movementCheck = _balls.Any(b => b._moving);
if (movementCheck)
{
if (!Globals.Instance._anyMovement)
{
Globals.Instance._anyMovement = true;
//EmitSignal(SignalName.DetectMovement, true);
}
}
else
{
if (Globals.Instance._anyMovement)
{
Globals.Instance._anyMovement = false;
//EmitSignal(SignalName.DetectMovement, false);
}
}
}
// public void PotBall(Node2D BODY)
// {
// if (BODY is Ball)
// {
// Ball ball = (Ball)BODY;
// if (ball.GetParentOrNull<Manager>() == _player)
// {
// // _player.PotWorker(ball.GetParent<Worker>());
// }
// else
// {
// ball.Pot();
// _balls.Remove(ball);
// RemoveChild(ball);
// ball.QueueFree();
// }
// }
// }
public void Start(PlayerManager PLAYER, ComputerManager COMPUTER)
{
// _current = true;
// // GenerateBalls();
Globals.Instance._currentBattle = this;
// _player.Start();
int diameter = 36;
Table table = GetNode<Table>("Table");
List<Ball> computerBalls = COMPUTER._balls;
List<Ball> playerBalls = PLAYER._balls;
List<Ball> rack = new();
rack.AddRange(computerBalls);
rack.AddRange(playerBalls);
int rows = rack.Max(b => b._rackPosition.Y);
Ball rackBall;
int r, c;
for (int i = 0; i < rack.Count; i++)
{
rackBall = rack[i];
c = rackBall._rackPosition.X;
r = Math.Abs(rackBall._rackPosition.Y - rows);
if (c > 0)
{
Vector2 position = new Vector2(table.GlobalPosition.X - (r * (diameter / 2)) + ((c - 1) * diameter), table.GlobalPosition.Y - table.Texture.GetSize().Y / 4 - (r * diameter));
if (PLAYER._id == rackBall._ownerId)
{
PLAYER.PlaceBall(rackBall, position);
}
if (COMPUTER._id == rackBall._ownerId)
{
COMPUTER.PlaceBall(rackBall, position);
}
}
}
// PLAYER.PotBall();
}
}