minor changes, next step is to add 2-3 friendly pegs, 2 neutral pegs, 2 hostile pegs, 2 buildings and all associated actions for these additions
This commit is contained in:
@@ -9,9 +9,16 @@ public partial class Map : TileMapLayer
|
||||
public int _minX, _maxX, _minY, _maxY, _mainSource = 0;
|
||||
public string _isSolidString = "is_solid";
|
||||
public Vector2 _cellSize, _sizeInPixels, _sizeInCells;
|
||||
public List<Vector2I> _cells = new(), _leftmostColumn = new(), _rightmostColumn = new(), _topRow = new(), _bottomRow = new();
|
||||
public List<Vector2I> _leftmostColumn = new(), _rightmostColumn = new(), _topRow = new(), _bottomRow = new();
|
||||
public AStarGrid2D _astar = new();
|
||||
public Dictionary<Vector2I, Peg> _addressOccupants = new();
|
||||
public List<Vector2I> _cells
|
||||
{
|
||||
get
|
||||
{
|
||||
return [.. GetUsedCells()];
|
||||
}
|
||||
}
|
||||
public int _firstOpenRow
|
||||
{
|
||||
get
|
||||
@@ -72,7 +79,6 @@ public partial class Map : TileMapLayer
|
||||
{
|
||||
base._Ready();
|
||||
_cellSize = TileSet.TileSize;
|
||||
_cells = [.. GetUsedCells()];
|
||||
_cells.ForEach(c => _addressOccupants[c] = null);
|
||||
_minX = _cells.Min(c => c.X);
|
||||
_maxX = _cells.Max(c => c.X);
|
||||
@@ -149,10 +155,8 @@ public partial class Map : TileMapLayer
|
||||
}
|
||||
PEG._address = ADDRESS;
|
||||
}
|
||||
|
||||
_addressOccupants[ADDRESS] = PEG;
|
||||
SetCellSolid(ADDRESS);
|
||||
PEG._path.Add(ADDRESS);
|
||||
}
|
||||
|
||||
public void SetCellSolid(Vector2I ADDRESS)
|
||||
@@ -175,11 +179,11 @@ public partial class Map : TileMapLayer
|
||||
EvaluateSolidCells();
|
||||
}
|
||||
|
||||
public List<Vector2I> GetPath(Vector2I FROM, Vector2I TO, bool INCLUDE_FROM = false)
|
||||
public List<Vector2I> GetPath(Vector2I FROM, Vector2I TO, bool INCLUDE_FROM = false, bool PARTIAL = false)
|
||||
{
|
||||
_astar.SetPointSolid(FROM, false);
|
||||
|
||||
List<Vector2I> pathTaken = [.. _astar.GetIdPath(FROM, TO)];
|
||||
List<Vector2I> pathTaken = [.. _astar.GetIdPath(FROM, TO, PARTIAL)];
|
||||
_astar.SetPointSolid(FROM, true);
|
||||
|
||||
if (!INCLUDE_FROM)
|
||||
|
||||
@@ -44,22 +44,21 @@ public partial class Peg : HoverableNode
|
||||
|
||||
}
|
||||
|
||||
public virtual List<Vector2I> GetBestPath()
|
||||
public virtual List<Vector2I> GetBestPath(bool PARTIAL = false)
|
||||
{
|
||||
Map map = _pegController._playArea._map;
|
||||
List<Vector2I> goals = GetGoals();
|
||||
List<List<Vector2I>> paths = new();
|
||||
|
||||
for (int i = 0; i < goals.Count; i++)
|
||||
{
|
||||
paths.Add(map.GetPath(_address, goals[i]));
|
||||
List<Vector2I> path = map.GetPath(_address, goals[i], false, PARTIAL);
|
||||
if (path.Count > 0)
|
||||
{
|
||||
return path;
|
||||
}
|
||||
|
||||
}
|
||||
List<List<Vector2I>> pathsOverZeroCount = [.. paths.Where(p => p.Count > 0)];
|
||||
if (pathsOverZeroCount.Count == 0)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
return pathsOverZeroCount.OrderBy(p => p.Count).ToList()[0];
|
||||
return [];
|
||||
}
|
||||
|
||||
public virtual List<Vector2I> GetVisibleCells()
|
||||
@@ -71,18 +70,9 @@ public partial class Peg : HoverableNode
|
||||
public virtual List<Vector2I> GetGoals()
|
||||
{
|
||||
Map map = _pegController._playArea._map;
|
||||
TileMapLayer pathLayer = _pegController._playArea.GetNode<TileMapLayer>("PathLayer");
|
||||
List<Vector2I> pl = [.. pathLayer.GetUsedCells()];
|
||||
List<Vector2I> visible = GetVisibleCells();
|
||||
if (_id == 4)
|
||||
for (int i = 0; i < pl.Count; i++)
|
||||
{
|
||||
Vector2I cell = pl[i];
|
||||
pathLayer.GetUsedCells().ToList().ForEach(c => pathLayer.SetCell(cell,0,Vector2I.Down + Vector2I.Right*(visible.IndexOf(cell) > -1 ? 1 : 4)));
|
||||
|
||||
}
|
||||
List<Vector2I> unoccupied = [.. visible.Where(c => !map._astar.IsPointSolid(c))];
|
||||
List<Vector2I> closest = [.. unoccupied.Where(c => c.Y == (_disposition == -1 ? unoccupied.Min(c => c.Y) : unoccupied.Max(c => c.Y))).OrderByDescending(c => Math.Abs(c.X - _address.X))];
|
||||
List<Vector2I> closest = [.. unoccupied.OrderByDescending(c => c.Y * _disposition).ThenByDescending(c => Math.Abs(c.X - _address.X))];
|
||||
return closest;
|
||||
}
|
||||
|
||||
|
||||
+17
-5
@@ -85,9 +85,10 @@ public partial class PegController : TurnController
|
||||
{
|
||||
action.DoImmediately(peg);
|
||||
string key = action._priority + ":" + loop;
|
||||
|
||||
if (!_tweenStages.ContainsKey(key))
|
||||
{
|
||||
_tweenStages[key] = new();
|
||||
_tweenStages[key] = new();
|
||||
}
|
||||
_tweenStages[key].Add(new(peg, action));
|
||||
if (!anyPegsActed)
|
||||
@@ -104,7 +105,6 @@ public partial class PegController : TurnController
|
||||
|
||||
public void HandlePegClick(Node CLICKED_NODE, int CLICK_TYPE)
|
||||
{
|
||||
TileMapLayer pathLayer = _playArea.GetNode<TileMapLayer>("PathLayer");
|
||||
if (CLICKED_NODE is not Peg peg)
|
||||
{
|
||||
return;
|
||||
@@ -113,10 +113,21 @@ public partial class PegController : TurnController
|
||||
{
|
||||
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++)
|
||||
// pathLayer.GetUsedCells().ToList().ForEach(c => pathLayer.SetCell(c,0,Vector2I.Down*4));
|
||||
// for (int i = 0; i < newPath.Count; i++)
|
||||
// {
|
||||
// pathLayer.SetCell(newPath[i],0,Vector2I.One);
|
||||
// }
|
||||
Map map = _playArea._map;
|
||||
TileMapLayer pathLayer = _playArea.GetNode<TileMapLayer>("PathLayer");
|
||||
List<Vector2I> pl = [.. pathLayer.GetUsedCells()];
|
||||
List<Vector2I> visible = peg.GetVisibleCells();
|
||||
|
||||
for (int i = 0; i < pl.Count; i++)
|
||||
{
|
||||
pathLayer.SetCell(newPath[i],0,Vector2I.One);
|
||||
Vector2I cell = pl[i];
|
||||
pathLayer.GetUsedCells().ToList().ForEach(c => pathLayer.SetCell(cell,0,Vector2I.Down + Vector2I.Right*(visible.IndexOf(cell) > -1 ? 1 : 4)));
|
||||
|
||||
}
|
||||
}
|
||||
else if (CLICK_TYPE == 2)
|
||||
@@ -149,6 +160,7 @@ public partial class PegController : TurnController
|
||||
public void ProcessTween()
|
||||
{
|
||||
_tweenStages = _tweenStages.OrderBy(s => int.Parse(s.Key.Split(":")[0])).ThenBy(s => int.Parse(s.Key.Split(":")[1])).ToDictionary();
|
||||
|
||||
if (_tweenStages.Count <= 0)
|
||||
{
|
||||
EndTurn();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
public partial class BasicMovement : PegAction
|
||||
{
|
||||
@@ -17,11 +18,15 @@ 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];
|
||||
|
||||
Tween subtween = CreateTween();
|
||||
subtween.TweenProperty(PEG, "global_position", map.GetCellPositionFromAddress(cell), 0.25f);
|
||||
Vector2 target = map.GetCellPositionFromAddress(cell);
|
||||
|
||||
subtween.TweenProperty(PEG, "global_position", target, 0.25f);
|
||||
PEG._path.RemoveAt(0);
|
||||
return subtween;
|
||||
}
|
||||
@@ -36,7 +41,9 @@ public partial class BasicMovement : PegAction
|
||||
return;
|
||||
}
|
||||
Vector2I cell = path[0];
|
||||
|
||||
map.SetCellPeg(cell, PEG);
|
||||
PEG._path.Add(cell);
|
||||
}
|
||||
|
||||
public override bool MeetsCriteria(Peg PEG)
|
||||
@@ -44,4 +51,6 @@ public partial class BasicMovement : PegAction
|
||||
return base.MeetsCriteria(PEG) && PEG._address.Y > PEG._pegController._playArea._map._firstOpenRow;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
public partial class Spearman : FriendlyPeg
|
||||
{
|
||||
public override void _Ready()
|
||||
{
|
||||
base._Ready();
|
||||
_stamina = 2;
|
||||
_visibility = 4;
|
||||
}
|
||||
|
||||
public override List<Vector2I> GetGoals()
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://dd4k8egcg3r2v
|
||||
@@ -0,0 +1,36 @@
|
||||
[gd_scene format=3 uid="uid://b5rrpaj7up7w3"]
|
||||
|
||||
[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"]
|
||||
|
||||
[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="Spearman" type="StaticBody2D" unique_id=1417697759]
|
||||
input_pickable = true
|
||||
physics_material_override = SubResource("PhysicsMaterial_7k104")
|
||||
script = ExtResource("1_rd6ui")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1762191899]
|
||||
shape = SubResource("CircleShape2D_4gyqm")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="." unique_id=1941012605]
|
||||
texture_filter = 1
|
||||
scale = Vector2(0.5, 0.5)
|
||||
texture = ExtResource("2_v2nt8")
|
||||
|
||||
[node name="Actions" type="Node2D" parent="." unique_id=2023031702]
|
||||
|
||||
[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"]
|
||||
Reference in New Issue
Block a user