-
Notifications
You must be signed in to change notification settings - Fork 1
/
GhostSpawner.gd
39 lines (30 loc) · 908 Bytes
/
GhostSpawner.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
extends Node2D
onready var working_i: Sprite = $working_i
onready var working: Sprite = $working
onready var not_working_i: Sprite = $notworking_i
onready var not_working: Sprite = $notworking
onready var t: Timer = $Timer
var health: int = 5
var enemy_scene: Resource = load("res://src/entity/enemy/enemy.tscn")
export var timer_time: int = 5
func _ready():
t.wait_time = timer_time
working.visible = true
working_i.visible = true
call_deferred("spawn")
func _on_Timer_timeout():
spawn()
func spawn():
var enemy: KinematicBody2D = enemy_scene.instance()
get_parent().add_child(enemy)
enemy.global_position = global_position
func _on_Area2D_area_entered(area):
if (area.has_method("IS_BULLET") && health > 0):
health -= 1
area.queue_free()
if (health <= 0):
t.stop()
working.visible = false
working_i.visible = false
not_working.visible = true
not_working_i.visible = true