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:
2026-07-02 03:15:15 -04:00
parent 909f466f92
commit cbdca6f3cb
16 changed files with 170 additions and 50 deletions
+3 -3
View File
@@ -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;
}
+11 -4
View File
@@ -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;
}
}
+15 -2
View File
@@ -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];
}
}
+24 -1
View File
@@ -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();
}
}