diff options
| author | Matheus <matheus.guedes.mg.m@gmail.com> | 2025-08-25 17:52:41 -0300 |
|---|---|---|
| committer | Matheus <matheus.guedes.mg.m@gmail.com> | 2025-08-25 17:52:41 -0300 |
| commit | 5f0098b04fe71059471cf82730f341ce06c9fe68 (patch) | |
| tree | 60bb4eda1679323ddd905c879b410afcc31891dd /scripts/map | |
| parent | 7419e7237c3c5b3f1184babfcd826b7f788b599a (diff) | |
Inimigos spawnando. Campeões estompando.
Diffstat (limited to 'scripts/map')
| -rw-r--r-- | scripts/map/DungeonGenerator.cs | 38 | ||||
| -rw-r--r-- | scripts/map/Map.cs | 3 |
2 files changed, 36 insertions, 5 deletions
diff --git a/scripts/map/DungeonGenerator.cs b/scripts/map/DungeonGenerator.cs index 68bde06..6e9223c 100644 --- a/scripts/map/DungeonGenerator.cs +++ b/scripts/map/DungeonGenerator.cs @@ -1,11 +1,11 @@ using Godot; -using System; -using System.Drawing; -using System.Linq; -using System.Net.NetworkInformation; public partial class DungeonGenerator : Node { + private static readonly Godot.Collections.Array<ActorDefinition> enemies = [ + GD.Load<ActorDefinition>("res://assets/definitions/actor/Skeleton.tres") + ]; + [ExportCategory("Dimension")] [Export] private int width = 80; @@ -21,6 +21,10 @@ public partial class DungeonGenerator : Node [Export] private int iterations = 3; + [ExportCategory("Monster RNG")] + [Export] + private int maxMonsterPerRoom = 2; + public override void _Ready() { base._Ready(); @@ -74,18 +78,42 @@ public partial class DungeonGenerator : Node -rng.RandiRange(1, 2) ); - GD.Print($"Division {room}"); CarveRoom(data, room); if (first) { first = false; player.GridPosition = room.GetCenter(); + } else { + PlaceEntities(data, room); } } return data; } + private void PlaceEntities(MapData data, Rect2I room) { + int monsterAmount = rng.RandiRange(0, maxMonsterPerRoom); + + Vector2I position = new( + rng.RandiRange(room.Position.X, room.End.X - 1), + rng.RandiRange(room.Position.Y, room.End.Y - 1) + ); + + bool canPlace = true; + foreach (Actor actor in data.Actors) { + if (actor.GridPosition == position) { + canPlace = false; + break; + } + } + + if (canPlace) { + ActorDefinition definition = enemies.PickRandom(); + Enemy enemy = new Enemy(position, data, definition); + data.InsertActor(enemy); + } + } + private static void HorizontalCorridor(MapData data, int y, int xBegin, int xEnd) { int begin = (xBegin < xEnd) ? xBegin : xEnd; int end = (xEnd > xBegin) ? xEnd : xBegin; diff --git a/scripts/map/Map.cs b/scripts/map/Map.cs index 52ff588..29f5e62 100644 --- a/scripts/map/Map.cs +++ b/scripts/map/Map.cs @@ -49,5 +49,8 @@ public partial class Map : Node2D public void UpdateFOV(Vector2I pos) { fieldOfView.UpdateFOV(Map_Data, pos, fovRadius); + foreach (Actor actor in Map_Data.Actors) { + actor.Visible = Map_Data.GetTile(actor.GridPosition).IsInView; + } } } |
