Implement health bar system: add HealthBar class for managing health, integrate health updates in HUDLayer, and modify enemy attack handling to reflect damage taken.
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
class BladeOfRecursion
|
||||
def initialize
|
||||
@damage = 1
|
||||
@range = 200
|
||||
@speed = 500
|
||||
@x = 0
|
||||
@y = 0
|
||||
@direction = nil
|
||||
end
|
||||
|
||||
def attack(direction)
|
||||
@direction = direction
|
||||
@x, @y = $bus.get(:player_position)
|
||||
end
|
||||
|
||||
def update(dt)
|
||||
return unless @direction
|
||||
|
||||
@x += Math.cos(@direction) * @speed * dt
|
||||
@y += Math.sin(@direction) * @speed * dt
|
||||
|
||||
$bus.get(:attack, @x, @y, @range, @damage)
|
||||
|
||||
# If the blade has traveled its max range, reset it
|
||||
player_x, player_y = $bus.get(:player_position)
|
||||
if Math.hypot(@x - player_x, @y - player_y) > @range
|
||||
@direction = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
+10
-2
@@ -20,8 +20,16 @@ class WeaponHandler
|
||||
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
|
||||
if $bus.get(:count, selected_item) > 0
|
||||
if Gosu.button_down?(Gosu::KB_SPACE)
|
||||
direction = $bus.get(:player_direction)
|
||||
weapon.attack(direction)
|
||||
elsif Gosu.button_down?(Gosu::MS_LEFT)
|
||||
player_x, player_y = $bus.get(:player_position)
|
||||
mouse_x, mouse_y = $bus.get(:mouse_position)
|
||||
direction = Math.atan2(mouse_y - player_y, mouse_x - player_x)
|
||||
weapon.attack(direction)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -6,6 +6,10 @@ class LorentzField
|
||||
@active = false
|
||||
@font = Gosu::Font.new(24, name: "assets/fonts/tn.ttf")
|
||||
|
||||
$bus.on(:lorentz_field?) do
|
||||
next @active
|
||||
end
|
||||
|
||||
$bus.on(:lorentz_field) do
|
||||
if @active
|
||||
t = @time
|
||||
@@ -27,12 +31,12 @@ class LorentzField
|
||||
end
|
||||
end
|
||||
|
||||
def attack
|
||||
def attack(_direction)
|
||||
return if @active
|
||||
$bus.emit(:consume, :lorentz_field, 1)
|
||||
@active = true
|
||||
@time = 0
|
||||
$bus.emit(:lorentz_field?, true)
|
||||
$bus.emit(:lorentz_field!, true)
|
||||
end
|
||||
|
||||
def update(dt)
|
||||
@@ -42,7 +46,7 @@ class LorentzField
|
||||
if @time >= BASE_TIME
|
||||
@time = 0
|
||||
@active = false
|
||||
$bus.emit(:lorentz_field?, false)
|
||||
$bus.emit(:lorentz_field!, false)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ class OccamsRazor
|
||||
@range = 45 # how many pixels from player center to enemy center the attack hits, this is a melee weapon so it should be small
|
||||
end
|
||||
|
||||
def attack
|
||||
def attack(_direction)
|
||||
return if @active
|
||||
|
||||
@active = true
|
||||
@@ -16,7 +16,7 @@ class OccamsRazor
|
||||
|
||||
# Check for enemies in range and deal damage
|
||||
player_x, player_y = $bus.get(:player_position)
|
||||
$bus.emit(:occams_razor_attack, player_x, player_y, @range, @damage)
|
||||
$bus.emit(:attack, player_x, player_y, @range, @damage)
|
||||
end
|
||||
|
||||
def update(dt)
|
||||
|
||||
Reference in New Issue
Block a user