Skip to content

Commit

Permalink
GAME OVER!
Browse files Browse the repository at this point in the history
Add game over menu with two buttons
  • Loading branch information
Nartynka committed Oct 29, 2022
1 parent 2cd0c63 commit 39c3ea4
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 5 deletions.
11 changes: 11 additions & 0 deletions Menus/GameOverMenu.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
extends CenterContainer

func _on_LoadBtn_pressed():
SoundFx.play("Click", -20)
SaveAndLoad.is_loading = true
get_tree().change_scene("res://World/World.tscn")


func _on_QuitBtn_pressed():
SoundFx.play("Click", -20)
get_tree().quit()
51 changes: 51 additions & 0 deletions Menus/GameOverMenu.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
[gd_scene load_steps=3 format=2]

[ext_resource path="res://UI/DefaultTheme.tres" type="Theme" id=1]
[ext_resource path="res://Menus/GameOverMenu.gd" type="Script" id=2]

[node name="GameOverMenu" type="CenterContainer"]
pause_mode = 2
anchor_right = 1.0
anchor_bottom = 1.0
theme = ExtResource( 1 )
script = ExtResource( 2 )

[node name="VBoxContainer" type="VBoxContainer" parent="."]
margin_left = 102.0
margin_top = 74.0
margin_right = 218.0
margin_bottom = 105.0

[node name="Label" type="Label" parent="VBoxContainer"]
margin_right = 116.0
margin_bottom = 7.0
text = "GAME OVER!"
align = 1

[node name="Gap" type="Control" parent="VBoxContainer"]
margin_top = 11.0
margin_right = 116.0
margin_bottom = 11.0

[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
margin_top = 15.0
margin_right = 116.0
margin_bottom = 31.0

[node name="LoadBtn" type="Button" parent="VBoxContainer/HBoxContainer"]
margin_right = 56.0
margin_bottom = 16.0
rect_min_size = Vector2( 56, 16 )
size_flags_horizontal = 3
size_flags_vertical = 3
text = "Load"

[node name="QuitBtn" type="Button" parent="VBoxContainer/HBoxContainer"]
margin_left = 60.0
margin_right = 116.0
margin_bottom = 16.0
rect_min_size = Vector2( 56, 16 )
text = "Quitt"

[connection signal="pressed" from="VBoxContainer/HBoxContainer/LoadBtn" to="." method="_on_LoadBtn_pressed"]
[connection signal="pressed" from="VBoxContainer/HBoxContainer/QuitBtn" to="." method="_on_QuitBtn_pressed"]
2 changes: 1 addition & 1 deletion Menus/PauseMenu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func set_pause(new_value):
SoundFx.play("Unpause", -10)

func _process(delta):
if Input.is_action_just_pressed("ui_cancel"):
if Input.is_action_just_pressed("ui_cancel") and Utils.get_player():
self.paused = !paused

func _on_QuitButton_pressed():
Expand Down
2 changes: 2 additions & 0 deletions Player/Player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var double_jump = false

var PlayerStats = ResourceLoader.PlayerStats

signal player_death
signal door_entered(door)

onready var sprite = $Sprite
Expand Down Expand Up @@ -272,6 +273,7 @@ func _on_Hurtbox_hit(damage):
Input.start_joy_vibration(0, 1, 1, 0.7)

func on_death():
emit_signal("player_death")
queue_free()


Expand Down
2 changes: 1 addition & 1 deletion Utils.gd
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func get_player():
if player:
return player[player.size()-1]

func _input(event):
func _input(_event):
if Input.is_action_just_pressed("fullscreen"):
OS.window_fullscreen = !OS.window_fullscreen
if Input.get_connected_joypads():
Expand Down
13 changes: 10 additions & 3 deletions World/World.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ onready var currentLevel = $Level_00
func _ready():
VisualServer.set_default_clear_color(Color.black)
Music.play_queue()

if SaveAndLoad.is_loading:
SaveAndLoad.load_game()
SaveAndLoad.is_loading = false

Utils.get_player().connect("door_entered", self, "_on_door_entered")

var player = Utils.get_player()
player.connect("door_entered", self, "_on_door_entered")
player.connect("player_death", self, "_on_Player_player_death")

func change_levels(door):
var offset = currentLevel.position
Expand All @@ -31,3 +33,8 @@ func get_door(ignore_door, connection):

func _on_door_entered(door):
call_deferred("change_levels", door)


func _on_Player_player_death():
yield(get_tree().create_timer(1), "timeout")
get_tree().change_scene("res://Menus/GameOverMenu.tscn")

0 comments on commit 39c3ea4

Please sign in to comment.