feat: add names to dragons
This commit is contained in:
parent
f07b28d2dc
commit
ca4959af32
10 changed files with 91 additions and 15 deletions
|
@ -4,7 +4,7 @@ class_name DragonEntity
|
|||
|
||||
@export var dragon: DragonSprite
|
||||
|
||||
signal on_pick(position: Vector2, hat: Texture2D, shirt: Texture2D, shoes: Texture2D)
|
||||
signal on_pick(position: Vector2, hat: Texture2D, shirt: Texture2D, shoes: Texture2D, dragon_name: String)
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
|
@ -15,9 +15,13 @@ func _input_event(viewport, event, shape_idx) -> void:
|
|||
if event is InputEventMouseButton \
|
||||
and event.button_index == MOUSE_BUTTON_LEFT \
|
||||
and event.is_pressed():
|
||||
on_pick.emit(position, dragon.hat.texture, dragon.shirt.texture, dragon.shoes.texture)
|
||||
on_pick.emit(position, dragon.hat.texture, dragon.shirt.texture, dragon.shoes.texture, dragon.name_label.text)
|
||||
queue_free()
|
||||
|
||||
|
||||
func dress(hat: Texture2D, shirt: Texture2D, shoes: Texture2D):
|
||||
dragon.dress(hat, shirt, shoes)
|
||||
|
||||
|
||||
func set_dragon_name(dragon_name: String):
|
||||
dragon.set_dragon_name(dragon_name)
|
||||
|
|
|
@ -5,9 +5,26 @@ class_name DragonSprite
|
|||
@export var hat: Sprite2D
|
||||
@export var shirt: Sprite2D
|
||||
@export var shoes: Sprite2D
|
||||
@export var name_label: Label
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
name_label.hide()
|
||||
|
||||
|
||||
func dress(hat: Texture2D, shirt: Texture2D, shoes: Texture2D):
|
||||
self.hat.texture = hat
|
||||
self.shirt.texture = shirt
|
||||
self.shoes.texture = shoes
|
||||
|
||||
|
||||
func set_dragon_name(dragon_name: String):
|
||||
name_label.text = dragon_name
|
||||
|
||||
|
||||
func _on_area_2d_mouse_entered() -> void:
|
||||
name_label.show()
|
||||
|
||||
|
||||
func _on_area_2d_mouse_exited() -> void:
|
||||
name_label.hide()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=6 format=3 uid="uid://baa8gpicw2yg0"]
|
||||
[gd_scene load_steps=7 format=3 uid="uid://baa8gpicw2yg0"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://fdqnc2qrrvn1" path="res://assets/sprites/icon.svg" id="1_ixu8j"]
|
||||
[ext_resource type="Script" uid="uid://bjiap06gs02j" path="res://scenes/dragons/dragon_sprite.gd" id="1_oaoux"]
|
||||
|
@ -6,11 +6,21 @@
|
|||
[ext_resource type="Texture2D" uid="uid://dc2uk6tqtwl4n" path="res://assets/sprites/shirt.png" id="3_oaoux"]
|
||||
[ext_resource type="Texture2D" uid="uid://8srlwinjr3tt" path="res://assets/sprites/shoes.png" id="4_yf7bj"]
|
||||
|
||||
[node name="Dragon" type="Node2D" node_paths=PackedStringArray("hat", "shirt", "shoes")]
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_oaoux"]
|
||||
size = Vector2(128, 129)
|
||||
|
||||
[node name="Dragon" type="Node2D" node_paths=PackedStringArray("hat", "shirt", "shoes", "name_label")]
|
||||
script = ExtResource("1_oaoux")
|
||||
hat = NodePath("Sprite/Hat")
|
||||
shirt = NodePath("Sprite/Shirt")
|
||||
shoes = NodePath("Sprite/Shoes")
|
||||
name_label = NodePath("Label")
|
||||
|
||||
[node name="Area2D" type="Area2D" parent="."]
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
|
||||
position = Vector2(64, 64.5)
|
||||
shape = SubResource("RectangleShape2D_oaoux")
|
||||
|
||||
[node name="Sprite" type="Sprite2D" parent="."]
|
||||
position = Vector2(0, 1)
|
||||
|
@ -34,3 +44,16 @@ position = Vector2(48, 39)
|
|||
scale = Vector2(0.353516, 0.353516)
|
||||
texture = ExtResource("4_yf7bj")
|
||||
offset = Vector2(64, 64)
|
||||
|
||||
[node name="Label" type="Label" parent="."]
|
||||
offset_top = 105.0
|
||||
offset_right = 128.0
|
||||
offset_bottom = 128.0
|
||||
theme_override_colors/font_color = Color(1, 1, 1, 1)
|
||||
theme_override_colors/font_outline_color = Color(0, 0, 0, 1)
|
||||
theme_override_constants/outline_size = 5
|
||||
text = "AAAAAAAA"
|
||||
horizontal_alignment = 1
|
||||
|
||||
[connection signal="mouse_entered" from="Area2D" to="." method="_on_area_2d_mouse_entered"]
|
||||
[connection signal="mouse_exited" from="Area2D" to="." method="_on_area_2d_mouse_exited"]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue