adding in some example pegs and their actions. organizing folders, still working on pathing for some reason it won't move sometimes, and causes the looping to break

This commit is contained in:
2026-06-26 02:36:01 -04:00
parent fc32baa071
commit 350d2bc4d1
33 changed files with 366 additions and 165 deletions
+13 -17
View File
@@ -1,7 +1,7 @@
using System.Collections.Generic;
using Godot;
public partial class Attack : RigidBody2D
public partial class Ball : RigidBody2D
{
[Signal]
public delegate void HitEventHandler(Node NODE);
@@ -9,7 +9,7 @@ public partial class Attack : RigidBody2D
public delegate void BucketEnteredEventHandler();
public bool _hovered = false;
public int _damage = 1;
public int _healthChange = -1, _hits = 0;
public Vector2 _speed;
public Path2D _predictionPath;
public Commander _commanderOwner;
@@ -21,6 +21,16 @@ public partial class Attack : RigidBody2D
_predictionPath = GetNode<Path2D>("PredictedPath");
}
public void Act(Node BODY)
{
EmitSignal(SignalName.Hit, BODY);
if (BODY is Peg peg)
{
peg.ChangeHealth(_healthChange, _commanderOwner);
_hits++;
}
}
public override void _PhysicsProcess(double delta)
{
base._PhysicsProcess(delta);
@@ -49,19 +59,5 @@ public partial class Attack : RigidBody2D
GravityScale = 1;
}
public void TakeAction(Node BODY)
{
EmitSignal(SignalName.Hit, BODY);
if (BODY is Peg peg)
{
peg.TakeDamage(_damage, _commanderOwner);
}
}
public void OnMouseEntered(){
_hovered = true;
}
public void OnMouseExited(){
_hovered = true;
}
}
View File
+4 -4
View File
@@ -5,7 +5,7 @@ public partial class Bucket : Node2D
{
[Signal]
public delegate void AttackEnteredEventHandler(Attack ATTACK);
public delegate void BallEnteredEventHandler(Ball BALL);
public int _minX = -500, _maxX = 500, _movementSign = 1, _movementSpeed = 3;
public Vector2 _startPoisition;
@@ -27,10 +27,10 @@ public partial class Bucket : Node2D
}
public void OnBodyEntered(Node2D BODY)
{
if (BODY is Attack attack)
if (BODY is Ball ball)
{
EmitSignal(SignalName.AttackEntered, attack);
attack.EnteredBucket();
EmitSignal(SignalName.BallEntered, ball);
ball.EnteredBucket();
}
}
}
+20 -20
View File
@@ -6,18 +6,18 @@ public partial class Commander : Sprite2D
[Signal]
public delegate void ActionsUpEventHandler();
public int _actionsMax = 1, _actions;
public PackedScene _attackScene = GD.Load<PackedScene>("res://Attack.tscn");
public Attack _attack;
public PackedScene _ballScene = GD.Load<PackedScene>("res://Ball.tscn");
public Ball _ball;
public PlayerController _playerController;
public override void _Process(double delta)
{
base._Process(delta);
if (_attack != null)
if (_ball != null)
{
if (_attack.Position.Y > GetViewportRect().Size.Y + 50)
if (_ball.Position.Y > GetViewportRect().Size.Y + 50)
{
UnloadAttack();
UnloadBall();
if (_actions <= 0)
{
EmitSignal(SignalName.ActionsUp);
@@ -26,34 +26,34 @@ public partial class Commander : Sprite2D
}
}
public void AttackEnteredBucket()
public void BallEnteredBucket()
{
_actions += (_actions + 1) > _actionsMax ? 0 : 1;
UnloadAttack();
UnloadBall();
}
public void LoadAttack(Vector2 OFFSET)
public void LoadBall(Vector2 OFFSET)
{
if (_attack == null)
if (_ball == null)
{
_attack = _attackScene.Instantiate<Attack>();
_attack.Position = OFFSET;
_attack._commanderOwner = this;
_attack.GravityScale = 0;
_attack.BucketEntered += AttackEnteredBucket;
AddChild(_attack);
_ball = _ballScene.Instantiate<Ball>();
_ball.Position = OFFSET;
_ball._commanderOwner = this;
_ball.GravityScale = 0;
_ball.BucketEntered += BallEnteredBucket;
AddChild(_ball);
}
}
public void ShootCurrentAttack(Vector2 FORCE){
public void ShootCurrentBall(Vector2 FORCE){
_attack.Shoot(FORCE);
_ball.Shoot(FORCE);
_actions--;
}
public void UnloadAttack()
public void UnloadBall()
{
_attack.QueueFree();
_attack = null;
_ball.QueueFree();
_ball = null;
}
}
+6
View File
@@ -1,5 +1,6 @@
using Godot;
using System;
using System.Collections.Generic;
public partial class Globals : Node2D
{
@@ -7,4 +8,9 @@ public partial class Globals : Node2D
public static float _gravity = (float)ProjectSettings.GetSetting("physics/2d/default_gravity"), _drag = (float)ProjectSettings.GetSetting("physics/2d/default_linear_damp");
public static MouseHandler _mouse;
public static T GetRandomFromList<T>(List<T> TYPED_LIST)
{
return TYPED_LIST[_rng.Next(0,TYPED_LIST.Count)];
}
}
+36 -46
View File
@@ -7,59 +7,48 @@ public partial class Peg : HoverableNode
{
[Signal]
public delegate void DeathEventHandler(Peg THIS);
public bool _track = false, _warp = false;
public int _damage = 1, _health = 2, _stamina, _staminaRemaining, _visibilityRange = 4, _hitRange, _attackCost = 1;
public int _id, _health = 2, _healthMax = 2, _stamina, _staminaRemaining, _visibility = 4, _movement = 0, _movementCost = 1;
public Dictionary<string, int> _priorities = new()
{
{"attack", 1000000}, // 1000000 to 1999999 reserved for attack priorities
{"ball", 1000000}, // 1000000 to 1999999 reserved for ball priorities
{"movement", 0} // 0 to 999999 reserved for movement priorities
};
public Vector2I _address = -Vector2I.One, _range = Vector2I.Up;
public List<Vector2I> _path = new();
public float _movement = 0;
public PegController _pegController;
public Sprite2D _attack;
public PegAction _action;
public override void _Ready()
{
base._Ready();
_attack = GetNode<Sprite2D>("Attack");
}
public void Attack()
public virtual void Act()
{
// _attack.Visible = true;
Tween subtween = CreateTween();
subtween.TweenProperty(_attack, "visible", true, 0.0f);
subtween.TweenProperty(_attack, "global_position", Vector2.Zero, 0.5f);
subtween.TweenCallback(Callable.From(() =>
if (_action == null)
{
_pegController._playerController.ChangeHealth(-1, this);
_attack.Position = Vector2.Zero;
_attack.Visible = false;
}));
int key = _priorities["attack"];
if (!_pegController._tweenStages.ContainsKey(key))
{
_pegController._tweenStages[key] = new();
GD.Print("NO ACTION");
return;
}
_pegController._tweenStages[key].Add(subtween);
_staminaRemaining = Math.Max(_staminaRemaining - 2, 0);
Tween subtween = _action.CreateAnimation(this);
if (!_pegController._tweenStages.ContainsKey(_action._priority))
{
_pegController._tweenStages[_action._priority] = new();
}
_pegController._tweenStages[_action._priority].Add(subtween);
_staminaRemaining = Math.Max(_staminaRemaining - _action._cost, 0);
}
public bool CanAttack()
public virtual bool CanAct()
{
return _staminaRemaining > 0 && _address.Y <= _hitRange;
return _staminaRemaining > 0 && _address.Y <= _action._range && _action._usesRemaining > 0 && _staminaRemaining <= _action._cost;
}
public bool CanMove()
public virtual bool CanMove()
{
// GD.Print(_staminaRemaining," ",_address.Y," ", CONTROLLER._playArea._map._firstOpenRow);
return _staminaRemaining > 0 && _address.Y > _pegController._playArea._map._firstOpenRow;
}
public void CounterAttack(Commander COMMANDER)
public virtual void CounterAct(Commander COMMANDER)
{
}
@@ -68,31 +57,27 @@ public partial class Peg : HoverableNode
{
Map map = _pegController._playArea._map;
List<Vector2I> goals = GetGoals();
// List<List<Vector2I>> paths = new();
Vector2I bestGoal = goals[0];
float bestCost = map._astar._EstimateCost(_address, bestGoal);
List<Vector2I> bestPath = map.GetPath(_address, goals[0]);
for (int i = 1; i < goals.Count; i++)
{
Vector2I testGoal = goals[i];
float testCost = map._astar._EstimateCost(_address, testGoal);
if (testCost < bestCost)
List<Vector2I> testPath = map.GetPath(_address, testGoal);
if (testPath.Count < bestPath.Count)
{
bestCost = testCost;
bestGoal = testGoal;
bestPath = testPath;
}
}
// List<Vector2I> bestPath = paths.Where(p => p.Count > 0).OrderBy(p => p.Count).ToList()[0];
List<Vector2I> bestPath = map.GetPath(_address, bestGoal);
return bestPath;
}
public virtual List<Vector2I> GetGoals()
{
Map map = _pegController._playArea._map;
return [.. map._cells.Where(c => c.Y == Math.Max(_address.Y - _visibilityRange, map._firstOpenRow)).Where(c => !map._astar.IsPointSolid(c))];
return [.. map._cells.Where(c => c.Y == map._firstOpenRow).Where(c => !map._astar.IsPointSolid(c))];
}
public void Move(Vector2I PATH_STEP)
public virtual void Move(Vector2I PATH_STEP)
{
_pegController._playArea._map.SetCellPeg(PATH_STEP, this);
_path.Add(PATH_STEP);
@@ -100,29 +85,34 @@ public partial class Peg : HoverableNode
Tween subtween = CreateTween();
subtween.TweenProperty(this, "global_position", _pegController._playArea._map.GetCellPositionFromAddress(PATH_STEP), 0.25f);
int key = _priorities["movement"] + _pegController._actionLoop;
GD.Print(key);
if (!_pegController._tweenStages.ContainsKey(key))
{
_pegController._tweenStages[key] = new();
}
_pegController._tweenStages[key].Add(subtween);
_staminaRemaining--;
_staminaRemaining -= _movementCost;
}
public void StartTurn()
public virtual void StartTurn()
{
_staminaRemaining = _stamina;
_action._usesRemaining = _action._usesMax;
}
public void TakeDamage(int DAMAGE, Commander ATTACKER)
public virtual void ChangeHealth(int DELTA, Commander BALLER)
{
_health -= DAMAGE;
CounterAttack(ATTACKER);
_health += DELTA;
CounterAct(BALLER);
if (_health <= 0)
{
EmitSignal(SignalName.Death, this);
}
else if (_health > _healthMax)
{
_health = _healthMax;
}
}
}
+40 -30
View File
@@ -2,62 +2,75 @@ using Godot;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection.Metadata;
using System.Threading.Tasks;
using System.Xml;
public partial class PegController : TurnController
{
public int _actionLoop = 0;
public PackedScene _hostilePegScene = GD.Load<PackedScene>("res://hostile_peg.tscn");
public int _actionLoop = 0, _pegsCreated = 0, _pegsDestroyed = 0;
public List<PackedScene> _hostilePegScenes;
public List<Peg> _pegs = new();
public PlayerController _playerController;
public Dictionary<int, List<Tween>> _tweenStages = new();
public Tween _tween;
public XmlDocument _pegProbabilities = new();
public override void _Ready()
{
base._Ready();
_hostilePegScenes = [.. Directory.GetFiles("Pegs/HostilePegs/", "*.tscn").Select(f => GD.Load<PackedScene>(f))];
// _pegProbabilities.Load("res://PegProbabilities.xml");
}
public void AddHostilePegs(int PEG_COUNT = 1)
{
for (int i = 0; i < PEG_COUNT; i++)
{
HostilePeg newHostilePeg = _hostilePegScene.Instantiate<HostilePeg>();
HostilePeg newHostilePeg = Globals.GetRandomFromList(_hostilePegScenes).Instantiate<HostilePeg>();
newHostilePeg._id = _pegsCreated;
newHostilePeg.Death += HandlePegRemoval;
newHostilePeg.Click += HandlePegClick;
newHostilePeg._stamina = Globals._rng.Next(2,4+1);
newHostilePeg.Modulate = new Color(newHostilePeg._stamina == 2 ? "#FF0000" : newHostilePeg._stamina == 3 ? "#00FF00" : "#0000FF");
newHostilePeg._pegController = this;
List<Vector2I> unoccupied = [.. _playArea._map._bottomRow.Where(c => _pegs.All(e => e._address != c))];
Vector2I randomCell = unoccupied[Globals._rng.Next(unoccupied.Count)];
SetPeg(newHostilePeg, randomCell);
_pegs.Add(newHostilePeg);
AddChild(newHostilePeg);
_pegsCreated++;
}
}
public void AddHostilePegs(List<Vector2I> POSITIONS)
{
for (int i = 0; i < POSITIONS.Count; i++)
{
HostilePeg newHostilePeg = _hostilePegScene.Instantiate<HostilePeg>();
HostilePeg newHostilePeg = Globals.GetRandomFromList(_hostilePegScenes).Instantiate<HostilePeg>();
newHostilePeg._id = _pegsCreated;
newHostilePeg.Death += HandlePegRemoval;
newHostilePeg.Click += HandlePegClick;
newHostilePeg._stamina = Globals._rng.Next(2,4+1);
newHostilePeg._hitRange = Globals._rng.Next(1,2+1);
newHostilePeg.GetNode<Sprite2D>("Sprite2D").SelfModulate = new Color(newHostilePeg._stamina == 2 ? "#FF0000" : newHostilePeg._stamina == 3 ? "#00FF00" : "#0000FF");
newHostilePeg._pegController = this;
SetPeg(newHostilePeg, POSITIONS[i]);
_pegs.Add(newHostilePeg);
AddChild(newHostilePeg);
_pegsCreated++;
}
}
public List<Peg> GetRemainingPegs()
{
return [.. _pegs.Where(e => e.CanMove() || e.CanAttack())];
return [.. _pegs.Where(e => e.CanMove() || e.CanAct())];
}
public void HandlePegActions()
public void HandlePegTurn()
{
_actionLoop = 0;
_tweenStages.Clear();
@@ -66,30 +79,31 @@ public partial class PegController : TurnController
_pegs.ForEach(e => e._path.Clear());
List<Peg> remainingPegs = GetRemainingPegs();
while (remainingPegs.Count > 0 && _actionLoop <100)
while (remainingPegs.Count > 0 && _actionLoop < 100)
{
for (int i = 0; i < remainingPegs.Count; i++)
{
Peg peg = remainingPegs[i];
if (!peg.CanMove() && !peg.CanAttack())
{
GD.Print(i);
}
HandlePegPathing(peg);
HandlePegAttacking(peg);
HandlePegAction(peg);
}
remainingPegs = GetRemainingPegs();
_actionLoop++;
if (_actionLoop == 100)
{
GD.Print(string.Join(", ",remainingPegs.Select(p => p._address.ToString() + p._staminaRemaining+p.CanMove()+p.CanAct())));
GD.Print("LOOPMAXEDOUT");
}
}
}
public void HandlePegAttacking(Peg PEG)
public void HandlePegAction(Peg PEG)
{
if (!PEG.CanAttack())
if (PEG.CanAct())
{
return;
PEG.Act();
}
PEG.Attack();
}
@@ -107,7 +121,6 @@ public partial class PegController : TurnController
TileMapLayer pathLayer = _playArea.GetNode<TileMapLayer>("PathLayer");
List<Vector2I> newPath = peg.GetBestPath();
pathLayer.GetUsedCells().ToList().ForEach(c => pathLayer.SetCell(c,0,Vector2I.Down*4));
for (int i = 0; i < newPath.Count; i++)
{
@@ -127,10 +140,10 @@ public partial class PegController : TurnController
return;
}
List<Vector2I> path = PEG.GetBestPath();
if (path?.Count == 0)
{
// PEG.Move(PEG._path.LastOrDefault(PEG._address), this);
GD.Print(PEG._address, " PATH0");
return;
}
@@ -142,6 +155,7 @@ public partial class PegController : TurnController
_pegs.Remove(PEG_TO_REMOVE);
_playArea._map.SetCellPeg(PEG_TO_REMOVE._address, null);
PEG_TO_REMOVE.QueueFree();
_pegsDestroyed++;
}
public void HandlePegSort()
@@ -191,7 +205,7 @@ public partial class PegController : TurnController
public override void StartTurn()
{
AddHostilePegs(1);
AddHostilePegs(4);
for (int i = 0; i < _pegs.Count; i++)
{
@@ -200,17 +214,13 @@ public partial class PegController : TurnController
HandlePegSort();
HandlePegActions();
HandlePegTurn();
ProcessTween();
}
public void SetPeg(Peg PEG, Vector2I CELL)
{
if (CELL == new Vector2I(16, 14))
{
PEG._track = true;
}
_playArea._map.SetCellPeg(CELL, PEG);
PEG.GlobalPosition = _playArea._map.GetCellPositionFromAddress(CELL);
}
+3
View File
@@ -0,0 +1,3 @@
<xml>
</xml>
+32
View File
@@ -0,0 +1,32 @@
using Godot;
using System;
using System.Linq;
public partial class Shortbow : PegAction
{
public override void _Ready()
{
base._Ready();
_priority = 1000;
_healthChange = -1;
_cost = 2;
_range = 1;
_usesMax = 1;
_usesRemaining = _usesMax;
}
public override Tween CreateAnimation(Peg PEG)
{
Vector2 target = PEG._pegController._playerController._towers.OrderBy(t => (t.GlobalPosition - GlobalPosition).Length()).ToList()[0].GlobalPosition;
Tween subtween = CreateTween();
subtween.TweenProperty(_image, "visible", true, 0.0f);
subtween.TweenProperty(_image, "global_position", target, 0.5f);
subtween.TweenCallback(Callable.From(() =>
{
PEG._pegController._playerController.ChangeHealth(_healthChange, this);
Position = Vector2.Zero;
Visible = false;
}));
return subtween;
}
}
+1
View File
@@ -0,0 +1 @@
uid://dt7qbvowj1sm4
+31
View File
@@ -0,0 +1,31 @@
using Godot;
using System;
using System.Linq;
public partial class Shortsword : PegAction
{
public override void _Ready()
{
base._Ready();
_priority = 1000;
_healthChange = -2;
_cost = 2;
_range = 0;
_usesMax = 1;
_usesRemaining = _usesMax;
}
public override Tween CreateAnimation(Peg PEG)
{
Vector2 target = PEG.GlobalPosition + (Vector2.Up * 50);
Tween subtween = CreateTween();
subtween.TweenProperty(_image, "visible", true, 0.0f);
subtween.TweenProperty(_image, "global_position", target, 0.5f);
subtween.TweenCallback(Callable.From(() =>
{
PEG._pegController._playerController.ChangeHealth(_healthChange, this);
_image.Position = Vector2.Zero;
_image.Visible = false;
}));
return subtween;
}
}
+1
View File
@@ -0,0 +1 @@
uid://td6dv1t4y5os
+8
View File
@@ -0,0 +1,8 @@
[gd_scene format=3 uid="uid://duspilwelsiy3"]
[ext_resource type="Script" uid="uid://dt7qbvowj1sm4" path="res://Pegs/Actions/Shortbow.cs" id="1_yhiab"]
[node name="Shortbow" type="Node2D" unique_id=518048625]
script = ExtResource("1_yhiab")
[node name="Image" type="Sprite2D" parent="." unique_id=944294157]
+12
View File
@@ -0,0 +1,12 @@
[gd_scene format=3 uid="uid://c6df6ib0qan5g"]
[ext_resource type="Script" uid="uid://td6dv1t4y5os" path="res://Pegs/Actions/Shortsword.cs" id="1_rflgk"]
[ext_resource type="Texture2D" uid="uid://32m5teus1cjj" path="res://Art/tower.png" id="2_fs74r"]
[node name="Shortsword" type="Node2D" unique_id=518048625]
script = ExtResource("1_rflgk")
[node name="Image" type="Sprite2D" parent="." unique_id=906537972]
visible = false
scale = Vector2(0.1, 0.1)
texture = ExtResource("2_fs74r")
-6
View File
@@ -12,10 +12,4 @@ public partial class HostilePeg : Peg
base._Ready();
}
// public void OnMouseEntered(){
// _hovered = true;
// }
// public void OnMouseExited(){
// _hovered = false;
// }
}
+12
View File
@@ -0,0 +1,12 @@
using Godot;
using System;
public partial class Archer : HostilePeg
{
public override void _Ready()
{
base._Ready();
_stamina = 2;
_action = GetNode<Shortbow>("Shortbow");
}
}
+1
View File
@@ -0,0 +1 @@
uid://b3a0x3r3yx861
+12
View File
@@ -0,0 +1,12 @@
using Godot;
using System;
public partial class Infantry : HostilePeg
{
public override void _Ready()
{
base._Ready();
_stamina = 3;
_action = GetNode<Shortsword>("Shortsword");
}
}
+1
View File
@@ -0,0 +1 @@
uid://xlg4cblo1vf1
+38
View File
@@ -0,0 +1,38 @@
[gd_scene format=3 uid="uid://dwqhme11j5ihb"]
[ext_resource type="Script" uid="uid://b3a0x3r3yx861" path="res://Pegs/HostilePegs/Archer.cs" id="1_ij48w"]
[ext_resource type="Texture2D" uid="uid://nwj4n7if8kqd" path="res://Art/circle25r.png" id="2_j7but"]
[ext_resource type="PackedScene" uid="uid://duspilwelsiy3" path="res://Pegs/Actions/shortbow.tscn" id="3_c81uf"]
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_7k104"]
bounce = 0.5
[sub_resource type="CircleShape2D" id="CircleShape2D_4gyqm"]
radius = 12.5
[sub_resource type="CircleShape2D" id="CircleShape2D_6w6fg"]
radius = 12.5
[node name="Archer" type="StaticBody2D" unique_id=1417697759]
input_pickable = true
physics_material_override = SubResource("PhysicsMaterial_7k104")
script = ExtResource("1_ij48w")
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1762191899]
shape = SubResource("CircleShape2D_4gyqm")
[node name="Sprite2D" type="Sprite2D" parent="." unique_id=1941012605]
self_modulate = Color(0, 0, 1, 1)
texture_filter = 1
scale = Vector2(0.5, 0.5)
texture = ExtResource("2_j7but")
[node name="Shortbow" parent="." unique_id=518048625 instance=ExtResource("3_c81uf")]
[node name="HoverBounds" type="Area2D" parent="." unique_id=937525982]
[node name="CollisionShape2D" type="CollisionShape2D" parent="HoverBounds" unique_id=2142666816]
shape = SubResource("CircleShape2D_6w6fg")
[connection signal="mouse_entered" from="." to="." method="OnMouseEntered"]
[connection signal="mouse_exited" from="." to="." method="OnMouseExited"]
+38
View File
@@ -0,0 +1,38 @@
[gd_scene format=3 uid="uid://d55ut168gh3k"]
[ext_resource type="Script" uid="uid://xlg4cblo1vf1" path="res://Pegs/HostilePegs/Infantry.cs" id="1_wlksp"]
[ext_resource type="Texture2D" uid="uid://nwj4n7if8kqd" path="res://Art/circle25r.png" id="2_b77ka"]
[ext_resource type="PackedScene" uid="uid://c6df6ib0qan5g" path="res://Pegs/Actions/shortsword.tscn" id="3_lwlv5"]
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_7k104"]
bounce = 0.5
[sub_resource type="CircleShape2D" id="CircleShape2D_4gyqm"]
radius = 12.5
[sub_resource type="CircleShape2D" id="CircleShape2D_6w6fg"]
radius = 12.5
[node name="Infantry" type="StaticBody2D" unique_id=1417697759]
input_pickable = true
physics_material_override = SubResource("PhysicsMaterial_7k104")
script = ExtResource("1_wlksp")
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1762191899]
shape = SubResource("CircleShape2D_4gyqm")
[node name="Sprite2D" type="Sprite2D" parent="." unique_id=1941012605]
self_modulate = Color(1, 0, 0, 1)
texture_filter = 1
scale = Vector2(0.5, 0.5)
texture = ExtResource("2_b77ka")
[node name="Shortsword" parent="." unique_id=518048625 instance=ExtResource("3_lwlv5")]
[node name="HoverBounds" type="Area2D" parent="." unique_id=937525982]
[node name="CollisionShape2D" type="CollisionShape2D" parent="HoverBounds" unique_id=2142666816]
shape = SubResource("CircleShape2D_6w6fg")
[connection signal="mouse_entered" from="." to="." method="OnMouseEntered"]
[connection signal="mouse_exited" from="." to="." method="OnMouseExited"]
+19
View File
@@ -0,0 +1,19 @@
using Godot;
using System;
public partial class PegAction : Node2D
{
public int _priority, _healthChange, _cost, _range, _usesMax, _usesRemaining, _triggers = 0;
public Sprite2D _image;
public override void _Ready()
{
base._Ready();
_image = GetNode<Sprite2D>("Image");
}
public virtual Tween CreateAnimation(Peg PEG)
{
return null;
}
}
+1
View File
@@ -0,0 +1 @@
uid://dpa15pxib2qyr
+4 -7
View File
@@ -1,8 +1,8 @@
[gd_scene format=3 uid="uid://drt7w0eqp13tu"]
[gd_scene format=3 uid="uid://43ty0uit6ylb"]
[ext_resource type="Script" uid="uid://dfba4vq6jv0a6" path="res://HostilePeg.cs" id="1_nc8fp"]
[ext_resource type="Script" uid="uid://dfba4vq6jv0a6" path="res://Pegs/HostilePeg.cs" id="1_nc8fp"]
[ext_resource type="Texture2D" uid="uid://nwj4n7if8kqd" path="res://Art/circle25r.png" id="2_0icqg"]
[ext_resource type="Texture2D" uid="uid://m4wfj36twmqy" path="res://Art/attack.png" id="3_en3ow"]
[ext_resource type="PackedScene" uid="uid://bj2qrn0l01us1" path="res://Pegs/peg_action.tscn" id="3_nc8fp"]
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_7k104"]
bounce = 0.5
@@ -26,10 +26,7 @@ texture_filter = 1
scale = Vector2(0.5, 0.5)
texture = ExtResource("2_0icqg")
[node name="Attack" type="Sprite2D" parent="." unique_id=1776738311]
visible = false
texture_filter = 1
texture = ExtResource("3_en3ow")
[node name="PegAction" parent="." unique_id=637569115 instance=ExtResource("3_nc8fp")]
[node name="HoverBounds" type="Area2D" parent="." unique_id=937525982]
+8
View File
@@ -0,0 +1,8 @@
[gd_scene format=3 uid="uid://bj2qrn0l01us1"]
[ext_resource type="Script" uid="uid://dpa15pxib2qyr" path="res://Pegs/PegAction.cs" id="1_8o8tf"]
[node name="PegAction" type="Node2D" unique_id=460007250]
script = ExtResource("1_8o8tf")
[node name="Image" type="Sprite2D" parent="." unique_id=1133735272]
+1 -1
View File
@@ -9,7 +9,7 @@ public partial class PlayerController : TurnController
[Signal]
public delegate void DeathEventHandler(PlayerController THIS);
public bool _dead = false;
public int _health, _healthMax = 100;
public int _health, _healthMax = 100, _gold = 0;
public PegController _pegController;
public PackedScene _commanderScene = GD.Load<PackedScene>("res://Commander.tscn");
public List<Tower> _towers = new();
+9 -16
View File
@@ -9,7 +9,7 @@ public partial class Tower : HoverableNode
public int _launchSpeed = 1000, _arcIterations = 50;
public Vector2 _aimOffset, _arcEnd;
public List<Vector2> _arc = new();
public Marker2D _offset, _attackSpawn;
public Marker2D _offset, _ballSpawn;
public Area2D _area;
public Commander _commander;
public override void _Ready()
@@ -17,7 +17,7 @@ public partial class Tower : HoverableNode
base._Ready();
_offset = GetNode<Marker2D>("Offset");
_attackSpawn = GetNode<Marker2D>("AttackSpawn");
_ballSpawn = GetNode<Marker2D>("BallSpawn");
// Click += HandleClick;
}
public override void _Process(double delta)
@@ -29,19 +29,19 @@ public partial class Tower : HoverableNode
{
if (_arcEnd != GetGlobalMousePosition())
{
DrawArc(_attackSpawn.GlobalPosition, GetGlobalMousePosition());
DrawArc(_ballSpawn.GlobalPosition, GetGlobalMousePosition());
}
if (Input.IsActionJustPressed("rightClick"))
{
_commander.UnloadAttack();
_commander.UnloadBall();
_aiming = false;
}
else if (Input.IsActionJustPressed("leftClick"))
{
_aimOffset = ToLaunchVector(CalculateLaunchAngle(_attackSpawn.GlobalPosition, GetGlobalMousePosition()));
_aimOffset = ToLaunchVector(CalculateLaunchAngle(_ballSpawn.GlobalPosition, GetGlobalMousePosition()));
_commander.ShootCurrentAttack(_aimOffset);
_commander.ShootCurrentBall(_aimOffset);
ClearArc();
_aiming = false;
@@ -52,7 +52,7 @@ public partial class Tower : HoverableNode
if (Input.IsActionJustPressed("leftClick"))
{
_aiming = true;
_commander.LoadAttack(_attackSpawn.Position);
_commander.LoadBall(_ballSpawn.Position);
}
}
}
@@ -112,7 +112,7 @@ public partial class Tower : HoverableNode
public void ClearArc()
{
Path2D path = _commander._attack.GetNode<Path2D>("PredictedPath");
Path2D path = _commander._ball.GetNode<Path2D>("PredictedPath");
path.Curve.ClearPoints();
}
@@ -144,7 +144,7 @@ public partial class Tower : HoverableNode
}
}
Path2D path = _commander._attack.GetNode<Path2D>("PredictedPath");
Path2D path = _commander._ball.GetNode<Path2D>("PredictedPath");
path.Curve.ClearPoints();
for (int i = 0; i < arc.Count; i++)
@@ -193,11 +193,4 @@ public partial class Tower : HoverableNode
return Vector2.FromAngle(ANGLE) * _launchSpeed;
}
public void OnMouseEntered(){
_hovered = true;
}
public void OnMouseExited(){
_hovered = true;
}
}
+5 -5
View File
@@ -1,7 +1,7 @@
[gd_scene format=3 uid="uid://cevk7yax5tvej"]
[ext_resource type="Script" uid="uid://dm2gyxmgwbmg8" path="res://Attack.cs" id="1_63pi1"]
[ext_resource type="Texture2D" uid="uid://nwj4n7if8kqd" path="res://Art/circle25r.png" id="2_hqc8w"]
[ext_resource type="Script" uid="uid://dm2gyxmgwbmg8" path="res://Ball.cs" id="1_41u45"]
[ext_resource type="Texture2D" uid="uid://nwj4n7if8kqd" path="res://Art/circle25r.png" id="2_ktgx5"]
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_63pi1"]
bounce = 0.25
@@ -11,19 +11,19 @@ radius = 12.5
[sub_resource type="Curve2D" id="Curve2D_63pi1"]
[node name="Attack" type="RigidBody2D" unique_id=1225359241]
[node name="Ball" type="RigidBody2D" unique_id=1225359241]
input_pickable = true
physics_material_override = SubResource("PhysicsMaterial_63pi1")
contact_monitor = true
max_contacts_reported = 100
script = ExtResource("1_63pi1")
script = ExtResource("1_41u45")
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1448070524]
shape = SubResource("CircleShape2D_7yfhp")
[node name="Sprite2D" type="Sprite2D" parent="." unique_id=1583277900]
scale = Vector2(0.5, 0.5)
texture = ExtResource("2_hqc8w")
texture = ExtResource("2_ktgx5")
[node name="Ray" type="RayCast2D" parent="." unique_id=113171676]
+3 -3
View File
@@ -2,9 +2,9 @@
[ext_resource type="Script" uid="uid://cg1m762ed04kv" path="res://Main.cs" id="1_ig7tw"]
[ext_resource type="PackedScene" uid="uid://dumcridek4xy3" path="res://play_area.tscn" id="2_1bvp3"]
[ext_resource type="PackedScene" uid="uid://c6b188d2a20eq" path="res://peg_controller.tscn" id="4_1bvp3"]
[ext_resource type="PackedScene" path="res://peg_controller.tscn" id="3_lquwl"]
[ext_resource type="PackedScene" uid="uid://b7kvx7p0b2086" path="res://player_controller.tscn" id="4_lquwl"]
[ext_resource type="PackedScene" uid="uid://by0a5f2ft0u03" path="res://mouse_handler.tscn" id="5_lquwl"]
[ext_resource type="PackedScene" path="res://mouse_handler.tscn" id="5_lquwl"]
[node name="Main" type="Node" unique_id=535208469]
script = ExtResource("1_ig7tw")
@@ -12,7 +12,7 @@ script = ExtResource("1_ig7tw")
[node name="PlayArea" parent="." unique_id=1123610167 instance=ExtResource("2_1bvp3")]
position = Vector2(360, 180)
[node name="PegController" parent="." unique_id=1894449838 instance=ExtResource("4_1bvp3")]
[node name="PegController" parent="." unique_id=197453707 instance=ExtResource("3_lquwl")]
[node name="PlayerController" parent="." unique_id=364781168 instance=ExtResource("4_lquwl")]
+3 -6
View File
@@ -1,8 +1,8 @@
[gd_scene format=3 uid="uid://b06qhbc336iwh"]
[gd_scene format=3 uid="uid://01m32xxk1ryh"]
[ext_resource type="Script" uid="uid://g2ucwg3k342p" path="res://Peg.cs" id="1_cavuh"]
[ext_resource type="Texture2D" uid="uid://nwj4n7if8kqd" path="res://Art/circle25r.png" id="2_cut4e"]
[ext_resource type="Texture2D" uid="uid://m4wfj36twmqy" path="res://Art/attack.png" id="3_inmy4"]
[ext_resource type="PackedScene" uid="uid://bj2qrn0l01us1" path="res://Pegs/peg_action.tscn" id="3_cavuh"]
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_7k104"]
bounce = 0.5
@@ -23,10 +23,7 @@ texture_filter = 1
scale = Vector2(0.5, 0.5)
texture = ExtResource("2_cut4e")
[node name="Attack" type="Sprite2D" parent="." unique_id=1776738311]
visible = false
texture_filter = 1
texture = ExtResource("3_inmy4")
[node name="PegAction" parent="." unique_id=637569115 instance=ExtResource("3_cavuh")]
[node name="HoverBounds" type="Area2D" parent="." unique_id=2086452813]
+3 -3
View File
@@ -1,6 +1,6 @@
[gd_scene format=3 uid="uid://c6b188d2a20eq"]
[gd_scene format=3 uid="uid://bxlt2ap0dym1x"]
[ext_resource type="Script" uid="uid://brsi76xcgx3et" path="res://PegController.cs" id="1_tkpyo"]
[ext_resource type="Script" path="res://PegController.cs" id="1_31br5"]
[node name="PegController" type="Node2D" unique_id=197453707]
script = ExtResource("1_tkpyo")
script = ExtResource("1_31br5")
+1 -1
View File
@@ -21,7 +21,7 @@ debug_color = Color(0.6411928, 0.52469516, 0, 0.41960785)
[node name="Offset" type="Marker2D" parent="." unique_id=2053853274]
position = Vector2(25, -50)
[node name="AttackSpawn" type="Marker2D" parent="." unique_id=715904909]
[node name="BallSpawn" type="Marker2D" parent="." unique_id=715904909]
position = Vector2(0, -24)
[connection signal="mouse_entered" from="HoverBounds" to="." method="OnMouseEntered"]