diff --git a/Gameplay/Actor.cs b/Gameplay/Actor.cs index 26181ae..0c785f8 100644 --- a/Gameplay/Actor.cs +++ b/Gameplay/Actor.cs @@ -3,7 +3,7 @@ using System; using System.Collections.Generic; using System.Linq; -public partial class Actor : Sprite2D +public partial class Actor : Node2D { public bool _available = false, _hovered = false, _selected = false; public int _health, _healthMax; @@ -15,6 +15,7 @@ public partial class Actor : Sprite2D public Ball _hoveredBall = null; public Ball _selectedBall = null; public Ball _heldBall = null; + public ActorPanel _panel; public Sprite2D _tempBallSprite = new(); @@ -23,7 +24,7 @@ public partial class Actor : Sprite2D PackedScene scene = ResourceLoader.Load("res://Gameplay/actor.tscn"); Actor newActor = scene.Instantiate(); - newActor.Texture = GD.Load("res://art/ness.png"); + newActor.GetNode("Sprite").Texture = GD.Load("res://art/ness.png"); Ball newBall = Ball._Create(0); newActor._balls.Add(newBall); @@ -44,6 +45,7 @@ public partial class Actor : Sprite2D newActor._healthMax = newActor._health; ActorPanel newActorPanel = ActorPanel._Create(newActor); + newActor._panel = newActorPanel; newActor.AddChild(newActorPanel); return newActor; @@ -51,6 +53,13 @@ public partial class Actor : Sprite2D public override void _Process(double DELTA_) { + if (_panel._hovered) + { + if (Input.IsActionJustReleased("left_click")) + { + _selected = true; + } + } if (_ballBag.Count > 0 && _selected) { if (_heldBall == null) @@ -65,6 +74,7 @@ public partial class Actor : Sprite2D { _heldBall = _ballBag[(_ballBag.IndexOf(_heldBall) - 1) < 0 ? ^1 : (_ballBag.IndexOf(_heldBall) - 1)]; } + Vector2 mousePosition = GetViewport().GetMousePosition(); if (_tempBallSprite.Texture == null) { @@ -73,28 +83,49 @@ public partial class Actor : Sprite2D AddChild(_tempBallSprite); } _tempBallSprite.Texture = _heldBall.GetNode("Image").Texture; + _tempBallSprite.ZIndex = 1; } if (_startArea == null) { _startArea = Globals.Instance._currentBattle.GetNode("Table").GetNode("PlayerStartArea").GetNode("CollisionShape2D"); } - _tempBallSprite.Position = new Vector2(Math.Min(Math.Max(mousePosition.X, _startArea.GlobalPosition.X - ((RectangleShape2D)(_startArea.Shape)).Size.X / 2), _startArea.GlobalPosition.X + ((RectangleShape2D)(_startArea.Shape)).Size.X / 2), Math.Min(Math.Max(mousePosition.Y, _startArea.GlobalPosition.Y - ((RectangleShape2D)(_startArea.Shape)).Size.Y / 2), _startArea.GlobalPosition.Y + ((RectangleShape2D)(_startArea.Shape)).Size.Y / 2)); - if (Input.IsActionJustReleased("left_click")) + _tempBallSprite.Position = mousePosition; + if (_tempBallSprite.Position.X >= _startArea.GlobalPosition.X - ((RectangleShape2D)(_startArea.Shape)).Size.X / 2 && _tempBallSprite.Position.X <= _startArea.GlobalPosition.X + ((RectangleShape2D)(_startArea.Shape)).Size.X / 2 && _tempBallSprite.Position.Y >= _startArea.GlobalPosition.Y - ((RectangleShape2D)(_startArea.Shape)).Size.Y / 2 && _tempBallSprite.Position.Y <= _startArea.GlobalPosition.Y + ((RectangleShape2D)(_startArea.Shape)).Size.Y / 2) { - _heldBall.Place(_tempBallSprite.Position); - AddChild(_heldBall); - int ballIndex = _ballBag.IndexOf(_heldBall); - _ballBag.Remove(_heldBall); - _tempBallSprite.Texture = null; - if (_ballBag.Count > 0) + if (Input.IsActionJustReleased("left_click")) { - _heldBall = _ballBag[ballIndex - (ballIndex > _ballBag.Count ? 1 : 0)]; + _heldBall.Place(_tempBallSprite.Position); + int ballIndex = _ballBag.IndexOf(_heldBall); + + AddChild(_heldBall); + + _ballBag.Remove(_heldBall); + _tempBallSprite.Texture = null; + if (_ballBag.Count > 0) + { + _heldBall = _ballBag[ballIndex - (ballIndex > _ballBag.Count ? 1 : 0)]; + } + else + { + _heldBall = null; + } } } } else { + for (int i = 0; i < _balls.Count; i++) + { + if (_balls[i]._potted) + { + _balls[i]._potted = false; + _balls[i].Sleeping = true; + _ballBag.Add(_balls[i]); + RemoveChild(_balls[i]); + + } + } if (_balls.Any(b => b._hovered)) { _hoveredBall = _balls.Single(b => b._hovered); diff --git a/Gameplay/ActorPanel.cs b/Gameplay/ActorPanel.cs index 915bf0d..1a8f4da 100644 --- a/Gameplay/ActorPanel.cs +++ b/Gameplay/ActorPanel.cs @@ -3,18 +3,22 @@ using System; public partial class ActorPanel : Panel { + public bool _hovered = false; + public Actor _actor; public static ActorPanel _Create(Actor ACTOR) { PackedScene scene = ResourceLoader.Load("res://Gameplay/actor_panel.tscn"); ActorPanel newActorPanel = scene.Instantiate(); - newActorPanel.SetSprite(ACTOR.Texture); - newActorPanel.SetMax(ACTOR._healthMax); - newActorPanel.SetValue(ACTOR._health); - newActorPanel.SetPosition(new Vector2(1500, 0)); + newActorPanel._actor = ACTOR; + newActorPanel.SetSprite(newActorPanel._actor.GetNode("Sprite").Texture); + newActorPanel.SetMax(newActorPanel._actor._healthMax); + newActorPanel.SetValue(newActorPanel._actor._health); + newActorPanel.SetPosition(new Vector2(50, 300)); return newActorPanel; } + public void SetPosition(Vector2 POSITION) { Position = POSITION; @@ -25,12 +29,24 @@ public partial class ActorPanel : Panel } public void SetValue(int VALUE) { - GetNode("Health").GetNode("Value").Text = VALUE.ToString(); - GetNode("Health").GetNode("Bar").Value = VALUE; + GetNode("Health").GetNode("Value").Text = VALUE.ToString(); + GetNode("Health").GetNode("Bar").Value = VALUE; } public void SetMax(int MAX) { - GetNode("Health").GetNode("Max").Text = MAX.ToString(); - GetNode("Health").GetNode("Bar").MaxValue = MAX; + GetNode("Health").GetNode("Max").Text = MAX.ToString(); + GetNode("Health").GetNode("Bar").MaxValue = MAX; } + + private void OnMouseEntered() + { + _hovered = true; + GD.Print(_hovered); + } + + private void OnMouseExited() + { + _hovered = false; + GD.Print(_hovered); + } } diff --git a/Gameplay/Ball.cs b/Gameplay/Ball.cs index f2d013c..63950f5 100644 --- a/Gameplay/Ball.cs +++ b/Gameplay/Ball.cs @@ -4,7 +4,7 @@ using System.Data; public partial class Ball : RigidBody2D { - public bool _placed = false, _potted = false, _available = false, _hovered = false, _selected = false, _aimed = false, _moving = false; + public bool _placed = false, _potted = false, _available = false, _hovered = false, _selected = false, _aimed = false, _moving = false, _isCue = false; public int _defense, _defenseMax; public float _moveThreshold = 5.0f; @@ -16,10 +16,12 @@ public partial class Ball : RigidBody2D if (NUMBER == 0) { fileName = "res://art/cue_ball.png"; + newBall._isCue = true; } else { - fileName = "res://art/ball_"+NUMBER+".png"; + fileName = "res://art/ball_" + NUMBER + ".png"; + newBall._isCue = false; ; } Texture2D image = GD.Load(fileName); newBall.GetNode("Image").Texture = image; diff --git a/Gameplay/Battle.cs b/Gameplay/Battle.cs index 6cc4a73..623fa22 100644 --- a/Gameplay/Battle.cs +++ b/Gameplay/Battle.cs @@ -101,10 +101,10 @@ public partial class Battle : Node { return; } - if (BODY == _player._selectedActor._selectedBall) + if (((Ball)BODY)._isCue) { - _player._selectedActor._selectedBall._potted = true; - _player._selectedActor._selectedBall._placed = false; + ((Ball)BODY)._potted = true; + ((Ball)BODY)._placed = false; } else { diff --git a/Gameplay/actor.tscn b/Gameplay/actor.tscn index 873f669..90a8c18 100644 --- a/Gameplay/actor.tscn +++ b/Gameplay/actor.tscn @@ -2,5 +2,8 @@ [ext_resource type="Script" uid="uid://b4mr2vn8mw6r4" path="res://Gameplay/Actor.cs" id="1_hr3hk"] -[node name="Actor" type="Sprite2D"] +[node name="Actor" type="Node2D"] script = ExtResource("1_hr3hk") + +[node name="Sprite" type="Sprite2D" parent="."] +visible = false diff --git a/Gameplay/actor_panel.tscn b/Gameplay/actor_panel.tscn index 0db6556..18656b5 100644 --- a/Gameplay/actor_panel.tscn +++ b/Gameplay/actor_panel.tscn @@ -6,27 +6,27 @@ bg_color = Color(1, 1, 1, 1) [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_mmnuv"] -bg_color = Color(0.259294, 0.259294, 0.259294, 1) +bg_color = Color(0.133196, 0.133196, 0.133196, 1) [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_dg1wx"] -bg_color = Color(0.6, 1, 0.6, 1) +bg_color = Color(0.376575, 0.904155, 0.434351, 1) [node name="ActorPanel" type="Panel"] -anchors_preset = -1 -offset_left = -100.0 -offset_top = -150.0 -offset_right = 100.0 -offset_bottom = 150.0 +offset_right = 422.0 +offset_bottom = 130.0 grow_horizontal = 2 grow_vertical = 2 theme_override_styles/panel = SubResource("StyleBoxFlat_e1ofl") script = ExtResource("1_dg1wx") -[node name="RichTextLabel" type="RichTextLabel" parent="."] +[node name="Name" type="RichTextLabel" parent="."] layout_mode = 0 -offset_right = 207.0 -offset_bottom = 40.0 +offset_left = 20.0 +offset_top = 8.0 +offset_right = 170.0 +offset_bottom = 48.0 theme_override_colors/default_color = Color(0, 0, 0, 1) +theme_override_font_sizes/normal_font_size = 24 text = "Actor Name" horizontal_alignment = 1 vertical_alignment = 1 @@ -34,56 +34,81 @@ vertical_alignment = 1 [node name="Image" type="Sprite2D" parent="."] position = Vector2(100, 75) -[node name="Health" type="Node2D" parent="."] -position = Vector2(100, 150) +[node name="Health" type="Control" parent="."] +anchors_preset = 0 +offset_left = 207.0 +offset_top = 6.0 +offset_right = 417.0 +offset_bottom = 51.0 -[node name="Name" type="RichTextLabel" parent="Health"] -offset_left = -80.0 -offset_top = -26.0 -offset_bottom = -1.0 +[node name="Label" type="RichTextLabel" parent="Health"] +layout_mode = 2 +offset_left = 15.0 +offset_top = 2.0 +offset_right = 115.0 +offset_bottom = 42.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 theme_override_colors/default_color = Color(0, 0, 0, 1) +theme_override_font_sizes/normal_font_size = 24 text = "Health" vertical_alignment = 1 -metadata/_edit_use_anchors_ = true [node name="Max" type="RichTextLabel" parent="Health"] -offset_top = -26.0 -offset_right = 80.0 -offset_bottom = -1.0 +layout_mode = 2 +offset_left = 83.0 +offset_top = 2.0 +offset_right = 148.0 +offset_bottom = 42.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 theme_override_colors/default_color = Color(0, 0, 0, 1) +theme_override_font_sizes/normal_font_size = 24 text = "000" horizontal_alignment = 2 vertical_alignment = 1 -metadata/_edit_use_anchors_ = true [node name="Separator" type="RichTextLabel" parent="Health"] -offset_top = -26.0 -offset_right = 50.0 -offset_bottom = -1.0 +layout_mode = 2 +offset_left = 112.0 +offset_top = 2.0 +offset_right = 161.0 +offset_bottom = 42.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 theme_override_colors/default_color = Color(0, 0, 0, 1) +theme_override_font_sizes/normal_font_size = 24 text = "/ " horizontal_alignment = 2 vertical_alignment = 1 -metadata/_edit_use_anchors_ = true [node name="Value" type="RichTextLabel" parent="Health"] -offset_top = -26.0 -offset_right = 40.0 -offset_bottom = -1.0 +layout_mode = 2 +offset_left = 156.0 +offset_top = 2.0 +offset_right = 205.0 +offset_bottom = 42.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 theme_override_colors/default_color = Color(0, 0, 0, 1) +theme_override_font_sizes/normal_font_size = 24 text = "000" horizontal_alignment = 2 vertical_alignment = 1 -metadata/_edit_use_anchors_ = true [node name="Bar" type="ProgressBar" parent="Health"] -offset_left = -80.0 -offset_top = -3.0 -offset_right = 81.0 -offset_bottom = 4.0 +layout_mode = 2 +offset_left = 17.0 +offset_top = 36.0 +offset_right = 204.0 +offset_bottom = 44.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 theme_override_styles/background = SubResource("StyleBoxFlat_mmnuv") theme_override_styles/fill = SubResource("StyleBoxFlat_dg1wx") step = 1.0 show_percentage = false -metadata/_edit_use_anchors_ = true + +[connection signal="mouse_entered" from="." to="." method="OnMouseEntered"] +[connection signal="mouse_exited" from="." to="." method="OnMouseExited"] diff --git a/Gameplay/ball.tscn b/Gameplay/ball.tscn index ecc6dea..49ffb47 100644 --- a/Gameplay/ball.tscn +++ b/Gameplay/ball.tscn @@ -17,6 +17,7 @@ shader_parameter/globe_magnitude = 0.0 radius = 18.0 [node name="Ball" type="RigidBody2D" groups=["balls"]] +z_index = 1 input_pickable = true physics_material_override = SubResource("PhysicsMaterial_yj7wd") continuous_cd = 2