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:
@@ -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
|
||||
Reference in New Issue
Block a user