7-14-25 1:27PM

This commit is contained in:
2025-07-14 13:27:07 -04:00
parent 0a5f6be26d
commit be4a1fc794
16 changed files with 291 additions and 106 deletions

89
Gameplay/Actor.cs Normal file
View File

@@ -0,0 +1,89 @@
using Godot;
using System;
using System.Collections.Generic;
using System.Linq;
public partial class Actor : Node
{
public bool _available, _hovered, _selected;
public List<Cue> _cues = new();
public Cue _activeCue;
public List<Ball> _balls = new();
public Ball _activeBall;
public static Actor Create(string SCENENAME)
{
PackedScene scene = ResourceLoader.Load<PackedScene>("res://Gameplay/"+SCENENAME+".tscn");
Actor newActor = scene.Instantiate<Actor>();
return newActor;
}
public override void _Ready()
{
Ball newBall = Ball.Create("ball", 0);
AddChild(newBall);
_balls.Add(newBall);
if (_activeBall == null)
{
_activeBall = _balls[0];
}
Cue newCue = Cue.Create("cue");
AddChild(newCue);
_cues.Add(newCue);
if (_activeCue == null)
{
_activeCue = _cues[0];
_activeCue.Shoot += OnCueShoot;
}
}
public override void _Process(double DELTA_)
{
if (!_activeBall._placed)
{
Vector2 mousePosition = GetViewport().GetMousePosition();
_activeBall.Position = mousePosition;
if (Input.IsActionJustReleased("left_click"))
{
_activeBall.Place(mousePosition);
}
}
else
{
_hovered = _activeBall._hovered;
if (_activeCue._shown)
{
if (!_activeBall._available)
{
_activeCue.HideCue();
}
}
else // (!_activeCue._shown)
{
if (_activeBall._available)
{
_activeCue.ShowCue(_activeBall);
}
}
}
}
//public void ResetCueBall()
//{
//_cueBall = Ball.Create("ball", 0, _startPosition);
//_cueBall.SetName("CueBall");
//AddChild(_cueBall);
//Texture2D image = GD.Load<Texture2D>("res://art/cue_ball.png");
//_cueBall.GetNode<Sprite2D>("Image").Texture = image;
//_cueBall._placed = true;
//_balls = GetTree().GetNodesInGroup("balls").Select(b => (Ball)b).ToList<Ball>();
//}
private void OnCueShoot(Vector2 IMPULSE)
{
_activeBall.ApplyCentralImpulse(IMPULSE);
}
}

1
Gameplay/Actor.cs.uid Normal file
View File

@@ -0,0 +1 @@
uid://b4mr2vn8mw6r4

View File

@@ -3,57 +3,61 @@ using System;
public partial class Ball : RigidBody2D public partial class Ball : RigidBody2D
{ {
public bool _placed, _potted, _available, _hovered, _selected, _aimed, _moving;
public bool _placed, _available, _hovered, _selected, _aimed, _moving;
public float _moveThreshold = 5.0f; public float _moveThreshold = 5.0f;
public static Ball Create(int number, Vector2 position) public static Ball Create(string SCENENAME, int NUMBER)
{ {
PackedScene scene = ResourceLoader.Load<PackedScene>("res://Gameplay/ball.tscn"); PackedScene scene = ResourceLoader.Load<PackedScene>("res://Gameplay/"+SCENENAME+".tscn");
Ball newBall = scene.Instantiate<Ball>(); Ball newBall = scene.Instantiate<Ball>();
string fileName; string fileName;
if (number == 0) if (NUMBER == 0)
{ {
fileName = "res://art/cue_ball.png"; fileName = "res://art/cue_ball.png";
} }
else else
{ {
fileName = "res://art/ball_"+number+".png"; fileName = "res://art/ball_"+NUMBER+".png";
} }
Texture2D image = GD.Load<Texture2D>(fileName); Texture2D image = GD.Load<Texture2D>(fileName);
newBall.GetNode<Sprite2D>("Image").Texture = image; newBall.GetNode<Sprite2D>("Image").Texture = image;
newBall.Position = position;
return newBall; return newBall;
} }
public override void _Ready() public override void _Ready()
{ {
SetProcess(false);
_placed = false; _placed = false;
_available = false;
_hovered = false; _hovered = false;
_selected = false; _selected = false;
_aimed = false; _aimed = false;
_moving = false; _moving = false;
_available = false;
} }
public override void _Process(double delta_) public override void _Process(double DELTA_)
{ {
_moving = false;
if (LinearVelocity.Length() > 0 && LinearVelocity.Length() < _moveThreshold) if (LinearVelocity.Length() > 0 && LinearVelocity.Length() < _moveThreshold)
{ {
Sleeping = true; Sleeping = true;
if (_moving)
{
_moving = false;
}
} }
else if (LinearVelocity.Length() >= _moveThreshold) else if (LinearVelocity.Length() >= _moveThreshold)
{ {
_moving = true; if (!_moving)
{
_moving = true;
}
} }
if (!((Battle)GetParent()).CheckMovement()) if (!Globals.Instance._anyMovement)
{ {
if (!_available) if (!_available)
{ {
_available = true; _available = true;
GetParent().GetNode<Cue>("Cue").ShowCue();
} }
} }
else else
@@ -61,9 +65,26 @@ public partial class Ball : RigidBody2D
if (_available) if (_available)
{ {
_available = false; _available = false;
GetParent().GetNode<Cue>("Cue").HideCue();
} }
} }
}
public void Place(Vector2 POSITION)
{
_placed = true;
Position = POSITION;
SetProcess(true);
}
private void OnMouseEntered()
{
_hovered = true;
}
private void OnMouseExited()
{
_hovered = false;
} }
} }

View File

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

View File

@@ -4,18 +4,28 @@ using System;
public partial class Cue : Sprite2D public partial class Cue : Sprite2D
{ {
[Signal] [Signal]
public delegate void ShootEventHandler(Vector2 impulse); public delegate void ShootEventHandler(Vector2 IMPULSE);
public bool _shown;
public int _powerDirection = 1; public int _powerDirection = 1;
public float _power = 0.0f, _maxPower = 8.0f; public float _power = 0.0f, _maxPower = 8.0f;
public ProgressBar _progressBar; public ProgressBar _progressBar;
public override void _Ready() public static Cue Create(string SCENENAME)
{ {
_progressBar = GetParent().GetNode<ProgressBar>("PowerBar"); PackedScene scene = ResourceLoader.Load<PackedScene>("res://Gameplay/"+SCENENAME+".tscn");
Cue newCue = scene.Instantiate<Cue>();
Texture2D image = GD.Load<Texture2D>("res://art/cue.png");
newCue.Texture = image;
return newCue;
} }
public override void _Process(double delta_) public override void _Ready()
{
//_progressBar = GetParent().GetNode<ProgressBar>("PowerBar");
}
public override void _Process(double DELTA_)
{ {
Vector2 mousePosition = GetViewport().GetMousePosition(); Vector2 mousePosition = GetViewport().GetMousePosition();
LookAt(mousePosition); LookAt(mousePosition);
@@ -46,19 +56,20 @@ public partial class Cue : Sprite2D
public void HideCue() public void HideCue()
{ {
_shown = false;
SetProcess(false); SetProcess(false);
Hide(); Hide();
_progressBar.Hide(); //_progressBar.Hide();
} }
public void ShowCue() public void ShowCue(Ball CUEBALL)
{ {
Ball cueBall = GetParent().GetNode<Ball>("CueBall"); _shown = true;
SetProcess(true); SetProcess(true);
Position = cueBall.Position; Position = CUEBALL.Position;
_progressBar.Position = new Vector2(cueBall.Position.X - _progressBar.Size.X / 2, cueBall.Position.Y + _progressBar.Size.Y / 2); //_progressBar.Position = new Vector2(CUEBALL.Position.X - _progressBar.Size.X / 2, CUEBALL.Position.Y + _progressBar.Size.Y / 2);
Show(); Show();
_progressBar.Show(); //_progressBar.Show();
} }
} }

15
Gameplay/Globals.cs Normal file
View File

@@ -0,0 +1,15 @@
using Godot;
using System;
public partial class Globals : Node
{
public static Globals Instance;
public bool _anyMovement;
public Battle _currentBattle;
public override void _Ready()
{
Instance = this;
}
}

1
Gameplay/Globals.cs.uid Normal file
View File

@@ -0,0 +1 @@
uid://brjvplo1avnoq

23
Gameplay/Player.cs Normal file
View File

@@ -0,0 +1,23 @@
using Godot;
using System;
public partial class Player : Node
{
public bool _available, _selected;
public Actor _actor;
public Battle _currentBattle;
public override void _Ready()
{
_actor = Actor.Create("actor");
AddChild(_actor);
}
public override void _Process(double DELTA_)
{
}
}

1
Gameplay/Player.cs.uid Normal file
View File

@@ -0,0 +1 @@
uid://b66ysicyh0m1s

View File

@@ -8,8 +8,8 @@ public partial class PowerBar : ProgressBar
} }
public override void _Process(double delta) public override void _Process(double DELTA_)
{ {
Value = GetParent().GetNode<Cue>("Cue")._power / GetParent().GetNode<Cue>("Cue")._maxPower * 100; Value = GetParent().GetNode<Actor>("Actor").GetNode<Cue>("Cue")._power / GetParent().GetNode<Actor>("Actor").GetNode<Cue>("Cue")._maxPower * 100;
} }
} }

6
Gameplay/actor.tscn Normal file
View File

@@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://72tgm5p8d32r"]
[ext_resource type="Script" uid="uid://b4mr2vn8mw6r4" path="res://Gameplay/Actor.cs" id="1_hr3hk"]
[node name="Actor" type="Node"]
script = ExtResource("1_hr3hk")

View File

@@ -1,9 +1,8 @@
[gd_scene load_steps=8 format=3 uid="uid://5ymxo45j4ryt"] [gd_scene load_steps=5 format=3 uid="uid://5ymxo45j4ryt"]
[ext_resource type="Script" uid="uid://0c1u4l8lu07h" path="res://Gameplay/Battle.cs" id="1_i431l"] [ext_resource type="Script" uid="uid://0c1u4l8lu07h" path="res://Gameplay/Battle.cs" id="1_i431l"]
[ext_resource type="PackedScene" uid="uid://dsprg4uahkylm" path="res://Gameplay/table.tscn" id="2_6t8i5"] [ext_resource type="PackedScene" uid="uid://dsprg4uahkylm" path="res://Gameplay/table.tscn" id="2_6t8i5"]
[ext_resource type="PackedScene" uid="uid://dm4xk16ce0j" path="res://Gameplay/cue.tscn" id="3_dw4jg"] [ext_resource type="PackedScene" uid="uid://cdaxqopr35lll" path="res://Gameplay/player.tscn" id="2_ogveh"]
[ext_resource type="Script" uid="uid://dbfpn1p62siat" path="res://Gameplay/PowerBar.cs" id="4_0npn6"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_tivnh"] [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_tivnh"]
bg_color = Color(0.111197, 0.111197, 0.111197, 1) bg_color = Color(0.111197, 0.111197, 0.111197, 1)
@@ -12,32 +11,17 @@ border_width_top = 2
border_width_right = 2 border_width_right = 2
border_width_bottom = 2 border_width_bottom = 2
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_ajequ"] [node name="Battle" type="Node" groups=["battles"]]
bg_color = Color(1, 1, 1, 0.458824)
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_aytjx"]
bg_color = Color(0.92549, 0.0901961, 0.0627451, 1)
[node name="Battle" type="Node"]
script = ExtResource("1_i431l") script = ExtResource("1_i431l")
[node name="Table" parent="." instance=ExtResource("2_6t8i5")] [node name="Table" parent="." instance=ExtResource("2_6t8i5")]
[node name="Player" parent="." instance=ExtResource("2_ogveh")]
[node name="PottedPanel" type="Panel" parent="."] [node name="PottedPanel" type="Panel" parent="."]
offset_top = 678.0 offset_top = 678.0
offset_right = 1200.0 offset_right = 1200.0
offset_bottom = 778.0 offset_bottom = 778.0
theme_override_styles/panel = SubResource("StyleBoxFlat_tivnh") theme_override_styles/panel = SubResource("StyleBoxFlat_tivnh")
[node name="Cue" parent="." instance=ExtResource("3_dw4jg")] [connection signal="SetCurrent" from="." to="Player" method="BattleStart"]
[node name="PowerBar" type="ProgressBar" parent="."]
z_index = 1
offset_right = 100.0
offset_bottom = 30.0
theme_override_styles/background = SubResource("StyleBoxFlat_ajequ")
theme_override_styles/fill = SubResource("StyleBoxFlat_aytjx")
show_percentage = false
script = ExtResource("4_0npn6")
[connection signal="Shoot" from="Cue" to="." method="OnCueShoot"]

23
Gameplay/player.tscn Normal file
View File

@@ -0,0 +1,23 @@
[gd_scene load_steps=5 format=3 uid="uid://cdaxqopr35lll"]
[ext_resource type="Script" uid="uid://b66ysicyh0m1s" path="res://Gameplay/Player.cs" id="1_4flbx"]
[ext_resource type="Script" uid="uid://dbfpn1p62siat" path="res://Gameplay/PowerBar.cs" id="2_onrkg"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_i3pqv"]
bg_color = Color(1, 1, 1, 0.458824)
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_hqtel"]
bg_color = Color(0.92549, 0.0901961, 0.0627451, 1)
[node name="Player" type="Node"]
script = ExtResource("1_4flbx")
[node name="PowerBar" type="ProgressBar" parent="."]
visible = false
z_index = 1
offset_right = 100.0
offset_bottom = 30.0
theme_override_styles/background = SubResource("StyleBoxFlat_i3pqv")
theme_override_styles/fill = SubResource("StyleBoxFlat_hqtel")
show_percentage = false
script = ExtResource("2_onrkg")

View File

@@ -32,7 +32,7 @@ radius = 28.75
height = 154.0 height = 154.0
[sub_resource type="CircleShape2D" id="CircleShape2D_v5i0k"] [sub_resource type="CircleShape2D" id="CircleShape2D_v5i0k"]
radius = 28.0713 radius = 15.0333
[sub_resource type="RectangleShape2D" id="RectangleShape2D_s3o1g"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_s3o1g"]
size = Vector2(192.5, 520) size = Vector2(192.5, 520)
@@ -113,7 +113,7 @@ shape = SubResource("CapsuleShape2D_bhh2s")
[node name="Pots" type="Area2D" parent="."] [node name="Pots" type="Area2D" parent="."]
[node name="TL" type="CollisionShape2D" parent="Pots"] [node name="TL" type="CollisionShape2D" parent="Pots"]
position = Vector2(56, 616) position = Vector2(55, 617)
shape = SubResource("CircleShape2D_v5i0k") shape = SubResource("CircleShape2D_v5i0k")
[node name="TR" type="CollisionShape2D" parent="Pots"] [node name="TR" type="CollisionShape2D" parent="Pots"]
@@ -121,7 +121,7 @@ position = Vector2(56, 63)
shape = SubResource("CircleShape2D_v5i0k") shape = SubResource("CircleShape2D_v5i0k")
[node name="R" type="CollisionShape2D" parent="Pots"] [node name="R" type="CollisionShape2D" parent="Pots"]
position = Vector2(593, 49) position = Vector2(593, 43)
shape = SubResource("CircleShape2D_v5i0k") shape = SubResource("CircleShape2D_v5i0k")
[node name="BR" type="CollisionShape2D" parent="Pots"] [node name="BR" type="CollisionShape2D" parent="Pots"]
@@ -133,7 +133,7 @@ position = Vector2(1135, 616)
shape = SubResource("CircleShape2D_v5i0k") shape = SubResource("CircleShape2D_v5i0k")
[node name="L" type="CollisionShape2D" parent="Pots"] [node name="L" type="CollisionShape2D" parent="Pots"]
position = Vector2(593, 629) position = Vector2(593, 634)
shape = SubResource("CircleShape2D_v5i0k") shape = SubResource("CircleShape2D_v5i0k")
[node name="PlayerStartArea" type="Area2D" parent="."] [node name="PlayerStartArea" type="Area2D" parent="."]

6
globals.tscn Normal file
View File

@@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://dw3f81s6epejq"]
[ext_resource type="Script" uid="uid://brjvplo1avnoq" path="res://Gameplay/Globals.cs" id="1_f6yec"]
[node name="Globals" type="Node"]
script = ExtResource("1_f6yec")

View File

@@ -15,6 +15,10 @@ run/main_scene="uid://yqtgkxjjexag"
config/features=PackedStringArray("4.4", "C#", "Forward Plus") config/features=PackedStringArray("4.4", "C#", "Forward Plus")
config/icon="res://icon.svg" config/icon="res://icon.svg"
[autoload]
Globals="*res://Gameplay/Globals.cs"
[display] [display]
window/size/viewport_width=1200 window/size/viewport_width=1200