Enhance game over scene: implement GameOver class with options for retry and main menu, add background image, and handle mouse and keyboard interactions.
This commit is contained in:
@@ -18,7 +18,7 @@ class EnemyHandler
|
||||
def spawn!
|
||||
# For now, just spawn a single enemy at a fixed location
|
||||
start_room_coords = $bus.get(:start_room_coords)
|
||||
if @enemies.empty?
|
||||
if @enemies.empty? && start_room_coords
|
||||
@enemies << Force.new((start_room_coords[0] * 2 + 1 + 4) * 60 + 30, (start_room_coords[1] * 2 + 1 + 4) * 60 + 30)
|
||||
end
|
||||
end
|
||||
|
||||
+7
-4
@@ -8,7 +8,10 @@ class HealthBar
|
||||
|
||||
def take_damage(amount)
|
||||
@health -= amount
|
||||
@health = 0 if @health < 0
|
||||
if @health <= 0
|
||||
@health = 0
|
||||
$bus.emit(:change_scene, GameOver)
|
||||
end
|
||||
end
|
||||
|
||||
def heal(amount)
|
||||
@@ -16,12 +19,12 @@ class HealthBar
|
||||
@health = @max_health if @health > @max_health
|
||||
end
|
||||
|
||||
def draw(x, y)
|
||||
def draw
|
||||
# Draw the background of the health bar (red)
|
||||
Gosu.draw_rect(x, y, 100, 10, Gosu::Color::RED)
|
||||
Gosu.draw_rect(30, 10, 100, 10, Gosu::Color::RED)
|
||||
|
||||
# Draw the foreground of the health bar (green) based on current health
|
||||
health_width = (health.to_f / max_health) * 100
|
||||
Gosu.draw_rect(x, y, health_width, 10, Gosu::Color::GREEN)
|
||||
Gosu.draw_rect(30, 10, health_width, 10, Gosu::Color::GREEN)
|
||||
end
|
||||
end
|
||||
+1
-1
@@ -17,7 +17,7 @@ class HUDLayer
|
||||
@hud_bg.draw(0, 0, Float::INFINITY)
|
||||
|
||||
@inventory.draw
|
||||
@health.draw(10, 10)
|
||||
@health.draw
|
||||
|
||||
@hud_fg.draw(0, 0, Float::INFINITY)
|
||||
end
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
class LorentzField
|
||||
BASE_TIME = 25 # Base time for the field to be active in seconds
|
||||
|
||||
def initialize
|
||||
def initialize(bus)
|
||||
@bus = bus
|
||||
@time = 0
|
||||
@active = false
|
||||
@font = Gosu::Font.new(24, name: "assets/fonts/tn.ttf")
|
||||
|
||||
$bus.on(:lorentz_field?) do
|
||||
@bus.on(:lorentz_field?) do
|
||||
next @active
|
||||
end
|
||||
|
||||
$bus.on(:lorentz_field) do
|
||||
@bus.on(:lorentz_field) do
|
||||
if @active
|
||||
t = @time
|
||||
remaining = BASE_TIME - t
|
||||
@@ -33,10 +34,10 @@ class LorentzField
|
||||
|
||||
def attack(_direction)
|
||||
return if @active
|
||||
$bus.emit(:consume, :lorentz_field, 1)
|
||||
@bus.emit(:consume, :lorentz_field, 1)
|
||||
@active = true
|
||||
@time = 0
|
||||
$bus.emit(:lorentz_field!, true)
|
||||
@bus.emit(:lorentz_field!, true)
|
||||
end
|
||||
|
||||
def update(dt)
|
||||
@@ -46,7 +47,7 @@ class LorentzField
|
||||
if @time >= BASE_TIME
|
||||
@time = 0
|
||||
@active = false
|
||||
$bus.emit(:lorentz_field!, false)
|
||||
@bus.emit(:lorentz_field!, false)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user