Fix enemy direction
This commit is contained in:
parent
817680d377
commit
42daf02e72
5 changed files with 200 additions and 108 deletions
|
@ -1,106 +0,0 @@
|
|||
[gd_scene load_steps=14 format=3 uid="uid://bdkpehb7sykww"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/enemies/enemy.gd" id="1_b4ul5"]
|
||||
[ext_resource type="Texture2D" uid="uid://b046l0oy0hyj2" path="res://assets/spritesheets/enemy-1.png" id="2_v0ees"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_17kv3"]
|
||||
atlas = ExtResource("2_v0ees")
|
||||
region = Rect2(0, 1, 188, 188)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_1wwrx"]
|
||||
atlas = ExtResource("2_v0ees")
|
||||
region = Rect2(188, 1, 188, 188)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_xvkeb"]
|
||||
atlas = ExtResource("2_v0ees")
|
||||
region = Rect2(376, 1, 188, 188)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_usecb"]
|
||||
atlas = ExtResource("2_v0ees")
|
||||
region = Rect2(564, 1, 188, 188)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_pq6ve"]
|
||||
atlas = ExtResource("2_v0ees")
|
||||
region = Rect2(752, 1, 188, 188)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_ni7yh"]
|
||||
atlas = ExtResource("2_v0ees")
|
||||
region = Rect2(0, 189, 188, 188)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_kmn0w"]
|
||||
atlas = ExtResource("2_v0ees")
|
||||
region = Rect2(188, 189, 188, 188)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_v3qv0"]
|
||||
atlas = ExtResource("2_v0ees")
|
||||
region = Rect2(376, 189, 188, 188)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_hmvpc"]
|
||||
atlas = ExtResource("2_v0ees")
|
||||
region = Rect2(564, 189, 188, 188)
|
||||
|
||||
[sub_resource type="SpriteFrames" id="SpriteFrames_kipn1"]
|
||||
animations = [{
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_17kv3")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_1wwrx")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_xvkeb")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_usecb")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_pq6ve")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_ni7yh")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_kmn0w")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_v3qv0")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_hmvpc")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"default",
|
||||
"speed": 5.0
|
||||
}]
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_5hy1j"]
|
||||
radius = 18.9995
|
||||
height = 39.999
|
||||
|
||||
[node name="Enemy" type="PathFollow2D"]
|
||||
rotation = 0.00699289
|
||||
loop = false
|
||||
script = ExtResource("1_b4ul5")
|
||||
|
||||
[node name="EnemyBody" type="CharacterBody2D" parent="." groups=["Enemy"]]
|
||||
|
||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="EnemyBody"]
|
||||
position = Vector2(9.15527e-05, 0.00012207)
|
||||
scale = Vector2(0.176347, 0.175058)
|
||||
sprite_frames = SubResource("SpriteFrames_kipn1")
|
||||
autoplay = "default"
|
||||
frame_progress = 0.735051
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="EnemyBody"]
|
||||
position = Vector2(-0.992983, 1.00696)
|
||||
shape = SubResource("CapsuleShape2D_5hy1j")
|
||||
|
||||
[node name="HealthBar" type="ProgressBar" parent="EnemyBody"]
|
||||
modulate = Color(0.431373, 0.815686, 0, 1)
|
||||
offset_left = -15.1814
|
||||
offset_top = -25.8945
|
||||
offset_right = 86.8186
|
||||
offset_bottom = 1.10553
|
||||
scale = Vector2(0.3, 0.3)
|
||||
show_percentage = false
|
171
scenes/enemies/orc.tscn
Normal file
171
scenes/enemies/orc.tscn
Normal file
|
@ -0,0 +1,171 @@
|
|||
[gd_scene load_steps=21 format=3 uid="uid://dldnbqg4oc3my"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/enemies/enemy.gd" id="1_7wn36"]
|
||||
[ext_resource type="Texture2D" uid="uid://ddot33oyu6vlh" path="res://assets/spritesheets/enemies/orc.png" id="2_mmtjp"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_q1cra"]
|
||||
atlas = ExtResource("2_mmtjp")
|
||||
region = Rect2(1536, 2048, 512, 512)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_5omxp"]
|
||||
atlas = ExtResource("2_mmtjp")
|
||||
region = Rect2(0, 2560, 512, 512)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_8gkeg"]
|
||||
atlas = ExtResource("2_mmtjp")
|
||||
region = Rect2(512, 2560, 512, 512)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_ahq7s"]
|
||||
atlas = ExtResource("2_mmtjp")
|
||||
region = Rect2(1024, 2560, 512, 512)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_oqxmm"]
|
||||
atlas = ExtResource("2_mmtjp")
|
||||
region = Rect2(1536, 0, 512, 512)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_beao0"]
|
||||
atlas = ExtResource("2_mmtjp")
|
||||
region = Rect2(0, 512, 512, 512)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_4642r"]
|
||||
atlas = ExtResource("2_mmtjp")
|
||||
region = Rect2(512, 512, 512, 512)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_u131r"]
|
||||
atlas = ExtResource("2_mmtjp")
|
||||
region = Rect2(1024, 512, 512, 512)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_xq474"]
|
||||
atlas = ExtResource("2_mmtjp")
|
||||
region = Rect2(1536, 4096, 512, 512)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_ux3e3"]
|
||||
atlas = ExtResource("2_mmtjp")
|
||||
region = Rect2(0, 4608, 512, 512)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_o0ky4"]
|
||||
atlas = ExtResource("2_mmtjp")
|
||||
region = Rect2(512, 4608, 512, 512)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_mbwp0"]
|
||||
atlas = ExtResource("2_mmtjp")
|
||||
region = Rect2(1024, 4608, 512, 512)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_hiwr4"]
|
||||
atlas = ExtResource("2_mmtjp")
|
||||
region = Rect2(1536, 6144, 512, 512)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_0g3a4"]
|
||||
atlas = ExtResource("2_mmtjp")
|
||||
region = Rect2(0, 6656, 512, 512)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_cuf0k"]
|
||||
atlas = ExtResource("2_mmtjp")
|
||||
region = Rect2(512, 6656, 512, 512)
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_g34yj"]
|
||||
atlas = ExtResource("2_mmtjp")
|
||||
region = Rect2(1024, 6656, 512, 512)
|
||||
|
||||
[sub_resource type="SpriteFrames" id="SpriteFrames_ebg80"]
|
||||
animations = [{
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_q1cra")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_5omxp")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_8gkeg")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_ahq7s")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"back",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_oqxmm")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_beao0")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_4642r")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_u131r")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"front",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_xq474")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_ux3e3")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_o0ky4")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_mbwp0")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"left",
|
||||
"speed": 5.0
|
||||
}, {
|
||||
"frames": [{
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_hiwr4")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_0g3a4")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_cuf0k")
|
||||
}, {
|
||||
"duration": 1.0,
|
||||
"texture": SubResource("AtlasTexture_g34yj")
|
||||
}],
|
||||
"loop": true,
|
||||
"name": &"right",
|
||||
"speed": 5.0
|
||||
}]
|
||||
|
||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_5hy1j"]
|
||||
radius = 21.0065
|
||||
height = 42.013
|
||||
|
||||
[node name="Enemy" type="PathFollow2D"]
|
||||
rotation = 0.00699289
|
||||
rotates = false
|
||||
loop = false
|
||||
script = ExtResource("1_7wn36")
|
||||
|
||||
[node name="EnemyBody" type="CharacterBody2D" parent="." groups=["Enemy"]]
|
||||
|
||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="EnemyBody"]
|
||||
position = Vector2(9.15527e-05, 0.00012207)
|
||||
scale = Vector2(0.09, 0.089)
|
||||
sprite_frames = SubResource("SpriteFrames_ebg80")
|
||||
animation = &"right"
|
||||
autoplay = "right"
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="EnemyBody"]
|
||||
position = Vector2(-0.992983, 1.00696)
|
||||
shape = SubResource("CapsuleShape2D_5hy1j")
|
||||
|
||||
[node name="HealthBar" type="ProgressBar" parent="EnemyBody"]
|
||||
modulate = Color(0.431373, 0.815686, 0, 1)
|
||||
offset_left = -15.1814
|
||||
offset_top = -25.8945
|
||||
offset_right = 86.8186
|
||||
offset_bottom = 1.10553
|
||||
scale = Vector2(0.3, 0.3)
|
||||
show_percentage = false
|
|
@ -4,6 +4,8 @@ var config = null
|
|||
var enemy_id: int = 0
|
||||
var health: int = 0
|
||||
var speed: int = 0
|
||||
var direction_progress = []
|
||||
var direction = []
|
||||
|
||||
func set_config(config_path):
|
||||
config = load(config_path).new()
|
||||
|
@ -12,12 +14,26 @@ func set_enemy(id: int):
|
|||
enemy_id = id
|
||||
health = config.enemy[enemy_id]['health']
|
||||
speed = config.enemy[enemy_id]['speed']
|
||||
|
||||
func set_direction():
|
||||
var path_direction = config.game['path_direction']
|
||||
for x in path_direction:
|
||||
direction_progress.append(x['progress'])
|
||||
direction.append(x['direction'])
|
||||
|
||||
func _process(delta):
|
||||
update_healthbar()
|
||||
change_direction(get_progress())
|
||||
if health <= 0:
|
||||
queue_free()
|
||||
set_progress(get_progress() + speed * delta)
|
||||
|
||||
func change_direction(current_progress):
|
||||
if !direction_progress.is_empty():
|
||||
if current_progress > direction_progress[0]:
|
||||
$EnemyBody/AnimatedSprite2D.play(direction[0])
|
||||
direction_progress.erase(direction_progress[0])
|
||||
direction.erase(direction[0])
|
||||
|
||||
func update_healthbar():
|
||||
$EnemyBody/HealthBar.value = health
|
||||
|
|
|
@ -4,7 +4,17 @@ class_name Config
|
|||
|
||||
var game = {
|
||||
"spawn_timer": 3.0,
|
||||
"offset": [-30.0, 30.0]
|
||||
"offset": [-30.0, 30.0],
|
||||
"path_direction": [
|
||||
{
|
||||
"progress": 570,
|
||||
"direction": "front"
|
||||
},
|
||||
{
|
||||
"progress": 855,
|
||||
"direction": "right"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
var menu = [
|
||||
|
|
|
@ -7,7 +7,7 @@ var config = load(config_path).new()
|
|||
|
||||
var spawn_first: bool = true
|
||||
|
||||
var enemy: PackedScene = preload("res://scenes/enemies/enemy_1.tscn")
|
||||
var enemy: PackedScene = preload("res://scenes/enemies/orc.tscn")
|
||||
|
||||
func _ready():
|
||||
summon()
|
||||
|
@ -25,4 +25,5 @@ func summon():
|
|||
add_child(enemy_instance)
|
||||
enemy_instance.set_config(config_path)
|
||||
enemy_instance.set_enemy(0)
|
||||
enemy_instance.set_direction()
|
||||
enemy_instance.set_v_offset(rng.randf_range(config.game['offset'][0], config.game['offset'][1]))
|
||||
|
|
Loading…
Reference in a new issue