From 84004a9f67b2de7a3adf455c2dc42eb9bab35163 Mon Sep 17 00:00:00 2001 From: Daanish Date: Wed, 25 Mar 2026 09:20:06 +0000 Subject: [PATCH] Add debug teleportation and player position display; enhance maze debug output --- game/character.rb | 10 +++++++ game/scene.rb | 11 ++++---- utils/maze.rb | 66 +++++++++++++++++++++++++++-------------------- 3 files changed, 53 insertions(+), 34 deletions(-) diff --git a/game/character.rb b/game/character.rb index e6a576e..cfa4d54 100644 --- a/game/character.rb +++ b/game/character.rb @@ -1,4 +1,6 @@ class Character + attr_reader :world_x, :world_y + SPEED = 2.5 SIZE = [25, 30] @@ -89,6 +91,14 @@ class Character @world_y -= dy 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 cam_x = @world_x - SCREEN_SIZE[0] / 2.0 cam_y = @world_y - SCREEN_SIZE[1] / 2.0 diff --git a/game/scene.rb b/game/scene.rb index 303199d..43917bc 100644 --- a/game/scene.rb +++ b/game/scene.rb @@ -51,13 +51,14 @@ class Game < Scene end @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 def draw_fog(camera) cam_x, cam_y = camera cell = 10 - i_radius = 80.0 - o_radius = 360.0 + i_radius = 90.0 + o_radius = 400.0 # Player screen position px = SCREEN_SIZE[0] / 2.0 @@ -71,20 +72,18 @@ class Game < Scene sx = i * cell sy = j * cell - dist = Math.sqrt((sx - px)**2 + (sy - py)**2) - + if dist < i_radius next # fully clear elsif dist > o_radius alpha = 255 else t = (dist - i_radius) / (o_radius - i_radius) # 0..1 - world_x = (sx + cam_x) * 0.005 world_y = (sy + cam_y) * 0.005 - # 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 alpha = (t * (1.0 + noise) * 255).to_i.clamp(0, 255) end diff --git a/utils/maze.rb b/utils/maze.rb index 179e840..e272ec1 100644 --- a/utils/maze.rb +++ b/utils/maze.rb @@ -10,6 +10,13 @@ class MazeData crate_rooms! carve_passages_from(0, 0) 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 def width @@ -61,9 +68,36 @@ class MazeData true 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 - BOSS_ROOM_SIZE = 5 + BOSS_ROOM_SIZE = 3 BOSS_ROOM = 16 N, S, W, E = 1, 2, 4, 8 DX = { E => 1, W => -1, N => 0, S => 0 } @@ -81,8 +115,8 @@ class MazeData def fix_room_entrances! @boss_rooms.each do |x, y| - @grid[y][x + 2] |= N - @grid[y - 1][x + 2] |= S + @grid[y][x + 1] |= N + @grid[y - 1][x + 1] |= S end end @@ -134,29 +168,5 @@ class MazeData end 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 \ No newline at end of file