diff --git a/Main.tscn b/Main.tscn index 3408eb6..bcacac2 100644 --- a/Main.tscn +++ b/Main.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=23 format=2] +[gd_scene load_steps=26 format=2] [ext_resource path="res://assets/Backgrounds/bgmuck.png" type="Texture" id=1] [ext_resource path="res://src/playerC/Player.tscn" type="PackedScene" id=2] @@ -9,6 +9,9 @@ [ext_resource path="res://src/enemyC/EnemyC.tscn" type="PackedScene" id=7] [ext_resource path="res://assets/Fonts/QuinqueFive.tres" type="DynamicFont" id=8] [ext_resource path="res://src/UI_Dialog.tscn" type="PackedScene" id=9] +[ext_resource path="res://assets/UI/Healthbar.png" type="Texture" id=10] +[ext_resource path="res://assets/UI/Healthbar-Indicator.png" type="Texture" id=11] +[ext_resource path="res://src/UI/HealthBar.gd" type="Script" id=12] [sub_resource type="ConvexPolygonShape2D" id=2] points = PoolVector2Array( 16, 16, 0, 16, 0, 0, 16, 0 ) @@ -230,3 +233,17 @@ margin_bottom = 53.0 custom_fonts/font = ExtResource( 8 ) text = "In a world where danger lurks in your plumbing. One thing decides to do another thing and we all determine it wasn't worth it. Hello World" autowrap = true + +[node name="CanvasLayer" type="CanvasLayer" parent="."] +layer = 2 + +[node name="HealthBar" type="TextureProgress" parent="CanvasLayer"] +margin_left = 2.0 +margin_top = 2.0 +margin_right = 104.0 +margin_bottom = 14.0 +value = 50.0 +texture_under = ExtResource( 10 ) +texture_progress = ExtResource( 11 ) +texture_progress_offset = Vector2( 1, 1 ) +script = ExtResource( 12 ) diff --git a/assets/UI/Healthbar-Indicator.png b/assets/UI/Healthbar-Indicator.png new file mode 100644 index 0000000..071fb87 Binary files /dev/null and b/assets/UI/Healthbar-Indicator.png differ diff --git a/assets/UI/Healthbar-Indicator.png.import b/assets/UI/Healthbar-Indicator.png.import new file mode 100644 index 0000000..8f5cca8 --- /dev/null +++ b/assets/UI/Healthbar-Indicator.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/Healthbar-Indicator.png-cbbde6797adcb3b0445dfd4f9ab1961a.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/UI/Healthbar-Indicator.png" +dest_files=[ "res://.import/Healthbar-Indicator.png-cbbde6797adcb3b0445dfd4f9ab1961a.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=false +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/assets/UI/Healthbar-Indicator.tres b/assets/UI/Healthbar-Indicator.tres new file mode 100644 index 0000000..e9f7a46 --- /dev/null +++ b/assets/UI/Healthbar-Indicator.tres @@ -0,0 +1,3 @@ +[gd_resource type="StreamTexture" format=2] + +[resource] diff --git a/assets/UI/Healthbar.png b/assets/UI/Healthbar.png new file mode 100644 index 0000000..b1c74da Binary files /dev/null and b/assets/UI/Healthbar.png differ diff --git a/assets/UI/Healthbar.png.import b/assets/UI/Healthbar.png.import new file mode 100644 index 0000000..224bce8 --- /dev/null +++ b/assets/UI/Healthbar.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/Healthbar.png-838f5c013355fbdfe1abb6dec9197215.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/UI/Healthbar.png" +dest_files=[ "res://.import/Healthbar.png-838f5c013355fbdfe1abb6dec9197215.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=false +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +process/normal_map_invert_y=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/src/UI/HealthBar.gd b/src/UI/HealthBar.gd new file mode 100644 index 0000000..bdf8f3b --- /dev/null +++ b/src/UI/HealthBar.gd @@ -0,0 +1,16 @@ +extends TextureProgress + + +# Declare member variables here. Examples: +# var a = 2 +# var b = "text" + + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + value = PlayerInfo.player_health diff --git a/src/playerC/Player-KinematicBody2D.gd b/src/playerC/Player-KinematicBody2D.gd index 7fc6ba1..c35b524 100644 --- a/src/playerC/Player-KinematicBody2D.gd +++ b/src/playerC/Player-KinematicBody2D.gd @@ -6,6 +6,8 @@ onready var player_hurtbox = $Hurtbox_Component/CollisionShape2D onready var gun = $Gun +func _ready() -> void: + PlayerInfo.player_health = $Health_Component.health #var sound_effects = preload("res://src/playerC/resources/sound_effects.tres") @@ -40,6 +42,7 @@ func gotcha(damage): $Health_Component.take_damage(damage) if $Health_Component.health > 0: movement_state_machine.change_state($movement_state_machine/hurt) + PlayerInfo.player_health = $Health_Component.health yield( get_tree().create_timer(2 + $movement_state_machine/hurt.timeout_seconds), "timeout") $Hurtbox_Component.set_hurtbox(true)