Thursday, 07 August 2025 19:00:19
This commit is contained in:
@@ -15,7 +15,7 @@ public partial class Ball : RigidBody2D
|
|||||||
|
|
||||||
public bool _active = false, _placed = false, _potted = false, _available = false, _hovered = false, _selected = false, _aimed = false, _launched = false, _moving = false, _isCue = false;
|
public bool _active = false, _placed = false, _potted = false, _available = false, _hovered = false, _selected = false, _aimed = false, _launched = false, _moving = false, _isCue = false;
|
||||||
public float _moveThreshold = 5.0f;
|
public float _moveThreshold = 5.0f;
|
||||||
public string _imagePath = null;
|
public string _id, _imagePath = null;
|
||||||
public Vector2I _rackPosition = new Vector2I(0, 0);
|
public Vector2I _rackPosition = new Vector2I(0, 0);
|
||||||
public Manager _owner = null;
|
public Manager _owner = null;
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ public partial class Ball : RigidBody2D
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (LinearVelocity.Length() >= _moveThreshold)
|
else if (LinearVelocity.Length() >= _moveThreshold && !Sleeping)
|
||||||
{
|
{
|
||||||
ProcessOnMovement();
|
ProcessOnMovement();
|
||||||
if (!_moving)
|
if (!_moving)
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ public partial class BallSprite : Area2D
|
|||||||
[Signal]
|
[Signal]
|
||||||
public delegate void OnUnhoverEventHandler();
|
public delegate void OnUnhoverEventHandler();
|
||||||
public bool _active = false, _hovered = false, _held = false;
|
public bool _active = false, _hovered = false, _held = false;
|
||||||
public string _imagePath;
|
public string _id, _imagePath;
|
||||||
public Vector2 _rackPosition = new Vector2(0, 0);
|
public Vector2I _rackPosition = new Vector2I(0, 0);
|
||||||
public Manager _owner = null;
|
public Manager _owner = null;
|
||||||
|
|
||||||
public void SetSprite(string PATH)
|
public void SetSprite(string PATH)
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ public partial class Cue : Sprite2D
|
|||||||
|
|
||||||
public void Doff()
|
public void Doff()
|
||||||
{
|
{
|
||||||
|
_power = 0;
|
||||||
_donned = false;
|
_donned = false;
|
||||||
SetProcess(false);
|
SetProcess(false);
|
||||||
Hide();
|
Hide();
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ using System.Linq;
|
|||||||
public partial class Manager : Node
|
public partial class Manager : Node
|
||||||
{
|
{
|
||||||
public bool _dead, _ready;
|
public bool _dead, _ready;
|
||||||
public int _ballsMoving = 0, _health = 10, _healthMax, _placeLimit = 8;
|
public int _ballsMoving = 0, _health = 10, _healthMax;
|
||||||
public string _imagePath;
|
public string _imagePath;
|
||||||
public Node _hoveredNode = null;
|
public Node _hoveredNode = null;
|
||||||
public Node _selectedNode = null;
|
public Node _selectedNode = null;
|
||||||
@@ -16,12 +16,15 @@ public partial class Manager : Node
|
|||||||
public ManagerPanel _managerPanel = null;
|
public ManagerPanel _managerPanel = null;
|
||||||
public BallReturn _ballReturn = null;
|
public BallReturn _ballReturn = null;
|
||||||
public Rack _rack = null;
|
public Rack _rack = null;
|
||||||
|
public Table _table;
|
||||||
|
public Area2D _kitchen;
|
||||||
|
public Ball _cueBall;
|
||||||
|
public BallSprite _cueBallSprite;
|
||||||
public List<Ball> _balls = new();
|
public List<Ball> _balls = new();
|
||||||
public List<BallSprite> _ballSprites = new();
|
public List<BallSprite> _ballSprites = new();
|
||||||
public List<Worker> _workers = new();
|
public List<Worker> _workers = new();
|
||||||
public List<Vector2I> _initialRackPositions =
|
public List<Vector2I> _initialRackPositions =
|
||||||
[
|
[
|
||||||
new Vector2I(0, 1),
|
|
||||||
new Vector2I(1, 1),
|
new Vector2I(1, 1),
|
||||||
new Vector2I(3, 1),
|
new Vector2I(3, 1),
|
||||||
new Vector2I(4, 1),
|
new Vector2I(4, 1),
|
||||||
@@ -40,8 +43,11 @@ public partial class Manager : Node
|
|||||||
];
|
];
|
||||||
// denoted by c1r1 notation where (3,1) translates to row 1 column 3
|
// denoted by c1r1 notation where (3,1) translates to row 1 column 3
|
||||||
// column 0 represents the ball return where the row represents its order in the return,
|
// column 0 represents the ball return where the row represents its order in the return,
|
||||||
// (0,0) denotes a ball that is not on the screen
|
// cue ball reserves the position (0,0)
|
||||||
|
// (0, 1+) denotes a ballin the ball return
|
||||||
|
// (0,-1+) denotes a ball that is not on the screen, the closer to 0 numbers get placed in the return first if the cool down is equal
|
||||||
// numbers should increase from top to bottom and left to right from the player's perspective
|
// numbers should increase from top to bottom and left to right from the player's perspective
|
||||||
|
//
|
||||||
|
|
||||||
// PACKED SCENES
|
// PACKED SCENES
|
||||||
public PackedScene _ballScene = ResourceLoader.Load<PackedScene>("res://Gameplay/ball.tscn");
|
public PackedScene _ballScene = ResourceLoader.Load<PackedScene>("res://Gameplay/ball.tscn");
|
||||||
@@ -62,41 +68,11 @@ public partial class Manager : Node
|
|||||||
_ballReturn = _managerPanel.GetNode<BallReturn>("BallReturn");
|
_ballReturn = _managerPanel.GetNode<BallReturn>("BallReturn");
|
||||||
_rack = _managerPanel.GetNode<Rack>("Rack");
|
_rack = _managerPanel.GetNode<Rack>("Rack");
|
||||||
|
|
||||||
Ball newBall;
|
AddBall("res://art/cue_ball.png", new Vector2I(0, 0), true);
|
||||||
newBall = _ballScene.Instantiate<Ball>();
|
|
||||||
newBall.SetSprite("res://art/cue_ball.png");
|
|
||||||
newBall._rackPosition = _initialRackPositions[0];
|
|
||||||
newBall._owner = this;
|
|
||||||
newBall.OnHover += SetHovered;
|
|
||||||
newBall.OnMovement += MovingChange;
|
|
||||||
_balls.Add(newBall);
|
|
||||||
|
|
||||||
BallSprite newBallSprite;
|
|
||||||
newBallSprite = _ballSpriteScene.Instantiate<BallSprite>();
|
|
||||||
newBallSprite.SetSprite(newBall._imagePath);
|
|
||||||
newBallSprite._rackPosition = _initialRackPositions[0];
|
|
||||||
newBallSprite._owner = this;
|
|
||||||
newBallSprite.OnHover += SetHovered;
|
|
||||||
_ballSprites.Add(newBallSprite);
|
|
||||||
|
|
||||||
|
|
||||||
for (int i = 1; i <= 15; i++)
|
for (int i = 1; i <= 15; i++)
|
||||||
{
|
{
|
||||||
newBall = _ballScene.Instantiate<Ball>();
|
AddBall("res://art/ball_" + i + ".png", _initialRackPositions[i - 1], false);
|
||||||
newBall.SetSprite("res://art/ball_" + i + ".png");
|
|
||||||
newBall._rackPosition = _initialRackPositions[i];
|
|
||||||
newBall._owner = this;
|
|
||||||
newBall.OnHover += SetHovered;
|
|
||||||
newBall.OnMovement += MovingChange;
|
|
||||||
_balls.Add(newBall);
|
|
||||||
|
|
||||||
newBallSprite = _ballSpriteScene.Instantiate<BallSprite>();
|
|
||||||
newBallSprite.SetSprite(newBall._imagePath);
|
|
||||||
newBallSprite._rackPosition = _initialRackPositions[i];
|
|
||||||
_rack.SetSprite((int)newBallSprite._rackPosition.Y, (int)newBallSprite._rackPosition.X, newBallSprite._imagePath);
|
|
||||||
newBallSprite._owner = this;
|
|
||||||
newBallSprite.OnHover += SetHovered;
|
|
||||||
_ballSprites.Add(newBallSprite);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_managerPanel.SetManager(this);
|
_managerPanel.SetManager(this);
|
||||||
@@ -106,69 +82,134 @@ public partial class Manager : Node
|
|||||||
{
|
{
|
||||||
if (_ballsMoving == 0)
|
if (_ballsMoving == 0)
|
||||||
{
|
{
|
||||||
if (_ready)
|
if (_cueBall._placed)
|
||||||
{
|
{
|
||||||
if (_hoveredNode is Ball || _selectedNode is Ball)
|
if (_selectedNode is Ball)
|
||||||
{
|
{
|
||||||
if ((Ball)_selectedNode == null || ((Ball)_selectedNode != _hoveredNode && _hoveredNode is Ball))
|
if (Input.IsActionJustReleased("right_click"))
|
||||||
{
|
|
||||||
if (Input.IsActionJustReleased("left_click"))
|
|
||||||
{
|
|
||||||
_selectedNode = (Ball)_hoveredNode;
|
|
||||||
((Ball)_selectedNode)._selected = true;
|
|
||||||
_cue.Don(((Ball)_selectedNode).Position);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (Input.IsActionJustReleased("right_click"))
|
|
||||||
{
|
{
|
||||||
((Ball)_selectedNode)._selected = false;
|
((Ball)_selectedNode)._selected = false;
|
||||||
_selectedNode = null;
|
_selectedNode = null;
|
||||||
_cue.Doff();
|
_cue.Doff();
|
||||||
}
|
}
|
||||||
else if (_hoveredNode == null)
|
if (Input.IsActionJustReleased("left_click") && _cue._power == 0)
|
||||||
{
|
{
|
||||||
if (Input.IsActionJustReleased("left_click") && (Ball)_selectedNode != null && _cue._power == 0)
|
((Ball)_selectedNode)._selected = false;
|
||||||
|
_cue.Doff();
|
||||||
|
|
||||||
|
if (_hoveredNode != null)
|
||||||
|
{
|
||||||
|
_selectedNode = (Ball)_hoveredNode;
|
||||||
|
((Ball)_selectedNode)._selected = true;
|
||||||
|
if (_selectedNode == _cueBall)
|
||||||
|
{
|
||||||
|
_cue.Don(_cueBall.Position);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
((Ball)_selectedNode)._selected = false;
|
|
||||||
_selectedNode = null;
|
_selectedNode = null;
|
||||||
_cue.Doff();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (_hoveredNode is Ball)
|
||||||
|
{
|
||||||
|
if ((Ball)_selectedNode != _hoveredNode && _cue._power == 0)
|
||||||
|
{
|
||||||
|
if (Input.IsActionJustReleased("left_click"))
|
||||||
|
{
|
||||||
|
_selectedNode = (Ball)_hoveredNode;
|
||||||
|
((Ball)_selectedNode)._selected = true;
|
||||||
|
if (_selectedNode == _cueBall)
|
||||||
|
{
|
||||||
|
_cue.Don(((Ball)_selectedNode).Position);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_cue.Doff();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (_selectedNode is BallSprite)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (_hoveredNode is BallSprite)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (_hoveredNode is BallSprite || _selectedNode is BallSprite)
|
if (_selectedNode == _cueBallSprite)
|
||||||
{
|
{
|
||||||
if (_selectedNode != null)
|
Vector2 mousePosition = GetViewport().GetMousePosition();
|
||||||
|
_cueBallSprite.Position = mousePosition;
|
||||||
|
if (Input.IsActionJustReleased("left_click"))
|
||||||
{
|
{
|
||||||
Vector2 mousePosition = GetViewport().GetMousePosition();
|
if (_table._kitchenHovered)
|
||||||
((BallSprite)_selectedNode).Position = mousePosition;
|
|
||||||
if (Input.IsActionJustReleased("left_click"))
|
|
||||||
{
|
{
|
||||||
Ball ball = _balls.Single(b => b._rackPosition == ((BallSprite)_hoveredNode)._rackPosition);
|
PlaceBall(_cueBallSprite, mousePosition);
|
||||||
PlaceBall(ball, mousePosition);
|
|
||||||
_hoveredNode = null;
|
_hoveredNode = null;
|
||||||
_selectedNode = null;
|
_selectedNode = null;
|
||||||
if (_balls.Where(b => b._placed).ToList().Count >= _placeLimit)
|
|
||||||
{
|
|
||||||
_ready = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
else if (_hoveredNode == _cueBallSprite)
|
||||||
|
{
|
||||||
|
if (Input.IsActionJustReleased("left_click"))
|
||||||
{
|
{
|
||||||
if (Input.IsActionJustReleased("left_click"))
|
_selectedNode = _cueBallSprite;
|
||||||
{
|
|
||||||
_selectedNode = (BallSprite)_hoveredNode;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void ChangeHealth(int CHANGE)
|
public virtual void AddBall(string IMAGEPATH, Vector2I RACKPOSITION, bool ISCUE)
|
||||||
|
{
|
||||||
|
Ball newBall;
|
||||||
|
BallSprite newBallSprite;
|
||||||
|
Guid ballGuid = Guid.NewGuid();
|
||||||
|
string ballId = ballGuid.ToString();
|
||||||
|
|
||||||
|
newBall = _ballScene.Instantiate<Ball>();
|
||||||
|
newBall.SetSprite(IMAGEPATH);
|
||||||
|
newBall._rackPosition = RACKPOSITION;
|
||||||
|
newBall._isCue = ISCUE;
|
||||||
|
newBall._owner = this;
|
||||||
|
newBall._id = ballId;
|
||||||
|
newBall.OnHover += SetHovered;
|
||||||
|
newBall.OnMovement += MovingChange;
|
||||||
|
if (newBall._isCue)
|
||||||
|
{
|
||||||
|
_cueBall = newBall;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_balls.Add(newBall);
|
||||||
|
}
|
||||||
|
|
||||||
|
newBallSprite = _ballSpriteScene.Instantiate<BallSprite>();
|
||||||
|
newBallSprite.SetSprite(newBall._imagePath);
|
||||||
|
newBallSprite._rackPosition = newBall._rackPosition;
|
||||||
|
newBallSprite._owner = this;
|
||||||
|
newBallSprite._id = newBall._id;
|
||||||
|
newBallSprite.OnHover += SetHovered;
|
||||||
|
if (newBall._isCue)
|
||||||
|
{
|
||||||
|
_cueBallSprite = newBallSprite;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_ballSprites.Add(newBallSprite);
|
||||||
|
_rack.SetSprite((int)newBallSprite._rackPosition.Y, (int)newBallSprite._rackPosition.X, newBallSprite._imagePath, newBall._id);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ChangeHealth(int CHANGE)
|
||||||
{
|
{
|
||||||
_health += CHANGE;
|
_health += CHANGE;
|
||||||
_health = Math.Min(_health, _healthMax);
|
_health = Math.Min(_health, _healthMax);
|
||||||
@@ -178,54 +219,60 @@ public partial class Manager : Node
|
|||||||
_dead = true;
|
_dead = true;
|
||||||
_health = 0;
|
_health = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
GetNode<ManagerPanel>("Panel").SetValue(_health);
|
GetNode<ManagerPanel>("Panel").SetValue(_health);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BallSprite GetSpriteFromBall(Ball BALL)
|
||||||
|
{
|
||||||
|
BallSprite ballSprite = _cueBallSprite._id == BALL._id ? _cueBallSprite : _ballSprites.Single(b => b._id == BALL._id);
|
||||||
|
return ballSprite;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Ball GetBallFromSprite(BallSprite BALLSPRITE)
|
||||||
|
{
|
||||||
|
Ball ball = _cueBall._id == BALLSPRITE._id ? _cueBall : _balls.Single(b => b._id == BALLSPRITE._id);
|
||||||
|
return ball;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void MovingChange(Ball BALL, bool MOVING)
|
public void MovingChange(Ball BALL, bool MOVING)
|
||||||
{
|
|
||||||
if (MOVING)
|
|
||||||
{
|
|
||||||
_ballsMoving++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_ballsMoving--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual void PlaceBall(Ball BALL, Vector2 POSITION)
|
|
||||||
{
|
{
|
||||||
|
if (MOVING)
|
||||||
BALL._available = true;
|
|
||||||
BALL.Position = POSITION;
|
|
||||||
BALL._active = true;
|
|
||||||
BALL._placed = true;
|
|
||||||
BALL._potted = false;
|
|
||||||
BALL._active = true;
|
|
||||||
if (!GetChildren().Contains(BALL))
|
|
||||||
{
|
{
|
||||||
AddChild(BALL);
|
_ballsMoving++;
|
||||||
}
|
|
||||||
|
|
||||||
BallSprite ballSprite = _ballSprites.Single(s => s._rackPosition == BALL._rackPosition);
|
|
||||||
|
|
||||||
ballSprite._active = false;
|
|
||||||
if (GetChildren().Contains(ballSprite))
|
|
||||||
{
|
|
||||||
RemoveChild(ballSprite);
|
|
||||||
}
|
|
||||||
_ballReturn._returnCount = _balls.Where(b => b._potted).ToList().Count;
|
|
||||||
if (_ballReturn._returnCount > 0)
|
|
||||||
{
|
|
||||||
_ready = false;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_ready = true;
|
_ballsMoving--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual void PlaceBall(BallSprite BALLSSPRITE, Vector2 POSITION)
|
||||||
|
{
|
||||||
|
Ball ball = GetBallFromSprite(BALLSSPRITE);
|
||||||
|
ball._available = true;
|
||||||
|
ball.Position = POSITION;
|
||||||
|
ball._active = true;
|
||||||
|
ball._placed = true;
|
||||||
|
ball._potted = false;
|
||||||
|
ball._active = true;
|
||||||
|
|
||||||
|
if (!GetChildren().Contains(ball))
|
||||||
|
{
|
||||||
|
AddChild(ball);
|
||||||
|
}
|
||||||
|
|
||||||
|
BALLSSPRITE._active = false;
|
||||||
|
if (GetChildren().Contains(BALLSSPRITE))
|
||||||
|
{
|
||||||
|
RemoveChild(BALLSSPRITE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// _ballReturn._returnCount = _balls.Where(b => b._potted).ToList().Count;
|
||||||
|
|
||||||
|
// _ready = _ballReturn._returnCount > 0;
|
||||||
|
}
|
||||||
|
|
||||||
public virtual void PotBall(Ball BALL, Pocket POCKET)
|
public virtual void PotBall(Ball BALL, Pocket POCKET)
|
||||||
{
|
{
|
||||||
BALL.Sleeping = true;
|
BALL.Sleeping = true;
|
||||||
@@ -235,12 +282,14 @@ public partial class Manager : Node
|
|||||||
BALL._placed = false;
|
BALL._placed = false;
|
||||||
BALL._potted = true;
|
BALL._potted = true;
|
||||||
BALL._active = false;
|
BALL._active = false;
|
||||||
|
MovingChange(BALL, false);
|
||||||
|
|
||||||
if (GetChildren().Contains(BALL))
|
if (GetChildren().Contains(BALL))
|
||||||
{
|
{
|
||||||
RemoveChild(BALL);
|
RemoveChild(BALL);
|
||||||
}
|
}
|
||||||
|
|
||||||
BallSprite ballSprite = _ballSprites.Single(s => s._rackPosition == BALL._rackPosition);
|
BallSprite ballSprite = GetSpriteFromBall(BALL);
|
||||||
int pottedCount = _ballReturn._returnCount;
|
int pottedCount = _ballReturn._returnCount;
|
||||||
ballSprite.Position = new Vector2(_ballReturn.GlobalPosition.X + _ballReturn.Size.X / 2, _ballReturn.GlobalPosition.Y + 50 * (pottedCount + 1));
|
ballSprite.Position = new Vector2(_ballReturn.GlobalPosition.X + _ballReturn.Size.X / 2, _ballReturn.GlobalPosition.Y + 50 * (pottedCount + 1));
|
||||||
ballSprite._active = true;
|
ballSprite._active = true;
|
||||||
@@ -248,49 +297,45 @@ public partial class Manager : Node
|
|||||||
{
|
{
|
||||||
CallDeferred(MethodName.AddChild, ballSprite);
|
CallDeferred(MethodName.AddChild, ballSprite);
|
||||||
}
|
}
|
||||||
_ballReturn._returnCount = _balls.Where(b => b._potted).ToList().Count;
|
|
||||||
if (_ballReturn._returnCount > 0)
|
// _ballReturn._returnCount = _balls.Where(b => b._potted).ToList().Count;
|
||||||
{
|
|
||||||
_ready = false;
|
// _ready = _ballReturn._returnCount > 0;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_ready = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetHovered(Node NODE, bool HOVERED)
|
public void SetHovered(Node NODE, bool HOVERED)
|
||||||
{
|
{
|
||||||
if (HOVERED)
|
if (HOVERED)
|
||||||
{
|
{
|
||||||
if (_hoveredNode == null)
|
if (_hoveredNode == null)
|
||||||
{
|
{
|
||||||
if (NODE is Ball)
|
if (NODE is Ball)
|
||||||
{
|
{
|
||||||
_hoveredNode = (Ball)NODE;
|
_hoveredNode = (Ball)NODE;
|
||||||
}
|
}
|
||||||
else if (NODE is BallSprite)
|
else if (NODE is BallSprite)
|
||||||
{
|
{
|
||||||
_hoveredNode = (BallSprite)NODE;
|
_hoveredNode = (BallSprite)NODE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_hoveredNode = null;
|
_hoveredNode = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetRack()
|
// public void SetRack()
|
||||||
{
|
// {
|
||||||
for (int i = 0; i < _ballSprites.Count; i++)
|
// for (int i = 0; i < _ballSprites.Count; i++)
|
||||||
{
|
// {
|
||||||
if ((int)_ballSprites[i]._rackPosition.Y > 0 && (int)_ballSprites[i]._rackPosition.X > 0)
|
// if ((int)_ballSprites[i]._rackPosition.Y > 0 && (int)_ballSprites[i]._rackPosition.X > 0)
|
||||||
{
|
// {
|
||||||
_rack.SetSprite((int)_ballSprites[i]._rackPosition.Y, (int)_ballSprites[i]._rackPosition.X, _ballSprites[i]._imagePath);
|
// _rack.SetSprite((int)_ballSprites[i]._rackPosition.Y, (int)_ballSprites[i]._rackPosition.X, _ballSprites[i]._imagePath);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
public void SetSprite(string PATH)
|
public void SetSprite(string PATH)
|
||||||
{
|
{
|
||||||
@@ -299,31 +344,34 @@ public partial class Manager : Node
|
|||||||
|
|
||||||
public virtual void Start(Table TABLE)
|
public virtual void Start(Table TABLE)
|
||||||
{
|
{
|
||||||
|
_table = TABLE;
|
||||||
int diameter = 36;
|
int diameter = 36;
|
||||||
|
|
||||||
int rows = _balls.Max(b => b._rackPosition.Y);
|
int rows = _balls.Max(b => b._rackPosition.Y);
|
||||||
|
|
||||||
Ball rackBall;
|
BallSprite rackBallSprite;
|
||||||
int r, c;
|
int r, c;
|
||||||
for (int i = 0; i < _balls.Count; i++)
|
for (int i = 0; i < _ballSprites.Count; i++)
|
||||||
{
|
{
|
||||||
rackBall = _balls[i];
|
rackBallSprite = _ballSprites[i];
|
||||||
c = rackBall._rackPosition.X;
|
c = rackBallSprite._rackPosition.X;
|
||||||
r = Math.Abs(rackBall._rackPosition.Y - rows);
|
r = Math.Abs(rackBallSprite._rackPosition.Y - rows);
|
||||||
if (c > 0)
|
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));
|
Vector2 position = new Vector2(TABLE.GlobalPosition.X - (r * (diameter / 2)) + ((c - 1) * diameter), TABLE.GlobalPosition.Y - TABLE.Texture.GetSize().Y / 4 - (r * diameter));
|
||||||
|
PlaceBall(rackBallSprite, position);
|
||||||
PlaceBall(rackBall, position);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TABLE.OnBallPotted += PotBall;
|
TABLE.OnBallPotted += PotBall;
|
||||||
|
|
||||||
// PLAYER.PotBall();
|
// PLAYER.PotBall();
|
||||||
SetRack();
|
// SetRack();
|
||||||
PotBall(_balls[0], null);
|
|
||||||
|
_kitchen = _table.GetNode<Area2D>("Kitchen");
|
||||||
|
_cueBallSprite.Position = _kitchen.GlobalPosition;
|
||||||
|
_cueBallSprite._active = true;
|
||||||
|
AddChild(_cueBallSprite);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnCueShoot(Vector2 IMPULSE)
|
private void OnCueShoot(Vector2 IMPULSE)
|
||||||
|
|||||||
@@ -3,8 +3,10 @@ using System;
|
|||||||
|
|
||||||
public partial class Rack : Sprite2D
|
public partial class Rack : Sprite2D
|
||||||
{
|
{
|
||||||
public void SetSprite(int ROW, int COLUMN, string IMAGEPATH)
|
public void SetSprite(int ROW, int COLUMN, string IMAGEPATH, string ID)
|
||||||
{
|
{
|
||||||
GetNode<Node2D>("R" + ROW).GetNode<BallSprite>("C" + COLUMN).SetSprite(IMAGEPATH);
|
BallSprite ballSprite = GetNode<Node2D>("R" + ROW).GetNode<BallSprite>("C" + COLUMN);
|
||||||
|
ballSprite._id = ID;
|
||||||
|
ballSprite.SetSprite(IMAGEPATH);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ public partial class Table : Sprite2D
|
|||||||
{
|
{
|
||||||
[Signal]
|
[Signal]
|
||||||
public delegate void OnBallPottedEventHandler(Ball THIS, Pocket POCKET);
|
public delegate void OnBallPottedEventHandler(Ball THIS, Pocket POCKET);
|
||||||
|
public bool _kitchenHovered;
|
||||||
List<Pocket> _pockets;
|
List<Pocket> _pockets;
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
@@ -21,6 +22,9 @@ public partial class Table : Sprite2D
|
|||||||
{
|
{
|
||||||
_pockets[i].OnBallPotted += BallPotted;
|
_pockets[i].OnBallPotted += BallPotted;
|
||||||
}
|
}
|
||||||
|
GetNode<Area2D>("Kitchen").MouseEntered += KitchenHovered;
|
||||||
|
GetNode<Area2D>("Kitchen").MouseExited += KitchenUnhovered;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void BallPotted(Node NODE, Pocket POCKET)
|
public void BallPotted(Node NODE, Pocket POCKET)
|
||||||
@@ -30,4 +34,14 @@ public partial class Table : Sprite2D
|
|||||||
EmitSignal(SignalName.OnBallPotted, (Ball)NODE, POCKET);
|
EmitSignal(SignalName.OnBallPotted, (Ball)NODE, POCKET);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void KitchenHovered()
|
||||||
|
{
|
||||||
|
_kitchenHovered = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void KitchenUnhovered()
|
||||||
|
{
|
||||||
|
_kitchenHovered = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user