From 01029bb6a2311eed397991dd7733db2e972f7faf Mon Sep 17 00:00:00 2001 From: Daanish Date: Sat, 28 Mar 2026 12:37:09 +0000 Subject: [PATCH] Implement chest spawning logic and room check in ObjectHandler; add room detection to MazeData --- game/placeables/base.rb | 25 +++++++++++++++++++++++++ utils/maze.rb | 9 ++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/game/placeables/base.rb b/game/placeables/base.rb index 2f404ca..73ec819 100644 --- a/game/placeables/base.rb +++ b/game/placeables/base.rb @@ -88,10 +88,35 @@ class ObjectHandler def initialize start_room_coords = $bus.get(:start_room_coords) @objects = [] + + #spawn_chests! end def spawn_chests! world_size = $bus.get(:maze_size) || [0, 0] + + cell_size = 6 # tweak this (bigger = more spread out) + + (0...world_size[0]).step(cell_size) do |cx| + (0...world_size[1]).step(cell_size) do |cy| + + # Random position inside this cell + x = cx + rand(cell_size) + y = cy + rand(cell_size) + + next if x >= world_size[0] || y >= world_size[1] + + # Keep your spawn exclusion + next if (x - 2).abs <= 1 && (y - 2).abs <= 1 + + next if $bus.get(:room?, x, y) + + # Chance per cell instead of per tile + if rand < 0.6 + @objects << Chest.new(x, y) + end + end + end end def add(object) diff --git a/utils/maze.rb b/utils/maze.rb index 4a273c3..fa95c30 100644 --- a/utils/maze.rb +++ b/utils/maze.rb @@ -19,6 +19,13 @@ class MazeData next @start_room ? [@start_room[0] * 2 + 1, @start_room[1] * 2 + 1] : nil end + $bus.on(:room?) do |gx, gy| + ([@start_room] + @boss_rooms).any? do |rx, ry| + gx.between?(rx, rx + BOSS_ROOM_SIZE) && + gy.between?(ry, ry + BOSS_ROOM_SIZE) + end + end + return unless DEBUG print_debug @@ -26,7 +33,7 @@ class MazeData next @boss_rooms.first ? [@boss_rooms.first[0] * 2 + 1, @boss_rooms.first[1] * 2 + 1] : nil end end - + def solve(x1, y1, x2, y2) # explain why dijkstra's is fine here: # A* hueristics make it possible to chose a longer path through rooms instead of a shorter path through corridors, which is not what we want for enemy pathfinding