Skip to content

Commit

Permalink
add life
Browse files Browse the repository at this point in the history
  • Loading branch information
janekx21 committed Oct 16, 2023
1 parent 9d079c8 commit d86ddf5
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 3 deletions.
9 changes: 9 additions & 0 deletions code/HeartDisplay.gd
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions code/player.gd
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
31 changes: 29 additions & 2 deletions scenes/game.tscn
Original file line number Diff line number Diff line change
@@ -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"]
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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"]
3 changes: 2 additions & 1 deletion scenes/player.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Binary file added tex/suit_hearts.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions tex/suit_hearts.png.import
Original file line number Diff line number Diff line change
@@ -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
Binary file added tex/suit_hearts_broken.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions tex/suit_hearts_broken.png.import
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d86ddf5

Please sign in to comment.