Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add game over UI #9

Merged
merged 2 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions scenes/game_over.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[gd_scene load_steps=2 format=3 uid="uid://cks4pkf2c1woh"]

[ext_resource type="Script" path="res://scripts/scenes/game_over.gd" id="1_qirxm"]

[node name="GameOver" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_qirxm")

[node name="ColorRect" type="ColorRect" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
color = Color(0, 0, 0, 0.752941)

[node name="CenterContainer" type="CenterContainer" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2

[node name="VBoxContainer" type="VBoxContainer" parent="CenterContainer"]
layout_mode = 2

[node name="GameOverLabel" type="Label" parent="CenterContainer/VBoxContainer"]
layout_mode = 2
theme_override_font_sizes/font_size = 64
text = "Game Over"
horizontal_alignment = 1

[node name="StatsLabel" type="Label" parent="CenterContainer/VBoxContainer"]
layout_mode = 2
theme_override_font_sizes/font_size = 32
text = "Rooms cleared: 0"
horizontal_alignment = 1

[node name="ContinueButton" type="Button" parent="CenterContainer/VBoxContainer"]
custom_minimum_size = Vector2(400, 100)
layout_mode = 2
theme_override_font_sizes/font_size = 32
text = "Continue"
8 changes: 3 additions & 5 deletions scenes/pause_menu.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=2 format=3]
[gd_scene load_steps=2 format=3 uid="uid://dtnutgtckwipv"]

[ext_resource type="Script" path="res://scripts/pause_menu.gd" id="1_p7luq"]

Expand All @@ -19,8 +19,8 @@ anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
color = Color(0, 0, 0, 0.5)
mouse_filter = 1
color = Color(0, 0, 0, 0.5)

[node name="PanelContainer" type="PanelContainer" parent="."]
layout_mode = 1
Expand All @@ -43,12 +43,10 @@ theme_override_constants/margin_left = 16
theme_override_constants/margin_top = 16
theme_override_constants/margin_right = 16
theme_override_constants/margin_bottom = 16
mouse_filter = 1

[node name="VBoxContainer" type="VBoxContainer" parent="PanelContainer/MarginContainer"]
layout_mode = 2
theme_override_constants/separation = 16
mouse_filter = 1

[node name="Label" type="Label" parent="PanelContainer/MarginContainer/VBoxContainer"]
layout_mode = 2
Expand All @@ -68,4 +66,4 @@ custom_minimum_size = Vector2(200, 50)
layout_mode = 2
size_flags_horizontal = 4
mouse_default_cursor_shape = 2
text = "Quit to Menu"
text = "Quit to Menu"
30 changes: 30 additions & 0 deletions scripts/managers/combat_manager.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
extends Node

const GAME_OVER_SCENE = preload("res://scenes/game_over.tscn")

var current_energy: int = 3
var max_energy: int = 3
var is_player_turn: bool = true
Expand All @@ -9,6 +11,8 @@ var is_player_turn: bool = true
@onready var energy_label: Label = $"../UI/HUD/EnergyMarginContainer/EnergyTexture/EnergyLabel"

func _ready() -> void:
# Connect to player death
$"../Player".connect("died", _on_player_died)
await hand_manager.ready
start_turn()

Expand Down Expand Up @@ -37,3 +41,29 @@ func can_play_card(card_cost: int) -> bool:
func spend_energy(amount: int) -> void:
current_energy -= amount
energy_label.text = str(current_energy)

func _on_player_died() -> void:
# Save meta progression
GameState.end_run(false)

var game_over = GAME_OVER_SCENE.instantiate()
get_node("/root/Main").add_child(game_over)

# Update stats display
var stats_label = game_over.get_node("CenterContainer/VBoxContainer/StatsLabel")
stats_label.text = "Rooms cleared: %d" % GameState.current_run

# Connect continue signal
game_over.continue_pressed.connect(_on_game_over_continue)
game_over.open()

# Pause the game
get_tree().paused = true

func _on_game_over_continue() -> void:
# Unpause
get_tree().paused = false
# Remove game over screen
get_node("/root/Main").get_node("GameOver").queue_free()
# Return to main menu
get_node("/root/Main").show_main_menu()
8 changes: 3 additions & 5 deletions scripts/player.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
extends Node2D

signal died

var health: int = 40
var max_health: int = 40
var block: int = 0
Expand All @@ -24,7 +26,7 @@ func take_damage(amount: int) -> void:
update_health_display()

if health <= 0:
die()
died.emit()

func gain_block(amount: int) -> void:
block += amount
Expand All @@ -34,7 +36,3 @@ func gain_block(amount: int) -> void:
func update_health_display() -> void:
var block_text = " [" + str(block) + "]" if block > 0 else ""
health_label.text = str(health) + "/" + str(max_health) + block_text

func die() -> void:
print("Game Over!")
# Handle game over logic
15 changes: 15 additions & 0 deletions scripts/scenes/game_over.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
extends Control

signal continue_pressed

func _ready() -> void:
# Disable inputs behind the game over screen
mouse_filter = Control.MOUSE_FILTER_STOP
$CenterContainer/VBoxContainer/ContinueButton.pressed.connect(_on_continue_pressed)

func _on_continue_pressed() -> void:
continue_pressed.emit()

func open() -> void:
show()
$CenterContainer/VBoxContainer/ContinueButton.grab_focus()
Loading