From 1f33e9cd8223da7c92b0ec3ffa3af97ecda6deed Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Sat, 14 Nov 2026 10:31:37 +0100 Subject: Setup Team + add powerup tcsn --- Spatial.gd | 82 +++++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 52 insertions(+), 30 deletions(-) (limited to 'Spatial.gd') diff --git a/Spatial.gd b/Spatial.gd index 25330aa..64f0ad8 100644 --- a/Spatial.gd +++ b/Spatial.gd @@ -1,43 +1,65 @@ extends Spatial -var box = preload("res://box.tscn") +const t = preload("res://team.gd") +var b = preload("res://box.tscn") + +var blue_points = 0 +var pink_points = 0 func randpos() -> float: - return randf() * 5 + return randf() * 6.0 -func _entered(node: Node): - if node == get_node("mesh/MeshInstance2/basefloor"): - pass +func set_points(box, points): + var team = box.myteam -func _exited(node: Node): - if node == get_node("mesh/MeshInstance2/basefloor"): - pass + if team == t.Team.BLUE: + blue_points += points + else: + pink_points += points -# Called when the node enters the scene tree for the first time. -func _ready(): - randomize() + print("Team blue has %d points" % blue_points) + print("Team pink has %d points" % pink_points) + +func _entered(box): + set_points(box, 1) + +func _exited(box): + set_points(box, -1) + +func create_box(team): + var box = b.instance() + var x = randpos() + var z = randpos() - for _i in range(30): - var b = box.instance() - var x = randpos() - var z = randpos() + box.set_team(team) + box.set_floor(get_node("mesh/MeshInstance2/basefloor")) - if x < 2.0 and z > 2.0: - x += 2 - x = fmod(x, 5) - elif z < 2.0: - z += 2 - z = fmod(z, 5) + if x < 2.0 and z > 2.0: + x += 2 + x = fmod(x, 6) + elif z < 2.0: + z += 2 + z = fmod(z, 6) - if randi() & 1: - x = -x + if randi() & 1: + x = -x - if randi() & 1: - z = -z + if randi() & 1: + z = -z + + var pos = Vector3(x, 10, z) + + box.translate(pos) + box.connect("entered", self, "_entered") + box.connect("exited", self, "_exited") + add_child(box) + +# Called when the node enters the scene tree for the first time. +func _ready(): + randomize() - var pos = Vector3(x, 10, z) + for _i in range(15): + create_box(t.Team.PINK) - b.translate(pos) - b.connect("body_entered", self, "_entered") - b.connect("body_exited", self, "_exited") - add_child(b) + for _i in range(15): + create_box(t.Team.BLUE) -- cgit v1.2.3