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:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user