Refactor debug checks to use event bus settings for consistency across game components.
This commit is contained in:
+2
-2
@@ -114,7 +114,7 @@ class Character
|
|||||||
end
|
end
|
||||||
|
|
||||||
# teleport to boss room for debug purposes
|
# teleport to boss room for debug purposes
|
||||||
if DEBUG && Gosu.button_down?(Gosu::KB_T)
|
if $bus.get(:settings, :debug) && Gosu.button_down?(Gosu::KB_T)
|
||||||
room_coords = $bus.get(:boss_room_coords)
|
room_coords = $bus.get(:boss_room_coords)
|
||||||
if room_coords
|
if room_coords
|
||||||
@world_x, @world_y = [room_coords[0] * 60 + 5, room_coords[1] * 60 + 5]
|
@world_x, @world_y = [room_coords[0] * 60 + 5, room_coords[1] * 60 + 5]
|
||||||
@@ -138,7 +138,7 @@ class Character
|
|||||||
frame_index = ((elapsed * 7).floor) % 6
|
frame_index = ((elapsed * 7).floor) % 6
|
||||||
@animations[@current_animation][frame_index].draw(sprite_x, sprite_y, sprite_y + 30, 1.8, 1.8)
|
@animations[@current_animation][frame_index].draw(sprite_x, sprite_y, sprite_y + 30, 1.8, 1.8)
|
||||||
|
|
||||||
return unless DEBUG
|
return unless $bus.get(:settings, :debug)
|
||||||
|
|
||||||
Gosu.draw_rect(cx, cy, SIZE[0], SIZE[1], Gosu::Color.new(0x8000FF00), cy)
|
Gosu.draw_rect(cx, cy, SIZE[0], SIZE[1], Gosu::Color.new(0x8000FF00), cy)
|
||||||
end
|
end
|
||||||
|
|||||||
+1
-1
@@ -76,7 +76,7 @@ class EnemyAI
|
|||||||
end
|
end
|
||||||
|
|
||||||
def draw
|
def draw
|
||||||
return unless DEBUG
|
return unless $bus.get(:settings, :debug)
|
||||||
cam_x, cam_y = $bus.get(:camera_pos) || [0, 0]
|
cam_x, cam_y = $bus.get(:camera_pos) || [0, 0]
|
||||||
@waypoints.each do |wx, wy|
|
@waypoints.each do |wx, wy|
|
||||||
Gosu.draw_rect(wx - cam_x - 5, wy - cam_y - 5, 10, 10, Gosu::Color.new(0x88ffff00), Float::INFINITY)
|
Gosu.draw_rect(wx - cam_x - 5, wy - cam_y - 5, 10, 10, Gosu::Color.new(0x88ffff00), Float::INFINITY)
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ class Inventory
|
|||||||
if id == Gosu::MS_LEFT
|
if id == Gosu::MS_LEFT
|
||||||
@inventory_selected = type
|
@inventory_selected = type
|
||||||
elsif id == Gosu::MS_RIGHT
|
elsif id == Gosu::MS_RIGHT
|
||||||
if DEBUG && [:wood, :metal, :science].include?(type)
|
if $bus.get(:settings, :debug) && [:wood, :metal, :science].include?(type)
|
||||||
@grid[row_idx][col_idx][1][0] = max
|
@grid[row_idx][col_idx][1][0] = max
|
||||||
else
|
else
|
||||||
craft(type, ctrl: Gosu.button_down?(Gosu::KB_RIGHT_CONTROL) || Gosu.button_down?(Gosu::KB_LEFT_CONTROL))
|
craft(type, ctrl: Gosu.button_down?(Gosu::KB_RIGHT_CONTROL) || Gosu.button_down?(Gosu::KB_LEFT_CONTROL))
|
||||||
|
|||||||
+1
-1
@@ -103,7 +103,7 @@ class Maze
|
|||||||
|
|
||||||
@spritesheet[index - 1].draw(screen_x, screen_y, screen_y, scale, scale)
|
@spritesheet[index - 1].draw(screen_x, screen_y, screen_y, scale, scale)
|
||||||
|
|
||||||
next unless DEBUG
|
next unless $bus.get(:settings, :debug)
|
||||||
|
|
||||||
shapes = shapes_for(index, gx * tile_size, gy * tile_size)
|
shapes = shapes_for(index, gx * tile_size, gy * tile_size)
|
||||||
shapes.each do |shape|
|
shapes.each do |shape|
|
||||||
|
|||||||
+1
-1
@@ -100,7 +100,7 @@ class Prop
|
|||||||
Gosu.draw_rect(bar_x, bar_y, bar_width, bar_height, Gosu::Color::RED, screen_y - 19)
|
Gosu.draw_rect(bar_x, bar_y, bar_width, bar_height, Gosu::Color::RED, screen_y - 19)
|
||||||
end
|
end
|
||||||
|
|
||||||
return unless DEBUG
|
return unless $bus.get(:settings, :debug)
|
||||||
|
|
||||||
# collision box centered on same point
|
# collision box centered on same point
|
||||||
Gosu.draw_rect(screen_x - SIZE[0] / 2, screen_y - SIZE[1], *SIZE, Gosu::Color.new(0x88ff0000), Float::INFINITY)
|
Gosu.draw_rect(screen_x - SIZE[0] / 2, screen_y - SIZE[1], *SIZE, Gosu::Color.new(0x88ff0000), Float::INFINITY)
|
||||||
|
|||||||
+2
-2
@@ -38,8 +38,8 @@ class Game < Scene
|
|||||||
@enemies.draw
|
@enemies.draw
|
||||||
@props.draw
|
@props.draw
|
||||||
@hud.draw
|
@hud.draw
|
||||||
draw_fog!
|
draw_fog! if $bus.get(:settings, :fog)
|
||||||
draw_debug! if DEBUG
|
draw_debug! if $bus.get(:settings, :debug)
|
||||||
end
|
end
|
||||||
|
|
||||||
def draw_debug!
|
def draw_debug!
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
require 'gosu'
|
require 'gosu'
|
||||||
|
|
||||||
require_relative 'settings/configuration'
|
|
||||||
require_relative 'utils/bus'
|
require_relative 'utils/bus'
|
||||||
|
$bus = EventBus.new
|
||||||
|
|
||||||
|
require_relative 'settings/configuration'
|
||||||
require_relative 'utils/utils'
|
require_relative 'utils/utils'
|
||||||
require_relative 'utils/scene'
|
require_relative 'utils/scene'
|
||||||
require_relative 'settings/scene'
|
require_relative 'settings/scene'
|
||||||
require_relative 'menu/scene'
|
require_relative 'menu/scene'
|
||||||
require_relative 'game/scene'
|
require_relative 'game/scene'
|
||||||
|
|
||||||
$bus = EventBus.new
|
|
||||||
|
|
||||||
# Main window
|
# Main window
|
||||||
class Window < Gosu::Window
|
class Window < Gosu::Window
|
||||||
def initialize
|
def initialize
|
||||||
|
|||||||
@@ -3,4 +3,21 @@
|
|||||||
SCREEN_SIZE = [720, 480].freeze
|
SCREEN_SIZE = [720, 480].freeze
|
||||||
N, S, W, E = 1, 2, 4, 8
|
N, S, W, E = 1, 2, 4, 8
|
||||||
|
|
||||||
DEBUG = ARGV.include?("--debug")
|
# Config module to hold global settings that can be toggled in the settings scene, and accessed anywhere else in the code via the event bus
|
||||||
|
module Config
|
||||||
|
@config = {
|
||||||
|
debug: ARGV.include?("--debug"),
|
||||||
|
fog: true,
|
||||||
|
torches_lightup: false
|
||||||
|
}
|
||||||
|
|
||||||
|
$bus.on(:settings) do |k|
|
||||||
|
next @config[k]
|
||||||
|
end
|
||||||
|
|
||||||
|
module_function
|
||||||
|
|
||||||
|
def toggle(key)
|
||||||
|
@config[key] = !@config[key]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|||||||
+1
-1
@@ -26,7 +26,7 @@ class MazeData
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return unless DEBUG
|
return unless $bus.get(:settings, :debug)
|
||||||
|
|
||||||
print_debug
|
print_debug
|
||||||
$bus.on(:boss_room_coords) do
|
$bus.on(:boss_room_coords) do
|
||||||
|
|||||||
Reference in New Issue
Block a user