extends Node2D var game_node = null # Called when the node enters the scene tree for the first time. func _ready(): get_window().grab_focus() # Replace with function body. game_node = get_tree().root.get_child(0) func _process(_delta): # detect when one enemy goes too far var change_dir = false for child in game_node.get_children(): if child is Enemy: var x = child.transform.get_origin().x if x < 0 or x > 600: # not using collision detection properly change_dir = true break # change directions of all enemies if change_dir: for child in game_node.get_children(): if child is Enemy: child.direction *= -1 child.go_down()