8-2-2025 @ 3:51 AM

This commit is contained in:
2025-08-02 03:51:34 -04:00
parent a8373726f9
commit 50e4f8fcb5
12 changed files with 348 additions and 86 deletions

View File

@@ -15,9 +15,10 @@ public partial class Ball : RigidBody2D
[Signal]
public delegate void OnStopEventHandler();
public int _ownerId;
public bool _active = false, _placed = false, _potted = false, _available = false, _hovered = false, _selected = false, _aimed = false, _launched = false, _moving = false, _isCue = false;
public Vector2I _rackPosition = new Vector2I(0, 0);
public float _moveThreshold = 5.0f;
public Vector2 _newPosition = new Vector2(-1, -1);
public override void _Process(double DELTA_)
{

View File

@@ -1,12 +1,15 @@
using Godot;
using System;
public partial class PlaceholderBall : Area2D
public partial class BallSprite : Area2D
{
public bool _active = false, _hovered = false, _held = false;
public int _ownerId;
public string _imagePath;
public Vector2 _rackPosition = new Vector2(0, 0);
public void SetSprite(string PATH)
{
_imagePath = PATH;
GetNode<Sprite2D>("Image").Texture = GD.Load<Texture2D>(PATH);
}

View File

@@ -5,7 +5,6 @@ using System.Linq;
public partial class Battle : Node
{
public bool _current;
public Vector2 _startPosition = new Vector2(890, 340);
public Manager _turn;
@@ -73,51 +72,38 @@ public partial class Battle : Node
Globals.Instance._currentBattle = this;
// _player.Start();
int count = 1;
int columns = 0;
int diameter = 36;
Table table = GetNode<Table>("Table");
Ball eightBall = COMPUTER._balls[0];
List<Ball> computerBalls = COMPUTER._balls.Values.ToList();
computerBalls.RemoveAt(0);
Ball cueBall = PLAYER._balls[0];
List<Ball> playerBalls = PLAYER._balls.Values.ToList();
playerBalls.RemoveAt(0);
List<Ball> randomRack = new();
randomRack.AddRange(computerBalls);
randomRack.AddRange(playerBalls);
int n = randomRack.Count;
while (n > 1) {
n--;
int k = Globals.Instance._random.Next(n + 1);
Ball value = randomRack[k];
randomRack[k] = randomRack[n];
randomRack[n] = value;
}
randomRack.Insert(4, eightBall);
randomRack.Insert(0, cueBall);
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;
for (int i = 0; i < 5; i++)
int r, c;
for (int i = 0; i < rack.Count; i++)
{
for (int j = 0; j <= columns; j++)
rackBall = rack[i];
c = rackBall._rackPosition.X;
r = Math.Abs(rackBall._rackPosition.Y - rows);
if (c > 0)
{
Vector2 position = new Vector2(table.GlobalPosition.X - (i * (diameter / 2)) + (j * (diameter)), table.GlobalPosition.Y - table.Texture.GetSize().Y / 4 - (i * diameter));
rackBall = randomRack[count];
if (PLAYER._balls.ContainsValue(rackBall))
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._balls.ContainsValue(rackBall))
if (COMPUTER._id == rackBall._ownerId)
{
COMPUTER.PlaceBall(rackBall, position);
}
count += 1;
}
columns += 1;
}
// PLAYER.PotBall();
}
}

View File

@@ -1,20 +1,40 @@
using Godot;
using System;
using System.Collections.Generic;
using System.Linq;
public partial class ComputerManager : Manager
{
public int _id = 1;
public List<Vector2I> _initialRackPositions =
[
new Vector2I(2, 3),
new Vector2I(2, 1),
new Vector2I(5, 1),
new Vector2I(1, 2),
new Vector2I(3, 2),
new Vector2I(3, 3),
new Vector2I(1, 4),
new Vector2I(1, 5)
];
public override void _Ready()
{
Ball newBall;
// newBall = _ballScene.Instantiate<Ball>();
// newBall.SetSprite("res://art/cue_ball.png");
// _balls.Add(0, newBall);
BallSprite newBallSprite;
for (int i = 8; i <= 15; i++)
{
newBall = _ballScene.Instantiate<Ball>();
newBall.SetSprite("res://art/ball_" + i + ".png");
_balls.Add(i - 8, newBall);
newBall._rackPosition = _initialRackPositions[i - 8];
newBall._ownerId = _id;
_balls.Add(newBall);
newBallSprite = _ballSpriteScene.Instantiate<BallSprite>();
newBallSprite.SetSprite("res://art/ball_" + i + ".png");
newBallSprite._rackPosition = _initialRackPositions[i - 8];
newBallSprite._ownerId = _id;
_ballSprites.Add(newBallSprite);
}
}

View File

@@ -10,15 +10,16 @@ public partial class Manager : Node
public int _health = 10, _healthMax, _placeLimit = 8;
public string _imagePath;
public Cue _cue;
public Dictionary<int, Worker> _workers = new();
public Dictionary<int, Ball> _balls = new();
public Dictionary<int, PlaceholderBall> _placeholderBalls = new();
public List<Worker> _workers = new();
public List<Ball> _balls = new();
public List<BallSprite> _ballSprites = new();
public Ball _selectedBall = null;
public CollisionShape2D _startArea;
// PACKED SCENES
public PackedScene _ballScene = ResourceLoader.Load<PackedScene>("res://Gameplay/ball.tscn");
public PackedScene _placeholdeBallScene = ResourceLoader.Load<PackedScene>("res://Gameplay/ball.tscn");
public PackedScene _ballSpriteScene = ResourceLoader.Load<PackedScene>("res://Gameplay/ball_sprite.tscn");
public PackedScene _cueScene = ResourceLoader.Load<PackedScene>("res://Gameplay/cue.tscn");
public PackedScene _workerScene = ResourceLoader.Load<PackedScene>("res://Gameplay/worker.tscn");
@@ -41,7 +42,7 @@ public partial class Manager : Node
}
}
public void PlaceBall(Ball BALL, Vector2 POSITION)
public virtual void PlaceBall(Ball BALL, Vector2 POSITION)
{
BALL._available = true;
@@ -50,13 +51,13 @@ public partial class Manager : Node
BALL._placed = true;
BALL._potted = false;
BALL._active = true;
AddChild(BALL);
// _placeholderBalls[BALLNUMBER]._active = false;
// RemoveChild(_placeholderBalls[BALLNUMBER]);
if (!GetChildren().Contains(BALL))
{
AddChild(BALL);
}
}
public void PotBall(Ball BALL)
public virtual void PotBall(Ball BALL)
{
BALL.Sleeping = true;
BALL._available = false;
@@ -65,10 +66,10 @@ public partial class Manager : Node
BALL._placed = false;
BALL._potted = true;
BALL._active = false;
RemoveChild(BALL);
// _placeholderBalls[BALLNUMBER]._active = true;
// AddChild(_placeholderBalls[BALLNUMBER]);
if (GetChildren().Contains(BALL))
{
RemoveChild(BALL);
}
}
public void SetSprite(string PATH)

View File

@@ -4,6 +4,7 @@ using System;
public partial class ManagerPanel : Panel
{
public bool _hovered = false;
public int _returnCount = 0;
public void SetPosition(Vector2 POSITION)
{

View File

@@ -5,9 +5,21 @@ using System.Linq;
public partial class PlayerManager : Manager
{
public int _id = 0;
public List<Vector2I> _initialRackPositions =
[
new Vector2I(0, 1),
new Vector2I(1, 1),
new Vector2I(3, 1),
new Vector2I(4, 1),
new Vector2I(2, 2),
new Vector2I(4, 2),
new Vector2I(1, 3),
new Vector2I(2, 4)
];
public Ball _hoveredBall = null;
public PlaceholderBall _hoveredPlaceholderBall = null;
public PlaceholderBall _heldPlaceholderBall = null;
public BallSprite _hoveredBallSprite = null;
public BallSprite _heldBallSprite = null;
public Worker _hoveredWorker = null;
public ManagerPanel _managerPanel = null;
public Panel _ballReturn = null;
@@ -21,26 +33,43 @@ public partial class PlayerManager : Manager
_managerPanel.SetSprite(_imagePath);
_managerPanel.SetValue(_health);
_managerPanel.SetMax(_healthMax);
_ballReturn = _managerPanel.GetNode<Panel>("BallReturn");
GD.Print(_ballReturn.GlobalPosition);
Ball newBall;
newBall = _ballScene.Instantiate<Ball>();
newBall.SetSprite("res://art/cue_ball.png");
_balls.Add(0, newBall);
newBall._rackPosition = _initialRackPositions[0];
newBall._ownerId = _id;
_balls.Add(newBall);
BallSprite newBallSprite;
newBallSprite = _ballSpriteScene.Instantiate<BallSprite>();
newBallSprite.SetSprite("res://art/cue_ball.png");
newBallSprite._rackPosition = _initialRackPositions[0];
newBallSprite._ownerId = _id;
_ballSprites.Add(newBallSprite);
for (int i = 1; i <= 7; i++)
{
newBall = _ballScene.Instantiate<Ball>();
newBall.SetSprite("res://art/ball_" + i + ".png");
_balls.Add(i, newBall);
newBall._rackPosition = _initialRackPositions[i];
newBall._ownerId = _id;
_balls.Add(newBall);
newBallSprite = _ballSpriteScene.Instantiate<BallSprite>();
newBallSprite.SetSprite("res://art/ball_" + i + ".png");
newBallSprite._rackPosition = _initialRackPositions[i];
newBallSprite._ownerId = _id;
_ballSprites.Add(newBallSprite);
}
}
public override void _Process(double DELTA_)
{
// Panel ballReturn = GetNode<ManagerPanel>("Panel").GetNode<Panel>("BallReturn");
// WORKER.ChangeBallPosition(new Vector2(ballReturn.GlobalPosition.X + ballReturn.Size.X / 2, ballReturn.GlobalPosition.Y + 50));
if (_ready)
{
if ((_selectedBall == null || _selectedBall != _hoveredBall) && (_hoveredBall?._available ?? false))
@@ -70,16 +99,16 @@ public partial class PlayerManager : Manager
}
else
{
if (_heldPlaceholderBall != null)
if (_heldBallSprite != null)
{
Vector2 mousePosition = GetViewport().GetMousePosition();
_heldPlaceholderBall.Position = mousePosition;
_heldBallSprite.Position = mousePosition;
if (Input.IsActionJustReleased("left_click"))
{
int index = _placeholderBalls.Single(p => p.Value == _heldPlaceholderBall).Key;
PlaceBall(_balls[index], mousePosition);
_heldPlaceholderBall = null;
if (_balls.Where(b => b.Value._placed).ToList().Count >= _placeLimit)
Ball ball = _balls.Single(b => b._rackPosition == _heldBallSprite._rackPosition);
PlaceBall(ball, mousePosition);
_heldBallSprite = null;
if (_balls.Where(b => b._placed).ToList().Count >= _placeLimit)
{
_ready = true;
}
@@ -89,7 +118,7 @@ public partial class PlayerManager : Manager
{
if (Input.IsActionJustReleased("left_click"))
{
_heldPlaceholderBall = _hoveredPlaceholderBall;
_heldBallSprite = _hoveredBallSprite;
}
}
}
@@ -104,11 +133,14 @@ public partial class PlayerManager : Manager
public override void Start()
{
for (int i = 0; i < _placeholderBalls.Count; i++)
{
_placeholderBalls[i].Position = new Vector2(_ballReturn.GlobalPosition.X + _ballReturn.Size.X / 2, _ballReturn.GlobalPosition.Y + 50 * (i + 1));
_placeholderBalls[i].AddChild(_placeholderBalls[i]);
}
PotBall(_balls[0]);
// for (int i = 0; i < _ballSprites.Count; i++)
// {
// GD.Print(_ballSprites[i]._rackPosition);
// // _ballSprites[i].Position = new Vector2(_ballReturn.GlobalPosition.X + _ballReturn.Size.X / 2, _ballReturn.GlobalPosition.Y + 50 * (i + 1));
// // _ballSprites[i].AddChild(_ballSprites[i]);
// }
}
public void HoverBall(Ball BALL, bool HOVERED)
@@ -129,4 +161,37 @@ public partial class PlayerManager : Manager
}
}
public override void PlaceBall(Ball BALL, Vector2 POSITION)
{
base.PlaceBall(BALL, POSITION);
BallSprite ballSprite = _ballSprites.Single(s => s._rackPosition == BALL._rackPosition);
ballSprite._active = false;
if (GetChildren().Contains(ballSprite))
{
RemoveChild(ballSprite);
}
_managerPanel._returnCount = _balls.Where(b=>b._potted).ToList().Count;
}
public override void PotBall(Ball BALL)
{
base.PotBall(BALL);
BallSprite ballSprite = _ballSprites.Single(s => s._rackPosition == BALL._rackPosition);
int pottedCount = _managerPanel._returnCount;
GD.Print(_ballReturn.GlobalPosition);
ballSprite.Position = new Vector2(_ballReturn.GlobalPosition.X + _ballReturn.Size.X / 2, _ballReturn.GlobalPosition.Y + 50 * (pottedCount + 1));
ballSprite._active = true;
if (!GetChildren().Contains(ballSprite))
{
AddChild(ballSprite);
GD.Print(ballSprite.Position);
}
_managerPanel._returnCount = _balls.Where(b=>b._potted).ToList().Count;
}
}

View File

@@ -1,11 +1,11 @@
[gd_scene load_steps=3 format=3 uid="uid://cxvrswwjwxgxj"]
[gd_scene load_steps=3 format=3 uid="uid://tmer0me1qpaa"]
[ext_resource type="Script" uid="uid://c2rt5f831l1l1" path="res://Gameplay/PlaceholderBall.cs" id="1_bwons"]
[ext_resource type="Script" uid="uid://c2rt5f831l1l1" path="res://Gameplay/BallSprite.cs" id="1_bwons"]
[sub_resource type="CircleShape2D" id="CircleShape2D_vjx3o"]
radius = 18.0
[node name="BallPlaceholder" type="Area2D"]
[node name="BallSprite" type="Area2D"]
z_index = 2
script = ExtResource("1_bwons")

View File

@@ -1,6 +1,8 @@
[gd_scene load_steps=7 format=3 uid="uid://8kv00jc35dma"]
[gd_scene load_steps=9 format=3 uid="uid://8kv00jc35dma"]
[ext_resource type="Script" uid="uid://c4ekvurl6q7jn" path="res://Gameplay/ManagerPanel.cs" id="1_8n1hc"]
[ext_resource type="Texture2D" uid="uid://cgnwfc387vche" path="res://art/rack.png" id="2_sx67n"]
[ext_resource type="Texture2D" uid="uid://ck4ta2f0ofjs0" path="res://art/cue_ball.png" id="3_2t778"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_e1ofl"]
bg_color = Color(1, 1, 1, 1)
@@ -126,7 +128,7 @@ offset_bottom = 800.0
mouse_filter = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_j2own")
[node name="Desk" type="Panel" parent="."]
[node name="Team" type="Panel" parent="."]
layout_mode = 0
offset_top = 150.0
offset_right = 450.0
@@ -134,17 +136,166 @@ offset_bottom = 800.0
mouse_filter = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_j2own")
[node name="DeskOrnament1" type="Panel" parent="Desk"]
[node name="T1" type="Panel" parent="Team"]
layout_mode = 0
offset_left = 50.0
offset_top = 50.0
offset_right = 100.0
offset_bottom = 100.0
offset_left = 13.0
offset_top = 25.0
offset_right = 63.0
offset_bottom = 75.0
theme_override_styles/panel = SubResource("StyleBoxFlat_058dj")
[node name="Sprite2D" type="Sprite2D" parent="Desk/DeskOrnament1"]
position = Vector2(50, 50)
scale = Vector2(1.5, 1.5)
[node name="Image" type="Sprite2D" parent="Team/T1"]
position = Vector2(25, 25)
[node name="T2" type="Panel" parent="Team"]
offset_left = 88.0
offset_top = 25.0
offset_right = 138.0
offset_bottom = 75.0
theme_override_styles/panel = SubResource("StyleBoxFlat_058dj")
[node name="Image" type="Sprite2D" parent="Team/T2"]
position = Vector2(25, 25)
[node name="T3" type="Panel" parent="Team"]
offset_left = 163.0
offset_top = 25.0
offset_right = 213.0
offset_bottom = 75.0
theme_override_styles/panel = SubResource("StyleBoxFlat_058dj")
[node name="Image" type="Sprite2D" parent="Team/T3"]
position = Vector2(25, 25)
[node name="T4" type="Panel" parent="Team"]
offset_left = 238.0
offset_top = 25.0
offset_right = 288.0
offset_bottom = 75.0
theme_override_styles/panel = SubResource("StyleBoxFlat_058dj")
[node name="Image" type="Sprite2D" parent="Team/T4"]
position = Vector2(25, 25)
[node name="T5" type="Panel" parent="Team"]
offset_left = 13.0
offset_top = 100.0
offset_right = 63.0
offset_bottom = 150.0
theme_override_styles/panel = SubResource("StyleBoxFlat_058dj")
[node name="Image" type="Sprite2D" parent="Team/T5"]
position = Vector2(25, 25)
[node name="T6" type="Panel" parent="Team"]
offset_left = 88.0
offset_top = 100.0
offset_right = 138.0
offset_bottom = 150.0
theme_override_styles/panel = SubResource("StyleBoxFlat_058dj")
[node name="Image" type="Sprite2D" parent="Team/T6"]
position = Vector2(25, 25)
[node name="T7" type="Panel" parent="Team"]
offset_left = 163.0
offset_top = 100.0
offset_right = 213.0
offset_bottom = 150.0
theme_override_styles/panel = SubResource("StyleBoxFlat_058dj")
[node name="Image" type="Sprite2D" parent="Team/T7"]
position = Vector2(25, 25)
[node name="T8" type="Panel" parent="Team"]
offset_left = 238.0
offset_top = 100.0
offset_right = 288.0
offset_bottom = 150.0
theme_override_styles/panel = SubResource("StyleBoxFlat_058dj")
[node name="Image" type="Sprite2D" parent="Team/T8"]
position = Vector2(25, 25)
[node name="Rack" type="Sprite2D" parent="."]
position = Vector2(313, 175)
texture = ExtResource("2_sx67n")
centered = false
[node name="B15" type="Sprite2D" parent="Rack"]
position = Vector2(62.5, 90)
scale = Vector2(0.5, 0.5)
texture = ExtResource("3_2t778")
[node name="B14" type="Sprite2D" parent="Rack"]
position = Vector2(73.125, 71)
scale = Vector2(0.5, 0.5)
texture = ExtResource("3_2t778")
[node name="B13" type="Sprite2D" parent="Rack"]
position = Vector2(51.875, 71)
scale = Vector2(0.5, 0.5)
texture = ExtResource("3_2t778")
[node name="B12" type="Sprite2D" parent="Rack"]
position = Vector2(83.75, 52)
scale = Vector2(0.5, 0.5)
texture = ExtResource("3_2t778")
[node name="B11" type="Sprite2D" parent="Rack"]
position = Vector2(62.5, 52)
scale = Vector2(0.5, 0.5)
texture = ExtResource("3_2t778")
[node name="B10" type="Sprite2D" parent="Rack"]
position = Vector2(41.25, 52)
scale = Vector2(0.5, 0.5)
texture = ExtResource("3_2t778")
[node name="B9" type="Sprite2D" parent="Rack"]
position = Vector2(94.875, 33)
scale = Vector2(0.5, 0.5)
texture = ExtResource("3_2t778")
[node name="B8" type="Sprite2D" parent="Rack"]
position = Vector2(73.125, 33)
scale = Vector2(0.5, 0.5)
texture = ExtResource("3_2t778")
[node name="B7" type="Sprite2D" parent="Rack"]
position = Vector2(51.875, 33)
scale = Vector2(0.5, 0.5)
texture = ExtResource("3_2t778")
[node name="B6" type="Sprite2D" parent="Rack"]
position = Vector2(30.125, 33)
scale = Vector2(0.5, 0.5)
texture = ExtResource("3_2t778")
[node name="B5" type="Sprite2D" parent="Rack"]
position = Vector2(105, 14)
scale = Vector2(0.5, 0.5)
texture = ExtResource("3_2t778")
[node name="B4" type="Sprite2D" parent="Rack"]
position = Vector2(83.75, 14)
scale = Vector2(0.5, 0.5)
texture = ExtResource("3_2t778")
[node name="B3" type="Sprite2D" parent="Rack"]
position = Vector2(62.5, 14)
scale = Vector2(0.5, 0.5)
texture = ExtResource("3_2t778")
[node name="B2" type="Sprite2D" parent="Rack"]
position = Vector2(41.25, 14)
scale = Vector2(0.5, 0.5)
texture = ExtResource("3_2t778")
[node name="B1" type="Sprite2D" parent="Rack"]
position = Vector2(20, 14)
scale = Vector2(0.5, 0.5)
texture = ExtResource("3_2t778")
[connection signal="mouse_entered" from="." to="." method="OnMouseEntered"]
[connection signal="mouse_exited" from="." to="." method="OnMouseExited"]

BIN
art/rack.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 998 B

34
art/rack.png.import Normal file
View File

@@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://cgnwfc387vche"
path="res://.godot/imported/rack.png-d2927e002816364016250342f4c97b50.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://art/rack.png"
dest_files=["res://.godot/imported/rack.png-d2927e002816364016250342f4c97b50.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1