continuing to switch to MapCell orientation
This commit is contained in:
@@ -23,6 +23,8 @@ public partial class Main : Node
|
||||
|
||||
_playerController._playArea = _playArea;
|
||||
_pegController._playArea = _playArea;
|
||||
_playerController._map = _playArea._map;
|
||||
_pegController._map = _playArea._map;
|
||||
|
||||
_playerController.TurnDone += ChangeTurn;
|
||||
_playerController.Death += EndGame;
|
||||
|
||||
@@ -3,6 +3,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Dynamic;
|
||||
using System.Linq;
|
||||
using System.Reflection.Metadata.Ecma335;
|
||||
|
||||
public partial class Map : TileMapLayer
|
||||
{
|
||||
@@ -109,6 +110,11 @@ public partial class Map : TileMapLayer
|
||||
}
|
||||
return new Vector2I((int)Math.Floor(POSITION.X / _cellSize.X), (int)Math.Floor(POSITION.Y / _cellSize.Y));
|
||||
}
|
||||
public Vector2 GetCellPosition(MapCell CELL)
|
||||
{
|
||||
return CELL.GlobalPosition;
|
||||
}
|
||||
|
||||
public Vector2 GetCellPositionFromAddress(Vector2I CELL_ADDRESS)
|
||||
{
|
||||
return GlobalPosition + CELL_ADDRESS * _cellSize + _cellSize / 2;
|
||||
@@ -147,24 +153,24 @@ public partial class Map : TileMapLayer
|
||||
return rowCells.All(_astar.IsPointSolid);
|
||||
}
|
||||
|
||||
public void SetCellPeg(Vector2I ADDRESS, Peg PEG)
|
||||
public void SetCellPeg(MapCell CELL, Peg PEG)
|
||||
{
|
||||
if (PEG != null)
|
||||
{
|
||||
if (PEG._address != -Vector2I.One)
|
||||
{
|
||||
_cells[PEG._address]._occupant = null;
|
||||
SetCellSolid(PEG._address);
|
||||
CELL._occupant = null;
|
||||
SetCellSolid(_cells[PEG._address]);
|
||||
}
|
||||
PEG._address = ADDRESS;
|
||||
PEG._address = CELL._address;
|
||||
}
|
||||
_cells[ADDRESS]._occupant = PEG;
|
||||
SetCellSolid(ADDRESS);
|
||||
CELL._occupant = PEG;
|
||||
SetCellSolid(CELL);
|
||||
}
|
||||
|
||||
public void SetCellSolid(Vector2I ADDRESS)
|
||||
public void SetCellSolid(MapCell CELL)
|
||||
{
|
||||
_astar.SetPointSolid(ADDRESS, IsCellSolid(ADDRESS));
|
||||
_astar.SetPointSolid(CELL._address, IsCellSolid(CELL._address));
|
||||
// _astar.SetPointWeightScale(ADDRESS, IsCellSolid(ADDRESS) ? 1000 : 1);
|
||||
}
|
||||
|
||||
@@ -200,7 +206,7 @@ public partial class Map : TileMapLayer
|
||||
{
|
||||
for (int i = 0; i < _cells.Count; i++)
|
||||
{
|
||||
SetCellSolid(_cells.ElementAt(i).Value._address);
|
||||
SetCellSolid(_cells.ElementAt(i).Value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ using System;
|
||||
public partial class MapCellOccupant : HoverableNode
|
||||
{
|
||||
public Vector2I _address;
|
||||
public MapCell _cell;
|
||||
public Disposition _disposition = Disposition.NONE;
|
||||
public enum Disposition
|
||||
{
|
||||
|
||||
@@ -59,7 +59,8 @@ public partial class Peg : MapCellOccupant
|
||||
// }
|
||||
|
||||
// }
|
||||
return _pegController._playArea._map.GetPath(_address, Goal(), false, PARTIAL);
|
||||
MapCell goal = Goal();
|
||||
return _pegController._playArea._map.GetPath(_address, goal._address, false, PARTIAL);
|
||||
}
|
||||
|
||||
public virtual Dictionary<Vector2I, MapCell> GetEnemies()
|
||||
@@ -87,13 +88,13 @@ public partial class Peg : MapCellOccupant
|
||||
return _pegController._playArea._map.GetCellPositionFromAddress(_address);
|
||||
}
|
||||
|
||||
public virtual Vector2I Goal()
|
||||
public virtual MapCell 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];
|
||||
Dictionary<Vector2I, MapCell> visible = GetVisibleCells();
|
||||
Dictionary<Vector2I, MapCell> unoccupied = visible.Where(c => !map._astar.IsPointSolid(c.Key)).ToDictionary();
|
||||
Dictionary<Vector2I, MapCell> closest = unoccupied.OrderByDescending(c => c.Value._address.Y * (int)_disposition).ThenByDescending(c => Math.Abs(c.Value._address.X - _address.X)).ToDictionary();
|
||||
return closest.ElementAt(0).Value;
|
||||
}
|
||||
|
||||
public virtual void StartTurn()
|
||||
|
||||
+14
-12
@@ -41,8 +41,8 @@ public partial class PegController : TurnController
|
||||
|
||||
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)];
|
||||
Dictionary<Vector2I, MapCell> unoccupied = _playArea._map._bottomRow.Where(c => c.Value._occupant == null).ToDictionary();
|
||||
MapCell randomCell = unoccupied.ElementAt(Globals._rng.Next(unoccupied.Keys.Count)).Value;
|
||||
|
||||
SetPeg(newFriendlyPeg, randomCell);
|
||||
_pegs.Add(newFriendlyPeg);
|
||||
@@ -62,7 +62,7 @@ public partial class PegController : TurnController
|
||||
|
||||
newFriendlyPeg._pegController = this;
|
||||
|
||||
SetPeg(newFriendlyPeg, POSITIONS[i]);
|
||||
SetPeg(newFriendlyPeg, _map._cells[POSITIONS[i]]);
|
||||
_pegs.Add(newFriendlyPeg);
|
||||
AddChild(newFriendlyPeg);
|
||||
_pegsCreated++;
|
||||
@@ -80,8 +80,8 @@ public partial class PegController : TurnController
|
||||
|
||||
newHostilePeg._pegController = this;
|
||||
|
||||
List<Vector2I> unoccupied = [.. _playArea._map._bottomRow.Where(c => _pegs.All(e => e._address != c))];
|
||||
Vector2I randomCell = unoccupied[Globals._rng.Next(unoccupied.Count)];
|
||||
Dictionary<Vector2I, MapCell> unoccupied = _map._bottomRow.Where(c => c.Value._occupant == null).ToDictionary();
|
||||
MapCell randomCell = unoccupied.ElementAt(Globals._rng.Next(unoccupied.Count)).Value;
|
||||
|
||||
SetPeg(newHostilePeg, randomCell);
|
||||
_pegs.Add(newHostilePeg);
|
||||
@@ -100,8 +100,9 @@ public partial class PegController : TurnController
|
||||
newHostilePeg.Click += HandlePegClick;
|
||||
|
||||
newHostilePeg._pegController = this;
|
||||
newHostilePeg._map = _playArea._map;
|
||||
|
||||
SetPeg(newHostilePeg, POSITIONS[i]);
|
||||
SetPeg(newHostilePeg, _map._cells[POSITIONS[i]]);
|
||||
_pegs.Add(newHostilePeg);
|
||||
AddChild(newHostilePeg);
|
||||
_pegsCreated++;
|
||||
@@ -162,12 +163,12 @@ public partial class PegController : TurnController
|
||||
Map map = _playArea._map;
|
||||
TileMapLayer pathLayer = _playArea.GetNode<TileMapLayer>("PathLayer");
|
||||
List<Vector2I> pl = [.. pathLayer.GetUsedCells()];
|
||||
List<Vector2I> visible = peg.GetVisibleCells();
|
||||
Dictionary<Vector2I, MapCell> visible = peg.GetVisibleCells();
|
||||
|
||||
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)));
|
||||
pathLayer.GetUsedCells().ToList().ForEach(c => pathLayer.SetCell(cell,0,Vector2I.Down + Vector2I.Right*(visible.ContainsKey(cell) ? 1 : 4)));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -180,7 +181,7 @@ public partial class PegController : TurnController
|
||||
public void HandlePegRemoval(Peg PEG_TO_REMOVE)
|
||||
{
|
||||
_pegs.Remove(PEG_TO_REMOVE);
|
||||
_playArea._map.SetCellPeg(PEG_TO_REMOVE._address, null);
|
||||
_playArea._map.SetCellPeg(_map._cells[PEG_TO_REMOVE._address], null);
|
||||
PEG_TO_REMOVE.QueueFree();
|
||||
_pegsDestroyed++;
|
||||
}
|
||||
@@ -246,10 +247,11 @@ public partial class PegController : TurnController
|
||||
HandlePegTurn();
|
||||
}
|
||||
|
||||
public void SetPeg(Peg PEG, Vector2I CELL)
|
||||
public void SetPeg(Peg PEG, MapCell CELL)
|
||||
{
|
||||
_playArea._map.SetCellPeg(CELL, PEG);
|
||||
PEG.GlobalPosition = _playArea._map.GetCellPositionFromAddress(CELL);
|
||||
_map.SetCellPeg(CELL, PEG);
|
||||
PEG._cell = CELL;
|
||||
PEG.GlobalPosition = CELL.GlobalPosition;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -41,14 +41,14 @@ public partial class BasicMovement : PegAction
|
||||
}
|
||||
Vector2I cell = path[0];
|
||||
|
||||
map.SetCellPeg(cell, PEG);
|
||||
map.SetCellPeg(map._cells[cell], PEG);
|
||||
PEG._path.Add(cell);
|
||||
}
|
||||
|
||||
public override bool MeetsCriteria(Peg PEG)
|
||||
{
|
||||
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;
|
||||
return base.MeetsCriteria(PEG) && bestPath.Count > 0 && (int)PEG._pegController._playArea._map.GetCellTileData(bestPath[0]).GetCustomData("disposition") != -(int)PEG._disposition;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -18,28 +18,23 @@ public partial class ShootShortbow : PegAction
|
||||
|
||||
public override Tween CreateAnimation(Peg PEG)
|
||||
{
|
||||
Vector2 target = PEG._pegController._playArea._map.GetCellPositionFromAddress(Target(PEG));
|
||||
MapCell target = 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.TweenProperty(_image, "rotation", PEG.GetAngleTo(target.GlobalPosition), 0.0f);
|
||||
subtween.TweenProperty(_image, "global_position", target.GlobalPosition, 0.5f);
|
||||
subtween.TweenCallback(Callable.From(() =>
|
||||
{
|
||||
PEG._pegController._playerController.ChangeHealth(-1, this);
|
||||
((Peg)target._occupant)._pegController._playerController.ChangeHealth(-2, this);
|
||||
Position = Vector2.Zero;
|
||||
Visible = false;
|
||||
}));
|
||||
return subtween;
|
||||
}
|
||||
|
||||
public override Vector2I Target(Peg PEG)
|
||||
public override MapCell 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]; // return PEG._pegController._playerController._towers.OrderBy(t => (t.GlobalPosition - GlobalPosition).Length()).ToList()[0].GlobalPosition;
|
||||
return PEG.Goal();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,29 +18,24 @@ public partial class SwingShortsword : PegAction
|
||||
|
||||
public override Tween CreateAnimation(Peg PEG)
|
||||
{
|
||||
Vector2 target = PEG._pegController._playArea._map.GetCellPositionFromAddress(Target(PEG));
|
||||
MapCell target = 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, "global_position", target, 0.5f);
|
||||
subtween.TweenProperty(_image, "rotation", PEG.GetAngleTo(target.GlobalPosition), 0.0f);
|
||||
subtween.TweenProperty(_image, "global_position", target.GlobalPosition, 0.5f);
|
||||
subtween.TweenCallback(Callable.From(() =>
|
||||
{
|
||||
PEG._pegController._playerController.ChangeHealth(-2, this);
|
||||
((Peg)target._occupant)._pegController._playerController.ChangeHealth(-2, this);
|
||||
_image.Position = Vector2.Zero;
|
||||
_image.Visible = false;
|
||||
}));
|
||||
return subtween;
|
||||
}
|
||||
|
||||
public override Vector2I Target(Peg PEG)
|
||||
public override MapCell 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];
|
||||
return PEG.Goal();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,25 +16,22 @@ public partial class ThrustSpear : PegAction
|
||||
|
||||
public override Tween CreateAnimation(Peg PEG)
|
||||
{
|
||||
GD.Print(Name);
|
||||
Map map = PEG._pegController._playArea._map;
|
||||
Peg pegTarget = map._addressOccupants[Target(PEG)];
|
||||
Vector2 target = pegTarget.GlobalPosition;
|
||||
MapCell target = 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.TweenProperty(_image, "rotation", PEG.GetAngleTo(target.GlobalPosition), 0.0f);
|
||||
subtween.TweenProperty(_image, "global_position", target.GlobalPosition, 0.5f);
|
||||
subtween.TweenCallback(Callable.From(() =>
|
||||
{
|
||||
pegTarget.ChangeHealth(-1);
|
||||
((Peg)target._occupant).ChangeHealth(-1);
|
||||
_image.Position = Vector2.Zero;
|
||||
_image.Visible = false;
|
||||
}));
|
||||
return subtween;
|
||||
}
|
||||
|
||||
public override Vector2I Target(Peg PEG)
|
||||
public override MapCell Target(Peg PEG)
|
||||
{
|
||||
return PEG.Goal();
|
||||
}
|
||||
|
||||
@@ -12,15 +12,15 @@ public partial class Spearman : FriendlyPeg
|
||||
_visibility = 4;
|
||||
}
|
||||
|
||||
public override Vector2I Goal()
|
||||
public override MapCell Goal()
|
||||
{
|
||||
Map map = _pegController._playArea._map;
|
||||
List<Peg> enemies = [.. _pegController._pegs.Where(p => p._disposition == -_disposition)];
|
||||
Dictionary<Vector2I, MapCell> enemies = GetVisibleEnemies();
|
||||
if (enemies.Count == 0)
|
||||
{
|
||||
return _address;
|
||||
return _map._cells[_address];
|
||||
}
|
||||
List<Vector2I> closest = [.. enemies.OrderBy(e => (e._address - _address).Length()).Select(e => e._address)];
|
||||
return closest[0];
|
||||
Dictionary<Vector2I, MapCell> closest = enemies.OrderBy(e => (e.Value._occupant._address - _address).Length()).ToDictionary();
|
||||
return closest.ElementAt(0).Value;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -27,7 +27,7 @@ public partial class PegAction : Node2D
|
||||
{
|
||||
return PEG._staminaRemaining >= _cost
|
||||
&& _usesRemaining > 0
|
||||
&& (PEG._address - Target(PEG)).Length() <= _range;
|
||||
&& (PEG._address - Target(PEG)._address).Length() <= _range;
|
||||
}
|
||||
|
||||
public virtual void Reset()
|
||||
@@ -35,8 +35,8 @@ public partial class PegAction : Node2D
|
||||
_usesRemaining = _usesMax;
|
||||
}
|
||||
|
||||
public virtual Vector2I Target(Peg PEG)
|
||||
public virtual MapCell Target(Peg PEG)
|
||||
{
|
||||
return PEG._address;
|
||||
return PEG._cell;
|
||||
}
|
||||
}
|
||||
|
||||
+14
-14
@@ -32,21 +32,21 @@ public partial class PlayArea : Node2D
|
||||
public void HighlightCells()
|
||||
{
|
||||
TileMapLayer occupiedSpaces = GetNode<TileMapLayer>("OccupiedSpaces");
|
||||
_map._cells.ForEach(c =>
|
||||
{
|
||||
if (_map.HasOccupant(c))
|
||||
{
|
||||
occupiedSpaces.SetCell(c, 0, new Vector2I(4,0));
|
||||
}
|
||||
else if (_map._astar.IsPointSolid(c))
|
||||
{
|
||||
// _map._cells.ForEach(c =>
|
||||
// {
|
||||
// if (_map.HasOccupant(c))
|
||||
// {
|
||||
// occupiedSpaces.SetCell(c, 0, new Vector2I(4,0));
|
||||
// }
|
||||
// else if (_map._astar.IsPointSolid(c))
|
||||
// {
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
occupiedSpaces.SetCell(c, 0, Vector2I.Down*4);
|
||||
}
|
||||
});
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// occupiedSpaces.SetCell(c, 0, Vector2I.Down*4);
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ public partial class TurnController : Node2D
|
||||
[Signal]
|
||||
public delegate void TurnDoneEventHandler();
|
||||
public PlayArea _playArea;
|
||||
|
||||
public Map _map;
|
||||
public virtual void StartTurn()
|
||||
{
|
||||
|
||||
|
||||
Reference in New Issue
Block a user