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]
|
[Signal]
|
||||||
public delegate void DeathEventHandler(Enemy THIS);
|
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 Vector2I _range = Vector2I.Up;
|
||||||
public float _movement = 0;
|
public float _movement = 0;
|
||||||
public GridMarker _gridMarker;
|
public GridMarker _gridMarker;
|
||||||
public Commander _commander;
|
public EnemyController _enemyController;
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
@@ -32,28 +32,23 @@ 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();
|
PriorityQueue<GridMarker, float> queue = new();
|
||||||
queue.Enqueue(_gridMarker, 0f);
|
queue.Enqueue(_gridMarker, 0f);
|
||||||
Dictionary<GridMarker, GridMarker> cameFrom = new(), best = new();
|
Dictionary<GridMarker, GridMarker> cameFrom = new();
|
||||||
Dictionary<GridMarker, float> costSoFar = new();
|
Dictionary<GridMarker, float> costSoFar = new();
|
||||||
cameFrom[_gridMarker] = null;
|
cameFrom[_gridMarker] = null;
|
||||||
costSoFar[_gridMarker] = 0f;
|
costSoFar[_gridMarker] = 0f;
|
||||||
GridMarker current;
|
GridMarker current;
|
||||||
float newCost, priority;
|
float newCost, priority;
|
||||||
|
|
||||||
for (int i = 0; i < DESTINATIONS.Count; i++)
|
|
||||||
{
|
|
||||||
GridMarker destination = DESTINATIONS[i];
|
|
||||||
while (queue.Count > 0)
|
while (queue.Count > 0)
|
||||||
{
|
{
|
||||||
current = queue.Dequeue();
|
current = queue.Dequeue();
|
||||||
if (current == destination)
|
|
||||||
|
if (current == DESTINATION)
|
||||||
{
|
{
|
||||||
best = cameFrom;
|
break;
|
||||||
GD.Print("breaking at line 56");
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
List<GridMarker> neighbors = current.GetMarkersInRange(1.5f);
|
List<GridMarker> neighbors = current.GetMarkersInRange(1.5f);
|
||||||
@@ -64,12 +59,8 @@ public partial class Enemy : StaticBody2D
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
newCost = costSoFar[current] + 1;
|
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)
|
if (!costSoFar.TryGetValue(next, out float value) || newCost < value)
|
||||||
{
|
{
|
||||||
costSoFar[next] = newCost;
|
costSoFar[next] = newCost;
|
||||||
@@ -78,19 +69,17 @@ public partial class Enemy : StaticBody2D
|
|||||||
cameFrom[next] = current;
|
cameFrom[next] = current;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GD.Print(best.Last().Value._address);
|
|
||||||
List<GridMarker> path = new();
|
List<GridMarker> path = new();
|
||||||
GridMarker pathMarker = best.Last().Value;
|
GridMarker pathMarker = DESTINATION;
|
||||||
|
if (cameFrom.ContainsKey(pathMarker))
|
||||||
if (best.TryGetValue(pathMarker, out GridMarker marker))
|
|
||||||
{
|
{
|
||||||
while (pathMarker != null)
|
while (pathMarker != null)
|
||||||
{
|
{
|
||||||
path.Add(pathMarker);
|
path.Add(pathMarker);
|
||||||
pathMarker = marker;
|
pathMarker = cameFrom[pathMarker];
|
||||||
}
|
}
|
||||||
path.Reverse();
|
path.Reverse();
|
||||||
if (!INCLUDE_SELF)
|
if (!INCLUDE_SELF)
|
||||||
@@ -98,13 +87,11 @@ public partial class Enemy : StaticBody2D
|
|||||||
path.Remove(_gridMarker);
|
path.Remove(_gridMarker);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void TakeDamage(int DAMAGE, Commander ATTACKER)
|
public void TakeDamage(int DAMAGE, Commander ATTACKER)
|
||||||
{
|
{
|
||||||
GD.Print(_health, _health - DAMAGE);
|
|
||||||
_health -= DAMAGE;
|
_health -= DAMAGE;
|
||||||
CounterAttack(ATTACKER);
|
CounterAttack(ATTACKER);
|
||||||
if (_health <= 0)
|
if (_health <= 0)
|
||||||
|
|||||||
+23
-23
@@ -21,6 +21,7 @@ public partial class EnemyController : TurnController
|
|||||||
GridMarker randomMarker = unoccupiedMarkers[Globals._rng.Next(unoccupiedMarkers.Count)];
|
GridMarker randomMarker = unoccupiedMarkers[Globals._rng.Next(unoccupiedMarkers.Count)];
|
||||||
newEnemy._speed = Globals._rng.Next(2,4+1);
|
newEnemy._speed = Globals._rng.Next(2,4+1);
|
||||||
newEnemy.Modulate = new Color(newEnemy._speed == 2 ? "#FF0000" : newEnemy._speed == 3 ? "#00FF00" : "#0000FF");
|
newEnemy.Modulate = new Color(newEnemy._speed == 2 ? "#FF0000" : newEnemy._speed == 3 ? "#00FF00" : "#0000FF");
|
||||||
|
newEnemy._enemyController = this;
|
||||||
WarpEnemy(newEnemy, randomMarker);
|
WarpEnemy(newEnemy, randomMarker);
|
||||||
_enemies.Add(newEnemy);
|
_enemies.Add(newEnemy);
|
||||||
AddChild(newEnemy);
|
AddChild(newEnemy);
|
||||||
@@ -43,32 +44,31 @@ public partial class EnemyController : TurnController
|
|||||||
{
|
{
|
||||||
ENEMIES ??= _enemies;
|
ENEMIES ??= _enemies;
|
||||||
ENEMIES = [.. ENEMIES.OrderByDescending(e => e._gridMarker._address.Y).ThenByDescending(e => e._gridMarker._address.X)];
|
ENEMIES = [.. ENEMIES.OrderByDescending(e => e._gridMarker._address.Y).ThenByDescending(e => e._gridMarker._address.X)];
|
||||||
Tween tween = CreateTween();
|
// Tween tween = CreateTween();
|
||||||
tween.SetParallel();
|
// tween.SetParallel();
|
||||||
Dictionary<Enemy, List<GridMarker>> enemyPaths = new();
|
Dictionary<Enemy, List<GridMarker>> enemyPaths = new();
|
||||||
|
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++)
|
// for (int i = 0; i < ENEMIES.Count; i++)
|
||||||
{
|
// {
|
||||||
enemyPaths[ENEMIES[i]] = ENEMIES[i].Pathfinding(_grid._gridMarkers.ToList());
|
// 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();
|
int maxSteps = enemyPaths.Select(p => p.Value.Count).Max();
|
||||||
GD.Print(enemyPaths.Count, " ", maxSteps);
|
// GD.Print(maxSteps);
|
||||||
|
// for (int i = 0; i < maxSteps; i++)
|
||||||
for (int i = 0; i < maxSteps; i++)
|
// {
|
||||||
{
|
// Dictionary<Enemy, List<GridMarker>> qualifyingPaths = (Dictionary<Enemy, List<GridMarker>>)enemyPaths.Where(p => p.Value.Count <= maxSteps);
|
||||||
Dictionary<Enemy, List<GridMarker>> qualifyingPaths = (Dictionary<Enemy, List<GridMarker>>)enemyPaths.Where(p => p.Value.Count <= maxSteps);
|
// for (int j = 0; j < qualifyingPaths.Count; j++)
|
||||||
for (int j = 0; j < qualifyingPaths.Count; j++)
|
// {
|
||||||
{
|
// Enemy enemy = qualifyingPaths.ElementAt(j).Key;
|
||||||
Enemy enemy = qualifyingPaths.ElementAt(j).Key;
|
// GridMarker marker = qualifyingPaths.ElementAt(j).Value.ElementAt(i);
|
||||||
GridMarker marker = qualifyingPaths.ElementAt(j).Value.ElementAt(i);
|
// if (j == 0)
|
||||||
if (j == 0)
|
// {
|
||||||
{
|
// tween.Chain();
|
||||||
tween.Chain();
|
// }
|
||||||
}
|
// tween.TweenProperty(enemy, "global_position", enemy._gridMarker.GlobalPosition, 0.4f);
|
||||||
tween.TweenProperty(enemy, "global_position", enemy._gridMarker.GlobalPosition, 0.4f);
|
// }
|
||||||
}
|
// }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveEnemy(Enemy ENEMY_TO_REMOVE)
|
public void RemoveEnemy(Enemy ENEMY_TO_REMOVE)
|
||||||
|
|||||||
+9
-2
@@ -15,11 +15,18 @@ public partial class GridMarker : Marker2D
|
|||||||
base._Ready();
|
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)
|
if (_gridMarkers == null || _gridMarkers.Count == 0)
|
||||||
{
|
{
|
||||||
_gridMarkers = [.. GetTree().GetNodesInGroup("GridMarkers").Cast<GridMarker>()];
|
_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