space-invaders/scripts/game-controller.gd

26 lines
666 B
GDScript3
Raw Permalink Normal View History

2026-04-22 02:17:21 +00:00
extends Node2D
var game_node = null
2026-04-22 02:17:21 +00:00
# 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)
2026-04-22 02:17:21 +00:00
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()