Add debug teleportation and player position display; enhance maze debug output

This commit is contained in:
2026-03-25 09:20:06 +00:00
parent 8d643a3842
commit 84004a9f67
3 changed files with 53 additions and 34 deletions
+10
View File
@@ -1,4 +1,6 @@
class Character class Character
attr_reader :world_x, :world_y
SPEED = 2.5 SPEED = 2.5
SIZE = [25, 30] SIZE = [25, 30]
@@ -89,6 +91,14 @@ class Character
@world_y -= dy @world_y -= dy
end end
# teleport to boss room for debug purposes
if DEBUG && Gosu.button_down?(Gosu::KB_T)
room_coords = $bus.get(:boss_room_coords)
if room_coords
@world_x, @world_y = [room_coords[0] * 60 + 5, room_coords[1] * 60 + 5]
end
end
# Camera follow # Camera follow
cam_x = @world_x - SCREEN_SIZE[0] / 2.0 cam_x = @world_x - SCREEN_SIZE[0] / 2.0
cam_y = @world_y - SCREEN_SIZE[1] / 2.0 cam_y = @world_y - SCREEN_SIZE[1] / 2.0
+4 -5
View File
@@ -51,13 +51,14 @@ class Game < Scene
end end
@font.draw_text("FPS: #{@fps}", 5, 5, Float::INFINITY, 1, 1, Gosu::Color::YELLOW) @font.draw_text("FPS: #{@fps}", 5, 5, Float::INFINITY, 1, 1, Gosu::Color::YELLOW)
@font.draw_text("Player: [#{@character.world_x.round}, #{@character.world_y.round}]", 5, 30, Float::INFINITY, 1, 1, Gosu::Color::YELLOW)
end end
def draw_fog(camera) def draw_fog(camera)
cam_x, cam_y = camera cam_x, cam_y = camera
cell = 10 cell = 10
i_radius = 80.0 i_radius = 90.0
o_radius = 360.0 o_radius = 400.0
# Player screen position # Player screen position
px = SCREEN_SIZE[0] / 2.0 px = SCREEN_SIZE[0] / 2.0
@@ -71,7 +72,6 @@ class Game < Scene
sx = i * cell sx = i * cell
sy = j * cell sy = j * cell
dist = Math.sqrt((sx - px)**2 + (sy - py)**2) dist = Math.sqrt((sx - px)**2 + (sy - py)**2)
if dist < i_radius if dist < i_radius
@@ -80,11 +80,10 @@ class Game < Scene
alpha = 255 alpha = 255
else else
t = (dist - i_radius) / (o_radius - i_radius) # 0..1 t = (dist - i_radius) / (o_radius - i_radius) # 0..1
world_x = (sx + cam_x) * 0.005 world_x = (sx + cam_x) * 0.005
world_y = (sy + cam_y) * 0.005 world_y = (sy + cam_y) * 0.005
# Sample noise at world position so it scrolls with camera # Sample noise at world position so it scrolls with camera
# Add time-based offsets for animation
noise = (@noise[world_x + Gosu.milliseconds / 5000.0, world_y + Gosu.milliseconds / 6000.0] + 1.0) / 2.0 noise = (@noise[world_x + Gosu.milliseconds / 5000.0, world_y + Gosu.milliseconds / 6000.0] + 1.0) / 2.0
alpha = (t * (1.0 + noise) * 255).to_i.clamp(0, 255) alpha = (t * (1.0 + noise) * 255).to_i.clamp(0, 255)
end end
+38 -28
View File
@@ -10,6 +10,13 @@ class MazeData
crate_rooms! crate_rooms!
carve_passages_from(0, 0) carve_passages_from(0, 0)
fix_room_entrances! fix_room_entrances!
return unless DEBUG
print_debug
$bus.on_retrievable(:boss_room_coords) do
next @boss_rooms.first ? [@boss_rooms.first[0] * 2 + 1, @boss_rooms.first[1] * 2 + 1] : nil
end
end end
def width def width
@@ -61,9 +68,36 @@ class MazeData
true true
end end
def print_debug
wall_chars = {
0 => " ", # NONE
1 => "", # N
2 => "", # S
3 => "", # NS
4 => "", # W
5 => "", # NW
6 => "", # WS
7 => "", # WNS
8 => "", # E
9 => "", # NE
10 => "", # ES
11 => "", # ENS
12 => "", # EW
13 => "", # EWN
14 => "", # EWS
15 => "" # EWNS
}
(0...self.height).each do |y|
(0...self.width).each do |x|
print wall_chars[wall_type(x, y)]
end
puts
end
end
private private
BOSS_ROOM_SIZE = 5 BOSS_ROOM_SIZE = 3
BOSS_ROOM = 16 BOSS_ROOM = 16
N, S, W, E = 1, 2, 4, 8 N, S, W, E = 1, 2, 4, 8
DX = { E => 1, W => -1, N => 0, S => 0 } DX = { E => 1, W => -1, N => 0, S => 0 }
@@ -81,8 +115,8 @@ class MazeData
def fix_room_entrances! def fix_room_entrances!
@boss_rooms.each do |x, y| @boss_rooms.each do |x, y|
@grid[y][x + 2] |= N @grid[y][x + 1] |= N
@grid[y - 1][x + 2] |= S @grid[y - 1][x + 1] |= S
end end
end end
@@ -134,29 +168,5 @@ class MazeData
end end
if __FILE__ == $0 if __FILE__ == $0
WALL_CHARS = {
0 => " ", # NONE
1 => "", # N
2 => "", # S
3 => "", # NS
4 => "", # W
5 => "", # NW
6 => "", # WS
7 => "", # WNS
8 => "", # E
9 => "", # NE
10 => "", # ES
11 => "", # ENS
12 => "", # EW
13 => "", # EWN
14 => "", # EWS
15 => "" # EWNS
}
maze = MazeData.new(80, 80)
(0...maze.height).each do |y|
(0...maze.width).each do |x|
print WALL_CHARS[maze.wall_type(x, y)]
end
puts
end
end end