From deec0fb581e8985e6ce89b5c79f545ae855b42e2 Mon Sep 17 00:00:00 2001 From: Foohoo Date: Tue, 21 Oct 2025 11:31:32 +0100 Subject: [PATCH] add enemy slime --- scenes/game.tscn | 36 +++++++++++++----------- scenes/slime.tscn | 67 ++++++++++++++++++++++++++++++++++++++++++++ scripts/slime.gd | 21 ++++++++++++++ scripts/slime.gd.uid | 1 + 4 files changed, 109 insertions(+), 16 deletions(-) create mode 100644 scenes/slime.tscn create mode 100644 scripts/slime.gd create mode 100644 scripts/slime.gd.uid diff --git a/scenes/game.tscn b/scenes/game.tscn index 761bf4d..3826004 100644 --- a/scenes/game.tscn +++ b/scenes/game.tscn @@ -1,10 +1,11 @@ -[gd_scene load_steps=14 format=4 uid="uid://cy3dg66pt8abt"] +[gd_scene load_steps=15 format=4 uid="uid://cy3dg66pt8abt"] [ext_resource type="PackedScene" uid="uid://3wumh6kpw3ai" path="res://scenes/player.tscn" id="1_uwrxv"] [ext_resource type="Texture2D" uid="uid://0syymy7ijylx" path="res://assets/sprites/world_tileset.png" id="1_yqjtg"] [ext_resource type="PackedScene" uid="uid://xacwq0rohthg" path="res://scenes/platform.tscn" id="3_lnu2h"] [ext_resource type="PackedScene" uid="uid://dotk5aceo1m0k" path="res://scenes/coin.tscn" id="4_lbhrr"] [ext_resource type="PackedScene" uid="uid://dpox5fa2pojpo" path="res://scenes/killzone.tscn" id="5_iywne"] +[ext_resource type="PackedScene" uid="uid://bvw0afyajdmht" path="res://scenes/slime.tscn" id="6_p57ef"] [sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_iywne"] texture = ExtResource("1_yqjtg") @@ -307,6 +308,21 @@ sources/0 = SubResource("TileSetAtlasSource_lnu2h") [sub_resource type="WorldBoundaryShape2D" id="WorldBoundaryShape2D_iywne"] +[sub_resource type="Animation" id="Animation_lbhrr"] +length = 0.001 +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath(".:position") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 0, +"values": [Vector2(370, 69)] +} + [sub_resource type="Animation" id="Animation_lnu2h"] resource_name = "move" length = 2.0 @@ -324,21 +340,6 @@ tracks/0/keys = { "values": [Vector2(370, 69), Vector2(481, 69)] } -[sub_resource type="Animation" id="Animation_lbhrr"] -length = 0.001 -tracks/0/type = "value" -tracks/0/imported = false -tracks/0/enabled = true -tracks/0/path = NodePath(".:position") -tracks/0/interp = 1 -tracks/0/loop_wrap = true -tracks/0/keys = { -"times": PackedFloat32Array(0), -"transitions": PackedFloat32Array(1), -"update": 0, -"values": [Vector2(370, 69)] -} - [sub_resource type="AnimationLibrary" id="AnimationLibrary_iywne"] _data = { &"RESET": SubResource("Animation_lbhrr"), @@ -418,3 +419,6 @@ libraries = { &"": SubResource("AnimationLibrary_iywne") } autoplay = "move" + +[node name="Slime" parent="." instance=ExtResource("6_p57ef")] +position = Vector2(569, 96) diff --git a/scenes/slime.tscn b/scenes/slime.tscn new file mode 100644 index 0000000..c15fbec --- /dev/null +++ b/scenes/slime.tscn @@ -0,0 +1,67 @@ +[gd_scene load_steps=10 format=3 uid="uid://bvw0afyajdmht"] + +[ext_resource type="Script" uid="uid://cxpc8xcf3r6rg" path="res://scripts/slime.gd" id="1_n6pvg"] +[ext_resource type="Texture2D" uid="uid://do7enjpf3pftb" path="res://assets/sprites/slime_green.png" id="1_p2gj0"] +[ext_resource type="PackedScene" uid="uid://dpox5fa2pojpo" path="res://scenes/killzone.tscn" id="2_n6pvg"] + +[sub_resource type="AtlasTexture" id="AtlasTexture_pjw23"] +atlas = ExtResource("1_p2gj0") +region = Rect2(0, 24, 24, 24) + +[sub_resource type="AtlasTexture" id="AtlasTexture_2npkn"] +atlas = ExtResource("1_p2gj0") +region = Rect2(24, 24, 24, 24) + +[sub_resource type="AtlasTexture" id="AtlasTexture_fd6lc"] +atlas = ExtResource("1_p2gj0") +region = Rect2(48, 24, 24, 24) + +[sub_resource type="AtlasTexture" id="AtlasTexture_gstla"] +atlas = ExtResource("1_p2gj0") +region = Rect2(72, 24, 24, 24) + +[sub_resource type="SpriteFrames" id="SpriteFrames_v5wyi"] +animations = [{ +"frames": [{ +"duration": 1.0, +"texture": SubResource("AtlasTexture_pjw23") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_2npkn") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_fd6lc") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_gstla") +}], +"loop": true, +"name": &"default", +"speed": 7.0 +}] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_0l8pv"] +size = Vector2(10, 13) + +[node name="Slime" type="Node2D"] +script = ExtResource("1_n6pvg") + +[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."] +position = Vector2(0, -12) +sprite_frames = SubResource("SpriteFrames_v5wyi") +autoplay = "default" +frame_progress = 0.45857617 + +[node name="Killzone" parent="." instance=ExtResource("2_n6pvg")] + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Killzone"] +position = Vector2(0, -6.5) +shape = SubResource("RectangleShape2D_0l8pv") + +[node name="RayCastRight" type="RayCast2D" parent="."] +position = Vector2(0, -6) +target_position = Vector2(8, 0) + +[node name="RayCastLeft" type="RayCast2D" parent="."] +position = Vector2(0, -6) +target_position = Vector2(-9, 0) diff --git a/scripts/slime.gd b/scripts/slime.gd new file mode 100644 index 0000000..66ac133 --- /dev/null +++ b/scripts/slime.gd @@ -0,0 +1,21 @@ +extends Node2D + +@export var speed = 60 + +var direction = 1 + +@onready var ray_cast_right: RayCast2D = $RayCastRight +@onready var ray_cast_left: RayCast2D = $RayCastLeft +@onready var animated_sprite: AnimatedSprite2D = $AnimatedSprite2D + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta: float) -> void: + if ray_cast_right.is_colliding(): + direction = -1 + animated_sprite.flip_h = true + + if ray_cast_left.is_colliding(): + direction = 1 + animated_sprite.flip_h = false + + position.x += direction * speed * delta diff --git a/scripts/slime.gd.uid b/scripts/slime.gd.uid new file mode 100644 index 0000000..2b5d7b2 --- /dev/null +++ b/scripts/slime.gd.uid @@ -0,0 +1 @@ +uid://cxpc8xcf3r6rg