From 1945726bd1ab2e0a015584c411fdafaa0f63d818 Mon Sep 17 00:00:00 2001 From: ItsDrike Date: Mon, 3 Mar 2025 22:57:23 +0100 Subject: [PATCH] Make slime killable --- scenes/slime.tscn | 12 +++++ scenes/ui.tscn | 113 ++++++++++++++++++++++++++-------------------- scripts/slime.gd | 17 ++++++- 3 files changed, 92 insertions(+), 50 deletions(-) diff --git a/scenes/slime.tscn b/scenes/slime.tscn index 3ae7e17..0ae8a20 100644 --- a/scenes/slime.tscn +++ b/scenes/slime.tscn @@ -47,12 +47,14 @@ size = Vector2(10, 12) script = ExtResource("1_yja1u") [node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."] +position = Vector2(-1, 0) sprite_frames = SubResource("SpriteFrames_ck5td") animation = &"idle" autoplay = "idle" frame_progress = 0.99564 [node name="KillZone" parent="." instance=ExtResource("2_4sy8s")] +position = Vector2(-1, 0) [node name="CollisionShape2D" type="CollisionShape2D" parent="KillZone"] position = Vector2(0, 6) @@ -66,3 +68,13 @@ target_position = Vector2(12, 0) position = Vector2(0, 6) rotation = -0.00269656 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 diff --git a/scenes/ui.tscn b/scenes/ui.tscn index 18100ea..425bf06 100644 --- a/scenes/ui.tscn +++ b/scenes/ui.tscn @@ -51,24 +51,37 @@ layout_mode = 3 anchors_preset = 15 anchor_right = 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_vertical = 2 script = ExtResource("1_ootcf") [node name="PlayerInfoBox" type="Panel" parent="."] -layout_mode = 0 -offset_left = 24.0 -offset_top = 17.0 -offset_right = 374.0 -offset_bottom = 119.0 +layout_mode = 1 +anchors_preset = -1 +anchor_left = 0.021 +anchor_top = 0.026 +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") [node name="UsernameText" type="Label" parent="PlayerInfoBox"] layout_mode = 1 -offset_left = 100.0 -offset_top = 17.0 -offset_right = 238.0 -offset_bottom = 50.0 +anchors_preset = -1 +anchor_left = 0.286 +anchor_top = 0.167 +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_font_sizes/font_size = 12 text = "ItsDrike" @@ -76,27 +89,28 @@ vertical_alignment = 1 [node name="AvatarFrame" type="Panel" parent="PlayerInfoBox"] layout_mode = 1 -anchors_preset = 4 -anchor_top = 0.5 -anchor_bottom = 0.5 -offset_left = 24.0 -offset_top = -39.5 -offset_right = 84.0 -offset_bottom = 30.5 +anchors_preset = -1 +anchor_left = 0.069 +anchor_top = 0.113 +anchor_right = 0.24 +anchor_bottom = 0.799 +offset_left = -0.150002 +offset_top = -0.026001 +offset_bottom = 0.0019989 grow_vertical = 2 theme_override_styles/panel = SubResource("StyleBoxFlat_8y3hb") [node name="Avatar" type="TextureRect" parent="PlayerInfoBox/AvatarFrame"] layout_mode = 1 -anchors_preset = 8 -anchor_left = 0.5 -anchor_top = 0.5 -anchor_right = 0.5 -anchor_bottom = 0.5 -offset_left = -22.0 -offset_top = -31.0 -offset_right = 22.0 -offset_bottom = 33.0 +anchors_preset = -1 +anchor_left = 0.133 +anchor_top = 0.057 +anchor_right = 0.867 +anchor_bottom = 0.971 +offset_left = 0.02 +offset_top = 0.00999975 +offset_right = -0.0200043 +offset_bottom = 0.0299911 grow_horizontal = 2 grow_vertical = 2 texture = SubResource("AtlasTexture_b1xc8") @@ -104,13 +118,14 @@ expand_mode = 5 [node name="CoinFrame" type="Panel" parent="PlayerInfoBox"] layout_mode = 1 -anchors_preset = 1 -anchor_left = 1.0 -anchor_right = 1.0 -offset_left = -112.0 -offset_top = 14.0 -offset_right = -18.0 -offset_bottom = 44.0 +anchors_preset = -1 +anchor_left = 0.68 +anchor_top = 0.137 +anchor_right = 0.949 +anchor_bottom = 0.431 +offset_top = 0.0259991 +offset_right = -0.150024 +offset_bottom = 0.0379982 grow_horizontal = 0 theme_override_styles/panel = SubResource("StyleBoxFlat_3l4nn") @@ -120,23 +135,23 @@ anchors_preset = 4 anchor_top = 0.5 anchor_bottom = 0.5 offset_left = 4.0 -offset_top = -16.5 -offset_right = 36.0 -offset_bottom = 15.5 +offset_top = -15.0 +offset_right = 32.0 +offset_bottom = 14.0 grow_vertical = 2 texture = SubResource("AtlasTexture_hl771") expand_mode = 1 [node name="CoinAmountText" type="Label" parent="PlayerInfoBox/CoinFrame"] layout_mode = 1 -anchors_preset = 6 -anchor_left = 1.0 -anchor_top = 0.5 +anchors_preset = -1 +anchor_left = 0.426 +anchor_top = 0.15 anchor_right = 1.0 anchor_bottom = 0.5 -offset_left = -54.0 -offset_top = -10.5 -offset_bottom = 12.5 +offset_left = -4.044 +offset_top = -4.5 +offset_bottom = 15.0 grow_horizontal = 0 grow_vertical = 2 theme_override_fonts/font = ExtResource("3_7c0yq") @@ -146,14 +161,14 @@ vertical_alignment = 1 [node name="ExperienceProgress" type="ProgressBar" parent="PlayerInfoBox"] layout_mode = 1 -anchors_preset = 12 -anchor_top = 1.0 -anchor_right = 1.0 -anchor_bottom = 1.0 -offset_left = 100.0 -offset_top = -51.0 -offset_right = -18.0 -offset_bottom = -24.0 +anchors_preset = -1 +anchor_left = 0.286 +anchor_top = 0.5 +anchor_right = 0.949 +anchor_bottom = 0.765 +offset_left = -0.100006 +offset_right = -0.150024 +offset_bottom = -0.0300064 grow_horizontal = 2 grow_vertical = 0 theme_override_fonts/font = ExtResource("3_7c0yq") diff --git a/scripts/slime.gd b/scripts/slime.gd index 29d389e..a0038a5 100644 --- a/scripts/slime.gd +++ b/scripts/slime.gd @@ -4,12 +4,27 @@ extends Node2D @onready var ray_cast_right: RayCast2D = $RayCastRight @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 var direction = 1 -# Called every frame. 'delta' is the elapsed time since the previous frame. 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(): direction = -1 animated_sprite.flip_h = true