Finish creating_the_enemy of first 2D game

This commit is contained in:
Daniel Siepmann 2024-03-26 13:10:49 +01:00
parent 8cdfeb2bf0
commit a0f5b4e46c
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
2 changed files with 86 additions and 0 deletions

16
first_2d_game/Mob.gd Normal file
View file

@ -0,0 +1,16 @@
extends RigidBody2D
# Called when the node enters the scene tree for the first time.
func _ready():
var mob_types = $AnimatedSprite2D.sprite_frames.get_animation_names()
$AnimatedSprite2D.play(mob_types[randi() % mob_types.size())
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
func _on_visible_on_screen_notifier_2d_screen_exited():
queue_free()

70
first_2d_game/Mob.tscn Normal file
View file

@ -0,0 +1,70 @@
[gd_scene load_steps=10 format=3 uid="uid://df0p8vv7unjvu"]
[ext_resource type="Script" path="res://Mob.gd" id="1_ruw5w"]
[ext_resource type="Texture2D" uid="uid://c7h0onxpmk5c8" path="res://art/enemyFlyingAlt_1.png" id="1_uocd3"]
[ext_resource type="Texture2D" uid="uid://cy5gxggbhkygu" path="res://art/enemyFlyingAlt_2.png" id="2_qj0wg"]
[ext_resource type="Texture2D" uid="uid://c1u4xbef5epal" path="res://art/enemySwimming_1.png" id="3_oyldi"]
[ext_resource type="Texture2D" uid="uid://d104l5k6mybqh" path="res://art/enemySwimming_2.png" id="4_dfafq"]
[ext_resource type="Texture2D" uid="uid://db0lge6cm2okp" path="res://art/enemyWalking_1.png" id="5_fig2k"]
[ext_resource type="Texture2D" uid="uid://wmp167o3rysb" path="res://art/enemyWalking_2.png" id="6_2ax1q"]
[sub_resource type="SpriteFrames" id="SpriteFrames_sy8sf"]
animations = [{
"frames": [{
"duration": 1.0,
"texture": ExtResource("1_uocd3")
}, {
"duration": 1.0,
"texture": ExtResource("2_qj0wg")
}],
"loop": true,
"name": &"fly",
"speed": 3.0
}, {
"frames": [{
"duration": 1.0,
"texture": ExtResource("3_oyldi")
}, {
"duration": 1.0,
"texture": ExtResource("4_dfafq")
}],
"loop": true,
"name": &"swim",
"speed": 3.0
}, {
"frames": [{
"duration": 1.0,
"texture": ExtResource("5_fig2k")
}, {
"duration": 1.0,
"texture": ExtResource("6_2ax1q")
}],
"loop": true,
"name": &"walk",
"speed": 3.0
}]
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_hklup"]
radius = 36.0
height = 96.0
[node name="Mob" type="RigidBody2D"]
collision_mask = 0
gravity_scale = 0.0
script = ExtResource("1_ruw5w")
metadata/_edit_group_ = true
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
scale = Vector2(0.75, 0.75)
sprite_frames = SubResource("SpriteFrames_sy8sf")
animation = &"walk"
frame = 1
frame_progress = 0.0804377
[node name="VisibleOnScreenNotifier2D" type="VisibleOnScreenNotifier2D" parent="."]
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
rotation = 1.5708
shape = SubResource("CapsuleShape2D_hklup")
[connection signal="screen_exited" from="VisibleOnScreenNotifier2D" to="." method="_on_visible_on_screen_notifier_2d_screen_exited"]