Add HUD component and update player state management for lives
This commit is contained in:
@@ -30,7 +30,7 @@ size = Vector2(16, 32)
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_ps31c"]
|
||||
radius = 48.0
|
||||
|
||||
[node name="Brick Player" type="CharacterBody2D" node_paths=PackedStringArray("jump_sfx")]
|
||||
[node name="Brick Player" type="CharacterBody2D" node_paths=PackedStringArray("jump_sfx") groups=["player"]]
|
||||
collision_layer = 4
|
||||
collision_mask = 43
|
||||
script = ExtResource("1_8j4h4")
|
||||
|
78
objects/hud.tscn
Normal file
78
objects/hud.tscn
Normal file
@@ -0,0 +1,78 @@
|
||||
[gd_scene load_steps=8 format=3 uid="uid://byxf45ukq82pe"]
|
||||
|
||||
[ext_resource type="LabelSettings" uid="uid://rvn5ivivfvv6" path="res://resources/ui/hud_label_settings.tres" id="1_4dsh5"]
|
||||
[ext_resource type="Script" path="res://scripts/hud.gd" id="1_ueofj"]
|
||||
[ext_resource type="FontFile" uid="uid://xm0vbusjr7b7" path="res://fonts/PressStart2P-Regular.ttf" id="1_ygmwt"]
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_aa3sf"]
|
||||
bg_color = Color(0, 0, 0, 1)
|
||||
corner_detail = 1
|
||||
|
||||
[sub_resource type="Theme" id="Theme_auu2b"]
|
||||
default_font = ExtResource("1_ygmwt")
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_sp6hg"]
|
||||
bg_color = Color(0.47451, 0.47451, 0.47451, 1)
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_22dp1"]
|
||||
bg_color = Color(0.858824, 0.254902, 0.380392, 1)
|
||||
|
||||
[node name="HUD" type="Control" node_paths=PackedStringArray("coins_label", "health_progressbar", "lives_label")]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 4
|
||||
script = ExtResource("1_ueofj")
|
||||
coins_label = NodePath("Panel/PanelContainer/Coins label")
|
||||
health_progressbar = NodePath("Panel/PanelContainer/ProgressBar")
|
||||
lives_label = NodePath("Panel/PanelContainer/Lives")
|
||||
|
||||
[node name="Panel" type="Panel" parent="."]
|
||||
custom_minimum_size = Vector2(0, 16)
|
||||
layout_mode = 1
|
||||
anchors_preset = 10
|
||||
anchor_right = 1.0
|
||||
offset_bottom = 16.0
|
||||
grow_horizontal = 2
|
||||
theme_override_styles/panel = SubResource("StyleBoxFlat_aa3sf")
|
||||
|
||||
[node name="PanelContainer" type="HBoxContainer" parent="Panel"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 10
|
||||
anchor_right = 1.0
|
||||
offset_bottom = 16.0
|
||||
grow_horizontal = 2
|
||||
theme_override_constants/separation = 10
|
||||
|
||||
[node name="Health Label" type="Label" parent="Panel/PanelContainer"]
|
||||
layout_mode = 2
|
||||
text = "Health"
|
||||
label_settings = ExtResource("1_4dsh5")
|
||||
uppercase = true
|
||||
|
||||
[node name="ProgressBar" type="ProgressBar" parent="Panel/PanelContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 1
|
||||
theme = SubResource("Theme_auu2b")
|
||||
theme_override_styles/background = SubResource("StyleBoxFlat_sp6hg")
|
||||
theme_override_styles/fill = SubResource("StyleBoxFlat_22dp1")
|
||||
step = 0.1
|
||||
value = 60.0
|
||||
show_percentage = false
|
||||
|
||||
[node name="Lives" type="Label" parent="Panel/PanelContainer"]
|
||||
layout_mode = 2
|
||||
text = "Lives 3"
|
||||
label_settings = ExtResource("1_4dsh5")
|
||||
uppercase = true
|
||||
|
||||
[node name="Coins label" type="Label" parent="Panel/PanelContainer"]
|
||||
layout_mode = 2
|
||||
text = "Coins 33"
|
||||
label_settings = ExtResource("1_4dsh5")
|
||||
uppercase = true
|
@@ -53,6 +53,7 @@ enabled=PackedStringArray("res://addons/guide/plugin.cfg", "res://addons/phantom
|
||||
|
||||
coins=""
|
||||
levers=""
|
||||
player=""
|
||||
|
||||
[input]
|
||||
|
||||
|
13
resources/input/move.tres
Normal file
13
resources/input/move.tres
Normal file
@@ -0,0 +1,13 @@
|
||||
[gd_resource type="Resource" script_class="GUIDEAction" load_steps=2 format=3 uid="uid://c7h4sh2ilslsv"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/guide/guide_action.gd" id="1_abssq"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_abssq")
|
||||
name = &""
|
||||
action_value_type = 2
|
||||
block_lower_priority_actions = true
|
||||
emit_as_godot_actions = false
|
||||
is_remappable = false
|
||||
display_name = ""
|
||||
display_category = ""
|
101
resources/input/walk_mode.tres
Normal file
101
resources/input/walk_mode.tres
Normal file
@@ -0,0 +1,101 @@
|
||||
[gd_resource type="Resource" script_class="GUIDEMappingContext" load_steps=18 format=3 uid="uid://cb5pheu58dpqi"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/guide/guide_action_mapping.gd" id="1_20ds1"]
|
||||
[ext_resource type="Script" path="res://addons/guide/guide_mapping_context.gd" id="2_tdx85"]
|
||||
[ext_resource type="Resource" uid="uid://c7h4sh2ilslsv" path="res://resources/input/move.tres" id="2_wp2di"]
|
||||
[ext_resource type="Script" path="res://addons/guide/guide_input_mapping.gd" id="3_lq4l6"]
|
||||
[ext_resource type="Script" path="res://addons/guide/inputs/guide_input_key.gd" id="4_rtw28"]
|
||||
[ext_resource type="Script" path="res://addons/guide/modifiers/guide_modifier.gd" id="5_gbdho"]
|
||||
[ext_resource type="Script" path="res://addons/guide/triggers/guide_trigger.gd" id="6_3igdd"]
|
||||
|
||||
[sub_resource type="Resource" id="Resource_10hm2"]
|
||||
script = ExtResource("4_rtw28")
|
||||
key = 65
|
||||
shift = false
|
||||
control = false
|
||||
alt = false
|
||||
meta = false
|
||||
allow_additional_modifiers = true
|
||||
|
||||
[sub_resource type="Resource" id="Resource_f1rpj"]
|
||||
script = ExtResource("3_lq4l6")
|
||||
override_action_settings = false
|
||||
is_remappable = false
|
||||
display_name = ""
|
||||
display_category = ""
|
||||
input = SubResource("Resource_10hm2")
|
||||
modifiers = Array[ExtResource("5_gbdho")]([])
|
||||
triggers = Array[ExtResource("6_3igdd")]([])
|
||||
|
||||
[sub_resource type="Resource" id="Resource_ieje0"]
|
||||
script = ExtResource("4_rtw28")
|
||||
key = 68
|
||||
shift = false
|
||||
control = false
|
||||
alt = false
|
||||
meta = false
|
||||
allow_additional_modifiers = true
|
||||
|
||||
[sub_resource type="Resource" id="Resource_u07sv"]
|
||||
script = ExtResource("3_lq4l6")
|
||||
override_action_settings = false
|
||||
is_remappable = false
|
||||
display_name = ""
|
||||
display_category = ""
|
||||
input = SubResource("Resource_ieje0")
|
||||
modifiers = Array[ExtResource("5_gbdho")]([])
|
||||
triggers = Array[ExtResource("6_3igdd")]([])
|
||||
|
||||
[sub_resource type="Resource" id="Resource_mks6i"]
|
||||
script = ExtResource("4_rtw28")
|
||||
key = 87
|
||||
shift = false
|
||||
control = false
|
||||
alt = false
|
||||
meta = false
|
||||
allow_additional_modifiers = true
|
||||
|
||||
[sub_resource type="Resource" id="Resource_g45jq"]
|
||||
script = ExtResource("3_lq4l6")
|
||||
override_action_settings = false
|
||||
is_remappable = false
|
||||
display_name = ""
|
||||
display_category = ""
|
||||
input = SubResource("Resource_mks6i")
|
||||
modifiers = Array[ExtResource("5_gbdho")]([])
|
||||
triggers = Array[ExtResource("6_3igdd")]([])
|
||||
|
||||
[sub_resource type="Resource" id="Resource_rcwl7"]
|
||||
script = ExtResource("4_rtw28")
|
||||
key = 83
|
||||
shift = false
|
||||
control = false
|
||||
alt = false
|
||||
meta = false
|
||||
allow_additional_modifiers = true
|
||||
|
||||
[sub_resource type="Resource" id="Resource_ie1ig"]
|
||||
script = ExtResource("3_lq4l6")
|
||||
override_action_settings = false
|
||||
is_remappable = false
|
||||
display_name = ""
|
||||
display_category = ""
|
||||
input = SubResource("Resource_rcwl7")
|
||||
modifiers = Array[ExtResource("5_gbdho")]([])
|
||||
triggers = Array[ExtResource("6_3igdd")]([])
|
||||
|
||||
[sub_resource type="Resource" id="Resource_ahs5n"]
|
||||
script = ExtResource("1_20ds1")
|
||||
action = ExtResource("2_wp2di")
|
||||
input_mappings = Array[ExtResource("3_lq4l6")]([SubResource("Resource_f1rpj"), SubResource("Resource_u07sv"), SubResource("Resource_g45jq"), SubResource("Resource_ie1ig")])
|
||||
metadata/_guide_input_mappings_collapsed = false
|
||||
|
||||
[sub_resource type="Resource" id="Resource_4amy2"]
|
||||
script = ExtResource("1_20ds1")
|
||||
input_mappings = Array[ExtResource("3_lq4l6")]([])
|
||||
metadata/_guide_input_mappings_collapsed = false
|
||||
|
||||
[resource]
|
||||
script = ExtResource("2_tdx85")
|
||||
display_name = ""
|
||||
mappings = Array[ExtResource("1_20ds1")]([SubResource("Resource_ahs5n"), SubResource("Resource_4amy2")])
|
6
resources/ui/hud_label_settings.tres
Normal file
6
resources/ui/hud_label_settings.tres
Normal file
@@ -0,0 +1,6 @@
|
||||
[gd_resource type="LabelSettings" load_steps=2 format=3 uid="uid://rvn5ivivfvv6"]
|
||||
|
||||
[ext_resource type="FontFile" uid="uid://xm0vbusjr7b7" path="res://fonts/PressStart2P-Regular.ttf" id="1_q45se"]
|
||||
|
||||
[resource]
|
||||
font = ExtResource("1_q45se")
|
@@ -1,7 +1,8 @@
|
||||
[gd_scene load_steps=29 format=4 uid="uid://h60obxmju6mo"]
|
||||
[gd_scene load_steps=30 format=4 uid="uid://h60obxmju6mo"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://djifxc5x0dyrw" path="res://sprites/ppc_tileset.png" id="1_5lb42"]
|
||||
[ext_resource type="TileSet" uid="uid://cl4bn8lofqvky" path="res://tileset/village/tileset_village.tres" id="1_d680t"]
|
||||
[ext_resource type="PackedScene" uid="uid://byxf45ukq82pe" path="res://objects/hud.tscn" id="1_gbpkv"]
|
||||
[ext_resource type="Texture2D" uid="uid://dxvevrm15uus1" path="res://sprites/flowers_tileset.png" id="3_235u2"]
|
||||
[ext_resource type="PackedScene" uid="uid://54w4wisfj8v8" path="res://objects/coin.tscn" id="3_ygehw"]
|
||||
[ext_resource type="PackedScene" uid="uid://bqi5s710xb1ju" path="res://objects/brick_player.tscn" id="4_hetw8"]
|
||||
@@ -473,3 +474,7 @@ metadata/_edit_lock_ = true
|
||||
|
||||
[node name="Child" parent="." instance=ExtResource("21_8rhdx")]
|
||||
position = Vector2(877, -577)
|
||||
|
||||
[node name="CanvasLayer" type="CanvasLayer" parent="."]
|
||||
|
||||
[node name="HUD" parent="CanvasLayer" instance=ExtResource("1_gbpkv")]
|
||||
|
@@ -1,9 +1,14 @@
|
||||
class_name PlayerDeathComponent
|
||||
extends Node
|
||||
|
||||
@onready var gm: GM = $"/root/GameManager"
|
||||
|
||||
|
||||
func reset_scene() -> void:
|
||||
get_tree().reload_current_scene()
|
||||
|
||||
|
||||
func _on_health_component_on_death() -> void:
|
||||
# todo: play audio on death
|
||||
gm.remove_lives(1)
|
||||
call_deferred("reset_scene")
|
||||
|
@@ -2,17 +2,38 @@ class_name GM
|
||||
extends Node
|
||||
|
||||
var player_state = {
|
||||
"coins": 0,
|
||||
}
|
||||
"coins": 0,
|
||||
"lives": 3,
|
||||
}
|
||||
|
||||
|
||||
func add_coins(amount: int) -> void:
|
||||
player_state["coins"] += amount
|
||||
|
||||
|
||||
func set_coins(amount: int) -> void:
|
||||
player_state["coins"] = amount
|
||||
|
||||
|
||||
func get_coins() -> int:
|
||||
return player_state["coins"]
|
||||
|
||||
|
||||
func remove_coins(amount: int) -> void:
|
||||
player_state["coins"] -= amount
|
||||
|
||||
|
||||
func add_lives(amount: int) -> void:
|
||||
player_state["lives"] += amount
|
||||
|
||||
|
||||
func remove_lives(amount: int) -> void:
|
||||
player_state["lives"] -= amount
|
||||
|
||||
|
||||
func set_lives(amount: int) -> void:
|
||||
player_state["lives"] = amount
|
||||
|
||||
|
||||
func get_lives() -> int:
|
||||
return player_state["lives"]
|
51
scripts/hud.gd
Normal file
51
scripts/hud.gd
Normal file
@@ -0,0 +1,51 @@
|
||||
class_name Hud
|
||||
extends Node
|
||||
|
||||
@export var player_health: HealthComponent
|
||||
@export var coins_label: Label
|
||||
@export var health_progressbar: ProgressBar
|
||||
@export var lives_label: Label
|
||||
|
||||
@onready var game_manager: GM = $"/root/GameManager"
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
if not player_health:
|
||||
var nodes := get_tree().get_nodes_in_group("player")
|
||||
for node in nodes:
|
||||
player_health = node.get_node_or_null("HealthComponent")
|
||||
if player_health:
|
||||
break
|
||||
return
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if not game_manager:
|
||||
return
|
||||
|
||||
set_health_progressbar()
|
||||
set_lives_label()
|
||||
set_coins_label()
|
||||
|
||||
|
||||
func set_coins_label() -> void:
|
||||
if not game_manager:
|
||||
return
|
||||
|
||||
#todo: set internationalized text
|
||||
coins_label.text = "Coins: " + str(game_manager.get_coins())
|
||||
|
||||
|
||||
func set_lives_label() -> void:
|
||||
if not game_manager:
|
||||
return
|
||||
|
||||
lives_label.text = "Lives: " + str(game_manager.get_lives())
|
||||
|
||||
|
||||
func set_health_progressbar() -> void:
|
||||
if not player_health:
|
||||
return
|
||||
|
||||
health_progressbar.value = player_health.health
|
||||
health_progressbar.max_value = player_health.max_health
|
Reference in New Issue
Block a user