Add animation when the enemy die
This commit is contained in:
parent
bc72c1ef01
commit
a281d40bf5
8 changed files with 58 additions and 12 deletions
|
@ -305,4 +305,9 @@ show_percentage = false
|
|||
[node name="SlowTimer" type="Timer" parent="EnemyBody"]
|
||||
one_shot = true
|
||||
|
||||
[node name="DeadTimer" type="Timer" parent="EnemyBody"]
|
||||
wait_time = 3.0
|
||||
one_shot = true
|
||||
|
||||
[connection signal="timeout" from="EnemyBody/SlowTimer" to="." method="_on_slow_timer_timeout"]
|
||||
[connection signal="timeout" from="EnemyBody/DeadTimer" to="." method="_on_dead_timer_timeout"]
|
||||
|
|
|
@ -305,4 +305,9 @@ show_percentage = false
|
|||
[node name="SlowTimer" type="Timer" parent="EnemyBody"]
|
||||
one_shot = true
|
||||
|
||||
[node name="DeadTimer" type="Timer" parent="EnemyBody"]
|
||||
wait_time = 3.0
|
||||
one_shot = true
|
||||
|
||||
[connection signal="timeout" from="EnemyBody/SlowTimer" to="." method="_on_slow_timer_timeout"]
|
||||
[connection signal="timeout" from="EnemyBody/DeadTimer" to="." method="_on_dead_timer_timeout"]
|
||||
|
|
|
@ -305,4 +305,9 @@ show_percentage = false
|
|||
[node name="SlowTimer" type="Timer" parent="EnemyBody"]
|
||||
one_shot = true
|
||||
|
||||
[node name="DeadTimer" type="Timer" parent="EnemyBody"]
|
||||
wait_time = 3.0
|
||||
one_shot = true
|
||||
|
||||
[connection signal="timeout" from="EnemyBody/SlowTimer" to="." method="_on_slow_timer_timeout"]
|
||||
[connection signal="timeout" from="EnemyBody/DeadTimer" to="." method="_on_dead_timer_timeout"]
|
||||
|
|
|
@ -305,4 +305,9 @@ show_percentage = false
|
|||
[node name="SlowTimer" type="Timer" parent="EnemyBody"]
|
||||
one_shot = true
|
||||
|
||||
[node name="DeadTimer" type="Timer" parent="EnemyBody"]
|
||||
wait_time = 3.0
|
||||
one_shot = true
|
||||
|
||||
[connection signal="timeout" from="EnemyBody/SlowTimer" to="." method="_on_slow_timer_timeout"]
|
||||
[connection signal="timeout" from="EnemyBody/DeadTimer" to="." method="_on_dead_timer_timeout"]
|
||||
|
|
|
@ -305,4 +305,9 @@ show_percentage = false
|
|||
[node name="SlowTimer" type="Timer" parent="EnemyBody"]
|
||||
one_shot = true
|
||||
|
||||
[node name="DeadTimer" type="Timer" parent="EnemyBody"]
|
||||
wait_time = 3.0
|
||||
one_shot = true
|
||||
|
||||
[connection signal="timeout" from="EnemyBody/SlowTimer" to="." method="_on_slow_timer_timeout"]
|
||||
[connection signal="timeout" from="EnemyBody/DeadTimer" to="." method="_on_dead_timer_timeout"]
|
||||
|
|
|
@ -305,4 +305,9 @@ show_percentage = false
|
|||
[node name="SlowTimer" type="Timer" parent="EnemyBody"]
|
||||
one_shot = true
|
||||
|
||||
[node name="DeadTimer" type="Timer" parent="EnemyBody"]
|
||||
wait_time = 3.0
|
||||
one_shot = true
|
||||
|
||||
[connection signal="timeout" from="EnemyBody/SlowTimer" to="." method="_on_slow_timer_timeout"]
|
||||
[connection signal="timeout" from="EnemyBody/DeadTimer" to="." method="_on_dead_timer_timeout"]
|
||||
|
|
|
@ -8,11 +8,13 @@ var speed: float = 0
|
|||
var reward: int = 0
|
||||
var direction_progress = []
|
||||
var direction = []
|
||||
var current_direction = ''
|
||||
|
||||
var enemy_vol = Vector2(1,1)
|
||||
var old_enemy_pos
|
||||
var max_health: int = 0
|
||||
var is_slow: bool = false
|
||||
var is_dead: bool = false
|
||||
|
||||
func set_config(config_path):
|
||||
config = load(config_path).new()
|
||||
|
@ -40,17 +42,25 @@ func _ready():
|
|||
func _process(delta):
|
||||
update_healthbar()
|
||||
change_direction(get_progress())
|
||||
if health < 1:
|
||||
get_tree().current_scene.on_enemy_reward(reward)
|
||||
queue_free()
|
||||
set_progress(get_progress() + speed * delta)
|
||||
enemy_vol = global_position - old_enemy_pos
|
||||
old_enemy_pos = global_position
|
||||
if !is_dead:
|
||||
if health < 1:
|
||||
is_dead = true
|
||||
$EnemyBody.remove_from_group("Enemy")
|
||||
$EnemyBody/AnimatedSprite2D.play("{direction}_dead".format({"direction": current_direction}))
|
||||
get_tree().current_scene.on_enemy_reward(reward)
|
||||
$EnemyBody/DeadTimer.start()
|
||||
|
||||
set_progress(get_progress() + speed * delta)
|
||||
enemy_vol = global_position - old_enemy_pos
|
||||
old_enemy_pos = global_position
|
||||
else:
|
||||
$EnemyBody/HealthBar.visible = false
|
||||
|
||||
func change_direction(current_progress):
|
||||
if !direction_progress.is_empty():
|
||||
if current_progress > direction_progress[0]:
|
||||
$EnemyBody/AnimatedSprite2D.play(direction[0])
|
||||
current_direction = direction[0]
|
||||
direction_progress.erase(direction_progress[0])
|
||||
direction.erase(direction[0])
|
||||
|
||||
|
@ -78,5 +88,8 @@ func _on_slow_timer_timeout():
|
|||
speed = config.enemy[enemy_id]['speed']
|
||||
is_slow = false
|
||||
|
||||
func _on_dead_timer_timeout():
|
||||
destroy()
|
||||
|
||||
func destroy():
|
||||
queue_free()
|
||||
queue_free()
|
|
@ -51,11 +51,14 @@ func _physics_process(_delta):
|
|||
if enemies.is_empty():
|
||||
$AnimatedSprite2D.stop()
|
||||
else:
|
||||
var distance = global_position.distance_to(enemies[0].global_position)
|
||||
_update_look_at(enemies[0].global_position + enemies[0].enemy_vol * (distance / speed))
|
||||
if timer.is_stopped():
|
||||
$AnimatedSprite2D.play("default")
|
||||
_shoot()
|
||||
if !enemies[0].is_dead:
|
||||
var distance = global_position.distance_to(enemies[0].global_position)
|
||||
_update_look_at(enemies[0].global_position + enemies[0].enemy_vol * (distance / speed))
|
||||
if timer.is_stopped():
|
||||
$AnimatedSprite2D.play("default")
|
||||
_shoot()
|
||||
else:
|
||||
enemies.erase(enemies[0])
|
||||
|
||||
func _shoot():
|
||||
if bullet:
|
||||
|
|
Loading…
Reference in a new issue