starting to rework grid maps to be tile map layers
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 628 B |
@@ -0,0 +1,40 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://cf554xlykq1o4"
|
||||
path="res://.godot/imported/tile_set.png-fd4f1e60b744017efffa1399a3d8e420.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://Art/tile_set.png"
|
||||
dest_files=["res://.godot/imported/tile_set.png-fd4f1e60b744017efffa1399a3d8e420.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/uastc_level=0
|
||||
compress/rdo_quality_loss=0.0
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/channel_remap/red=0
|
||||
process/channel_remap/green=1
|
||||
process/channel_remap/blue=2
|
||||
process/channel_remap/alpha=3
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
@@ -7,11 +7,11 @@ public partial class Enemy : StaticBody2D
|
||||
{
|
||||
[Signal]
|
||||
public delegate void DeathEventHandler(Enemy THIS);
|
||||
public int _damage = 1, _health = 2, _speed;
|
||||
public int _damage = 1, _health = 2, _speed, _visibilityRange = 10;
|
||||
public Vector2I _range = Vector2I.Up;
|
||||
public float _movement = 0;
|
||||
public GridMarker _gridMarker;
|
||||
public Commander _commander;
|
||||
public EnemyController _enemyController;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
@@ -32,65 +32,54 @@ public partial class Enemy : StaticBody2D
|
||||
|
||||
}
|
||||
|
||||
public List<GridMarker> Pathfinding(List<GridMarker> DESTINATIONS, bool INCLUDE_SELF = false)
|
||||
public List<GridMarker> Pathfinding(GridMarker DESTINATION, bool INCLUDE_SELF = false)
|
||||
{
|
||||
PriorityQueue<GridMarker, float> queue = new();
|
||||
queue.Enqueue(_gridMarker, 0f);
|
||||
Dictionary<GridMarker, GridMarker> cameFrom = new(), best = new();
|
||||
Dictionary<GridMarker, GridMarker> cameFrom = new();
|
||||
Dictionary<GridMarker, float> costSoFar = new();
|
||||
cameFrom[_gridMarker] = null;
|
||||
costSoFar[_gridMarker] = 0f;
|
||||
GridMarker current;
|
||||
float newCost, priority;
|
||||
|
||||
for (int i = 0; i < DESTINATIONS.Count; i++)
|
||||
while (queue.Count > 0)
|
||||
{
|
||||
GridMarker destination = DESTINATIONS[i];
|
||||
while (queue.Count > 0)
|
||||
current = queue.Dequeue();
|
||||
|
||||
if (current == DESTINATION)
|
||||
{
|
||||
current = queue.Dequeue();
|
||||
if (current == destination)
|
||||
break;
|
||||
}
|
||||
|
||||
List<GridMarker> neighbors = current.GetMarkersInRange(1.5f);
|
||||
for (int j = 0; j < neighbors.Count; j++)
|
||||
{
|
||||
GridMarker next = neighbors[j];
|
||||
if (next._occupant != null)
|
||||
{
|
||||
best = cameFrom;
|
||||
GD.Print("breaking at line 56");
|
||||
continue;
|
||||
}
|
||||
|
||||
List<GridMarker> neighbors = current.GetMarkersInRange(1.5f);
|
||||
for (int j = 0; j < neighbors.Count; j++)
|
||||
newCost = costSoFar[current] + 1;
|
||||
if (!costSoFar.TryGetValue(next, out float value) || newCost < value)
|
||||
{
|
||||
GridMarker next = neighbors[j];
|
||||
if (next._occupant != null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
newCost = costSoFar[current] + 1;
|
||||
if (best.Count > 0 && newCost >= best.Count)
|
||||
{
|
||||
GD.Print("breaking at line 70");
|
||||
break;
|
||||
}
|
||||
if (!costSoFar.TryGetValue(next, out float value) || newCost < value)
|
||||
{
|
||||
costSoFar[next] = newCost;
|
||||
priority = newCost;
|
||||
queue.Enqueue(next, priority);
|
||||
cameFrom[next] = current;
|
||||
}
|
||||
costSoFar[next] = newCost;
|
||||
priority = newCost;
|
||||
queue.Enqueue(next, priority);
|
||||
cameFrom[next] = current;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
GD.Print(best.Last().Value._address);
|
||||
|
||||
List<GridMarker> path = new();
|
||||
GridMarker pathMarker = best.Last().Value;
|
||||
|
||||
if (best.TryGetValue(pathMarker, out GridMarker marker))
|
||||
GridMarker pathMarker = DESTINATION;
|
||||
if (cameFrom.ContainsKey(pathMarker))
|
||||
{
|
||||
while (pathMarker != null)
|
||||
{
|
||||
path.Add(pathMarker);
|
||||
pathMarker = marker;
|
||||
pathMarker = cameFrom[pathMarker];
|
||||
}
|
||||
path.Reverse();
|
||||
if (!INCLUDE_SELF)
|
||||
@@ -98,13 +87,11 @@ public partial class Enemy : StaticBody2D
|
||||
path.Remove(_gridMarker);
|
||||
}
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
public void TakeDamage(int DAMAGE, Commander ATTACKER)
|
||||
{
|
||||
GD.Print(_health, _health - DAMAGE);
|
||||
_health -= DAMAGE;
|
||||
CounterAttack(ATTACKER);
|
||||
if (_health <= 0)
|
||||
|
||||
+23
-23
@@ -21,6 +21,7 @@ public partial class EnemyController : TurnController
|
||||
GridMarker randomMarker = unoccupiedMarkers[Globals._rng.Next(unoccupiedMarkers.Count)];
|
||||
newEnemy._speed = Globals._rng.Next(2,4+1);
|
||||
newEnemy.Modulate = new Color(newEnemy._speed == 2 ? "#FF0000" : newEnemy._speed == 3 ? "#00FF00" : "#0000FF");
|
||||
newEnemy._enemyController = this;
|
||||
WarpEnemy(newEnemy, randomMarker);
|
||||
_enemies.Add(newEnemy);
|
||||
AddChild(newEnemy);
|
||||
@@ -43,32 +44,31 @@ public partial class EnemyController : TurnController
|
||||
{
|
||||
ENEMIES ??= _enemies;
|
||||
ENEMIES = [.. ENEMIES.OrderByDescending(e => e._gridMarker._address.Y).ThenByDescending(e => e._gridMarker._address.X)];
|
||||
Tween tween = CreateTween();
|
||||
tween.SetParallel();
|
||||
// Tween tween = CreateTween();
|
||||
// tween.SetParallel();
|
||||
Dictionary<Enemy, List<GridMarker>> enemyPaths = new();
|
||||
|
||||
for (int i = 0; i < ENEMIES.Count; i++)
|
||||
{
|
||||
enemyPaths[ENEMIES[i]] = ENEMIES[i].Pathfinding(_grid._gridMarkers.ToList());
|
||||
}
|
||||
ENEMIES[0].Pathfinding(_grid.GetMarkerByAddress(new Vector2I(ENEMIES[0]._gridMarker._address.X, ENEMIES[0]._gridMarker._address.Y - ENEMIES[0]._visibilityRange)));
|
||||
// for (int i = 0; i < ENEMIES.Count; i++)
|
||||
// {
|
||||
// enemyPaths[ENEMIES[i]] = ENEMIES[i].Pathfinding(_grid.GetMarkerByAddress(new Vector2I(ENEMIES[i]._gridMarker._address.X, 0)));
|
||||
// }
|
||||
|
||||
int maxSteps = enemyPaths.Select(p => p.Value.Count).Max();
|
||||
GD.Print(enemyPaths.Count, " ", maxSteps);
|
||||
|
||||
for (int i = 0; i < maxSteps; i++)
|
||||
{
|
||||
Dictionary<Enemy, List<GridMarker>> qualifyingPaths = (Dictionary<Enemy, List<GridMarker>>)enemyPaths.Where(p => p.Value.Count <= maxSteps);
|
||||
for (int j = 0; j < qualifyingPaths.Count; j++)
|
||||
{
|
||||
Enemy enemy = qualifyingPaths.ElementAt(j).Key;
|
||||
GridMarker marker = qualifyingPaths.ElementAt(j).Value.ElementAt(i);
|
||||
if (j == 0)
|
||||
{
|
||||
tween.Chain();
|
||||
}
|
||||
tween.TweenProperty(enemy, "global_position", enemy._gridMarker.GlobalPosition, 0.4f);
|
||||
}
|
||||
}
|
||||
// GD.Print(maxSteps);
|
||||
// for (int i = 0; i < maxSteps; i++)
|
||||
// {
|
||||
// Dictionary<Enemy, List<GridMarker>> qualifyingPaths = (Dictionary<Enemy, List<GridMarker>>)enemyPaths.Where(p => p.Value.Count <= maxSteps);
|
||||
// for (int j = 0; j < qualifyingPaths.Count; j++)
|
||||
// {
|
||||
// Enemy enemy = qualifyingPaths.ElementAt(j).Key;
|
||||
// GridMarker marker = qualifyingPaths.ElementAt(j).Value.ElementAt(i);
|
||||
// if (j == 0)
|
||||
// {
|
||||
// tween.Chain();
|
||||
// }
|
||||
// tween.TweenProperty(enemy, "global_position", enemy._gridMarker.GlobalPosition, 0.4f);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
public void RemoveEnemy(Enemy ENEMY_TO_REMOVE)
|
||||
|
||||
+9
-2
@@ -15,11 +15,18 @@ public partial class GridMarker : Marker2D
|
||||
base._Ready();
|
||||
}
|
||||
|
||||
public List<GridMarker> GetMarkersInRange(float RANGE = 1.0f){
|
||||
public List<GridMarker> GetMarkersInRange(float RANGE = 1.0f, bool INCLUDE_SELF = false){
|
||||
if (_gridMarkers == null || _gridMarkers.Count == 0)
|
||||
{
|
||||
_gridMarkers = [.. GetTree().GetNodesInGroup("GridMarkers").Cast<GridMarker>()];
|
||||
}
|
||||
return [.. _gridMarkers.Where(m => m._address.Length() <= RANGE).Cast<GridMarker>()];
|
||||
List<GridMarker> returnList = [.. _gridMarkers.Where(m => (_address - m._address).Length() <= RANGE).Cast<GridMarker>()];
|
||||
if (!INCLUDE_SELF)
|
||||
{
|
||||
returnList.Remove(this);
|
||||
}
|
||||
return returnList;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+822
-14
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user