mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-09 16:45:55 +00:00
Fixed spawn offset generation
This commit is contained in:
parent
13ac8e4f2f
commit
8c20e6f342
6 changed files with 182 additions and 40 deletions
17
Resources/RogueliteMaps/BigLarge.tres
Normal file
17
Resources/RogueliteMaps/BigLarge.tres
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
[gd_resource type="Resource" script_class="RogueliteRoomResource" load_steps=6 format=3 uid="uid://n6nb5yco60gi"]
|
||||
|
||||
[ext_resource type="Resource" uid="uid://cocl3qontm3be" path="res://Resources/Enemies/Base_Fairy.tres" id="1_ch23e"]
|
||||
[ext_resource type="Resource" uid="uid://cqfyuurvqb8m6" path="res://Resources/Enemies/Base_Fairy_Special.tres" id="2_l64su"]
|
||||
[ext_resource type="Resource" uid="uid://qbo6avc7x64b" path="res://Resources/Enemies/Fairy_Guard.tres" id="3_0b7uq"]
|
||||
[ext_resource type="Resource" uid="uid://cfdvg162u65sr" path="res://Resources/Enemies/Thermathron.tres" id="4_iwrey"]
|
||||
[ext_resource type="Script" uid="uid://bl2ne8w12e3a" path="res://Scripts/Resources/Roguelite/RogueliteRoomResource.cs" id="5_yivs1"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("5_yivs1")
|
||||
RoomName = &"Test"
|
||||
Type = 1
|
||||
ScenePath = &"uid://c3x64n451f3mk"
|
||||
Size = Vector2i(3, 2)
|
||||
DoorGridPositions = Array[Vector2i]([Vector2i(0, -1), Vector2i(0, 1), Vector2i(1, 0), Vector2i(-1, 0)])
|
||||
SpawnableEnemies = Array[Object]([ExtResource("1_ch23e"), ExtResource("2_l64su"), ExtResource("3_0b7uq"), ExtResource("4_iwrey")])
|
||||
metadata/_custom_type_script = "uid://bl2ne8w12e3a"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=20 format=3 uid="uid://bf1kqr3o6r6d4"]
|
||||
[gd_scene load_steps=21 format=3 uid="uid://bf1kqr3o6r6d4"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://doxmbokehw8ci" path="res://Scripts/GameManager.cs" id="1_wbqvu"]
|
||||
[ext_resource type="PackedScene" uid="uid://c4pr2707hbeph" path="res://Scenes/Actors/fsm_player.tscn" id="2_3fyis"]
|
||||
|
|
@ -18,6 +18,7 @@
|
|||
[ext_resource type="Resource" uid="uid://cmgiqsmujujss" path="res://Resources/RogueliteMaps/TestMapLongX3.tres" id="12_83bvc"]
|
||||
[ext_resource type="Script" uid="uid://cnkipcolyj61w" path="res://Scripts/AlarmManager.cs" id="12_eoca5"]
|
||||
[ext_resource type="PackedScene" uid="uid://b3tyacxxw88lx" path="res://Scenes/Utils/StreamPlayerWithName.tscn" id="13_4n7t6"]
|
||||
[ext_resource type="Resource" uid="uid://n6nb5yco60gi" path="res://Resources/RogueliteMaps/BigLarge.tres" id="13_y651a"]
|
||||
[ext_resource type="Script" uid="uid://3v6q0p5krqn7" path="res://Scripts/UI/Minimap.cs" id="16_pfafs"]
|
||||
|
||||
[node name="GameScene" type="Node2D"]
|
||||
|
|
@ -32,7 +33,7 @@ SpawnMarkers = Dictionary[int, NodePath]({
|
|||
[node name="Maps" type="Node2D" parent="." groups=["navigation_polygon_source_geometry_group"]]
|
||||
process_mode = 1
|
||||
script = ExtResource("4_jtlua")
|
||||
Rooms = Array[Object]([ExtResource("5_gwtv6"), ExtResource("6_gwtv6"), ExtResource("7_wbqvu"), ExtResource("8_3fyis"), ExtResource("9_go1yg"), ExtResource("5_pfafs"), ExtResource("11_68lig"), ExtResource("12_83bvc")])
|
||||
Rooms = Array[Object]([ExtResource("5_gwtv6"), ExtResource("6_gwtv6"), ExtResource("7_wbqvu"), ExtResource("8_3fyis"), ExtResource("9_go1yg"), ExtResource("5_pfafs"), ExtResource("11_68lig"), ExtResource("12_83bvc"), ExtResource("13_y651a")])
|
||||
|
||||
[node name="CameraController" type="Camera2D" parent="."]
|
||||
process_mode = 1
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ position = Vector2(159, 23)
|
|||
script = ExtResource("5_mqiea")
|
||||
|
||||
[node name="South" type="Marker2D" parent="Doors"]
|
||||
position = Vector2(159.196, 149.348)
|
||||
position = Vector2(159, 160)
|
||||
script = ExtResource("5_mqiea")
|
||||
Direction = 1
|
||||
|
||||
|
|
|
|||
104
Scenes/Maps/RogueliteMaps/RgBigLarge.tscn
Normal file
104
Scenes/Maps/RogueliteMaps/RgBigLarge.tscn
Normal file
File diff suppressed because one or more lines are too long
|
|
@ -19,7 +19,7 @@ public partial class RogueliteRoomManager : Node2D
|
|||
private Godot.Collections.Dictionary<Vector2I, RogueliteRoom> _roomGrid = new();
|
||||
|
||||
public Godot.Collections.Dictionary<Vector2I, RogueliteRoom> RoomGrid => _roomGrid;
|
||||
|
||||
|
||||
public List<RogueliteRoom> SpawnedRooms { get; private set; } = [];
|
||||
|
||||
[Export] public Vector2I SpawnOrigin { get; private set; } = Vector2I.Zero;
|
||||
|
|
@ -31,12 +31,13 @@ public partial class RogueliteRoomManager : Node2D
|
|||
[Export] public int DungeonWidth = 10;
|
||||
[Export] public int DungeonHeight = 10;
|
||||
[Export] public int MaxRooms = 12;
|
||||
//[Export] public int Seed = -1;
|
||||
[Export] public ulong Seed = 0;
|
||||
|
||||
[Export] public Vector2I TileSize { get; set; } = new Vector2I(16, 16);
|
||||
[Export] public Vector2I RoomSizeInTiles { get; set; } = new Vector2I(20, 10);
|
||||
|
||||
[Signal] public delegate void MapCreatedEventHandler();
|
||||
|
||||
[Signal]
|
||||
public delegate void MapCreatedEventHandler();
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
|
|
@ -74,21 +75,27 @@ public partial class RogueliteRoomManager : Node2D
|
|||
|
||||
private List<Vector2I> _mainPath = new();
|
||||
private List<RoomConnection> _connections = new();
|
||||
|
||||
|
||||
public List<RoomConnection> Connections => _connections;
|
||||
|
||||
private void GenerateStraightLineDungeon()
|
||||
{
|
||||
if (Seed > 0)
|
||||
{
|
||||
GD.Seed(Seed);
|
||||
}
|
||||
|
||||
Vector2I origin = Vector2I.Zero;
|
||||
var starterRoom = Rooms.Where(r => r.Type == RoomType.Starter).PickRandom();
|
||||
SpawnRoom(starterRoom, origin);
|
||||
_mainPath.Add(origin);
|
||||
|
||||
|
||||
var randomRoomsList = RegularRooms.Shuffle(DungeonLength).ToList();
|
||||
|
||||
|
||||
var currentPos = origin;
|
||||
_connections.Add(new RoomConnection(origin, currentPos + new Vector2I(0, 1)));
|
||||
Vector2I nextPos;
|
||||
|
||||
|
||||
for (int i = 0; i < DungeonLength; i++)
|
||||
{
|
||||
nextPos = currentPos + new Vector2I(0, 1);
|
||||
|
|
@ -96,62 +103,74 @@ public partial class RogueliteRoomManager : Node2D
|
|||
//var roomToSpawn = Rooms.Where(x => x.Type == RoomType.Regular).PickRandom();
|
||||
var roomToSpawn = randomRoomsList[i];
|
||||
|
||||
// First pick a random door on the from room
|
||||
//var doorOffset = Math.Min(0, GD.RandRange(0, currentRoom.Size.X - 1));
|
||||
|
||||
// We're already in the new room position, we do not care about previous anymore
|
||||
|
||||
var offset = 0;
|
||||
|
||||
|
||||
// Place it at a random X position
|
||||
if (roomToSpawn.Size.X > 1)
|
||||
{
|
||||
offset -= GD.RandRange(0, roomToSpawn.Size.X - 1);
|
||||
}
|
||||
|
||||
var posWithOffset = new Vector2I(offset, nextPos.Y);
|
||||
|
||||
if (!SpawnRoom(roomToSpawn, posWithOffset))
|
||||
nextPos += new Vector2I(offset, 0);
|
||||
|
||||
//var posWithOffset = nextPos + new Vector2I(offset, 0);
|
||||
|
||||
if (!SpawnRoom(roomToSpawn, nextPos))
|
||||
{
|
||||
GD.PrintErr("Could not spawn room");
|
||||
break;
|
||||
};
|
||||
}
|
||||
|
||||
_mainPath.Add(posWithOffset);
|
||||
|
||||
;
|
||||
|
||||
_mainPath.Add(nextPos);
|
||||
|
||||
// Place cursor at bottom of room
|
||||
if (roomToSpawn.Size.Y > 1)
|
||||
{
|
||||
nextPos += new Vector2I(0, roomToSpawn.Size.Y - 1);
|
||||
nextPos += new Vector2I(0, roomToSpawn.Size.Y - 1);
|
||||
}
|
||||
|
||||
|
||||
// Pick a random exit to continue
|
||||
var exit = Math.Min(0, GD.RandRange(0, roomToSpawn.Size.X - 1));
|
||||
|
||||
nextPos += new Vector2I(0, exit);
|
||||
|
||||
_connections.Add(new RoomConnection(currentPos, nextPos));
|
||||
var exit = GD.RandRange(0, roomToSpawn.Size.X - 1);
|
||||
if (exit < 0) exit = 0;
|
||||
|
||||
nextPos += new Vector2I(exit, 0);
|
||||
// nextPos is now the end of the room at the current exit
|
||||
|
||||
_connections.Add(new RoomConnection(nextPos, nextPos + new Vector2I(0, 1)));
|
||||
//+ new Vector2I(0, roomToSpawn.Size.Y -1)
|
||||
// Reset X offset
|
||||
//nextPos = new Vector2I(0, nextPos.Y);
|
||||
|
||||
|
||||
currentPos = nextPos;
|
||||
}
|
||||
|
||||
|
||||
nextPos = currentPos + new Vector2I(0, 1);
|
||||
|
||||
|
||||
var bossRoom = BossRooms.PickRandom();
|
||||
|
||||
|
||||
if (SpawnRoom(bossRoom, nextPos))
|
||||
{
|
||||
_mainPath.Add(nextPos);
|
||||
|
||||
|
||||
if (bossRoom.Size.Y > 1)
|
||||
{
|
||||
nextPos += new Vector2I(0, bossRoom.Size.Y - 1);
|
||||
nextPos += new Vector2I(0, bossRoom.Size.Y - 1);
|
||||
}
|
||||
|
||||
|
||||
_connections.Add(new RoomConnection(currentPos, nextPos));
|
||||
}
|
||||
else
|
||||
{
|
||||
GD.PrintErr("Could not spawn boss room");
|
||||
}
|
||||
|
||||
|
||||
foreach (var roomEntry in _roomGrid)
|
||||
{
|
||||
var room = roomEntry.Value;
|
||||
|
|
@ -161,10 +180,10 @@ public partial class RogueliteRoomManager : Node2D
|
|||
return _roomGrid.ContainsKey(neighborPos);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
EmitSignalMapCreated();
|
||||
}
|
||||
|
||||
|
||||
private void GenerateDungeon()
|
||||
{
|
||||
Vector2I origin = Vector2I.Zero;
|
||||
|
|
@ -202,7 +221,7 @@ public partial class RogueliteRoomManager : Node2D
|
|||
_connections.Add(new RoomConnection(currentPos, bossTargetPos.Value));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// private void SpawnRoomsBinaryTree()
|
||||
// {
|
||||
// var directions = new List<Vector2I>
|
||||
|
|
@ -286,7 +305,7 @@ public partial class RogueliteRoomManager : Node2D
|
|||
// });
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
private Vector2I? FindValidBossRoomLocation(Vector2I from, int maxSteps = 10)
|
||||
{
|
||||
var directions = new List<Vector2I> { Vector2I.Right, Vector2I.Left, Vector2I.Up, Vector2I.Down };
|
||||
|
|
@ -347,7 +366,7 @@ public partial class RogueliteRoomManager : Node2D
|
|||
{
|
||||
if (!CanPlaceRoom(gridPos, room.Size))
|
||||
return false;
|
||||
|
||||
|
||||
var position = gridPos * TileSize * RoomSizeInTiles;
|
||||
|
||||
var roomScene = GD.Load<PackedScene>(room.ScenePath);
|
||||
|
|
@ -356,7 +375,7 @@ public partial class RogueliteRoomManager : Node2D
|
|||
spawnedScene.GridPosition = gridPos;
|
||||
|
||||
SpawnedRooms.Add(spawnedScene);
|
||||
|
||||
|
||||
// for reference
|
||||
//SpawnRoom(room, origin + (room.Size * new Vector2(i, j) * tileSize));
|
||||
spawnedScene.Spawn();
|
||||
|
|
@ -379,7 +398,7 @@ public partial class RogueliteRoomManager : Node2D
|
|||
if (_roomGrid.ContainsKey(pos)) return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
1
Scripts/Utils/ShuffleExtensions.cs.uid
Normal file
1
Scripts/Utils/ShuffleExtensions.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cayi15oyskn85
|
||||
Loading…
Add table
Add a link
Reference in a new issue