diff options
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/Game.cs | 1 | ||||
| -rw-r--r-- | scripts/map/DungeonGenerator.cs | 38 | ||||
| -rw-r--r-- | scripts/map/Map.cs | 3 |
3 files changed, 36 insertions, 6 deletions
diff --git a/scripts/Game.cs b/scripts/Game.cs index 511b305..5c18cd7 100644 --- a/scripts/Game.cs +++ b/scripts/Game.cs @@ -3,7 +3,6 @@ using System; public partial class Game : Node { private static readonly ActorDefinition playerDefinition = GD.Load<ActorDefinition>("res://assets/definitions/actor/Player.tres"); - private static readonly ActorDefinition skeletonDefinition = GD.Load<ActorDefinition>("res://assets/definitions/actor/Skeleton.tres"); private Map Map; private InputHandler inputHandler; 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; + } } } |
