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:
2026-04-02 15:33:50 +01:00
parent 32de437f86
commit db7c2aa7a2
12 changed files with 100 additions and 28 deletions
+7 -4
View File
@@ -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
View File
@@ -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