Make slime killable

This commit is contained in:
ItsDrike 2025-03-03 22:57:23 +01:00
parent 0f056ccfd7
commit 1945726bd1
Signed by: ItsDrike
GPG key ID: FA2745890B7048C0
3 changed files with 92 additions and 50 deletions

View file

@ -47,12 +47,14 @@ size = Vector2(10, 12)
script = ExtResource("1_yja1u") script = ExtResource("1_yja1u")
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."] [node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
position = Vector2(-1, 0)
sprite_frames = SubResource("SpriteFrames_ck5td") sprite_frames = SubResource("SpriteFrames_ck5td")
animation = &"idle" animation = &"idle"
autoplay = "idle" autoplay = "idle"
frame_progress = 0.99564 frame_progress = 0.99564
[node name="KillZone" parent="." instance=ExtResource("2_4sy8s")] [node name="KillZone" parent="." instance=ExtResource("2_4sy8s")]
position = Vector2(-1, 0)
[node name="CollisionShape2D" type="CollisionShape2D" parent="KillZone"] [node name="CollisionShape2D" type="CollisionShape2D" parent="KillZone"]
position = Vector2(0, 6) position = Vector2(0, 6)
@ -66,3 +68,13 @@ target_position = Vector2(12, 0)
position = Vector2(0, 6) position = Vector2(0, 6)
rotation = -0.00269656 rotation = -0.00269656
target_position = Vector2(-12, 0) target_position = Vector2(-12, 0)
[node name="RayCastTopLeft" type="RayCast2D" parent="."]
position = Vector2(-5, 0)
target_position = Vector2(0, -7)
collision_mask = 2
[node name="RayCastTopRight" type="RayCast2D" parent="."]
position = Vector2(3, 0)
target_position = Vector2(0, -7)
collision_mask = 2

View file

@ -51,24 +51,37 @@ layout_mode = 3
anchors_preset = 15 anchors_preset = 15
anchor_right = 1.0 anchor_right = 1.0
anchor_bottom = 1.0 anchor_bottom = 1.0
offset_left = -5.0
offset_top = -2.0
offset_right = -5.0
offset_bottom = -2.0
grow_horizontal = 2 grow_horizontal = 2
grow_vertical = 2 grow_vertical = 2
script = ExtResource("1_ootcf") script = ExtResource("1_ootcf")
[node name="PlayerInfoBox" type="Panel" parent="."] [node name="PlayerInfoBox" type="Panel" parent="."]
layout_mode = 0 layout_mode = 1
offset_left = 24.0 anchors_preset = -1
offset_top = 17.0 anchor_left = 0.021
offset_right = 374.0 anchor_top = 0.026
offset_bottom = 119.0 anchor_right = 0.021
anchor_bottom = 0.026
offset_left = -0.192001
offset_top = 0.152
offset_right = 349.808
offset_bottom = 102.152
theme_override_styles/panel = SubResource("StyleBoxFlat_uwkun") theme_override_styles/panel = SubResource("StyleBoxFlat_uwkun")
[node name="UsernameText" type="Label" parent="PlayerInfoBox"] [node name="UsernameText" type="Label" parent="PlayerInfoBox"]
layout_mode = 1 layout_mode = 1
offset_left = 100.0 anchors_preset = -1
offset_top = 17.0 anchor_left = 0.286
offset_right = 238.0 anchor_top = 0.167
offset_bottom = 50.0 anchor_right = 0.68
anchor_bottom = 0.49
offset_left = -0.100006
offset_top = -0.0340004
offset_bottom = 0.0200005
theme_override_fonts/font = ExtResource("1_qrd6w") theme_override_fonts/font = ExtResource("1_qrd6w")
theme_override_font_sizes/font_size = 12 theme_override_font_sizes/font_size = 12
text = "ItsDrike" text = "ItsDrike"
@ -76,27 +89,28 @@ vertical_alignment = 1
[node name="AvatarFrame" type="Panel" parent="PlayerInfoBox"] [node name="AvatarFrame" type="Panel" parent="PlayerInfoBox"]
layout_mode = 1 layout_mode = 1
anchors_preset = 4 anchors_preset = -1
anchor_top = 0.5 anchor_left = 0.069
anchor_bottom = 0.5 anchor_top = 0.113
offset_left = 24.0 anchor_right = 0.24
offset_top = -39.5 anchor_bottom = 0.799
offset_right = 84.0 offset_left = -0.150002
offset_bottom = 30.5 offset_top = -0.026001
offset_bottom = 0.0019989
grow_vertical = 2 grow_vertical = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_8y3hb") theme_override_styles/panel = SubResource("StyleBoxFlat_8y3hb")
[node name="Avatar" type="TextureRect" parent="PlayerInfoBox/AvatarFrame"] [node name="Avatar" type="TextureRect" parent="PlayerInfoBox/AvatarFrame"]
layout_mode = 1 layout_mode = 1
anchors_preset = 8 anchors_preset = -1
anchor_left = 0.5 anchor_left = 0.133
anchor_top = 0.5 anchor_top = 0.057
anchor_right = 0.5 anchor_right = 0.867
anchor_bottom = 0.5 anchor_bottom = 0.971
offset_left = -22.0 offset_left = 0.02
offset_top = -31.0 offset_top = 0.00999975
offset_right = 22.0 offset_right = -0.0200043
offset_bottom = 33.0 offset_bottom = 0.0299911
grow_horizontal = 2 grow_horizontal = 2
grow_vertical = 2 grow_vertical = 2
texture = SubResource("AtlasTexture_b1xc8") texture = SubResource("AtlasTexture_b1xc8")
@ -104,13 +118,14 @@ expand_mode = 5
[node name="CoinFrame" type="Panel" parent="PlayerInfoBox"] [node name="CoinFrame" type="Panel" parent="PlayerInfoBox"]
layout_mode = 1 layout_mode = 1
anchors_preset = 1 anchors_preset = -1
anchor_left = 1.0 anchor_left = 0.68
anchor_right = 1.0 anchor_top = 0.137
offset_left = -112.0 anchor_right = 0.949
offset_top = 14.0 anchor_bottom = 0.431
offset_right = -18.0 offset_top = 0.0259991
offset_bottom = 44.0 offset_right = -0.150024
offset_bottom = 0.0379982
grow_horizontal = 0 grow_horizontal = 0
theme_override_styles/panel = SubResource("StyleBoxFlat_3l4nn") theme_override_styles/panel = SubResource("StyleBoxFlat_3l4nn")
@ -120,23 +135,23 @@ anchors_preset = 4
anchor_top = 0.5 anchor_top = 0.5
anchor_bottom = 0.5 anchor_bottom = 0.5
offset_left = 4.0 offset_left = 4.0
offset_top = -16.5 offset_top = -15.0
offset_right = 36.0 offset_right = 32.0
offset_bottom = 15.5 offset_bottom = 14.0
grow_vertical = 2 grow_vertical = 2
texture = SubResource("AtlasTexture_hl771") texture = SubResource("AtlasTexture_hl771")
expand_mode = 1 expand_mode = 1
[node name="CoinAmountText" type="Label" parent="PlayerInfoBox/CoinFrame"] [node name="CoinAmountText" type="Label" parent="PlayerInfoBox/CoinFrame"]
layout_mode = 1 layout_mode = 1
anchors_preset = 6 anchors_preset = -1
anchor_left = 1.0 anchor_left = 0.426
anchor_top = 0.5 anchor_top = 0.15
anchor_right = 1.0 anchor_right = 1.0
anchor_bottom = 0.5 anchor_bottom = 0.5
offset_left = -54.0 offset_left = -4.044
offset_top = -10.5 offset_top = -4.5
offset_bottom = 12.5 offset_bottom = 15.0
grow_horizontal = 0 grow_horizontal = 0
grow_vertical = 2 grow_vertical = 2
theme_override_fonts/font = ExtResource("3_7c0yq") theme_override_fonts/font = ExtResource("3_7c0yq")
@ -146,14 +161,14 @@ vertical_alignment = 1
[node name="ExperienceProgress" type="ProgressBar" parent="PlayerInfoBox"] [node name="ExperienceProgress" type="ProgressBar" parent="PlayerInfoBox"]
layout_mode = 1 layout_mode = 1
anchors_preset = 12 anchors_preset = -1
anchor_top = 1.0 anchor_left = 0.286
anchor_right = 1.0 anchor_top = 0.5
anchor_bottom = 1.0 anchor_right = 0.949
offset_left = 100.0 anchor_bottom = 0.765
offset_top = -51.0 offset_left = -0.100006
offset_right = -18.0 offset_right = -0.150024
offset_bottom = -24.0 offset_bottom = -0.0300064
grow_horizontal = 2 grow_horizontal = 2
grow_vertical = 0 grow_vertical = 0
theme_override_fonts/font = ExtResource("3_7c0yq") theme_override_fonts/font = ExtResource("3_7c0yq")

View file

@ -4,12 +4,27 @@ extends Node2D
@onready var ray_cast_right: RayCast2D = $RayCastRight @onready var ray_cast_right: RayCast2D = $RayCastRight
@onready var ray_cast_left: RayCast2D = $RayCastLeft @onready var ray_cast_left: RayCast2D = $RayCastLeft
@onready var ray_cast_top_left: RayCast2D = $RayCastTopLeft
@onready var ray_cast_top_right: RayCast2D = $RayCastTopRight
@onready var animated_sprite: AnimatedSprite2D = $AnimatedSprite2D @onready var animated_sprite: AnimatedSprite2D = $AnimatedSprite2D
var direction = 1 var direction = 1
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void: func _process(delta: float) -> void:
if direction == 1 and animated_sprite.flip_h == false:
animated_sprite.flip_h = true
if direction == -1 and animated_sprite.flip_h == true:
animated_sprite.flip_h = false
func _physics_process(delta: float) -> void:
move(delta)
if ray_cast_top_left.is_colliding() or ray_cast_top_right.is_colliding():
queue_free()
func move(delta: float) -> void:
"""Keep moving from left to right, changing direction when near something."""
if direction == 1 and ray_cast_right.is_colliding(): if direction == 1 and ray_cast_right.is_colliding():
direction = -1 direction = -1
animated_sprite.flip_h = true animated_sprite.flip_h = true