diff --git a/code/HeartDisplay.gd b/code/HeartDisplay.gd new file mode 100644 index 0000000..6466470 --- /dev/null +++ b/code/HeartDisplay.gd @@ -0,0 +1,9 @@ +extends HFlowContainer + +@export var player : Player + +func _process(delta: float) -> void: + var player_hp = player.hp + for child in get_children(): + var tex = child as TextureRect + tex.visible = int(str(tex.name)) <= player_hp.hp diff --git a/code/player.gd b/code/player.gd index 3ddee76..73cf449 100644 --- a/code/player.gd +++ b/code/player.gd @@ -1,7 +1,9 @@ extends CharacterBody3D +class_name Player @export var max_speed = 5 @export var acceleration = 60 +@export var hp : Hp func _physics_process(delta: float) -> void: var move = get_move() diff --git a/scenes/game.tscn b/scenes/game.tscn index dd893f5..a2c9bc9 100644 --- a/scenes/game.tscn +++ b/scenes/game.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=10 format=3 uid="uid://b51ha0wsiwdnk"] +[gd_scene load_steps=12 format=3 uid="uid://b51ha0wsiwdnk"] [ext_resource type="Script" path="res://code/CameraFollow.gd" id="1_vlvop"] [ext_resource type="PackedScene" uid="uid://c6clkgmt6mj40" path="res://scenes/player.tscn" id="1_yng7m"] @@ -7,6 +7,8 @@ [ext_resource type="PackedScene" uid="uid://dsbdqf2nvyuch" path="res://scenes/switch.tscn" id="4_qip34"] [ext_resource type="PackedScene" uid="uid://2syfxc5y7iaw" path="res://scenes/door.tscn" id="5_gedo6"] [ext_resource type="Script" path="res://code/hurtbox.gd" id="7_hku6y"] +[ext_resource type="Script" path="res://code/HeartDisplay.gd" id="8_7ok87"] +[ext_resource type="Texture2D" uid="uid://cp47nfegye1qs" path="res://tex/suit_hearts.png" id="9_7vmu5"] [sub_resource type="Environment" id="Environment_ktnj1"] background_mode = 2 @@ -26,11 +28,12 @@ target = NodePath("../Player") transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0) [node name="DirectionalLight3D" type="DirectionalLight3D" parent="."] -transform = Transform3D(1, 0, 0, 0, 0.258819, 0.965926, 0, -0.965926, 0.258819, 0, 0, 0) +transform = Transform3D(1, 0, 0, 0, 0.337818, 0.941211, 0, -0.941211, 0.337818, -6.28612, 0.125248, 0.0914339) [node name="World" type="Node" parent="."] [node name="Hexagon" parent="World" instance=ExtResource("3_yb1jf")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.153038, -1, -0.0133891) [node name="Hexagon2" parent="World" instance=ExtResource("3_yb1jf")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 4.31156, -1, -7.75663) @@ -76,4 +79,28 @@ damage_amount = 999999999999 [node name="CollisionShape3D" type="CollisionShape3D" parent="DeathTrigger"] shape = SubResource("WorldBoundaryShape3D_mnlg0") +[node name="HeathDisplay" type="HFlowContainer" parent="." node_paths=PackedStringArray("player")] +anchors_preset = 10 +anchor_right = 1.0 +offset_bottom = 128.0 +grow_horizontal = 2 +alignment = 1 +script = ExtResource("8_7ok87") +player = NodePath("../Player") + +[node name="1" type="TextureRect" parent="HeathDisplay"] +modulate = Color(1, 0.2, 0.411765, 1) +layout_mode = 2 +texture = ExtResource("9_7vmu5") + +[node name="2" type="TextureRect" parent="HeathDisplay"] +modulate = Color(1, 0.2, 0.411765, 1) +layout_mode = 2 +texture = ExtResource("9_7vmu5") + +[node name="3" type="TextureRect" parent="HeathDisplay"] +modulate = Color(1, 0.2, 0.411765, 1) +layout_mode = 2 +texture = ExtResource("9_7vmu5") + [connection signal="activate" from="Switch" to="Door" method="toggle"] diff --git a/scenes/player.tscn b/scenes/player.tscn index fa3ffa5..79f646b 100644 --- a/scenes/player.tscn +++ b/scenes/player.tscn @@ -14,9 +14,10 @@ height = 1.8 [sub_resource type="CapsuleShape3D" id="CapsuleShape3D_rvqs5"] radius = 0.6 -[node name="Player" type="CharacterBody3D"] +[node name="Player" type="CharacterBody3D" node_paths=PackedStringArray("hp")] script = ExtResource("1_mp6gu") max_speed = 6 +hp = NodePath("Hp") [node name="MeshInstance3D" type="MeshInstance3D" parent="."] mesh = SubResource("CapsuleMesh_a6ck7") diff --git a/tex/suit_hearts.png b/tex/suit_hearts.png new file mode 100644 index 0000000..f78ad95 Binary files /dev/null and b/tex/suit_hearts.png differ diff --git a/tex/suit_hearts.png.import b/tex/suit_hearts.png.import new file mode 100644 index 0000000..7ff6e43 --- /dev/null +++ b/tex/suit_hearts.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://cp47nfegye1qs" +path="res://.godot/imported/suit_hearts.png-b3be76c1662211edbec9b0a623868703.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://tex/suit_hearts.png" +dest_files=["res://.godot/imported/suit_hearts.png-b3be76c1662211edbec9b0a623868703.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/tex/suit_hearts_broken.png b/tex/suit_hearts_broken.png new file mode 100644 index 0000000..68c4efc Binary files /dev/null and b/tex/suit_hearts_broken.png differ diff --git a/tex/suit_hearts_broken.png.import b/tex/suit_hearts_broken.png.import new file mode 100644 index 0000000..897fa49 --- /dev/null +++ b/tex/suit_hearts_broken.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://cs5yyd0mfwta3" +path="res://.godot/imported/suit_hearts_broken.png-984eba8393e43570e9a2798327a3becc.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://tex/suit_hearts_broken.png" +dest_files=["res://.godot/imported/suit_hearts_broken.png-984eba8393e43570e9a2798327a3becc.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1