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 _potted = new(); public List _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() == _player) // { // // _player.PotWorker(ball.GetParent()); // } // 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"); List computerBalls = COMPUTER._balls; List playerBalls = PLAYER._balls; List 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 == rackBall._owner) { PLAYER.PlaceBall(rackBall, position); } if (COMPUTER == rackBall._owner) { COMPUTER.PlaceBall(rackBall, position); } } } // PLAYER.PotBall(); PLAYER.SetRack(); } }