still working on movement, for some reason some cells do not get set as solid that's why multiple can go on a cell
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Dynamic;
|
||||
using System.Linq;
|
||||
|
||||
public partial class Map : TileMapLayer
|
||||
@@ -33,17 +34,64 @@ public partial class Map : TileMapLayer
|
||||
SetupAstar();
|
||||
}
|
||||
|
||||
|
||||
public Vector2I GetAddressFromPosition(Vector2 POSITION)
|
||||
{
|
||||
if (POSITION.X < GlobalPosition.X || POSITION.Y < GlobalPosition.Y)
|
||||
{
|
||||
return new Vector2I(-1,-1);
|
||||
}
|
||||
else if (POSITION.X > (GlobalPosition + (new Vector2(_maxX, _maxY) * _cellSize)).X || POSITION.Y > (GlobalPosition + (new Vector2(_maxX, _maxY) * _cellSize)).Y)
|
||||
{
|
||||
return new Vector2I(-1,-1);
|
||||
}
|
||||
return new Vector2I((int)Math.Floor(POSITION.X / _cellSize.X), (int)Math.Floor(POSITION.Y / _cellSize.Y));
|
||||
}
|
||||
public Vector2 GetCellPositionFromAddress(Vector2I CELL_ADDRESS)
|
||||
{
|
||||
return GlobalPosition + CELL_ADDRESS * _cellSize + _cellSize / 2;
|
||||
}
|
||||
|
||||
public int GetFirstOpenRow()
|
||||
{
|
||||
for (int i = 0; i < _maxY; i++)
|
||||
{
|
||||
if (!IsRowFull(i))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
public Enemy GetOccupant(Vector2I CELL_TO_CHECK)
|
||||
{
|
||||
return _addressOccupants[CELL_TO_CHECK];
|
||||
}
|
||||
|
||||
public bool HasOccupant(Vector2I CELL_TO_CHECK)
|
||||
{
|
||||
return GetOccupant(CELL_TO_CHECK) != null;
|
||||
}
|
||||
|
||||
public void HighlightCells()
|
||||
{
|
||||
_cells.ForEach(c =>
|
||||
{
|
||||
if (HasOccupant(c))
|
||||
{
|
||||
SetCell(c, 0, new Vector2I(4,1));
|
||||
}
|
||||
else if (_astar.IsPointSolid(c))
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
SetCell(c, 0, new Vector2I(0, (c.X + c.Y) % 2 == 0 ? 0 : 1));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public bool IsCellSolid(Vector2I CELL_TO_CHECK)
|
||||
{
|
||||
bool hasOccupant = GetOccupant(CELL_TO_CHECK) != null;
|
||||
@@ -68,31 +116,27 @@ public partial class Map : TileMapLayer
|
||||
|
||||
public void SetCellEnemy(Vector2I ADDRESS, Enemy ENEMY)
|
||||
{
|
||||
if (ENEMY != null)
|
||||
{
|
||||
if (ENEMY._address != -(Vector2I)Vector2.Inf)
|
||||
{
|
||||
_addressOccupants[ENEMY._address] = null;
|
||||
}
|
||||
ENEMY._address = ADDRESS;
|
||||
}
|
||||
_addressOccupants[ENEMY._address] = null;
|
||||
SetCellSolid(ENEMY._address);
|
||||
|
||||
|
||||
ENEMY._address = ADDRESS;
|
||||
|
||||
_addressOccupants[ADDRESS] = ENEMY;
|
||||
|
||||
SetCellSolid(ADDRESS);
|
||||
|
||||
}
|
||||
|
||||
public void SetCellSolid(Vector2I ADDRESS)
|
||||
{
|
||||
_astar.SetPointSolid(ADDRESS, IsCellSolid(ADDRESS));
|
||||
// _astar.SetPointWeightScale(ADDRESS, IsCellSolid(ADDRESS) ? 1000 : 1);
|
||||
}
|
||||
|
||||
public void SetupAstar()
|
||||
{
|
||||
_astar.Region = new Rect2I(_minX, _minY, _topRow.Count, _leftmostColumn.Count);
|
||||
_astar.CellSize = _cellSize;
|
||||
_astar.DefaultComputeHeuristic = AStarGrid2D.Heuristic.Euclidean;
|
||||
_astar.DefaultComputeHeuristic = AStarGrid2D.Heuristic.Manhattan;
|
||||
_astar.DiagonalMode = AStarGrid2D.DiagonalModeEnum.Never;
|
||||
_astar.Update();
|
||||
EvaluateSolidCells();
|
||||
@@ -125,4 +169,6 @@ public partial class Map : TileMapLayer
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user