diff --git a/src/GUI/AmmoGUI.gd b/src/GUI/AmmoGUI.gd index 6a78079..a40fa42 100644 --- a/src/GUI/AmmoGUI.gd +++ b/src/GUI/AmmoGUI.gd @@ -1,12 +1,14 @@ -extends HBoxContainer +extends PanelContainer var ammo_texture := preload("res://assets/player/acid_shot_2.png") -var ammo_container_node := "HeartContainer" +var ammo_container_node := "AmmoContainer" + +onready var ammo_holder: HBoxContainer = $AmmoHolder func _on_Player_max_ammo_changed(ammo: int) -> void: - for child in get_children(): - remove_child(child) + for child in ammo_holder.get_children(): + ammo_holder.remove_child(child) child.queue_free() for i in ammo: var ammo_container := TextureRect.new() @@ -14,10 +16,10 @@ func _on_Player_max_ammo_changed(ammo: int) -> void: ammo_container.texture = ammo_texture var center_container := CenterContainer.new() center_container.add_child(ammo_container) - add_child(center_container) + ammo_holder.add_child(center_container) func _on_Player_ammo_changed(ammo: int) -> void: - for i in get_child_count(): - var ammo_container: TextureRect = get_child(i).get_node(ammo_container_node) + for i in ammo_holder.get_child_count(): + var ammo_container: TextureRect = ammo_holder.get_child(i).get_node(ammo_container_node) ammo_container.modulate = Color(1, 1, 1, 1) if ammo > i else Color(0.1, 0.1, 0.1, 0.5) diff --git a/src/GUI/AmmoGUI.tscn b/src/GUI/AmmoGUI.tscn index d2b3367..23ffac0 100644 --- a/src/GUI/AmmoGUI.tscn +++ b/src/GUI/AmmoGUI.tscn @@ -1,28 +1,43 @@ -[gd_scene load_steps=3 format=2] +[gd_scene load_steps=4 format=2] [ext_resource path="res://assets/player/acid_shot_2.png" type="Texture" id=1] [ext_resource path="res://src/GUI/AmmoGUI.gd" type="Script" id=2] +[ext_resource path="res://src/GUI/GameTheme.tres" type="Theme" id=3] -[node name="AmmoGUI" type="HBoxContainer"] -size_flags_vertical = 4 +[node name="AmmoGUI" type="PanelContainer"] +margin_right = 157.0 +margin_bottom = 29.0 +rect_min_size = Vector2( 0, 46 ) +size_flags_vertical = 8 +theme = ExtResource( 3 ) script = ExtResource( 2 ) __meta__ = { "_edit_use_anchors_": false } -[node name="PlaceHolderCenterContainer" type="CenterContainer" parent="."] +[node name="AmmoHolder" type="HBoxContainer" parent="."] +margin_left = 8.0 +margin_top = 16.0 +margin_right = 149.0 +margin_bottom = 29.0 +size_flags_vertical = 4 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="PlaceHolderCenterContainer" type="CenterContainer" parent="AmmoHolder"] margin_right = 25.0 margin_bottom = 13.0 __meta__ = { "_edit_use_anchors_": false } -[node name="PlaceHolderTextureRect" type="TextureRect" parent="PlaceHolderCenterContainer"] +[node name="PlaceHolderTextureRect" type="TextureRect" parent="AmmoHolder/PlaceHolderCenterContainer"] margin_right = 25.0 margin_bottom = 13.0 texture = ExtResource( 1 ) -[node name="PlaceHolderCenterContainer5" type="CenterContainer" parent="."] +[node name="PlaceHolderCenterContainer5" type="CenterContainer" parent="AmmoHolder"] margin_left = 29.0 margin_right = 54.0 margin_bottom = 13.0 @@ -30,12 +45,12 @@ __meta__ = { "_edit_use_anchors_": false } -[node name="PlaceHolderTextureRect" type="TextureRect" parent="PlaceHolderCenterContainer5"] +[node name="PlaceHolderTextureRect" type="TextureRect" parent="AmmoHolder/PlaceHolderCenterContainer5"] margin_right = 25.0 margin_bottom = 13.0 texture = ExtResource( 1 ) -[node name="PlaceHolderCenterContainer4" type="CenterContainer" parent="."] +[node name="PlaceHolderCenterContainer4" type="CenterContainer" parent="AmmoHolder"] margin_left = 58.0 margin_right = 83.0 margin_bottom = 13.0 @@ -43,12 +58,12 @@ __meta__ = { "_edit_use_anchors_": false } -[node name="PlaceHolderTextureRect" type="TextureRect" parent="PlaceHolderCenterContainer4"] +[node name="PlaceHolderTextureRect" type="TextureRect" parent="AmmoHolder/PlaceHolderCenterContainer4"] margin_right = 25.0 margin_bottom = 13.0 texture = ExtResource( 1 ) -[node name="PlaceHolderCenterContainer3" type="CenterContainer" parent="."] +[node name="PlaceHolderCenterContainer3" type="CenterContainer" parent="AmmoHolder"] margin_left = 87.0 margin_right = 112.0 margin_bottom = 13.0 @@ -56,12 +71,12 @@ __meta__ = { "_edit_use_anchors_": false } -[node name="PlaceHolderTextureRect" type="TextureRect" parent="PlaceHolderCenterContainer3"] +[node name="PlaceHolderTextureRect" type="TextureRect" parent="AmmoHolder/PlaceHolderCenterContainer3"] margin_right = 25.0 margin_bottom = 13.0 texture = ExtResource( 1 ) -[node name="PlaceHolderCenterContainer2" type="CenterContainer" parent="."] +[node name="PlaceHolderCenterContainer2" type="CenterContainer" parent="AmmoHolder"] margin_left = 116.0 margin_right = 141.0 margin_bottom = 13.0 @@ -69,7 +84,7 @@ __meta__ = { "_edit_use_anchors_": false } -[node name="PlaceHolderTextureRect" type="TextureRect" parent="PlaceHolderCenterContainer2"] +[node name="PlaceHolderTextureRect" type="TextureRect" parent="AmmoHolder/PlaceHolderCenterContainer2"] margin_right = 25.0 margin_bottom = 13.0 texture = ExtResource( 1 ) diff --git a/src/GUI/GameGUI.gd b/src/GUI/GameGUI.gd index 7a8b45b..ad2efc5 100644 --- a/src/GUI/GameGUI.gd +++ b/src/GUI/GameGUI.gd @@ -4,9 +4,9 @@ class_name GameGUI export(NodePath) var player_path onready var player: Player = get_node(player_path) -onready var health_gui = $CenterContainer/HBoxContainer/PanelContainer/HealthGUI -onready var ammo_gui = $CenterContainer/HBoxContainer/PanelContainer2/AmmoGUI -onready var score_gui = $CenterContainer/HBoxContainer/PanelContainer3/ScoreGUI +onready var health_gui = $HBoxContainer/HealthGUI +onready var ammo_gui = $HBoxContainer/AmmoGUI +onready var score_gui = $HBoxContainer/ScoreGUI onready var pause_menu = $CanvasLayer/PauseMenu onready var game_over_menu = $CanvasLayer/GameOverMenu @@ -41,9 +41,12 @@ func _unhandled_input(event: InputEvent) -> void: func _on_Player_health_depleted() -> void: + score_gui.save_high_score() game_over_menu.show() func _process(_delta: float) -> void: game_over_menu.time = score_gui.time - game_over_menu.score = score_gui.adjusted_score + game_over_menu.score = score_gui.score_adjusted + game_over_menu.high_time = score_gui.high_time + game_over_menu.high_score = score_gui.high_score_adjusted diff --git a/src/GUI/GameGUI.tscn b/src/GUI/GameGUI.tscn index 5f89110..1449461 100644 --- a/src/GUI/GameGUI.tscn +++ b/src/GUI/GameGUI.tscn @@ -23,68 +23,46 @@ __meta__ = { "_edit_use_anchors_": false } -[node name="CenterContainer" type="CenterContainer" parent="."] -anchor_left = 0.1 -anchor_top = 0.9 -anchor_right = 0.9 -anchor_bottom = 0.9 -margin_left = -20.0 -margin_top = -40.0 -margin_right = 20.0 -__meta__ = { -"_edit_use_anchors_": false -} - -[node name="HBoxContainer" type="HBoxContainer" parent="CenterContainer"] -margin_left = 43.0 -margin_right = 508.0 -margin_bottom = 46.0 +[node name="HBoxContainer" type="HBoxContainer" parent="."] +anchor_top = 0.925 +anchor_right = 1.0 +anchor_bottom = 0.925 +margin_top = -80.0 custom_constants/separation = 64 +alignment = 1 __meta__ = { "_edit_use_anchors_": false } -[node name="PanelContainer" type="PanelContainer" parent="CenterContainer/HBoxContainer"] -margin_right = 84.0 -margin_bottom = 46.0 -__meta__ = { -"_edit_use_anchors_": false -} +[node name="HealthGUI" parent="HBoxContainer" instance=ExtResource( 1 )] +margin_left = 37.0 +margin_top = 34.0 +margin_right = 121.0 +margin_bottom = 80.0 -[node name="HealthGUI" parent="CenterContainer/HBoxContainer/PanelContainer" instance=ExtResource( 1 )] -margin_left = 8.0 -margin_top = 12.0 -margin_right = 76.0 -margin_bottom = 33.0 +[node name="AmmoGUI" parent="HBoxContainer" instance=ExtResource( 2 )] +margin_left = 185.0 +margin_top = 34.0 +margin_right = 342.0 +margin_bottom = 80.0 -[node name="PanelContainer2" type="PanelContainer" parent="CenterContainer/HBoxContainer"] -margin_left = 148.0 -margin_right = 305.0 -margin_bottom = 46.0 -__meta__ = { -"_edit_use_anchors_": false -} +[node name="ScoreGUI" parent="HBoxContainer" instance=ExtResource( 7 )] +margin_left = 406.0 +margin_right = 602.0 +margin_bottom = 80.0 -[node name="AmmoGUI" parent="CenterContainer/HBoxContainer/PanelContainer2" instance=ExtResource( 2 )] -margin_left = 8.0 -margin_top = 16.0 -margin_right = 149.0 -margin_bottom = 29.0 - -[node name="PanelContainer3" type="PanelContainer" parent="CenterContainer/HBoxContainer"] -margin_left = 369.0 -margin_right = 465.0 -margin_bottom = 46.0 +[node name="CenterContainer" type="CenterContainer" parent="."] +anchor_left = 0.1 +anchor_top = 0.9 +anchor_right = 0.9 +anchor_bottom = 0.9 +margin_left = -20.0 +margin_top = -40.0 +margin_right = 20.0 __meta__ = { "_edit_use_anchors_": false } -[node name="ScoreGUI" parent="CenterContainer/HBoxContainer/PanelContainer3" instance=ExtResource( 7 )] -margin_left = 8.0 -margin_top = 8.0 -margin_right = 88.0 -margin_bottom = 38.0 - [node name="CanvasLayer" type="CanvasLayer" parent="."] layer = 100 diff --git a/src/GUI/GameOverMenu.gd b/src/GUI/GameOverMenu.gd index de68e41..2dc4d86 100644 --- a/src/GUI/GameOverMenu.gd +++ b/src/GUI/GameOverMenu.gd @@ -2,10 +2,14 @@ extends Control var score := 0.0 setget set_score var time := 0.0 setget set_time +var high_score := 0.0 setget set_high_score +var high_time := 0.0 setget set_high_time onready var audio_stream_player: AudioStreamPlayer = $AudioStreamPlayer -onready var time_value: Label = $Background/ColorRect/CenterContainer/VBoxContainer/TimeContainer/PanelContainer/TimeValue -onready var score_value: Label = $Background/ColorRect/CenterContainer/VBoxContainer/ScoreContainer/PanelContainer/ScoreValue +onready var time_value: Label = $Background/ColorRect/CenterContainer/VBoxContainer/GridContainer/TimePanelContainer/TimeValue +onready var score_value: Label = $Background/ColorRect/CenterContainer/VBoxContainer/GridContainer/ScorePanelContainer/ScoreValue +onready var high_time_value: Label = $Background/ColorRect/CenterContainer/VBoxContainer/GridContainer/HighTimePanelContainer/HighTimeValue +onready var high_score_value: Label = $Background/ColorRect/CenterContainer/VBoxContainer/GridContainer/HighScorePanelContainer/HighScoreValue func show() -> void: @@ -26,6 +30,18 @@ func set_score(value: float) -> void: score_value.text = "%.0f" % (score) +func set_high_time(value: float) -> void: + if high_time != value: + high_time = value + high_time_value.text = "%.0f" % (high_time) + + +func set_high_score(value: float) -> void: + if high_score != value: + high_score = value + high_score_value.text = "%.0f" % (high_score) + + func _on_ContinueButton_pressed() -> void: get_tree().paused = false var connected := get_tree().reload_current_scene() diff --git a/src/GUI/GameOverMenu.tscn b/src/GUI/GameOverMenu.tscn index b7936a3..439ca76 100644 --- a/src/GUI/GameOverMenu.tscn +++ b/src/GUI/GameOverMenu.tscn @@ -32,67 +32,72 @@ __meta__ = { "_edit_use_anchors_": false } -[node name="ContinueButton" type="Button" parent="Background/ColorRect"] -anchor_left = 0.5 -anchor_top = 0.825 -anchor_right = 0.5 -anchor_bottom = 0.825 -margin_left = -160.0 -margin_top = -45.0 -margin_right = 160.0 -rect_min_size = Vector2( 320, 0 ) -size_flags_horizontal = 4 -text = "Play Again!" -__meta__ = { -"_edit_use_anchors_": false -} - [node name="CenterContainer" type="CenterContainer" parent="Background/ColorRect"] anchor_right = 1.0 -anchor_bottom = 0.75 +anchor_bottom = 0.85 __meta__ = { "_edit_use_anchors_": false } [node name="VBoxContainer" type="VBoxContainer" parent="Background/ColorRect/CenterContainer"] -margin_left = 165.0 -margin_top = 77.0 -margin_right = 475.0 -margin_bottom = 283.0 +margin_left = 160.0 +margin_top = 43.0 +margin_right = 480.0 +margin_bottom = 365.0 theme = ExtResource( 1 ) -custom_constants/separation = 8 +custom_constants/separation = 16 __meta__ = { "_edit_use_anchors_": false } [node name="Label" type="Label" parent="Background/ColorRect/CenterContainer/VBoxContainer"] -margin_right = 310.0 +margin_right = 320.0 margin_bottom = 78.0 custom_fonts/font = SubResource( 1 ) text = "Game Over" align = 1 -[node name="TimeContainer" type="HBoxContainer" parent="Background/ColorRect/CenterContainer/VBoxContainer"] -margin_top = 86.0 -margin_right = 310.0 -margin_bottom = 142.0 -custom_constants/separation = 32 -alignment = 1 +[node name="GridContainer" type="GridContainer" parent="Background/ColorRect/CenterContainer/VBoxContainer"] +margin_top = 94.0 +margin_right = 320.0 +margin_bottom = 261.0 +custom_constants/vseparation = 8 +custom_constants/hseparation = 12 +columns = 3 + +[node name="Blank" type="Control" parent="Background/ColorRect/CenterContainer/VBoxContainer/GridContainer"] +margin_right = 80.0 +margin_bottom = 39.0 + +[node name="Blank2" type="Control" parent="Background/ColorRect/CenterContainer/VBoxContainer/GridContainer"] +margin_left = 92.0 +margin_right = 188.0 +margin_bottom = 39.0 + +[node name="Label2" type="Label" parent="Background/ColorRect/CenterContainer/VBoxContainer/GridContainer"] +margin_left = 200.0 +margin_right = 296.0 +margin_bottom = 39.0 +text = "Best" +align = 1 +__meta__ = { +"_edit_use_anchors_": false +} -[node name="TimeLabel" type="Label" parent="Background/ColorRect/CenterContainer/VBoxContainer/TimeContainer"] -margin_left = 51.0 -margin_top = 8.0 -margin_right = 131.0 -margin_bottom = 48.0 +[node name="TimeLabel" type="Label" parent="Background/ColorRect/CenterContainer/VBoxContainer/GridContainer"] +margin_top = 55.0 +margin_right = 80.0 +margin_bottom = 95.0 rect_min_size = Vector2( 80, 40 ) text = "Time" -[node name="PanelContainer" type="PanelContainer" parent="Background/ColorRect/CenterContainer/VBoxContainer/TimeContainer"] -margin_left = 163.0 -margin_right = 259.0 -margin_bottom = 56.0 +[node name="TimePanelContainer" type="PanelContainer" parent="Background/ColorRect/CenterContainer/VBoxContainer/GridContainer"] +margin_left = 92.0 +margin_top = 47.0 +margin_right = 188.0 +margin_bottom = 103.0 -[node name="TimeValue" type="Label" parent="Background/ColorRect/CenterContainer/VBoxContainer/TimeContainer/PanelContainer"] +[node name="TimeValue" type="Label" parent="Background/ColorRect/CenterContainer/VBoxContainer/GridContainer/TimePanelContainer"] margin_left = 8.0 margin_top = 8.0 margin_right = 88.0 @@ -101,27 +106,35 @@ rect_min_size = Vector2( 80, 40 ) text = "60" align = 1 -[node name="ScoreContainer" type="HBoxContainer" parent="Background/ColorRect/CenterContainer/VBoxContainer"] -margin_top = 150.0 -margin_right = 310.0 -margin_bottom = 206.0 -custom_constants/separation = 32 -alignment = 1 +[node name="HighTimePanelContainer" type="PanelContainer" parent="Background/ColorRect/CenterContainer/VBoxContainer/GridContainer"] +margin_left = 200.0 +margin_top = 47.0 +margin_right = 296.0 +margin_bottom = 103.0 -[node name="ScoreLabel" type="Label" parent="Background/ColorRect/CenterContainer/VBoxContainer/ScoreContainer"] -margin_left = 51.0 +[node name="HighTimeValue" type="Label" parent="Background/ColorRect/CenterContainer/VBoxContainer/GridContainer/HighTimePanelContainer"] +margin_left = 8.0 margin_top = 8.0 -margin_right = 131.0 +margin_right = 88.0 margin_bottom = 48.0 rect_min_size = Vector2( 80, 40 ) +text = "60" +align = 1 + +[node name="ScoreLabel" type="Label" parent="Background/ColorRect/CenterContainer/VBoxContainer/GridContainer"] +margin_top = 119.0 +margin_right = 80.0 +margin_bottom = 159.0 +rect_min_size = Vector2( 80, 40 ) text = "Score" -[node name="PanelContainer" type="PanelContainer" parent="Background/ColorRect/CenterContainer/VBoxContainer/ScoreContainer"] -margin_left = 163.0 -margin_right = 259.0 -margin_bottom = 56.0 +[node name="ScorePanelContainer" type="PanelContainer" parent="Background/ColorRect/CenterContainer/VBoxContainer/GridContainer"] +margin_left = 92.0 +margin_top = 111.0 +margin_right = 188.0 +margin_bottom = 167.0 -[node name="ScoreValue" type="Label" parent="Background/ColorRect/CenterContainer/VBoxContainer/ScoreContainer/PanelContainer"] +[node name="ScoreValue" type="Label" parent="Background/ColorRect/CenterContainer/VBoxContainer/GridContainer/ScorePanelContainer"] margin_left = 8.0 margin_top = 8.0 margin_right = 88.0 @@ -130,7 +143,34 @@ rect_min_size = Vector2( 80, 40 ) text = "100" align = 1 +[node name="HighScorePanelContainer" type="PanelContainer" parent="Background/ColorRect/CenterContainer/VBoxContainer/GridContainer"] +margin_left = 200.0 +margin_top = 111.0 +margin_right = 296.0 +margin_bottom = 167.0 + +[node name="HighScoreValue" type="Label" parent="Background/ColorRect/CenterContainer/VBoxContainer/GridContainer/HighScorePanelContainer"] +margin_left = 8.0 +margin_top = 8.0 +margin_right = 88.0 +margin_bottom = 48.0 +rect_min_size = Vector2( 80, 40 ) +text = "100" +align = 1 + +[node name="ContinueButton" type="Button" parent="Background/ColorRect/CenterContainer/VBoxContainer"] +margin_top = 277.0 +margin_right = 320.0 +margin_bottom = 322.0 +rect_min_size = Vector2( 320, 0 ) +mouse_default_cursor_shape = 2 +size_flags_horizontal = 4 +text = "Play Again!" +__meta__ = { +"_edit_use_anchors_": false +} + [node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."] stream = ExtResource( 4 ) -[connection signal="pressed" from="Background/ColorRect/ContinueButton" to="." method="_on_ContinueButton_pressed"] +[connection signal="pressed" from="Background/ColorRect/CenterContainer/VBoxContainer/ContinueButton" to="." method="_on_ContinueButton_pressed"] diff --git a/src/GUI/HealthGUI.gd b/src/GUI/HealthGUI.gd index 016240a..50977ef 100644 --- a/src/GUI/HealthGUI.gd +++ b/src/GUI/HealthGUI.gd @@ -1,12 +1,14 @@ -extends HBoxContainer +extends PanelContainer var heart_texture := preload("res://assets/collect/fly.png") var heart_container_node := "HeartContainer" +onready var health_holder: HBoxContainer = $HealthHolder + func _on_Player_max_health_changed(health: int) -> void: - for child in get_children(): - remove_child(child) + for child in health_holder.get_children(): + health_holder.remove_child(child) child.queue_free() for i in health: var heart_container := TextureRect.new() @@ -14,10 +16,10 @@ func _on_Player_max_health_changed(health: int) -> void: heart_container.texture = heart_texture var center_container := CenterContainer.new() center_container.add_child(heart_container) - add_child(center_container) + health_holder.add_child(center_container) func _on_Player_health_changed(health: int) -> void: - for i in get_child_count(): - var heart_container: TextureRect = get_child(i).get_node(heart_container_node) + for i in health_holder.get_child_count(): + var heart_container: TextureRect = health_holder.get_child(i).get_node(heart_container_node) heart_container.modulate = Color(1, 1, 1, 1) if health > i else Color(0.1, 0.1, 0.1, 0.5) diff --git a/src/GUI/HealthGUI.tscn b/src/GUI/HealthGUI.tscn index ec801f6..d33f861 100644 --- a/src/GUI/HealthGUI.tscn +++ b/src/GUI/HealthGUI.tscn @@ -1,40 +1,55 @@ -[gd_scene load_steps=3 format=2] +[gd_scene load_steps=4 format=2] [ext_resource path="res://assets/collect/fly.png" type="Texture" id=1] [ext_resource path="res://src/GUI/HealthGUI.gd" type="Script" id=2] +[ext_resource path="res://src/GUI/GameTheme.tres" type="Theme" id=3] + +[node name="HealthGUI" type="PanelContainer"] +margin_right = 82.0 +margin_bottom = 35.0 +rect_min_size = Vector2( 0, 46 ) +size_flags_vertical = 8 +theme = ExtResource( 3 ) +script = ExtResource( 2 ) +__meta__ = { +"_edit_use_anchors_": false +} -[node name="HealthGUI" type="HBoxContainer"] +[node name="HealthHolder" type="HBoxContainer" parent="."] +margin_left = 8.0 +margin_top = 12.0 +margin_right = 76.0 +margin_bottom = 33.0 size_flags_vertical = 4 -script = ExtResource( 2 ) __meta__ = { "_edit_use_anchors_": false } -[node name="PlaceHolderCenterContainer" type="CenterContainer" parent="."] +[node name="PlaceHolderCenterContainer" type="CenterContainer" parent="HealthHolder"] margin_right = 20.0 margin_bottom = 21.0 -[node name="PlaceHolderTextureRect" type="TextureRect" parent="PlaceHolderCenterContainer"] +[node name="PlaceHolderTextureRect" type="TextureRect" parent="HealthHolder/PlaceHolderCenterContainer"] margin_right = 20.0 margin_bottom = 21.0 texture = ExtResource( 1 ) -[node name="PlaceHolderCenterContainer3" type="CenterContainer" parent="."] +[node name="PlaceHolderCenterContainer3" type="CenterContainer" parent="HealthHolder"] margin_left = 24.0 margin_right = 44.0 margin_bottom = 21.0 -[node name="PlaceHolderTextureRect" type="TextureRect" parent="PlaceHolderCenterContainer3"] +[node name="PlaceHolderTextureRect" type="TextureRect" parent="HealthHolder/PlaceHolderCenterContainer3"] margin_right = 20.0 margin_bottom = 21.0 texture = ExtResource( 1 ) -[node name="PlaceHolderCenterContainer2" type="CenterContainer" parent="."] +[node name="PlaceHolderCenterContainer2" type="CenterContainer" parent="HealthHolder"] margin_left = 48.0 margin_right = 68.0 margin_bottom = 21.0 -[node name="PlaceHolderTextureRect" type="TextureRect" parent="PlaceHolderCenterContainer2"] +[node name="PlaceHolderTextureRect" type="TextureRect" parent="HealthHolder/PlaceHolderCenterContainer2"] margin_right = 20.0 margin_bottom = 21.0 texture = ExtResource( 1 ) diff --git a/src/GUI/PauseMenu.gd b/src/GUI/PauseMenu.gd index 6f04788..5da31f7 100644 --- a/src/GUI/PauseMenu.gd +++ b/src/GUI/PauseMenu.gd @@ -24,3 +24,10 @@ func _on_ContinueButton_pressed() -> void: audio_stream_player.play() get_tree().paused = false hide() + + +func _on_RestartButton_pressed() -> void: + get_tree().paused = false + var connected := get_tree().reload_current_scene() + if connected != OK: + push_error("Could not reload scene") diff --git a/src/GUI/PauseMenu.tscn b/src/GUI/PauseMenu.tscn index 59be04e..e65a612 100644 --- a/src/GUI/PauseMenu.tscn +++ b/src/GUI/PauseMenu.tscn @@ -41,28 +41,43 @@ __meta__ = { [node name="VBoxContainer" type="VBoxContainer" parent="ColorRect/CenterContainer"] margin_left = 223.0 -margin_top = 113.0 +margin_top = 80.0 margin_right = 417.0 -margin_bottom = 246.0 -custom_constants/separation = 10 +margin_bottom = 280.0 +custom_constants/separation = 16 + +[node name="RestartButton" type="Button" parent="ColorRect/CenterContainer/VBoxContainer"] +margin_left = 37.0 +margin_right = 157.0 +margin_bottom = 45.0 +rect_min_size = Vector2( 120, 0 ) +mouse_default_cursor_shape = 2 +size_flags_horizontal = 4 +text = "Restart" +__meta__ = { +"_edit_use_anchors_": false +} [node name="Label" type="Label" parent="ColorRect/CenterContainer/VBoxContainer"] +margin_top = 61.0 margin_right = 194.0 -margin_bottom = 78.0 +margin_bottom = 139.0 custom_fonts/font = SubResource( 1 ) text = "PAUSE" align = 1 [node name="ContinueButton" type="Button" parent="ColorRect/CenterContainer/VBoxContainer"] margin_left = 28.0 -margin_top = 88.0 +margin_top = 155.0 margin_right = 165.0 -margin_bottom = 133.0 +margin_bottom = 200.0 rect_min_size = Vector2( 120, 0 ) +mouse_default_cursor_shape = 2 size_flags_horizontal = 4 text = "Continue" [node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."] bus = "Sound Effects" +[connection signal="pressed" from="ColorRect/CenterContainer/VBoxContainer/RestartButton" to="." method="_on_RestartButton_pressed"] [connection signal="pressed" from="ColorRect/CenterContainer/VBoxContainer/ContinueButton" to="." method="_on_ContinueButton_pressed"] diff --git a/src/GUI/ScoreGUI.gd b/src/GUI/ScoreGUI.gd index d9e7850..2aef298 100644 --- a/src/GUI/ScoreGUI.gd +++ b/src/GUI/ScoreGUI.gd @@ -1,19 +1,41 @@ -extends HBoxContainer +extends GridContainer -onready var label: Label = $CenterContainer/Label +onready var score_label: Label = $ScorePanel/Score +onready var high_score_label: Label = $HighScorePanel/HighScore +var high_score_data := {} +var high_score := 0.0 +var high_time := 0.0 +var high_score_adjusted := 0.0 var score := 0.0 setget set_score var time := 0.0 var coins := 0 -var adjusted_score := 0.0 +var score_adjusted := 0.0 var enemies_deated := 0 var enemy_value := 5.0 +var high_score_path = "user://highscore.json" + + +func _enter_tree() -> void: + var file := File.new() + if file.file_exists(high_score_path): + var open = file.open(high_score_path, File.READ) + if open == OK: + while file.get_position() < file.get_len(): + high_score_data = parse_json(file.get_line()) + file.close() + for key in high_score_data: + set(key, high_score_data[key]) func set_score(value: float) -> void: if score != value: score = value - adjusted_score = score + coins + (enemies_deated * enemy_value) - label.text = "%.0f" % (adjusted_score) + score_adjusted = score + coins + (enemies_deated * enemy_value) + score_label.text = "%.0f" % (score_adjusted) + high_score = max(high_score, score) + high_time = max(high_time, time) + high_score_adjusted = max(high_score_adjusted, score_adjusted) + high_score_label.text = "%.0f" % (high_score_adjusted) func _on_Player_coins_changed(value: int) -> void: @@ -27,3 +49,18 @@ func _on_Enemy_defeated() -> void: func _process(delta: float) -> void: time += delta self.score += delta * Difficulty.speed_modifier + # Save high score every 5 seconds in case of accidental closure + if int(time) % 5 == 0: + save_high_score() + + +func save_high_score() -> void: + var file = File.new() + file.open(high_score_path, File.WRITE) + var data = { + "high_score": high_score, + "high_time": high_time, + "high_score_adjusted": high_score_adjusted, + } + file.store_line(to_json(data)) + file.close() diff --git a/src/GUI/ScoreGUI.tscn b/src/GUI/ScoreGUI.tscn index a47df77..d8ab3ed 100644 --- a/src/GUI/ScoreGUI.tscn +++ b/src/GUI/ScoreGUI.tscn @@ -4,26 +4,56 @@ [ext_resource path="res://src/GUI/ScoreGUI.gd" type="Script" id=2] [ext_resource path="res://src/GUI/GameFont-Small.tres" type="DynamicFont" id=3] -[node name="ScoreGUI" type="HBoxContainer"] +[node name="ScoreGUI" type="GridContainer"] margin_right = 80.0 margin_bottom = 14.0 rect_min_size = Vector2( 80, 0 ) size_flags_vertical = 4 theme = ExtResource( 1 ) +columns = 2 script = ExtResource( 2 ) __meta__ = { "_edit_use_anchors_": false } -[node name="CenterContainer" type="CenterContainer" parent="."] -margin_right = 80.0 +[node name="Blank" type="Control" parent="."] +margin_right = 96.0 margin_bottom = 30.0 -size_flags_horizontal = 3 -[node name="Label" type="Label" parent="CenterContainer"] -margin_left = 31.0 -margin_right = 48.0 +[node name="HighScoreLabel" type="Label" parent="."] +margin_left = 100.0 +margin_right = 196.0 margin_bottom = 30.0 custom_fonts/font = ExtResource( 3 ) +text = "Hi-Score" + +[node name="ScorePanel" type="PanelContainer" parent="."] +margin_top = 34.0 +margin_right = 96.0 +margin_bottom = 80.0 + +[node name="Score" type="Label" parent="ScorePanel"] +margin_left = 8.0 +margin_top = 8.0 +margin_right = 88.0 +margin_bottom = 38.0 +rect_min_size = Vector2( 80, 0 ) +custom_fonts/font = ExtResource( 3 ) text = "0" -align = 2 +align = 1 + +[node name="HighScorePanel" type="PanelContainer" parent="."] +margin_left = 100.0 +margin_top = 34.0 +margin_right = 196.0 +margin_bottom = 80.0 + +[node name="HighScore" type="Label" parent="HighScorePanel"] +margin_left = 8.0 +margin_top = 8.0 +margin_right = 88.0 +margin_bottom = 38.0 +rect_min_size = Vector2( 80, 0 ) +custom_fonts/font = ExtResource( 3 ) +text = "1337" +align = 1 diff --git a/src/Level/SplashScreen.gd b/src/Level/SplashScreen.gd index fccba1b..ea51055 100644 --- a/src/Level/SplashScreen.gd +++ b/src/Level/SplashScreen.gd @@ -1,6 +1,6 @@ extends Node -export(PackedScene) var first_scene := preload("res://src/Level/Sandbox1.tscn") +export(PackedScene) var first_scene := preload("res://src/Level/TreeLevel.tscn") func _input(event: InputEvent) -> void: diff --git a/src/Level/TreeLevel.tscn b/src/Level/TreeLevel.tscn new file mode 100644 index 0000000..42c723b --- /dev/null +++ b/src/Level/TreeLevel.tscn @@ -0,0 +1,39 @@ +[gd_scene load_steps=11 format=2] + +[ext_resource path="res://src/GUI/GameGUI.tscn" type="PackedScene" id=1] +[ext_resource path="res://src/Actors/Player.tscn" type="PackedScene" id=2] +[ext_resource path="res://src/Objects/ObstacleSpawner.tscn" type="PackedScene" id=3] +[ext_resource path="res://src/Level/TreeBackground.tscn" type="PackedScene" id=4] +[ext_resource path="res://src/Actors/Birb.tscn" type="PackedScene" id=5] +[ext_resource path="res://src/Objects/Coin.tscn" type="PackedScene" id=6] +[ext_resource path="res://src/Actors/Rock.tscn" type="PackedScene" id=7] +[ext_resource path="res://src/Objects/Heart.tscn" type="PackedScene" id=8] +[ext_resource path="res://sounds/theme/theme.ogg" type="AudioStream" id=9] +[ext_resource path="res://src/Level/Game.gd" type="Script" id=10] + +[node name="TreeLevel" type="Node"] +script = ExtResource( 10 ) + +[node name="GameGUI" parent="." instance=ExtResource( 1 )] +player_path = NodePath("../Player") + +[node name="TreeBackground" parent="." instance=ExtResource( 4 )] + +[node name="Player" parent="." instance=ExtResource( 2 )] +position = Vector2( 113, 57 ) + +[node name="ObstacleSpawner" parent="." instance=ExtResource( 3 )] +position = Vector2( 768, 320 ) +obstacles = [ ExtResource( 7 ), ExtResource( 5 ) ] + +[node name="PickupSpawner" parent="." instance=ExtResource( 3 )] +position = Vector2( 768, 224 ) +obstacles = [ ExtResource( 6 ), ExtResource( 8 ) ] + +[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."] +stream = ExtResource( 9 ) +autoplay = true +mix_target = 1 +bus = "Level" + +[connection signal="finished" from="AudioStreamPlayer" to="." method="_on_AudioStreamPlayer_finished"]