moved direction change logic to game-controller

This commit is contained in:
edgul committed 2026-04-21 22:55:40 -04:00
1 parent 25cad172e0
commit a563c0c93d
3 files changed
+23 -19

No files matched your search

+4 -11
View File
@@ -1,19 +1,12 @@
extends RigidBody2D
class_name Enemy extends RigidBody2D
var direction = 1
# there is probably a better built-in to use here
@export var direction:int = 1
const SPEED = 1
# signal triggerEdge(body, intentMessage)
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
func _process(delta):
func _process(_delta):
var x = get_transform().get_origin().x
# not sure why rigid body doesn't see wall hardcoded walls
if x < 0 or x > 300:
# triggerEdge.emit(body, )
direction *= -1 # switch direction
move_local_x(SPEED * direction)
+17 -8
View File
@@ -1,14 +1,23 @@
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)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
func _on_area_2d_trigger_active_signal(body, intentMessage):
print("game controller received trigger")
#if intentMessage == "destroy" and not body is Player:
#body.queue_free()
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