diff options
Diffstat (limited to 'Enemies')
-rw-r--r-- | Enemies/Enemy.tscn | 38 | ||||
-rw-r--r-- | Enemies/enemy.gd | 23 |
2 files changed, 61 insertions, 0 deletions
diff --git a/Enemies/Enemy.tscn b/Enemies/Enemy.tscn new file mode 100644 index 0000000..ac2cb22 --- /dev/null +++ b/Enemies/Enemy.tscn @@ -0,0 +1,38 @@ +[gd_scene load_steps=6 format=3 uid="uid://6d20yrqejxs8"] + +[ext_resource type="Texture2D" uid="uid://cduruhn8mecgn" path="res://Assets/Enemies/enemy-walk-01.png" id="1_v3aim"] +[ext_resource type="Script" path="res://Enemies/enemy.gd" id="1_x68ej"] +[ext_resource type="Texture2D" uid="uid://ysaejkoo1bnw" path="res://Assets/Enemies/enemy-walk-02.png" id="2_madb5"] + +[sub_resource type="CircleShape2D" id="CircleShape2D_p646n"] +radius = 8.0 + +[sub_resource type="SpriteFrames" id="SpriteFrames_n2gm8"] +animations = [{ +"frames": [{ +"duration": 1.0, +"texture": ExtResource("1_v3aim") +}, { +"duration": 1.0, +"texture": ExtResource("2_madb5") +}], +"loop": true, +"name": &"default", +"speed": 4.0 +}] + +[node name="Enemy" type="CharacterBody2D" groups=["enemy"]] +collision_layer = 2 +collision_mask = 17 +script = ExtResource("1_x68ej") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource("CircleShape2D_p646n") + +[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."] +texture_filter = 1 +sprite_frames = SubResource("SpriteFrames_n2gm8") + +[node name="VisibleOnScreenNotifier2D" type="VisibleOnScreenNotifier2D" parent="."] + +[connection signal="screen_entered" from="VisibleOnScreenNotifier2D" to="." method="_on_visible_on_screen_notifier_2d_screen_entered"] diff --git a/Enemies/enemy.gd b/Enemies/enemy.gd new file mode 100644 index 0000000..5818fb4 --- /dev/null +++ b/Enemies/enemy.gd @@ -0,0 +1,23 @@ +extends CharacterBody2D + + +const SPEED = 30 + + +func _ready() -> void: + set_physics_process(false) + + +func _physics_process(delta: float) -> void: + $AnimatedSprite2D.play() + + if not is_on_floor(): + velocity += get_gravity() * delta + + velocity.x = -SPEED + + move_and_slide() + + +func _on_visible_on_screen_notifier_2d_screen_entered() -> void: + set_physics_process(true) |