Refactor weapon system: implement WeaponHandler to manage LorentzField and prepare for additional weapons; update shader to incorporate lorentz_field uniform for visual effects.

This commit is contained in:
2026-03-29 22:22:06 +00:00
parent 3c8c481713
commit 1ea06f50d3
6 changed files with 114 additions and 20 deletions
+7
View File
@@ -2,6 +2,7 @@ require_relative 'maze'
require_relative 'hud/layer'
require_relative 'props/handler'
require_relative 'enemy/handler'
require_relative 'weapons/handler'
require_relative 'character'
require 'perlin'
@@ -17,6 +18,7 @@ class Game < Scene
@character = Character.new
@enemies = EnemyHandler.new
@props = PropsHandler.new
@weapons = WeaponHandler.new
@hud = HUDLayer.new
@@ -39,6 +41,7 @@ class Game < Scene
@props.draw
$bus.emit(:shade) if $bus.get(:settings, :fog)
@hud.draw
@weapons.draw
draw_debug! if $bus.get(:settings, :debug)
end
@@ -71,6 +74,7 @@ class Game < Scene
@character.update(dt)
@enemies.update(dt)
@props.update(dt)
@weapons.update(dt)
end
def button_down(id, pos)
@@ -78,5 +82,8 @@ class Game < Scene
return if @hud.button_down(id, pos)
return if @props.button_down(id, pos)
#return if @weapons.button_down(id, pos)
#@character.button_down(id)
end
end
+31
View File
@@ -0,0 +1,31 @@
require_relative 'lorentz_field'
#require_relative 'occams_razor'
#require_relative 'quantum_bow'
#require_relative 'blade_of_recursion'
class WeaponHandler
def initialize
@weapons = {
lorentz_field: LorentzField.new,
#occams_razor: OccamsRazor.new,
#quantum_bow: QuantumBow.new,
#blade_of_recursion: BladeOfRecursion.new
}
end
def update(dt)
@weapons.each_value { |weapon| weapon.update(dt) }
selected_item = $bus.get(:selected_item)
return unless @weapons.key?(selected_item)
weapon = @weapons[selected_item]
if $bus.get(:count, selected_item) > 0 && Gosu.button_down?(Gosu::KB_SPACE)
weapon.attack
end
end
def draw
@weapons.each_value(&:draw)
end
end
+51 -11
View File
@@ -1,16 +1,56 @@
class LorentzField < Weapon
class LorentzField
BASE_TIME = 25 # Base time for the field to be active in seconds
def initialize
super(
name: "Lorentz Field",
description: "A defensive weapon that creates a time distortion field around the user. While active, the field slows down incoming projectiles and enemies, giving the user a chance to react and evade. The field lasts for a short duration and has a cooldown period before it can be used again.",
image_path: "assets/images/lorentz_field.png",
cooldown: 5.0,
damage: 0,
range: 0,
area_of_effect: 0
)
@time = 0
@active = false
@font = Gosu::Font.new(24, name: "assets/fonts/tn.ttf")
$bus.on(:lorentz_field) do
if @active
t = @time
remaining = BASE_TIME - t
if t < 4
# fade in
next t / 4.0
elsif remaining < 4
# fade out
next remaining / 4.0
else
# fully active
next 1.0
end
else
next 0.0
end
end
end
def activate(user)
def attack
return if @active
$bus.emit(:consume, :lorentz_field, 1)
@active = true
@time = 0
end
def update(dt)
return unless @active
@time += dt
if @time >= BASE_TIME
@time = 0
@active = false
end
end
def draw
# for now draw the time
return unless @active
remaining = BASE_TIME - @time
text = "Lorentz Field: #{remaining.round(1)}s"
@font.draw_text(text, SCREEN_SIZE[0] / 2 - @font.text_width(text) / 2, 10, Float::INFINITY, 1, 1, Gosu::Color::CYAN)
end
end
+9
View File
@@ -0,0 +1,9 @@
class OccamsRazor
def initialize
#
end
def attack(dt)
#
end
end