Browse Source

:sparkles: added health bar

Felix Bytow 10 months ago
parent
commit
332193604f

+ 3 - 0
.gitignore

@@ -8,3 +8,6 @@ export/*
 export/web/*
 !export/web/.gitkeep
 
+# macOS
+.DS_Store
+

+ 27 - 0
assets/scenes/health_bar.gd

@@ -0,0 +1,27 @@
+extends Node2D
+
+signal health_changed(new_value: int)
+
+const MAX_HEALTH = 10
+
+@export var health: int = 10:
+	set(new_value):
+		var new_health = clampi(new_value, 0, MAX_HEALTH)
+		if new_health != health:
+			health = new_health
+			health_changed.emit(new_health)
+
+@onready var foreground: AnimatedSprite2D = $Foreground
+
+func _ready() -> void:
+	update_foreground()
+
+func _on_health_changed(_new_value: int) -> void:
+	update_foreground()
+
+func update_foreground():
+	if health != 0:
+		foreground.frame = MAX_HEALTH - health
+		foreground.visible = true
+	else:
+		foreground.visible = false

+ 65 - 0
assets/scenes/health_bar.tscn

@@ -0,0 +1,65 @@
+[gd_scene load_steps=14 format=3 uid="uid://bnoxyhq2ha6r1"]
+
+[ext_resource type="Script" path="res://assets/scenes/health_bar.gd" id="1_pe8px"]
+[ext_resource type="Texture2D" uid="uid://edktycyiq13w" path="res://assets/textures/health_bar/hbtrue_11.png" id="2_yle5t"]
+[ext_resource type="Texture2D" uid="uid://ckr4omb8rvtvp" path="res://assets/textures/health_bar/hbtrue_1.png" id="3_m3xml"]
+[ext_resource type="Texture2D" uid="uid://bpr10h2i0cv0p" path="res://assets/textures/health_bar/hbtrue_2.png" id="4_h2ca5"]
+[ext_resource type="Texture2D" uid="uid://cpnxe30l1h5cw" path="res://assets/textures/health_bar/hbtrue_3.png" id="5_8w1ew"]
+[ext_resource type="Texture2D" uid="uid://cd62w1sw7hshn" path="res://assets/textures/health_bar/hbtrue_4.png" id="6_gk8cn"]
+[ext_resource type="Texture2D" uid="uid://dtp3nhr2t4nt0" path="res://assets/textures/health_bar/hbtrue_5.png" id="7_r24lk"]
+[ext_resource type="Texture2D" uid="uid://ckhoug16gx6pv" path="res://assets/textures/health_bar/hbtrue_6.png" id="8_74yao"]
+[ext_resource type="Texture2D" uid="uid://cudelthljkpis" path="res://assets/textures/health_bar/hbtrue_7.png" id="9_rdawm"]
+[ext_resource type="Texture2D" uid="uid://bnl8kensmvvi1" path="res://assets/textures/health_bar/hbtrue_8.png" id="10_uu6n3"]
+[ext_resource type="Texture2D" uid="uid://sgp2igmpjfhn" path="res://assets/textures/health_bar/hbtrue_9.png" id="11_721y0"]
+[ext_resource type="Texture2D" uid="uid://3r50neduuppy" path="res://assets/textures/health_bar/hbtrue_10.png" id="12_ebhj2"]
+
+[sub_resource type="SpriteFrames" id="SpriteFrames_mciub"]
+animations = [{
+"frames": [{
+"duration": 1.0,
+"texture": ExtResource("3_m3xml")
+}, {
+"duration": 1.0,
+"texture": ExtResource("4_h2ca5")
+}, {
+"duration": 1.0,
+"texture": ExtResource("5_8w1ew")
+}, {
+"duration": 1.0,
+"texture": ExtResource("6_gk8cn")
+}, {
+"duration": 1.0,
+"texture": ExtResource("7_r24lk")
+}, {
+"duration": 1.0,
+"texture": ExtResource("8_74yao")
+}, {
+"duration": 1.0,
+"texture": ExtResource("9_rdawm")
+}, {
+"duration": 1.0,
+"texture": ExtResource("10_uu6n3")
+}, {
+"duration": 1.0,
+"texture": ExtResource("11_721y0")
+}, {
+"duration": 1.0,
+"texture": ExtResource("12_ebhj2")
+}],
+"loop": false,
+"name": &"default",
+"speed": 0.0
+}]
+
+[node name="HealthBar" type="Node2D"]
+script = ExtResource("1_pe8px")
+
+[node name="Background" type="Sprite2D" parent="."]
+texture = ExtResource("2_yle5t")
+
+[node name="Foreground" type="AnimatedSprite2D" parent="."]
+sprite_frames = SubResource("SpriteFrames_mciub")
+autoplay = "default"
+speed_scale = 2.08165e-12
+
+[connection signal="health_changed" from="." to="." method="_on_health_changed" flags=3]

BIN
assets/textures/health_bar/hbtrue_1.png


+ 34 - 0
assets/textures/health_bar/hbtrue_1.png.import

@@ -0,0 +1,34 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://ckr4omb8rvtvp"
+path="res://.godot/imported/hbtrue_1.png-a273c6ed48e46555e26453bafd0ed1fe.ctex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://assets/textures/health_bar/hbtrue_1.png"
+dest_files=["res://.godot/imported/hbtrue_1.png-a273c6ed48e46555e26453bafd0ed1fe.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

BIN
assets/textures/health_bar/hbtrue_10.png


+ 34 - 0
assets/textures/health_bar/hbtrue_10.png.import

@@ -0,0 +1,34 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://3r50neduuppy"
+path="res://.godot/imported/hbtrue_10.png-0a4c840422f7219453a72a508357917a.ctex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://assets/textures/health_bar/hbtrue_10.png"
+dest_files=["res://.godot/imported/hbtrue_10.png-0a4c840422f7219453a72a508357917a.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

BIN
assets/textures/health_bar/hbtrue_11.png


+ 34 - 0
assets/textures/health_bar/hbtrue_11.png.import

@@ -0,0 +1,34 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://edktycyiq13w"
+path="res://.godot/imported/hbtrue_11.png-1cb3a0d287fdbb04ca870f99b10c0529.ctex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://assets/textures/health_bar/hbtrue_11.png"
+dest_files=["res://.godot/imported/hbtrue_11.png-1cb3a0d287fdbb04ca870f99b10c0529.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

BIN
assets/textures/health_bar/hbtrue_2.png


+ 34 - 0
assets/textures/health_bar/hbtrue_2.png.import

@@ -0,0 +1,34 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://bpr10h2i0cv0p"
+path="res://.godot/imported/hbtrue_2.png-5669d4aeba870182ece1e253119eb07c.ctex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://assets/textures/health_bar/hbtrue_2.png"
+dest_files=["res://.godot/imported/hbtrue_2.png-5669d4aeba870182ece1e253119eb07c.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

BIN
assets/textures/health_bar/hbtrue_3.png


+ 34 - 0
assets/textures/health_bar/hbtrue_3.png.import

@@ -0,0 +1,34 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://cpnxe30l1h5cw"
+path="res://.godot/imported/hbtrue_3.png-bd691dc34619991f8c85d02eafd18489.ctex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://assets/textures/health_bar/hbtrue_3.png"
+dest_files=["res://.godot/imported/hbtrue_3.png-bd691dc34619991f8c85d02eafd18489.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

BIN
assets/textures/health_bar/hbtrue_4.png


+ 34 - 0
assets/textures/health_bar/hbtrue_4.png.import

@@ -0,0 +1,34 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://cd62w1sw7hshn"
+path="res://.godot/imported/hbtrue_4.png-9110005f73bef66c29015b75bd35e103.ctex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://assets/textures/health_bar/hbtrue_4.png"
+dest_files=["res://.godot/imported/hbtrue_4.png-9110005f73bef66c29015b75bd35e103.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

BIN
assets/textures/health_bar/hbtrue_5.png


+ 34 - 0
assets/textures/health_bar/hbtrue_5.png.import

@@ -0,0 +1,34 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://dtp3nhr2t4nt0"
+path="res://.godot/imported/hbtrue_5.png-ff89eda52ba427cfb40c9d71048bb380.ctex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://assets/textures/health_bar/hbtrue_5.png"
+dest_files=["res://.godot/imported/hbtrue_5.png-ff89eda52ba427cfb40c9d71048bb380.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

BIN
assets/textures/health_bar/hbtrue_6.png


+ 34 - 0
assets/textures/health_bar/hbtrue_6.png.import

@@ -0,0 +1,34 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://ckhoug16gx6pv"
+path="res://.godot/imported/hbtrue_6.png-85df00347013889146ef57348aa8986b.ctex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://assets/textures/health_bar/hbtrue_6.png"
+dest_files=["res://.godot/imported/hbtrue_6.png-85df00347013889146ef57348aa8986b.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

BIN
assets/textures/health_bar/hbtrue_7.png


+ 34 - 0
assets/textures/health_bar/hbtrue_7.png.import

@@ -0,0 +1,34 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://cudelthljkpis"
+path="res://.godot/imported/hbtrue_7.png-847e7e51e26607297efba7bece67b31e.ctex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://assets/textures/health_bar/hbtrue_7.png"
+dest_files=["res://.godot/imported/hbtrue_7.png-847e7e51e26607297efba7bece67b31e.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

BIN
assets/textures/health_bar/hbtrue_8.png


+ 34 - 0
assets/textures/health_bar/hbtrue_8.png.import

@@ -0,0 +1,34 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://bnl8kensmvvi1"
+path="res://.godot/imported/hbtrue_8.png-f2b35fe664171042df75303f93c8951b.ctex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://assets/textures/health_bar/hbtrue_8.png"
+dest_files=["res://.godot/imported/hbtrue_8.png-f2b35fe664171042df75303f93c8951b.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

BIN
assets/textures/health_bar/hbtrue_9.png


+ 34 - 0
assets/textures/health_bar/hbtrue_9.png.import

@@ -0,0 +1,34 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://sgp2igmpjfhn"
+path="res://.godot/imported/hbtrue_9.png-e9f599e651be96ed33528d62749bdb4d.ctex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://assets/textures/health_bar/hbtrue_9.png"
+dest_files=["res://.godot/imported/hbtrue_9.png-e9f599e651be96ed33528d62749bdb4d.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

+ 14 - 0
screens/game.gd

@@ -0,0 +1,14 @@
+extends Node2D
+
+@onready var health_bar = $HealthBar
+
+var direction = -1
+
+func _process(_delta: float) -> void:
+	if Input.is_action_pressed("ui_cancel"):
+		get_tree().change_scene_to_file("res://screens/main_menu.tscn")
+
+func _on_timer_timeout():
+	health_bar.health += direction
+	if health_bar.health == 0 || health_bar.health == health_bar.MAX_HEALTH:
+		direction *= -1

+ 14 - 1
screens/game.tscn

@@ -1,3 +1,16 @@
-[gd_scene format=3 uid="uid://c483fkssc36s"]
+[gd_scene load_steps=3 format=3 uid="uid://c483fkssc36s"]
+
+[ext_resource type="Script" path="res://screens/game.gd" id="1_4dd0q"]
+[ext_resource type="PackedScene" uid="uid://bnoxyhq2ha6r1" path="res://assets/scenes/health_bar.tscn" id="2_x77og"]
 
 [node name="Game" type="Node2D"]
+script = ExtResource("1_4dd0q")
+
+[node name="HealthBar" parent="." instance=ExtResource("2_x77og")]
+position = Vector2(640, 70)
+scale = Vector2(0.5, 0.5)
+
+[node name="Timer" type="Timer" parent="."]
+autostart = true
+
+[connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"]

+ 1 - 1
screens/main_menu.gd

@@ -9,7 +9,7 @@ func _ready():
 		quit_button.visible = false
 
 func _on_new_game_pressed():
-	pass # Replace with function body.
+	get_tree().change_scene_to_file("res://screens/game.tscn")
 
 func _on_quit_pressed():
 	get_tree().quit()