diff --git a/healthbar/healthbar.gd b/healthbar/healthbar.gd index 5566861..8a9f530 100644 --- a/healthbar/healthbar.gd +++ b/healthbar/healthbar.gd @@ -1,11 +1,13 @@ extends HBoxContainer -@export var initial_health : int = 5 @export var packedHeart : PackedScene; +var current_max_hp = 0 +var current_health = 0 func _ready() -> void: - for i in range(initial_health): - add_child(packedHeart.instantiate()) + #for i in range(initial_health): + #add_child(packedHeart.instantiate()) + pass func set_health(health : int): var i = 0 @@ -15,7 +17,27 @@ func set_health(health : int): heart.restore() else: heart.fade() + current_health = health +func set_maxhealth(new_max_hp : int): + if new_max_hp > current_max_hp: + for i in range(new_max_hp - current_max_hp): + add_child(packedHeart.instantiate()) + elif new_max_hp < current_max_hp: + var children = get_children() + for i in range(children.size()): + if new_max_hp < i+1: + children[i].queue_free() + current_health = min(current_health, current_max_hp) + else: pass + + current_max_hp = new_max_hp + set_health(current_max_hp) + func _on_player_health_changed(new_health: int) -> void: set_health(new_health) + + +func _on_player_max_hp_changed(new_max_hp: int) -> void: + set_maxhealth(new_max_hp) diff --git a/item_ui/item_ui.tscn b/item_ui/item_ui.tscn new file mode 100644 index 0000000..1f2de90 --- /dev/null +++ b/item_ui/item_ui.tscn @@ -0,0 +1,37 @@ +[gd_scene load_steps=3 format=3 uid="uid://73g8y37skebh"] + +[ext_resource type="Texture2D" uid="uid://cy70quh6k3s1j" path="res://icon.svg" id="1_lfuq2"] + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_8oq0s"] +draw_center = false +border_width_left = 5 +border_width_top = 5 +border_width_right = 5 +border_width_bottom = 5 +border_color = Color(0, 0, 0, 0.69411767) +border_blend = true +corner_radius_top_left = 50 +corner_radius_top_right = 50 +corner_radius_bottom_right = 50 +corner_radius_bottom_left = 50 + +[node name="ItemUI" type="MarginContainer"] +anchors_preset = 1 +anchor_left = 1.0 +anchor_right = 1.0 +offset_left = -150.0 +offset_bottom = 150.0 +grow_horizontal = 0 +theme_override_constants/margin_left = 25 +theme_override_constants/margin_top = 25 +theme_override_constants/margin_right = 25 +theme_override_constants/margin_bottom = 25 + +[node name="PanelContainer" type="PanelContainer" parent="."] +layout_mode = 2 +theme_override_styles/panel = SubResource("StyleBoxFlat_8oq0s") + +[node name="TextureRect" type="TextureRect" parent="PanelContainer"] +layout_mode = 2 +texture = ExtResource("1_lfuq2") +expand_mode = 1 diff --git a/items/item_spawn.gd b/items/item_spawn.gd index af9d37a..a9d6e88 100644 --- a/items/item_spawn.gd +++ b/items/item_spawn.gd @@ -31,7 +31,8 @@ func _ready(): var pool = choose_pool() var index = randi_range(0, pool.size() - 1) var packed_scene : PackedScene = pool[index] - pool.remove_at(index) + if remove_after_spawn: + pool.remove_at(index) var object = packed_scene.instantiate() add_child.call_deferred(object) object.reparent.call_deferred(get_parent()) diff --git a/main.tscn b/main.tscn index 5574953..381ec63 100644 --- a/main.tscn +++ b/main.tscn @@ -1,9 +1,10 @@ -[gd_scene load_steps=12 format=3 uid="uid://cxo6bq26huau7"] +[gd_scene load_steps=13 format=3 uid="uid://cxo6bq26huau7"] [ext_resource type="PackedScene" uid="uid://cmaovvr15b3qk" path="res://player/player.tscn" id="2_1bvp3"] [ext_resource type="Script" uid="uid://vgxh2xdevat7" path="res://world/earth.gd" id="2_lquwl"] [ext_resource type="PackedScene" uid="uid://jjoyj1ldafkf" path="res://world/earth.tscn" id="3_lquwl"] [ext_resource type="Script" uid="uid://colvx6wq0e8n7" path="res://world/building_generator.gd" id="4_1bvp3"] +[ext_resource type="PackedScene" uid="uid://73g8y37skebh" path="res://item_ui/item_ui.tscn" id="6_4c57u"] [ext_resource type="PackedScene" uid="uid://cjsrtswk4vgf2" path="res://healthbar/healthbar.tscn" id="6_7mycd"] [ext_resource type="PackedScene" uid="uid://dpdn2php3ydsv" path="res://death_screen/death_screen.tscn" id="7_5vw27"] [ext_resource type="PackedScene" uid="uid://4l3elvxpghw8" path="res://utils/platform.tscn" id="7_272bh"] @@ -44,6 +45,8 @@ autostart = true offset_right = 128.0 offset_bottom = 128.0 +[node name="ItemUI" parent="CanvasLayer" instance=ExtResource("6_4c57u")] + [node name="DeathScreen" parent="CanvasLayer" instance=ExtResource("7_5vw27")] visible = false @@ -64,6 +67,7 @@ position = Vector2(200, -3100) position = Vector2(0, -3100) [connection signal="health_changed" from="Player" to="CanvasLayer/Healthbar" method="_on_player_health_changed"] +[connection signal="max_hp_changed" from="Player" to="CanvasLayer/Healthbar" method="_on_player_max_hp_changed"] [connection signal="player_died" from="Player" to="CanvasLayer/DeathScreen" method="_on_player_player_died"] [connection signal="timeout" from="Building Generator/Timer" to="Building Generator" method="_on_timer_timeout"] [connection signal="visibility_changed" from="CanvasLayer/DeathScreen" to="Player" method="_on_death_screen_visibility_changed"] diff --git a/player/player.gd b/player/player.gd index 0193ec2..ca76900 100644 --- a/player/player.gd +++ b/player/player.gd @@ -22,13 +22,17 @@ var air_jumps_current = 1; # HP and Iframes signal health_changed(new_health : int) +signal max_hp_changed(new_max_hp : int) signal player_died var current_hp = 5: set(new_hp): current_hp = new_hp health_changed.emit(current_hp) -var max_hp = 5; +var max_hp = 5: + set(new_max_hp): + max_hp = new_max_hp + max_hp_changed.emit(max_hp) var hit_invulnerability = 0.5 var inv_time = 0; var dead = false; @@ -46,6 +50,10 @@ var atk_timer = 0 var active_item = null var item_cooldown = 0 +func _ready() -> void: + max_hp_changed.emit(max_hp) + health_changed.emit(current_hp) + func _physics_process(delta: float) -> void: manage_iframes(delta) manage_movement_options()