Implement logging system: add GameLogger class for managing log messages, integrate logging in HUDLayer and ShrodingersMine for enhanced gameplay feedback.
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
require_relative "inventory"
|
require_relative "inventory"
|
||||||
require_relative "health"
|
require_relative "health"
|
||||||
|
require_relative "logs"
|
||||||
|
|
||||||
class HUDLayer
|
class HUDLayer
|
||||||
def initialize
|
def initialize
|
||||||
@@ -7,17 +8,23 @@ class HUDLayer
|
|||||||
@hud_fg = Gosu::Image.new("assets/images/hud_fg.png", retro: true)
|
@hud_fg = Gosu::Image.new("assets/images/hud_fg.png", retro: true)
|
||||||
@inventory = Inventory.new
|
@inventory = Inventory.new
|
||||||
@health = HealthBar.new(100)
|
@health = HealthBar.new(100)
|
||||||
|
@logs = GameLogger.new
|
||||||
|
|
||||||
$bus.on(:enemy_attack) do |damage|
|
$bus.on(:enemy_attack) do |damage|
|
||||||
@health.take_damage(damage)
|
@health.take_damage(damage)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def update(dt)
|
||||||
|
@logs.update(dt)
|
||||||
|
end
|
||||||
|
|
||||||
def draw
|
def draw
|
||||||
@hud_bg.draw(0, 0, Float::INFINITY)
|
@hud_bg.draw(0, 0, Float::INFINITY)
|
||||||
|
|
||||||
@inventory.draw
|
@inventory.draw
|
||||||
@health.draw
|
@health.draw
|
||||||
|
@logs.draw
|
||||||
|
|
||||||
@hud_fg.draw(0, 0, Float::INFINITY)
|
@hud_fg.draw(0, 0, Float::INFINITY)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
class GameLogger
|
||||||
|
MAX_ENTRIES = 5 # max messages to show
|
||||||
|
DURATION = 3.0 # seconds each message stays
|
||||||
|
|
||||||
|
Entry = Struct.new(:text, :time)
|
||||||
|
|
||||||
|
def initialize
|
||||||
|
@entries = []
|
||||||
|
@font = Gosu::Font.new(10, name: 'assets/fonts/tn.ttf')
|
||||||
|
|
||||||
|
$bus.on(:log) do |msg|
|
||||||
|
log(msg)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# add a message
|
||||||
|
def log(msg)
|
||||||
|
@entries << Entry.new(msg, DURATION)
|
||||||
|
@entries.shift if @entries.size > MAX_ENTRIES
|
||||||
|
end
|
||||||
|
|
||||||
|
def update(dt)
|
||||||
|
@entries.each { |e| e.time -= dt }
|
||||||
|
@entries.reject! { |e| e.time <= 0 }
|
||||||
|
end
|
||||||
|
|
||||||
|
def draw
|
||||||
|
padding_x = 10
|
||||||
|
padding_y = 10
|
||||||
|
line_height = 24
|
||||||
|
|
||||||
|
# bottom-left start
|
||||||
|
base_x = padding_x
|
||||||
|
base_y = SCREEN_SIZE[1] - padding_y - line_height * @entries.size
|
||||||
|
|
||||||
|
@entries.each_with_index do |e, i|
|
||||||
|
@font.draw_text(
|
||||||
|
e.text,
|
||||||
|
base_x,
|
||||||
|
base_y + i * line_height,
|
||||||
|
Float::INFINITY,
|
||||||
|
1, 1,
|
||||||
|
Gosu::Color::YELLOW
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -25,6 +25,8 @@ class Game < Scene
|
|||||||
|
|
||||||
@camera = [0, 0]
|
@camera = [0, 0]
|
||||||
|
|
||||||
|
$bus.emit(:log, "Welcome to the Mist! Use WASD to move, SPACE or left-click to attack with your equipped weapon, and ESC to return to the menu.")
|
||||||
|
|
||||||
$bus.on(:player_move) do |pos|
|
$bus.on(:player_move) do |pos|
|
||||||
@camera = pos
|
@camera = pos
|
||||||
end
|
end
|
||||||
@@ -88,6 +90,7 @@ class Game < Scene
|
|||||||
@props.update(dt)
|
@props.update(dt)
|
||||||
@traps.update(dt)
|
@traps.update(dt)
|
||||||
@weapons.update(dt)
|
@weapons.update(dt)
|
||||||
|
@hud.update(dt)
|
||||||
end
|
end
|
||||||
|
|
||||||
def button_down(id, pos)
|
def button_down(id, pos)
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ class ShrodingersMine < Trap
|
|||||||
return false if entity == :character # shrodingers mine is safe for the player, so don't destroy it or cause a blast if the player steps on it
|
return false if entity == :character # shrodingers mine is safe for the player, so don't destroy it or cause a blast if the player steps on it
|
||||||
if rand < 0.7 # 70% chance to be a landmine, 30% chance to be a dud
|
if rand < 0.7 # 70% chance to be a landmine, 30% chance to be a dud
|
||||||
$bus.emit(:blast, @x, @y, 50, 50, :safe) # blast radius of 50 and damage of 50, and always safe for the player
|
$bus.emit(:blast, @x, @y, 50, 50, :safe) # blast radius of 50 and damage of 50, and always safe for the player
|
||||||
|
else
|
||||||
|
$bus.emit(:log, "You hear a click, but nothing happens. It was a dud!")
|
||||||
end
|
end
|
||||||
true # to destroy the trap
|
true # to destroy the trap
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ So,
|
|||||||
#make enemy spawn in the boss rooms with randomness + enemy count - done
|
#make enemy spawn in the boss rooms with randomness + enemy count - done
|
||||||
#make the lizard kind of enemy with very high health + dps but slow - done
|
#make the lizard kind of enemy with very high health + dps but slow - done
|
||||||
|
|
||||||
make blade work as planned
|
#make blade work as planned - done
|
||||||
make bow just normal
|
#make bow quantum - done
|
||||||
|
|
||||||
make minimap for the torches revealing teh maze
|
make minimap for the torches revealing teh maze
|
||||||
click on minimap makes game pause to allow pausing for safety
|
click on minimap makes game pause to allow pausing for safety
|
||||||
|
|||||||
Reference in New Issue
Block a user