mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 10:35:34 +00:00
Solid walls
This commit is contained in:
parent
eefe35fe73
commit
0322748d86
9 changed files with 94 additions and 52 deletions
|
|
@ -20,7 +20,7 @@ namespace Cirno.Scripts.Controllers;
|
|||
public partial class RogueliteRoom : Node2D
|
||||
{
|
||||
[Export] public RogueliteRoomResource RoomResource { get; set; }
|
||||
|
||||
|
||||
public RogueliteMapTheme MapTheme { get; set; }
|
||||
|
||||
public Vector2I GridPosition { get; set; } // Set by dungeon manager
|
||||
|
|
@ -31,7 +31,7 @@ public partial class RogueliteRoom : Node2D
|
|||
private Vector2 BaseRoomSize => MapTheme.TileSize * MapTheme.RoomSizeInTiles;
|
||||
|
||||
public Vector2 RoomSize => BaseRoomSize * RoomResource.Size;
|
||||
|
||||
|
||||
public Vector2I RandomBottomExit()
|
||||
{
|
||||
return BottomLeft + new Vector2I(GD.RandRange(0, RoomResource.Size.X - 1), 0);
|
||||
|
|
@ -63,7 +63,7 @@ public partial class RogueliteRoom : Node2D
|
|||
private List<EnemyFSMProxy> _enemies = [];
|
||||
|
||||
private Array<EnemyResource> SpawnableEnemies => RoomResource.SpawnableEnemies;
|
||||
|
||||
|
||||
private BlackCover _shroud;
|
||||
private bool _firstEnter = true;
|
||||
|
||||
|
|
@ -165,42 +165,40 @@ public partial class RogueliteRoom : Node2D
|
|||
var connection = connectionChecker.Invoke(doorEdge, neighborPos);
|
||||
|
||||
var connected = connection is not null;
|
||||
|
||||
|
||||
var door = this.CreateChildOf<Door>(marker, marker.Direction switch
|
||||
{
|
||||
DoorDirections.North => MapTheme.HorizontalDoorPrefab,
|
||||
DoorDirections.South => MapTheme.HorizontalDoorPrefab,
|
||||
DoorDirections.East => MapTheme.VerticalDoorPrefab,
|
||||
DoorDirections.West => MapTheme.VerticalDoorPrefab,
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
}, marker.GlobalPosition);
|
||||
|
||||
door.Close();
|
||||
|
||||
// door.State = DoorState.Closed;
|
||||
if (connected)
|
||||
{
|
||||
var door = this.CreateChildOf<Door>(marker, marker.Direction switch
|
||||
{
|
||||
DoorDirections.North => MapTheme.HorizontalDoorPrefab,
|
||||
DoorDirections.South => MapTheme.HorizontalDoorPrefab,
|
||||
DoorDirections.East => MapTheme.VerticalDoorPrefab,
|
||||
DoorDirections.West => MapTheme.VerticalDoorPrefab,
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
}, marker.GlobalPosition);
|
||||
|
||||
door.Close();
|
||||
|
||||
// door.State = DoorState.Closed;
|
||||
|
||||
_doors.Add(door);
|
||||
|
||||
if (doorEdge == connection.From)
|
||||
{
|
||||
connection.FromDoor = door;
|
||||
|
||||
|
||||
// Spawn lock if locked
|
||||
if (connection.IsLocked)
|
||||
{
|
||||
var doorLock = door.CreateChild<RogueliteDoorLock>(MapTheme.DoorLockPrefab);
|
||||
|
||||
doorLock.Connection = connection;
|
||||
|
||||
|
||||
doorLock.ZIndex += 2;
|
||||
|
||||
//doorLock.Targets.Add(door);
|
||||
//doorLock.Targets.Add(connection.ToDoor);
|
||||
doorLock.ActivationType = ActivationType.Open;
|
||||
}
|
||||
|
||||
}
|
||||
else if (doorEdge == connection.To)
|
||||
{
|
||||
|
|
@ -213,12 +211,29 @@ public partial class RogueliteRoom : Node2D
|
|||
}
|
||||
|
||||
_connections.Add(connection);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// var wall = this.CreateChild<Node2D>(WallPrefab, marker.GlobalPosition);
|
||||
// Move marker based on direction
|
||||
var newMarkerPosition = marker.Direction switch
|
||||
{
|
||||
DoorDirections.East => marker.GlobalPosition + new Vector2(-4,0),
|
||||
DoorDirections.West => marker.GlobalPosition + new Vector2(-12,0),
|
||||
DoorDirections.North => marker.GlobalPosition + new Vector2(0,0),
|
||||
DoorDirections.South => marker.GlobalPosition + new Vector2(0,-2),
|
||||
_ => marker.GlobalPosition
|
||||
};
|
||||
|
||||
marker.GlobalPosition = newMarkerPosition;
|
||||
|
||||
var wall = this.CreateChildOf<Node2D>(marker, marker.Direction switch
|
||||
{
|
||||
DoorDirections.North => MapTheme.HorizontalNorthWallPrefab,
|
||||
DoorDirections.South => MapTheme.HorizontalSouthWallPrefab,
|
||||
DoorDirections.East => MapTheme.VerticalWallPrefab,
|
||||
DoorDirections.West => MapTheme.VerticalWallPrefab,
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
}, marker.GlobalPosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -234,7 +249,7 @@ public partial class RogueliteRoom : Node2D
|
|||
if (marker is not RogueliteEnemySpawner spawner) continue;
|
||||
|
||||
var spawnedEnemy = spawner.Spawn(MapTheme);
|
||||
|
||||
|
||||
_enemies.Add(spawnedEnemy);
|
||||
|
||||
spawnedEnemy.Death += SpawnedEnemyOnDeath;
|
||||
|
|
@ -245,13 +260,13 @@ public partial class RogueliteRoom : Node2D
|
|||
{
|
||||
var markersContainer = this.GetNodeOrNull("Treasures");
|
||||
if (markersContainer == null) return;
|
||||
|
||||
|
||||
var markerNodes = markersContainer.GetChildren();
|
||||
|
||||
|
||||
var itemsPool = MapTheme.WeaponsLootTable.Items.ToList().Shuffle().ToList();
|
||||
|
||||
|
||||
var playerItems = InventoryManager.Instance.Items;
|
||||
|
||||
|
||||
foreach (var itemContainer in playerItems)
|
||||
{
|
||||
if (itemsPool.Contains(itemContainer.Item))
|
||||
|
|
@ -265,26 +280,26 @@ public partial class RogueliteRoom : Node2D
|
|||
GD.Print("No items to spawn in the item room found");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Queue<LootItem> spawnQueue = new();
|
||||
foreach (var item in itemsPool)
|
||||
{
|
||||
spawnQueue.Enqueue(item);
|
||||
}
|
||||
|
||||
|
||||
foreach (var markerNode in markerNodes)
|
||||
{
|
||||
if (markerNode is not Marker2D marker)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
var itemFound = spawnQueue.TryDequeue(out var item);
|
||||
|
||||
|
||||
if (!itemFound) return;
|
||||
|
||||
GD.Print($"Spawning {item.ItemKey} in treasure spot");
|
||||
|
||||
|
||||
// Spawn
|
||||
var dropScene = GD.Load<PackedScene>(item.DropScenePath);
|
||||
var dropInstance = marker.CreateChild<Node2D>(dropScene);
|
||||
|
|
@ -296,7 +311,7 @@ public partial class RogueliteRoom : Node2D
|
|||
// Get feature markers
|
||||
// Roll for chances
|
||||
// Spawn the objects
|
||||
|
||||
|
||||
var markersContainer = this.GetNodeOrNull("Features");
|
||||
if (markersContainer is null) return;
|
||||
|
||||
|
|
@ -308,18 +323,17 @@ public partial class RogueliteRoom : Node2D
|
|||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
double chance = GD.RandRange(0d, 100d);
|
||||
if (chance <= MapTheme.ChestChance)
|
||||
{
|
||||
var chest = marker.CreateChild<Chest>(MapTheme.ChestPrefab);
|
||||
|
||||
var loot = MapTheme.ChestLootTable.Items.ToList().Shuffle().First();
|
||||
|
||||
|
||||
chest.LootTable.Add(loot);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void SpawnedEnemyOnDeath(EnemyFSMProxy enemy)
|
||||
|
|
@ -337,11 +351,12 @@ public partial class RogueliteRoom : Node2D
|
|||
{
|
||||
foreach (var connection in _connections)
|
||||
{
|
||||
if(!connection.IsLocked)
|
||||
if (!connection.IsLocked)
|
||||
{
|
||||
connection.FromDoor?.Open();
|
||||
}
|
||||
if(!connection.IsLocked)
|
||||
|
||||
if (!connection.IsLocked)
|
||||
{
|
||||
connection.ToDoor?.Open();
|
||||
}
|
||||
|
|
@ -352,11 +367,12 @@ public partial class RogueliteRoom : Node2D
|
|||
{
|
||||
foreach (var connection in _connections)
|
||||
{
|
||||
if(!connection.IsLocked)
|
||||
if (!connection.IsLocked)
|
||||
{
|
||||
connection.FromDoor?.Close();
|
||||
}
|
||||
if(!connection.IsLocked)
|
||||
|
||||
if (!connection.IsLocked)
|
||||
{
|
||||
connection.ToDoor?.Close();
|
||||
}
|
||||
|
|
@ -375,7 +391,7 @@ public partial class RogueliteRoom : Node2D
|
|||
|
||||
_ = AlarmTriggerAsync(area.GlobalPosition, 1f);
|
||||
}
|
||||
|
||||
|
||||
// This might cause problems later if I delay enemy spawns
|
||||
if (_enemies.Count <= 0)
|
||||
{
|
||||
|
|
@ -458,12 +474,10 @@ public partial class RogueliteRoom : Node2D
|
|||
if (!RoomResource.StartShrouded) return;
|
||||
|
||||
var shroud = this.CreateChild<BlackCover>(MapTheme.ShroudPrefab);
|
||||
|
||||
|
||||
shroud.Position = new Vector2(RoomSize.X / 2, RoomSize.Y / 2);
|
||||
shroud.Scale = RoomSize;
|
||||
|
||||
_shroud = shroud;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue