Implement chest spawning logic and room check in ObjectHandler; add room detection to MazeData

This commit is contained in:
2026-03-28 12:37:09 +00:00
parent ba828d682c
commit 01029bb6a2
2 changed files with 33 additions and 1 deletions
+25
View File
@@ -88,10 +88,35 @@ class ObjectHandler
def initialize def initialize
start_room_coords = $bus.get(:start_room_coords) start_room_coords = $bus.get(:start_room_coords)
@objects = [] @objects = []
#spawn_chests!
end end
def spawn_chests! def spawn_chests!
world_size = $bus.get(:maze_size) || [0, 0] 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 end
def add(object) def add(object)
+8 -1
View File
@@ -19,6 +19,13 @@ class MazeData
next @start_room ? [@start_room[0] * 2 + 1, @start_room[1] * 2 + 1] : nil next @start_room ? [@start_room[0] * 2 + 1, @start_room[1] * 2 + 1] : nil
end 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 return unless DEBUG
print_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 next @boss_rooms.first ? [@boss_rooms.first[0] * 2 + 1, @boss_rooms.first[1] * 2 + 1] : nil
end end
end end
def solve(x1, y1, x2, y2) def solve(x1, y1, x2, y2)
# explain why dijkstra's is fine here: # 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 # 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