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:
@@ -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
|
||||
@@ -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
|
||||
@@ -0,0 +1,9 @@
|
||||
class OccamsRazor
|
||||
def initialize
|
||||
#
|
||||
end
|
||||
|
||||
def attack(dt)
|
||||
#
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user