summaryrefslogtreecommitdiff
path: root/scripts/map/DungeonGenerator.cs
diff options
context:
space:
mode:
authorMatheus <matheus.guedes.mg.m@gmail.com>2025-08-25 17:52:41 -0300
committerMatheus <matheus.guedes.mg.m@gmail.com>2025-08-25 17:52:41 -0300
commit5f0098b04fe71059471cf82730f341ce06c9fe68 (patch)
tree60bb4eda1679323ddd905c879b410afcc31891dd /scripts/map/DungeonGenerator.cs
parent7419e7237c3c5b3f1184babfcd826b7f788b599a (diff)
Inimigos spawnando. Campeões estompando.
Diffstat (limited to 'scripts/map/DungeonGenerator.cs')
-rw-r--r--scripts/map/DungeonGenerator.cs38
1 files changed, 33 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;