Files
SWGalaga/Scripts/enemy_spawner.gd

44 lines
1.1 KiB
GDScript3
Raw Permalink Normal View History

2024-06-03 05:29:11 -04:00
extends Node2D
signal scored()
var spawn_positions = null
var enemy = preload("res://Scenes/enemy_xwing.tscn")
2024-06-05 05:05:56 -04:00
var enemy2 = preload("res://Scenes/enemy_ywing.tscn")
2024-06-03 05:29:11 -04:00
func _ready():
randomize()
spawn_positions = $SpawnPositions.get_children()
func spawn_enemy():
var index = randi() % spawn_positions.size()
2024-06-05 05:05:56 -04:00
var enemy2 = enemy2.instantiate()
enemy2.global_position = spawn_positions[index].global_position
2024-06-03 05:29:11 -04:00
#connect error. unsure why.
#enemy.connect("enemy_died", get_tree().current_scene, "scored")
2024-06-05 05:05:56 -04:00
add_child(enemy2)
2024-06-03 05:29:11 -04:00
#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")