TowerDefense/enemies/enemy.gd

49 lines
1.1 KiB
GDScript3
Raw Normal View History

2025-03-26 18:55:43 +01:00
extends CharacterBody3D
class_name Enemy
2025-04-02 18:02:13 +02:00
@onready var death_vfx_packed : PackedScene = preload("res://VFX/death_particles.tscn")
@onready var sad_vfx_packed : PackedScene = preload("res://VFX/sad_particles.tscn")
2025-03-26 18:55:43 +01:00
@export var speed : int = 2
2025-04-02 18:02:13 +02:00
@export var max_life : int = 10
var health : int = 0 :
2025-03-26 18:55:43 +01:00
set(value):
health = value
2025-04-02 18:02:13 +02:00
if health >= max_life and is_alive:
2025-03-26 18:55:43 +01:00
death()
@onready var Path : PathFollow3D = get_parent()
2025-04-02 18:02:13 +02:00
2025-03-26 18:55:43 +01:00
var is_alive : bool = true
2025-04-02 18:02:13 +02:00
func _ready() -> void:
$HealthBar3D.set_up(health, max_life)
2025-03-26 18:55:43 +01:00
func _physics_process(delta: float) -> void:
2025-04-02 18:02:13 +02:00
if !is_alive:
return
2025-03-26 18:55:43 +01:00
Path.set_progress(Path.get_progress() + speed * delta)
if Path.get_progress_ratio() >= 0.99:
#Global.health -= 20
death()
func take_damage(damage : int) -> void:
2025-04-02 18:02:13 +02:00
health += damage
$HealthBar3D.update(health)
2025-03-26 18:55:43 +01:00
func death() -> void:
is_alive = false
#Global.enemies_alive -= 1
#Global.money += 50
2025-04-02 18:02:13 +02:00
$Sprite3D.visible = false
var death_vfx : CPUParticles3D = death_vfx_packed.instantiate()
get_tree().current_scene.add_child(death_vfx)
death_vfx.global_position = global_position
2025-03-26 18:55:43 +01:00
Path.queue_free()