Files
SWGalaga/Scripts/enemy_spawner.gd
2024-06-05 05:05:56 -04:00

44 lines
1.1 KiB
GDScript

extends Node2D
signal scored()
var spawn_positions = null
var enemy = preload("res://Scenes/enemy_xwing.tscn")
var enemy2 = preload("res://Scenes/enemy_ywing.tscn")
func _ready():
randomize()
spawn_positions = $SpawnPositions.get_children()
func spawn_enemy():
var index = randi() % spawn_positions.size()
var enemy2 = enemy2.instantiate()
enemy2.global_position = spawn_positions[index].global_position
#connect error. unsure why.
#enemy.connect("enemy_died", get_tree().current_scene, "scored")
add_child(enemy2)
#AI Generated code, doesn't work. connect error
#func spawn_enemy():
#var index = randi() % spawn_positions.size()
#var enemy_instance = enemy.instantiate()
#var world_node = get_node("res://Scenes/world.tscn")
#var world_script = world_node.get_script()
#enemy_instance.connect("enemy_died", world_script, 10)
#enemy_instance.global_position = spawn_positions[index].global_position
#add_child(enemy_instance)
func _on_spawn_timer_timeout():
spawn_enemy()
func enemy_died():
emit_signal("scored")
func missile_spawn():
print("Missile")