diff options
Diffstat (limited to 'Enemies/enemy.gd')
-rw-r--r-- | Enemies/enemy.gd | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/Enemies/enemy.gd b/Enemies/enemy.gd index 428f6ca..eed482d 100644 --- a/Enemies/enemy.gd +++ b/Enemies/enemy.gd @@ -2,15 +2,22 @@ class_name Enemy extends CharacterBody2D -const SPEED = 30 +@export var speed: float = 30.0 var direction = -1 : set(value): direction = value $AnimatedSprite2D.flip_h = direction > 0 +@onready var disable_timer = Timer.new() + func _ready() -> void: + disable_timer.wait_time = 3.0 + disable_timer.one_shot = true + disable_timer.timeout.connect(_on_disable_timer_timeout) + add_child(disable_timer) + process_mode = PROCESS_MODE_DISABLED @@ -20,7 +27,7 @@ func _physics_process(delta: float) -> void: if not is_on_floor(): velocity += get_gravity() * delta - velocity.x = direction * SPEED + velocity.x = direction * speed move_and_slide() if get_last_slide_collision(): @@ -66,8 +73,11 @@ func on_hit(projectile_position: Vector2): func _on_visible_on_screen_notifier_2d_screen_entered() -> void: + disable_timer.stop() process_mode = PROCESS_MODE_INHERIT func _on_visible_on_screen_notifier_2d_screen_exited() -> void: - return + disable_timer.start() + +func _on_disable_timer_timeout(): process_mode = PROCESS_MODE_DISABLED |