From 54f977283691ac45eb9c68804becd4b160ab4a10 Mon Sep 17 00:00:00 2001 From: Alan Youngblood Date: Tue, 26 Nov 2024 09:23:20 -0500 Subject: [PATCH] Tut18 Complete; hearts, shadows, etc. --- ActionRPG-HeartBeast/Player/Player.tscn | 7 +++++- ActionRPG-HeartBeast/Stats.gd | 13 +++++++++-- ActionRPG-HeartBeast/UI/HealthUI.gd | 11 ++++++--- ActionRPG-HeartBeast/UI/HealthUI.tscn | 26 ++++++++++++++++------ ActionRPG-HeartBeast/World.tscn | 8 ++++++- ActionRPG-HeartBeast/World/Bush.tscn | 7 +++++- ActionRPG-HeartBeast/World/Tree.tscn | 22 ++++++++++++++++++ ActionRPG-HeartBeast/build/web/index.html | 2 +- ActionRPG-HeartBeast/build/web/index.pck | Bin 2283408 -> 2289520 bytes 9 files changed, 80 insertions(+), 16 deletions(-) create mode 100644 ActionRPG-HeartBeast/World/Tree.tscn diff --git a/ActionRPG-HeartBeast/Player/Player.tscn b/ActionRPG-HeartBeast/Player/Player.tscn index 9d2e0c1..af26ee8 100644 --- a/ActionRPG-HeartBeast/Player/Player.tscn +++ b/ActionRPG-HeartBeast/Player/Player.tscn @@ -1,10 +1,11 @@ -[gd_scene load_steps=56 format=2] +[gd_scene load_steps=57 format=2] [ext_resource path="res://Player/Player.gd" type="Script" id=1] [ext_resource path="res://Player/Player.png" type="Texture" id=2] [ext_resource path="res://Overlap/Hitbox.tscn" type="PackedScene" id=3] [ext_resource path="res://Player/SwordHitbox.gd" type="Script" id=4] [ext_resource path="res://Overlap/Hurtbox.tscn" type="PackedScene" id=5] +[ext_resource path="res://Shadows/MediumShadow.png" type="Texture" id=6] [sub_resource type="CapsuleShape2D" id=1] radius = 4.0 @@ -650,6 +651,10 @@ height = 6.0 collision_layer = 2 script = ExtResource( 1 ) +[node name="ShadowSprite" type="Sprite" parent="."] +position = Vector2( 0, 1 ) +texture = ExtResource( 6 ) + [node name="Sprite" type="Sprite" parent="."] position = Vector2( 0, -9 ) texture = ExtResource( 2 ) diff --git a/ActionRPG-HeartBeast/Stats.gd b/ActionRPG-HeartBeast/Stats.gd index d7e6347..33a392d 100644 --- a/ActionRPG-HeartBeast/Stats.gd +++ b/ActionRPG-HeartBeast/Stats.gd @@ -1,13 +1,22 @@ extends Node -export(int) var max_health = 1 -onready var health = max_health setget set_health +export(int) var max_health = 1 setget set_max_health +var health = max_health setget set_health signal no_health signal health_changed(value) +signal max_health_changed(value) + +func set_max_health(value): + max_health = value + self.health = min(health, max_health) + emit_signal("max_health_changed", max_health) func set_health(value): health = value emit_signal("health_changed", health) if health <= 0: emit_signal("no_health") + +func _ready(): + self.health = max_health diff --git a/ActionRPG-HeartBeast/UI/HealthUI.gd b/ActionRPG-HeartBeast/UI/HealthUI.gd index 64e341f..31654e3 100644 --- a/ActionRPG-HeartBeast/UI/HealthUI.gd +++ b/ActionRPG-HeartBeast/UI/HealthUI.gd @@ -3,17 +3,22 @@ extends Control var hearts = 4 setget set_hearts var max_hearts = 4 setget set_max_hearts -onready var label = $Label +onready var heartUIFull = $HeartUIFull +onready var heartUIEmpty = $HeartUIEmpty func set_hearts(value): hearts = clamp(value, 0, max_hearts) - if label != null: - label.text = "HP = " + str(hearts) + if heartUIFull != null: + heartUIFull.rect_size.x = hearts * 15 func set_max_hearts(value): max_hearts = max(value, 1) + self.hearts = min(hearts, max_hearts) + if heartUIEmpty != null: + heartUIEmpty.rect_size.x = max_hearts * 15 func _ready(): self.max_hearts = PlayerStats.max_health self.hearts = PlayerStats.health PlayerStats.connect("health_changed", self, "set_hearts") + PlayerStats.connect("max_health_changed", self, "set_max_hearts") diff --git a/ActionRPG-HeartBeast/UI/HealthUI.tscn b/ActionRPG-HeartBeast/UI/HealthUI.tscn index 63772bb..07b8f2c 100644 --- a/ActionRPG-HeartBeast/UI/HealthUI.tscn +++ b/ActionRPG-HeartBeast/UI/HealthUI.tscn @@ -1,13 +1,25 @@ -[gd_scene load_steps=2 format=2] +[gd_scene load_steps=4 format=2] [ext_resource path="res://UI/HealthUI.gd" type="Script" id=1] +[ext_resource path="res://UI/HeartUIEmpty.png" type="Texture" id=2] +[ext_resource path="res://UI/HeartUIFull.png" type="Texture" id=3] [node name="HealthUI" type="Control"] -margin_right = 122.0 -margin_bottom = 25.0 +margin_left = 2.0 +margin_top = 2.0 +margin_right = 124.0 +margin_bottom = 27.0 script = ExtResource( 1 ) -[node name="Label" type="Label" parent="."] -margin_right = 42.0 -margin_bottom = 14.0 -text = "HP = 4" +[node name="HeartUIEmpty" type="TextureRect" parent="."] +margin_right = 59.0 +margin_bottom = 12.0 +texture = ExtResource( 2 ) +stretch_mode = 2 + +[node name="HeartUIFull" type="TextureRect" parent="."] +margin_right = 60.0 +margin_bottom = 11.0 +texture = ExtResource( 3 ) +expand = true +stretch_mode = 2 diff --git a/ActionRPG-HeartBeast/World.tscn b/ActionRPG-HeartBeast/World.tscn index e372d25..3f26d5c 100644 --- a/ActionRPG-HeartBeast/World.tscn +++ b/ActionRPG-HeartBeast/World.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=63 format=2] +[gd_scene load_steps=64 format=2] [ext_resource path="res://World/Bush.tscn" type="PackedScene" id=1] [ext_resource path="res://Player/Player.tscn" type="PackedScene" id=2] @@ -9,6 +9,7 @@ [ext_resource path="res://touch_controls/TouchControls.tscn" type="PackedScene" id=7] [ext_resource path="res://Enemies/Bat.tscn" type="PackedScene" id=8] [ext_resource path="res://UI/HealthUI.tscn" type="PackedScene" id=9] +[ext_resource path="res://World/Tree.tscn" type="PackedScene" id=10] [sub_resource type="TileSet" id=1] 0/name = "DirtTileset.png 0" @@ -595,6 +596,11 @@ position = Vector2( 48, 112 ) [node name="Grass10" parent="YSort/Grass" instance=ExtResource( 6 )] position = Vector2( 128, 121 ) +[node name="Trees" type="YSort" parent="YSort"] + +[node name="Tree" parent="YSort/Trees" instance=ExtResource( 10 )] +position = Vector2( 127, 40 ) + [node name="Bat" parent="YSort" instance=ExtResource( 8 )] position = Vector2( 198, 35 ) diff --git a/ActionRPG-HeartBeast/World/Bush.tscn b/ActionRPG-HeartBeast/World/Bush.tscn index 30cf1df..86152f5 100644 --- a/ActionRPG-HeartBeast/World/Bush.tscn +++ b/ActionRPG-HeartBeast/World/Bush.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=3 format=2] +[gd_scene load_steps=4 format=2] [ext_resource path="res://World/Bush.png" type="Texture" id=1] +[ext_resource path="res://Shadows/LargeShadow.png" type="Texture" id=2] [sub_resource type="CapsuleShape2D" id=1] radius = 7.99998 @@ -8,6 +9,10 @@ height = 12.0 [node name="Bush" type="StaticBody2D"] +[node name="ShadowSprite" type="Sprite" parent="."] +position = Vector2( 0, 6 ) +texture = ExtResource( 2 ) + [node name="Sprite" type="Sprite" parent="."] texture = ExtResource( 1 ) diff --git a/ActionRPG-HeartBeast/World/Tree.tscn b/ActionRPG-HeartBeast/World/Tree.tscn new file mode 100644 index 0000000..4ed62b6 --- /dev/null +++ b/ActionRPG-HeartBeast/World/Tree.tscn @@ -0,0 +1,22 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://Shadows/LargeShadow.png" type="Texture" id=1] +[ext_resource path="res://World/Tree.png" type="Texture" id=2] + +[sub_resource type="CapsuleShape2D" id=1] +radius = 9.0 +height = 8.0 + +[node name="Tree" type="StaticBody2D"] + +[node name="ShadowSprite" type="Sprite" parent="."] +texture = ExtResource( 1 ) + +[node name="Sprite" type="Sprite" parent="."] +position = Vector2( 0, -16 ) +texture = ExtResource( 2 ) + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +position = Vector2( 0, -1 ) +rotation = 1.5708 +shape = SubResource( 1 ) diff --git a/ActionRPG-HeartBeast/build/web/index.html b/ActionRPG-HeartBeast/build/web/index.html index 29077cc..82c7d81 100644 --- a/ActionRPG-HeartBeast/build/web/index.html +++ b/ActionRPG-HeartBeast/build/web/index.html @@ -139,7 +139,7 @@