implemented more code for adding more pegs, but still a lot of work to do on pathfinding, targeting, map etc.
This commit is contained in:
@@ -26,7 +26,7 @@ public partial class Ball : RigidBody2D
|
||||
EmitSignal(SignalName.Hit, BODY);
|
||||
if (BODY is Peg peg)
|
||||
{
|
||||
peg.ChangeHealth(_healthChange, _commanderOwner);
|
||||
peg.ChangeHealth(_healthChange);
|
||||
_hits++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ public partial class Map : TileMapLayer
|
||||
_astar.Update();
|
||||
for (int i = 0; i < _cells.Count; i++)
|
||||
{
|
||||
_astar.SetPointWeightScale(_cells[i], _cells[i].Y * 2);
|
||||
_astar.SetPointWeightScale(_cells[i], Math.Abs(_cells[i].Y * 2));
|
||||
}
|
||||
EvaluateSolidCells();
|
||||
}
|
||||
|
||||
@@ -11,7 +11,9 @@ texture = ExtResource("1_gfjgm")
|
||||
texture_region_size = Vector2i(40, 40)
|
||||
0:0/0 = 0
|
||||
1:0/0 = 0
|
||||
1:0/0/custom_data_1 = -1
|
||||
2:0/0 = 0
|
||||
2:0/0/custom_data_1 = 1
|
||||
3:0/0 = 0
|
||||
3:0/0/custom_data_0 = true
|
||||
4:0/0 = 0
|
||||
@@ -26,6 +28,8 @@ texture_region_size = Vector2i(40, 40)
|
||||
tile_size = Vector2i(40, 40)
|
||||
custom_data_layer_0/name = "is_solid"
|
||||
custom_data_layer_0/type = 1
|
||||
custom_data_layer_1/name = "disposition"
|
||||
custom_data_layer_1/type = 2
|
||||
sources/1 = SubResource("TileSetAtlasSource_trj13")
|
||||
pattern_0 = SubResource("TileMapPattern_fjt81")
|
||||
|
||||
|
||||
@@ -46,19 +46,24 @@ public partial class Peg : HoverableNode
|
||||
|
||||
public virtual List<Vector2I> GetBestPath(bool PARTIAL = false)
|
||||
{
|
||||
Map map = _pegController._playArea._map;
|
||||
List<Vector2I> goals = Target();
|
||||
// Map map = _pegController._playArea._map;
|
||||
// List<Vector2I> goals = Target();
|
||||
|
||||
for (int i = 0; i < goals.Count; i++)
|
||||
{
|
||||
List<Vector2I> path = map.GetPath(_address, goals[i], false, PARTIAL);
|
||||
if (path.Count > 0)
|
||||
{
|
||||
return path;
|
||||
}
|
||||
// for (int i = 0; i < goals.Count; i++)
|
||||
// {
|
||||
// List<Vector2I> path = map.GetPath(_address, goals[i], false, PARTIAL);
|
||||
// if (path.Count > 0)
|
||||
// {
|
||||
// return path;
|
||||
// }
|
||||
|
||||
}
|
||||
return [];
|
||||
// }
|
||||
return _pegController._playArea._map.GetPath(_address, Goal(), false, PARTIAL);
|
||||
}
|
||||
|
||||
public virtual List<Peg> GetEnemies()
|
||||
{
|
||||
return [.. _pegController._pegs.Where(p => p._disposition == -_disposition).OrderBy(p => (p._address - _address).Length())];
|
||||
}
|
||||
|
||||
public virtual List<Vector2I> GetVisibleCells()
|
||||
@@ -67,13 +72,10 @@ public partial class Peg : HoverableNode
|
||||
return [.. map._cells.Where(c => (c - _address).Length() <= _visibility)];
|
||||
}
|
||||
|
||||
public virtual List<Vector2I> Target()
|
||||
public virtual List<Peg> GetVisibleEnemies()
|
||||
{
|
||||
Map map = _pegController._playArea._map;
|
||||
List<Vector2I> visible = GetVisibleCells();
|
||||
List<Vector2I> unoccupied = [.. visible.Where(c => !map._astar.IsPointSolid(c))];
|
||||
List<Vector2I> closest = [.. unoccupied.OrderByDescending(c => c.Y * _disposition).ThenByDescending(c => Math.Abs(c.X - _address.X))];
|
||||
return closest;
|
||||
List<Vector2I> visible = GetVisibleCells();
|
||||
return [.. GetEnemies().Where(e => visible.Contains(e._address))];
|
||||
}
|
||||
|
||||
public Vector2 GetPositionFromAddress()
|
||||
@@ -81,16 +83,24 @@ public partial class Peg : HoverableNode
|
||||
return _pegController._playArea._map.GetCellPositionFromAddress(_address);
|
||||
}
|
||||
|
||||
public virtual Vector2I Goal()
|
||||
{
|
||||
Map map = _pegController._playArea._map;
|
||||
List<Vector2I> visible = GetVisibleCells();
|
||||
List<Vector2I> unoccupied = [.. visible.Where(c => !map._astar.IsPointSolid(c))];
|
||||
List<Vector2I> closest = [.. unoccupied.OrderByDescending(c => c.Y * _disposition).ThenByDescending(c => Math.Abs(c.X - _address.X))];
|
||||
return closest[0];
|
||||
}
|
||||
|
||||
public virtual void StartTurn()
|
||||
{
|
||||
_staminaRemaining = _stamina;
|
||||
_actions.ForEach(a => a.Reset());
|
||||
}
|
||||
|
||||
public virtual void ChangeHealth(int DELTA, Commander COMMANDER)
|
||||
public virtual void ChangeHealth(int DELTA)
|
||||
{
|
||||
_health += DELTA;
|
||||
CounterAct(COMMANDER);
|
||||
if (_health <= 0)
|
||||
{
|
||||
EmitSignal(SignalName.Death, this);
|
||||
|
||||
+49
-4
@@ -13,7 +13,7 @@ using System.Xml;
|
||||
public partial class PegController : TurnController
|
||||
{
|
||||
public int _pegsCreated = 0, _pegsDestroyed = 0;
|
||||
public List<PackedScene> _hostilePegScenes;
|
||||
public List<PackedScene> _hostilePegScenes, _friendlyPegScenes, _neutralPegScenes;
|
||||
public List<Peg> _pegs = new();
|
||||
public PlayerController _playerController;
|
||||
public Dictionary<string, List<Tuple<Peg, PegAction>>> _tweenStages = new();
|
||||
@@ -24,10 +24,51 @@ public partial class PegController : TurnController
|
||||
{
|
||||
base._Ready();
|
||||
_hostilePegScenes = [.. Directory.GetFiles("Pegs/HostilePegs/", "*.tscn").Select(f => GD.Load<PackedScene>(f))];
|
||||
_friendlyPegScenes = [.. Directory.GetFiles("Pegs/FriendlyPegs/", "*.tscn").Select(f => GD.Load<PackedScene>(f))];
|
||||
// _neutralPegScenes = [.. Directory.GetFiles("Pegs/NeutralPegs/", "*.tscn").Select(f => GD.Load<PackedScene>(f))];
|
||||
|
||||
// _pegProbabilities.Load("res://PegProbabilities.xml");
|
||||
}
|
||||
|
||||
public void AddFriendlyPegs(int PEG_COUNT = 1)
|
||||
{
|
||||
for (int i = 0; i < PEG_COUNT; i++)
|
||||
{
|
||||
FriendlyPeg newFriendlyPeg = Globals.GetRandomFromList(_friendlyPegScenes).Instantiate<FriendlyPeg>();
|
||||
newFriendlyPeg._id = _pegsCreated;
|
||||
newFriendlyPeg.Death += HandlePegRemoval;
|
||||
newFriendlyPeg.Click += HandlePegClick;
|
||||
|
||||
newFriendlyPeg._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(newFriendlyPeg, randomCell);
|
||||
_pegs.Add(newFriendlyPeg);
|
||||
AddChild(newFriendlyPeg);
|
||||
_pegsCreated++;
|
||||
}
|
||||
}
|
||||
public void AddFriendlyPegs(List<Vector2I> POSITIONS)
|
||||
{
|
||||
for (int i = 0; i < POSITIONS.Count; i++)
|
||||
{
|
||||
FriendlyPeg newFriendlyPeg = Globals.GetRandomFromList(_friendlyPegScenes).Instantiate<FriendlyPeg>();
|
||||
newFriendlyPeg._id = _pegsCreated;
|
||||
newFriendlyPeg.Scale *= _pegsCreated == 4 ? 1.5f : 1f;
|
||||
newFriendlyPeg.Death += HandlePegRemoval;
|
||||
newFriendlyPeg.Click += HandlePegClick;
|
||||
|
||||
newFriendlyPeg._pegController = this;
|
||||
|
||||
SetPeg(newFriendlyPeg, POSITIONS[i]);
|
||||
_pegs.Add(newFriendlyPeg);
|
||||
AddChild(newFriendlyPeg);
|
||||
_pegsCreated++;
|
||||
}
|
||||
}
|
||||
|
||||
public void AddHostilePegs(int PEG_COUNT = 1)
|
||||
{
|
||||
for (int i = 0; i < PEG_COUNT; i++)
|
||||
@@ -152,9 +193,13 @@ public partial class PegController : TurnController
|
||||
|
||||
public void Initiate()
|
||||
{
|
||||
List<Vector2I> positions = [.. _playArea.GetNode<TileMapLayer>("InitialPositions").GetUsedCells().OrderBy(c => c.Y).ThenBy(c => c.X)];
|
||||
|
||||
AddHostilePegs(positions);
|
||||
TileMapLayer init = _playArea.GetNode<TileMapLayer>("InitialPositions");
|
||||
List<Vector2I> initPos = [.. init.GetUsedCells()];
|
||||
List<Vector2I> positions = [.. initPos.OrderBy(c => c.Y).ThenBy(c => c.X)];
|
||||
List<Vector2I> hPositions = [.. positions.Where(c => (int)init.GetCellTileData(c).GetCustomData("disposition") == -1)];
|
||||
List<Vector2I> fPositions = [.. positions.Where(c => (int)init.GetCellTileData(c).GetCustomData("disposition") == 1)];
|
||||
AddHostilePegs(hPositions);
|
||||
AddFriendlyPegs(fPositions);
|
||||
}
|
||||
|
||||
public void ProcessTween()
|
||||
|
||||
@@ -18,7 +18,6 @@ public partial class BasicMovement : PegAction
|
||||
|
||||
public override Tween CreateAnimation(Peg PEG)
|
||||
{
|
||||
GD.Print(PEG._address);
|
||||
PegController pegController = PEG._pegController;
|
||||
Map map = pegController._playArea._map;
|
||||
Vector2I cell = PEG._path[0];
|
||||
@@ -33,7 +32,7 @@ public partial class BasicMovement : PegAction
|
||||
|
||||
public override void DoImmediately(Peg PEG)
|
||||
{
|
||||
List<Vector2I> path = PEG.GetBestPath();
|
||||
List<Vector2I> path = PEG.GetBestPath(true);
|
||||
PegController pegController = PEG._pegController;
|
||||
Map map = pegController._playArea._map;
|
||||
if (path?.Count == 0)
|
||||
@@ -48,7 +47,8 @@ public partial class BasicMovement : PegAction
|
||||
|
||||
public override bool MeetsCriteria(Peg PEG)
|
||||
{
|
||||
return base.MeetsCriteria(PEG) && PEG._address.Y > PEG._pegController._playArea._map._firstOpenRow;
|
||||
List<Vector2I> bestPath = PEG.GetBestPath(true);
|
||||
return base.MeetsCriteria(PEG) && bestPath.Count > 0 && (int)PEG._pegController._playArea._map.GetCellTileData(bestPath[0]).GetCustomData("disposition") != -PEG._disposition;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
public partial class ShootShortbow : PegAction
|
||||
@@ -10,16 +11,17 @@ public partial class ShootShortbow : PegAction
|
||||
_category = "attack";
|
||||
_priority = 1;
|
||||
_cost = 2;
|
||||
_range = 1;
|
||||
_range = 2;
|
||||
_usesMax = 1;
|
||||
_usesRemaining = _usesMax;
|
||||
}
|
||||
|
||||
public override Tween CreateAnimation(Peg PEG)
|
||||
{
|
||||
Vector2 target = Target(PEG);
|
||||
Vector2 target = PEG._pegController._playArea._map.GetCellPositionFromAddress(Target(PEG));
|
||||
Tween subtween = CreateTween();
|
||||
subtween.TweenProperty(_image, "visible", true, 0.0f);
|
||||
subtween.TweenProperty(_image, "rotation", PEG.GetAngleTo(target), 0.0f);
|
||||
subtween.TweenProperty(_image, "global_position", target, 0.5f);
|
||||
subtween.TweenCallback(Callable.From(() =>
|
||||
{
|
||||
@@ -30,9 +32,14 @@ public partial class ShootShortbow : PegAction
|
||||
return subtween;
|
||||
}
|
||||
|
||||
public override Vector2 Target(Peg PEG)
|
||||
public override Vector2I Target(Peg PEG)
|
||||
{
|
||||
return PEG._pegController._playerController._towers.OrderBy(t => (t.GlobalPosition - GlobalPosition).Length()).ToList()[0].GlobalPosition;
|
||||
List<Vector2I> closest = [.. PEG.GetVisibleCells().Where(c => (int)PEG._pegController._playArea._map.GetCellTileData(c).GetCustomData("disposition") == -PEG._disposition).OrderBy(c => (c - PEG._address).Length())];
|
||||
if (closest.Count == 0)
|
||||
{
|
||||
return -Vector2I.One;
|
||||
}
|
||||
return closest[0]; // return PEG._pegController._playerController._towers.OrderBy(t => (t.GlobalPosition - GlobalPosition).Length()).ToList()[0].GlobalPosition;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
public partial class SwingShortsword : PegAction
|
||||
@@ -10,17 +11,18 @@ public partial class SwingShortsword : PegAction
|
||||
_category = "attack";
|
||||
_priority = 1;
|
||||
_cost = 2;
|
||||
_range = 0;
|
||||
_range = 1;
|
||||
_usesMax = 1;
|
||||
_usesRemaining = _usesMax;
|
||||
}
|
||||
|
||||
public override Tween CreateAnimation(Peg PEG)
|
||||
{
|
||||
Vector2 target = PEG._disposition * Vector2.Down * PEG._pegController._playArea._map._cellSize;
|
||||
Vector2 target = PEG._pegController._playArea._map.GetCellPositionFromAddress(Target(PEG));
|
||||
// GD.Print(target);
|
||||
Tween subtween = CreateTween();
|
||||
subtween.TweenProperty(_image, "visible", true, 0.0f);
|
||||
subtween.TweenProperty(_image, "rotation", PEG.GetAngleTo(target), 0.0f);
|
||||
subtween.TweenProperty(_image, "position", target, 0.5f);
|
||||
subtween.TweenCallback(Callable.From(() =>
|
||||
{
|
||||
@@ -30,4 +32,15 @@ public partial class SwingShortsword : PegAction
|
||||
}));
|
||||
return subtween;
|
||||
}
|
||||
|
||||
public override Vector2I Target(Peg PEG)
|
||||
{
|
||||
List<Vector2I> closest = [.. PEG.GetVisibleCells().Where(c => (int)PEG._pegController._playArea._map.GetCellTileData(c).GetCustomData("disposition") == -PEG._disposition).OrderBy(c => (c - PEG._address).Length())];
|
||||
if (closest.Count == 0)
|
||||
{
|
||||
return -Vector2I.One;
|
||||
}
|
||||
return closest[0];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,10 +9,33 @@ public partial class ThrustSpear : PegAction
|
||||
_category = "attack";
|
||||
_priority = 1;
|
||||
_cost = 2;
|
||||
_range = 0;
|
||||
_range = 1;
|
||||
_usesMax = 1;
|
||||
_usesRemaining = _usesMax;
|
||||
}
|
||||
|
||||
public override Tween CreateAnimation(Peg PEG)
|
||||
{
|
||||
Map map = PEG._pegController._playArea._map;
|
||||
Peg pegTarget = map._addressOccupants[Target(PEG)];
|
||||
Tween subtween = CreateTween();
|
||||
|
||||
subtween.TweenProperty(_image, "visible", true, 0.0f);
|
||||
subtween.TweenProperty(_image, "rotation", PEG.GetAngleTo(pegTarget.GlobalPosition), 0.0f);
|
||||
subtween.TweenProperty(_image, "position", pegTarget, 0.5f);
|
||||
subtween.TweenCallback(Callable.From(() =>
|
||||
{
|
||||
pegTarget.ChangeHealth(-2);
|
||||
_image.Position = Vector2.Zero;
|
||||
_image.Visible = false;
|
||||
}));
|
||||
return subtween;
|
||||
}
|
||||
|
||||
public override Vector2I Target(Peg PEG)
|
||||
{
|
||||
return PEG.Goal();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -12,12 +12,15 @@ public partial class Spearman : FriendlyPeg
|
||||
_visibility = 4;
|
||||
}
|
||||
|
||||
public override List<Vector2I> Target()
|
||||
public override Vector2I Goal()
|
||||
{
|
||||
Map map = _pegController._playArea._map;
|
||||
List<Peg> enemies = [.. _pegController._pegs.Where(p => p._disposition == -_disposition)];
|
||||
List<Vector2I> neighboring = [.. map._cells.Where(c => enemies.Any(e => (e._address - c).Length() <= 1f))];
|
||||
List<Vector2I> closest = [.. neighboring.OrderBy(c => (c - _address).Length())];
|
||||
return closest;
|
||||
if (enemies.Count == 0)
|
||||
{
|
||||
return _address;
|
||||
}
|
||||
List<Vector2I> closest = [.. enemies.OrderBy(e => (e._address - _address).Length()).Select(e => e._address)];
|
||||
return closest[0];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
[ext_resource type="Script" uid="uid://dd4k8egcg3r2v" path="res://Pegs/FriendlyPegs/Spearman.cs" id="1_rd6ui"]
|
||||
[ext_resource type="Texture2D" uid="uid://nwj4n7if8kqd" path="res://Art/circle25r.png" id="2_v2nt8"]
|
||||
[ext_resource type="PackedScene" uid="uid://xx4n81m8hbxv" path="res://Pegs/Actions/thrust_spear.tscn" id="3_ig48t"]
|
||||
[ext_resource type="PackedScene" uid="uid://bup5oli00p3lg" path="res://Pegs/Actions/basic_movement.tscn" id="4_gi7y5"]
|
||||
|
||||
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_7k104"]
|
||||
bounce = 0.5
|
||||
@@ -21,12 +23,17 @@ script = ExtResource("1_rd6ui")
|
||||
shape = SubResource("CircleShape2D_4gyqm")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="." unique_id=1941012605]
|
||||
modulate = Color(1, 1, 0, 1)
|
||||
texture_filter = 1
|
||||
scale = Vector2(0.5, 0.5)
|
||||
texture = ExtResource("2_v2nt8")
|
||||
|
||||
[node name="Actions" type="Node2D" parent="." unique_id=2023031702]
|
||||
|
||||
[node name="ThrustSpear" parent="Actions" unique_id=460007250 instance=ExtResource("3_ig48t")]
|
||||
|
||||
[node name="BasicMovement" parent="Actions" unique_id=791425339 instance=ExtResource("4_gi7y5")]
|
||||
|
||||
[node name="HoverBounds" type="Area2D" parent="." unique_id=937525982]
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="HoverBounds" unique_id=2142666816]
|
||||
|
||||
@@ -30,7 +30,7 @@ texture = ExtResource("2_j7but")
|
||||
|
||||
[node name="Actions" type="Node2D" parent="." unique_id=96111050]
|
||||
|
||||
[node name="Shortbow" parent="Actions" unique_id=518048625 instance=ExtResource("3_c81uf")]
|
||||
[node name="ShootShortbow" parent="Actions" unique_id=518048625 instance=ExtResource("3_c81uf")]
|
||||
|
||||
[node name="BasicMovement" parent="Actions" unique_id=460007250 instance=ExtResource("3_j7but")]
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
[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/swing_shortsword.tscn" id="3_lwlv5"]
|
||||
[ext_resource type="PackedScene" path="res://Pegs/Actions/swing_shortsword.tscn" id="3_b77ka"]
|
||||
[ext_resource type="PackedScene" uid="uid://bup5oli00p3lg" path="res://Pegs/Actions/basic_movement.tscn" id="4_b77ka"]
|
||||
|
||||
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_7k104"]
|
||||
@@ -30,7 +30,7 @@ texture = ExtResource("2_b77ka")
|
||||
|
||||
[node name="Actions" type="Node2D" parent="." unique_id=1442443799]
|
||||
|
||||
[node name="Shortsword" parent="Actions" unique_id=518048625 instance=ExtResource("3_lwlv5")]
|
||||
[node name="Shortsword" parent="Actions" unique_id=518048625 instance=ExtResource("3_b77ka")]
|
||||
|
||||
[node name="BasicMovement" parent="Actions" unique_id=460007250 instance=ExtResource("4_b77ka")]
|
||||
|
||||
|
||||
+3
-3
@@ -27,7 +27,7 @@ public partial class PegAction : Node2D
|
||||
{
|
||||
return PEG._staminaRemaining >= _cost
|
||||
&& _usesRemaining > 0
|
||||
&& PEG._address.Y <= _range;
|
||||
&& (PEG._address - Target(PEG)).Length() <= _range;
|
||||
}
|
||||
|
||||
public virtual void Reset()
|
||||
@@ -35,8 +35,8 @@ public partial class PegAction : Node2D
|
||||
_usesRemaining = _usesMax;
|
||||
}
|
||||
|
||||
public virtual Vector2 Target(Peg PEG)
|
||||
public virtual Vector2I Target(Peg PEG)
|
||||
{
|
||||
return PEG.GlobalPosition;
|
||||
return PEG._address;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -20,8 +20,8 @@ public partial class PlayArea : Node2D
|
||||
CollisionShape2D regionBounds = _region.GetNode<CollisionShape2D>("Bounds");
|
||||
|
||||
_map = GetNode<Map>("Map");
|
||||
TileMapLayer occupiedSpaces = GetNode<TileMapLayer>("OccupiedSpaces");
|
||||
occupiedSpaces.SetCell(Vector2I.Zero, 0, new Vector2I(4,0));
|
||||
// TileMapLayer occupiedSpaces = GetNode<TileMapLayer>("OccupiedSpaces");
|
||||
// occupiedSpaces.SetCell(Vector2I.Zero, 0, new Vector2I(4,0));
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
|
||||
+11
-3
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user