space-invaders/scripts/game-controller.gd

24 lines
658 B
GDScript

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 RigidBody2D:
var x = child.transform.get_origin().x
if x < 0 or x > 300: # 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 RigidBody2D:
child.mydirection *= -1