Implement chest spawning logic and room check in ObjectHandler; add room detection to MazeData
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user