7-14-25 1:27PM
This commit is contained in:
@@ -5,40 +5,37 @@ using System.Linq;
|
||||
|
||||
public partial class Battle : Node
|
||||
{
|
||||
[Signal]
|
||||
public delegate void SetCurrentEventHandler(Battle BATTLE);
|
||||
//[Signal]
|
||||
//public delegate void DetectMovementEventHandler(bool BOOL);
|
||||
|
||||
public bool _anyMovement, _cueBallPotted;
|
||||
public bool _current;
|
||||
public Vector2 _startPosition = new Vector2(890, 340);
|
||||
public Ball _cueBall;
|
||||
public Player _player;
|
||||
public List<Sprite2D> _potted = new();
|
||||
public List<Ball> _balls;
|
||||
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_player = GetNode<Player>("Player");
|
||||
Start();
|
||||
|
||||
List<Area2D> pockets = GetNode<Table>("Table").GetChildren()
|
||||
.Where(n => n.GetName().ToString().ToLower().Contains("pocket"))
|
||||
.Select(n => (Area2D)n).ToList<Area2D>();
|
||||
.Select(n => (Area2D)n)
|
||||
.ToList<Area2D>();
|
||||
for (int i = 0; i < pockets.Count; i++)
|
||||
{
|
||||
pockets[i].BodyEntered += PottedBall;
|
||||
}
|
||||
_balls = GetTree().GetNodesInGroup("balls").Select(b => (Ball)b).ToList<Ball>();
|
||||
|
||||
}
|
||||
|
||||
public override void _Process(double delta_)
|
||||
public override void _Process(double DELTA_)
|
||||
{
|
||||
_anyMovement = CheckMovement();
|
||||
//if (!_cueBall._available)
|
||||
//{
|
||||
//GD.Print(1);
|
||||
//}
|
||||
if (_cueBallPotted && !_anyMovement) // LOGIC WILL ONLY APPLY TO CUE BALLS
|
||||
{
|
||||
ResetCueBall();
|
||||
_cueBallPotted = false;
|
||||
}
|
||||
CheckMovement();
|
||||
}
|
||||
|
||||
public void GenerateBalls()
|
||||
@@ -51,7 +48,8 @@ public partial class Battle : Node
|
||||
for (int j = 0; j < rows; j++)
|
||||
{
|
||||
Vector2 position = new Vector2(250 + (i*(diameter)), 267 + (j*(diameter)) + (i*(diameter / 2)));
|
||||
Ball ball = Ball.Create(count, position);
|
||||
Ball ball = Ball.Create("ball", count);
|
||||
ball.Place(position);
|
||||
AddChild(ball);
|
||||
|
||||
count += 1;
|
||||
@@ -61,57 +59,59 @@ public partial class Battle : Node
|
||||
}
|
||||
}
|
||||
|
||||
public bool CheckMovement()
|
||||
public void CheckMovement()
|
||||
{
|
||||
return _balls.Any(b => b._moving);
|
||||
}
|
||||
|
||||
public void PottedBall(Node2D body)
|
||||
{
|
||||
if (body == _cueBall)
|
||||
bool movementCheck = _balls.Any(b => b._moving && b._placed);
|
||||
if (movementCheck)
|
||||
{
|
||||
_cueBallPotted = true;
|
||||
RemoveCueBall();
|
||||
if (!Globals.Instance._anyMovement)
|
||||
{
|
||||
Globals.Instance._anyMovement = true;
|
||||
//EmitSignal(SignalName.DetectMovement, true);
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Sprite2D ballSprite = new Sprite2D();
|
||||
AddChild(ballSprite);
|
||||
ballSprite.Texture = body.GetNode<Sprite2D>("Image").Texture;
|
||||
_potted.Add(ballSprite);
|
||||
ballSprite.Position = new Vector2(50 * _potted.Count, 725);
|
||||
body.QueueFree();
|
||||
if (Globals.Instance._anyMovement)
|
||||
{
|
||||
Globals.Instance._anyMovement = false;
|
||||
//EmitSignal(SignalName.DetectMovement, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveCueBall()
|
||||
public void PottedBall(Node2D BODY)
|
||||
{
|
||||
Ball oldCueBall = _cueBall;
|
||||
_balls.Remove(oldCueBall);
|
||||
RemoveChild(oldCueBall);
|
||||
oldCueBall.QueueFree();
|
||||
}
|
||||
|
||||
public void ResetCueBall()
|
||||
{
|
||||
_cueBall = Ball.Create(0, _startPosition);
|
||||
_cueBall.SetName("CueBall");
|
||||
AddChild(_cueBall);
|
||||
Texture2D image = GD.Load<Texture2D>("res://art/cue_ball.png");
|
||||
_cueBall.GetNode<Sprite2D>("Image").Texture = image;
|
||||
_balls = GetTree().GetNodesInGroup("balls").Select(b => (Ball)b).ToList<Ball>();
|
||||
//_takingShot = false;
|
||||
if (BODY.GetType() != typeof(Ball)){
|
||||
return;
|
||||
}
|
||||
if (BODY == _player._actor._activeBall)
|
||||
{
|
||||
GD.Print(1);
|
||||
_player._actor._activeBall._potted = true;
|
||||
_player._actor._activeBall._placed = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
GD.Print(BODY);
|
||||
Sprite2D ballSprite = new Sprite2D();
|
||||
AddChild(ballSprite);
|
||||
ballSprite.Texture = BODY.GetNode<Sprite2D>("Image").Texture;
|
||||
_potted.Add(ballSprite);
|
||||
ballSprite.Position = new Vector2(50 * _potted.Count, 725);
|
||||
((Ball)BODY)._placed = false;
|
||||
((Ball)BODY)._potted = true;
|
||||
BODY.QueueFree();
|
||||
}
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
ResetCueBall();
|
||||
_current = true;
|
||||
GenerateBalls();
|
||||
GetNode<Cue>("Cue").ShowCue();
|
||||
}
|
||||
|
||||
private void OnCueShoot(Vector2 impulse)
|
||||
{
|
||||
_cueBall.ApplyCentralImpulse(impulse);
|
||||
|
||||
EmitSignal(SignalName.SetCurrent, this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user