Skip to content

Commit 44e011b

Browse files
authored
Fray's End: Add collision shape to elders staff
Check that the spriteframe used exists and if its path ends with "elder2.tres". If it is met, flip horizontally the collisions of the staff and the body. Fix #401
1 parent cc7abc0 commit 44e011b

2 files changed

Lines changed: 26 additions & 4 deletions

File tree

scenes/game_elements/characters/npcs/elder/components/elder.gd

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,26 @@ var _storybook: Storybook
3333
@onready var talk_behavior: TalkBehavior = %TalkBehavior
3434
@onready var _book_sound: AudioStreamPlayer2D = %BookSound
3535
@onready var _storybook_layer: CanvasLayer = %StorybookLayer
36+
@onready var _shapes: Array[CollisionShape2D] = [$BodyShape, $StaffShape]
3637

3738

3839
func _ready() -> void:
3940
super._ready()
41+
42+
# Verify if the sprite_frames resource exists and matches the mirrored asset
43+
var is_mirrored := sprite_frames and sprite_frames.resource_path.ends_with("elder2.tres")
44+
45+
for shape in _shapes:
46+
if shape:
47+
# Mirror or reset X position depending on the resource path
48+
if is_mirrored:
49+
shape.position.x = -abs(shape.position.x)
50+
else:
51+
shape.position.x = abs(shape.position.x)
52+
4053
if Engine.is_editor_hint():
4154
return
55+
4256
talk_behavior.dialogue = dialogue
4357
talk_behavior.before_dialogue = _before_dialogue
4458
interact_area.interaction_ended.connect(_on_interaction_ended)

scenes/game_elements/characters/npcs/elder/elder.tscn

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[gd_scene load_steps=9 format=3 uid="uid://bytkm0r5fe5xb"]
1+
[gd_scene load_steps=10 format=3 uid="uid://bytkm0r5fe5xb"]
22

33
[ext_resource type="Script" uid="uid://dedhjloxblho6" path="res://scenes/game_elements/characters/npcs/elder/components/elder.gd" id="1_jlpjw"]
44
[ext_resource type="Resource" uid="uid://ykdgo73x62wa" path="res://scenes/game_elements/characters/npcs/elder/components/story_quest_starter.dialogue" id="2_kqtes"]
@@ -11,6 +11,10 @@
1111
radius = 12.0
1212
height = 74.0
1313

14+
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_ak236"]
15+
radius = 8.0
16+
height = 24.0
17+
1418
[sub_resource type="RectangleShape2D" id="RectangleShape2D_3eksq"]
1519
size = Vector2(67, 72)
1620

@@ -27,13 +31,17 @@ position = Vector2(0, -40)
2731
sprite_frames = ExtResource("3_ak236")
2832
animation = &"idle"
2933
autoplay = "idle"
30-
frame_progress = 0.757037
3134

32-
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
33-
position = Vector2(8, 0)
35+
[node name="BodyShape" type="CollisionShape2D" parent="."]
36+
position = Vector2(1, 0)
3437
rotation = -1.5708
3538
shape = SubResource("CapsuleShape2D_3vyb7")
3639

40+
[node name="StaffShape" type="CollisionShape2D" parent="."]
41+
position = Vector2(49, 15)
42+
rotation = 1.5708
43+
shape = SubResource("CapsuleShape2D_ak236")
44+
3745
[node name="InteractArea" type="Area2D" parent="."]
3846
unique_name_in_owner = true
3947
collision_layer = 32

0 commit comments

Comments
 (0)