diff --git a/Attack.cs b/Ball.cs similarity index 80% rename from Attack.cs rename to Ball.cs index 796be06..211f448 100644 --- a/Attack.cs +++ b/Ball.cs @@ -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("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; - } + } diff --git a/Attack.cs.uid b/Ball.cs.uid similarity index 100% rename from Attack.cs.uid rename to Ball.cs.uid diff --git a/Bucket.cs b/Bucket.cs index 3010394..11b0d86 100644 --- a/Bucket.cs +++ b/Bucket.cs @@ -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(); } } } diff --git a/Commander.cs b/Commander.cs index 11b641f..327b543 100644 --- a/Commander.cs +++ b/Commander.cs @@ -6,18 +6,18 @@ public partial class Commander : Sprite2D [Signal] public delegate void ActionsUpEventHandler(); public int _actionsMax = 1, _actions; - public PackedScene _attackScene = GD.Load("res://Attack.tscn"); - public Attack _attack; + public PackedScene _ballScene = GD.Load("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.Position = OFFSET; - _attack._commanderOwner = this; - _attack.GravityScale = 0; - _attack.BucketEntered += AttackEnteredBucket; - AddChild(_attack); + _ball = _ballScene.Instantiate(); + _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; } } diff --git a/Globals.cs b/Globals.cs index 684501b..ac6bf4c 100644 --- a/Globals.cs +++ b/Globals.cs @@ -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(List TYPED_LIST) + { + return TYPED_LIST[_rng.Next(0,TYPED_LIST.Count)]; + } } diff --git a/Peg.cs b/Peg.cs index dd7ce47..3009ead 100644 --- a/Peg.cs +++ b/Peg.cs @@ -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 _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 _path = new(); - public float _movement = 0; public PegController _pegController; - public Sprite2D _attack; + public PegAction _action; public override void _Ready() { base._Ready(); - _attack = GetNode("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 goals = GetGoals(); - // List> paths = new(); - Vector2I bestGoal = goals[0]; - float bestCost = map._astar._EstimateCost(_address, bestGoal); + + List 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 testPath = map.GetPath(_address, testGoal); + if (testPath.Count < bestPath.Count) { - bestCost = testCost; - bestGoal = testGoal; + bestPath = testPath; } } - // List bestPath = paths.Where(p => p.Count > 0).OrderBy(p => p.Count).ToList()[0]; - List bestPath = map.GetPath(_address, bestGoal); return bestPath; } public virtual List 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; + } } } diff --git a/PegController.cs b/PegController.cs index 7414fab..5bb0d35 100644 --- a/PegController.cs +++ b/PegController.cs @@ -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("res://hostile_peg.tscn"); + public int _actionLoop = 0, _pegsCreated = 0, _pegsDestroyed = 0; + public List _hostilePegScenes; public List _pegs = new(); public PlayerController _playerController; public Dictionary> _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(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 newHostilePeg = Globals.GetRandomFromList(_hostilePegScenes).Instantiate(); + 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 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 POSITIONS) { for (int i = 0; i < POSITIONS.Count; i++) { - HostilePeg newHostilePeg = _hostilePegScene.Instantiate(); + HostilePeg newHostilePeg = Globals.GetRandomFromList(_hostilePegScenes).Instantiate(); + 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").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 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 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("PathLayer"); List 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 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); } diff --git a/PegProbabilities.html b/PegProbabilities.html new file mode 100644 index 0000000..cb65845 --- /dev/null +++ b/PegProbabilities.html @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/Pegs/Actions/Shortbow.cs b/Pegs/Actions/Shortbow.cs new file mode 100644 index 0000000..c69c9af --- /dev/null +++ b/Pegs/Actions/Shortbow.cs @@ -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; + } + +} diff --git a/Pegs/Actions/Shortbow.cs.uid b/Pegs/Actions/Shortbow.cs.uid new file mode 100644 index 0000000..bfaa971 --- /dev/null +++ b/Pegs/Actions/Shortbow.cs.uid @@ -0,0 +1 @@ +uid://dt7qbvowj1sm4 diff --git a/Pegs/Actions/Shortsword.cs b/Pegs/Actions/Shortsword.cs new file mode 100644 index 0000000..de678cc --- /dev/null +++ b/Pegs/Actions/Shortsword.cs @@ -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; + } +} diff --git a/Pegs/Actions/Shortsword.cs.uid b/Pegs/Actions/Shortsword.cs.uid new file mode 100644 index 0000000..af9864e --- /dev/null +++ b/Pegs/Actions/Shortsword.cs.uid @@ -0,0 +1 @@ +uid://td6dv1t4y5os diff --git a/Pegs/Actions/shortbow.tscn b/Pegs/Actions/shortbow.tscn new file mode 100644 index 0000000..42ffa32 --- /dev/null +++ b/Pegs/Actions/shortbow.tscn @@ -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] diff --git a/Pegs/Actions/shortsword.tscn b/Pegs/Actions/shortsword.tscn new file mode 100644 index 0000000..e46efcc --- /dev/null +++ b/Pegs/Actions/shortsword.tscn @@ -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") diff --git a/HostilePeg.cs b/Pegs/HostilePeg.cs similarity index 60% rename from HostilePeg.cs rename to Pegs/HostilePeg.cs index a671c12..aadae0a 100644 --- a/HostilePeg.cs +++ b/Pegs/HostilePeg.cs @@ -12,10 +12,4 @@ public partial class HostilePeg : Peg base._Ready(); } - // public void OnMouseEntered(){ - // _hovered = true; - // } - // public void OnMouseExited(){ - // _hovered = false; - // } } diff --git a/HostilePeg.cs.uid b/Pegs/HostilePeg.cs.uid similarity index 100% rename from HostilePeg.cs.uid rename to Pegs/HostilePeg.cs.uid diff --git a/Pegs/HostilePegs/Archer.cs b/Pegs/HostilePegs/Archer.cs new file mode 100644 index 0000000..751b9bf --- /dev/null +++ b/Pegs/HostilePegs/Archer.cs @@ -0,0 +1,12 @@ +using Godot; +using System; + +public partial class Archer : HostilePeg +{ + public override void _Ready() + { + base._Ready(); + _stamina = 2; + _action = GetNode("Shortbow"); + } +} diff --git a/Pegs/HostilePegs/Archer.cs.uid b/Pegs/HostilePegs/Archer.cs.uid new file mode 100644 index 0000000..b67f6f0 --- /dev/null +++ b/Pegs/HostilePegs/Archer.cs.uid @@ -0,0 +1 @@ +uid://b3a0x3r3yx861 diff --git a/Pegs/HostilePegs/Infantry.cs b/Pegs/HostilePegs/Infantry.cs new file mode 100644 index 0000000..c0d8877 --- /dev/null +++ b/Pegs/HostilePegs/Infantry.cs @@ -0,0 +1,12 @@ +using Godot; +using System; + +public partial class Infantry : HostilePeg +{ + public override void _Ready() + { + base._Ready(); + _stamina = 3; + _action = GetNode("Shortsword"); + } +} diff --git a/Pegs/HostilePegs/Infantry.cs.uid b/Pegs/HostilePegs/Infantry.cs.uid new file mode 100644 index 0000000..0bc0129 --- /dev/null +++ b/Pegs/HostilePegs/Infantry.cs.uid @@ -0,0 +1 @@ +uid://xlg4cblo1vf1 diff --git a/Pegs/HostilePegs/archer.tscn b/Pegs/HostilePegs/archer.tscn new file mode 100644 index 0000000..79d1421 --- /dev/null +++ b/Pegs/HostilePegs/archer.tscn @@ -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"] diff --git a/Pegs/HostilePegs/infantry.tscn b/Pegs/HostilePegs/infantry.tscn new file mode 100644 index 0000000..f5213db --- /dev/null +++ b/Pegs/HostilePegs/infantry.tscn @@ -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"] diff --git a/Pegs/PegAction.cs b/Pegs/PegAction.cs new file mode 100644 index 0000000..a085dc4 --- /dev/null +++ b/Pegs/PegAction.cs @@ -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("Image"); + } + + public virtual Tween CreateAnimation(Peg PEG) + { + return null; + } +} diff --git a/Pegs/PegAction.cs.uid b/Pegs/PegAction.cs.uid new file mode 100644 index 0000000..9e6d9fe --- /dev/null +++ b/Pegs/PegAction.cs.uid @@ -0,0 +1 @@ +uid://dpa15pxib2qyr diff --git a/hostile_peg.tscn b/Pegs/hostile_peg.tscn similarity index 79% rename from hostile_peg.tscn rename to Pegs/hostile_peg.tscn index dbe872d..575b78e 100644 --- a/hostile_peg.tscn +++ b/Pegs/hostile_peg.tscn @@ -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] diff --git a/Pegs/peg_action.tscn b/Pegs/peg_action.tscn new file mode 100644 index 0000000..738a4b4 --- /dev/null +++ b/Pegs/peg_action.tscn @@ -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] diff --git a/PlayerController.cs b/PlayerController.cs index cbcec34..5ed8f0f 100644 --- a/PlayerController.cs +++ b/PlayerController.cs @@ -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("res://Commander.tscn"); public List _towers = new(); diff --git a/Tower.cs b/Tower.cs index ec9b524..f141fc0 100644 --- a/Tower.cs +++ b/Tower.cs @@ -9,7 +9,7 @@ public partial class Tower : HoverableNode public int _launchSpeed = 1000, _arcIterations = 50; public Vector2 _aimOffset, _arcEnd; public List _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("Offset"); - _attackSpawn = GetNode("AttackSpawn"); + _ballSpawn = GetNode("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("PredictedPath"); + Path2D path = _commander._ball.GetNode("PredictedPath"); path.Curve.ClearPoints(); } @@ -144,7 +144,7 @@ public partial class Tower : HoverableNode } } - Path2D path = _commander._attack.GetNode("PredictedPath"); + Path2D path = _commander._ball.GetNode("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; - } - } diff --git a/attack.tscn b/ball.tscn similarity index 86% rename from attack.tscn rename to ball.tscn index 377106d..7218b25 100644 --- a/attack.tscn +++ b/ball.tscn @@ -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] diff --git a/main.tscn b/main.tscn index 6348e46..96c17f0 100644 --- a/main.tscn +++ b/main.tscn @@ -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")] diff --git a/peg.tscn b/peg.tscn index ddaa58f..5b0c7d4 100644 --- a/peg.tscn +++ b/peg.tscn @@ -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] diff --git a/peg_controller.tscn b/peg_controller.tscn index 961dea0..8bbdb31 100644 --- a/peg_controller.tscn +++ b/peg_controller.tscn @@ -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") diff --git a/tower.tscn b/tower.tscn index 69c1288..2894020 100644 --- a/tower.tscn +++ b/tower.tscn @@ -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"]