summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi92@disroot.org>2026-11-14 10:31:37 +0100
committerXavier Del Campo Romero <xavi92@disroot.org>2026-11-14 10:31:37 +0100
commit1f33e9cd8223da7c92b0ec3ffa3af97ecda6deed (patch)
tree5351940ce0040eb03a97b094f1a2f8418e37a18c
parent1b5c02c6ac4938d7891084ba3af66958c1cc05f3 (diff)
downloadnj26-1f33e9cd8223da7c92b0ec3ffa3af97ecda6deed.tar.gz
Setup Team + add powerup tcsn
-rw-r--r--Spatial.gd82
-rw-r--r--Spatial.tscn13
-rw-r--r--box.gd39
-rw-r--r--powerup.tscn15
-rw-r--r--project.godot6
-rw-r--r--team.gd6
-rw-r--r--zombie.gd2
7 files changed, 114 insertions, 49 deletions
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)
diff --git a/Spatial.tscn b/Spatial.tscn
index ce33746..a5980f0 100644
--- a/Spatial.tscn
+++ b/Spatial.tscn
@@ -66,15 +66,10 @@ environment = SubResource( 7 )
[node name="z1" parent="." instance=ExtResource( 2 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -4.07506, 0.208532, -1.55126 )
-[node name="OmniLight" type="OmniLight" parent="."]
-transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -5.96387, 1.75094, 1.36672 )
-light_color = Color( 0.921569, 0.00784314, 0.00784314, 1 )
-light_energy = 0.5
-
[node name="walls" type="Spatial" parent="."]
[node name="Node4" type="StaticBody" parent="walls"]
-transform = Transform( -4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 0, 0, -6 )
+transform = Transform( -4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 0, 0, -7 )
collision_layer = 3
collision_mask = 3
@@ -84,7 +79,7 @@ shape = SubResource( 5 )
[node name="MeshInstance" type="MeshInstance" parent="walls/Node4"]
[node name="Node3" type="StaticBody" parent="walls"]
-transform = Transform( -4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 0, 0, 6 )
+transform = Transform( -4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 0, 0, 7 )
collision_layer = 3
collision_mask = 3
@@ -94,7 +89,7 @@ shape = SubResource( 5 )
[node name="MeshInstance" type="MeshInstance" parent="walls/Node3"]
[node name="Node6" type="StaticBody" parent="walls"]
-transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -9, 0, 0 )
+transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -10, 0, 0 )
collision_layer = 3
collision_mask = 3
@@ -104,7 +99,7 @@ shape = SubResource( 3 )
[node name="MeshInstance" type="MeshInstance" parent="walls/Node6"]
[node name="Node5" type="StaticBody" parent="walls"]
-transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 9, 0, 0 )
+transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 10, 0, 0 )
collision_layer = 3
collision_mask = 3
diff --git a/box.gd b/box.gd
index 0572053..905a463 100644
--- a/box.gd
+++ b/box.gd
@@ -1,17 +1,38 @@
-extends RigidBody
+class_name Box extends RigidBody
+const t = preload("res://team.gd")
+signal entered
+signal exited
-# Declare member variables here. Examples:
-# var a = 2
-# var b = "text"
+var myteam = t.Team.BLUE
+var _floor: Node
+func set_team(team):
+ var mesh = get_node("MeshInstance")
+ var material = mesh.get_active_material(0).duplicate()
+ myteam = team
+
+ if myteam == t.Team.PINK:
+ material.set_albedo(Color(1, 0, 1, 1))
+ else:
+ material.set_albedo(Color(0, 0, 1, 1))
+
+ mesh.set_surface_material(0, material)
+
+func _entered(node: Node):
+ if node == _floor:
+ emit_signal("entered", self)
+
+func _exited(node: Node):
+ if node == _floor:
+ emit_signal("exited", self)
+
+func set_floor(node: Node):
+ _floor = node
-# Called when the node enters the scene tree for the first time.
func _ready():
contact_monitor = true
contacts_reported = 4
-
-# Called every frame. 'delta' is the elapsed time since the previous frame.
-#func _process(delta):
-# pass
+ connect("body_entered", self, "_entered")
+ connect("body_exited", self, "_exited")
diff --git a/powerup.tscn b/powerup.tscn
new file mode 100644
index 0000000..73de829
--- /dev/null
+++ b/powerup.tscn
@@ -0,0 +1,15 @@
+[gd_scene load_steps=3 format=2]
+
+[sub_resource type="CylinderMesh" id=1]
+radial_segments = 16
+
+[sub_resource type="BoxShape" id=2]
+
+[node name="Spatial" type="KinematicBody"]
+
+[node name="MeshInstance" type="MeshInstance" parent="."]
+transform = Transform( 0.830813, 0, 0, 0, 1.06244, 0, 0, 0, 1, 0, 0, 0 )
+mesh = SubResource( 1 )
+
+[node name="CollisionShape" type="CollisionShape" parent="."]
+shape = SubResource( 2 )
diff --git a/project.godot b/project.godot
index 331a9d2..a7f5723 100644
--- a/project.godot
+++ b/project.godot
@@ -9,12 +9,18 @@
config_version=4
_global_script_classes=[ {
+"base": "RigidBody",
+"class": "Box",
+"language": "GDScript",
+"path": "res://box.gd"
+}, {
"base": "KinematicBody",
"class": "Zombie",
"language": "GDScript",
"path": "res://zombie.gd"
} ]
_global_script_class_icons={
+"Box": "",
"Zombie": ""
}
diff --git a/team.gd b/team.gd
new file mode 100644
index 0000000..fff96cc
--- /dev/null
+++ b/team.gd
@@ -0,0 +1,6 @@
+extends Node
+
+enum Team {
+ PINK
+ BLUE
+}
diff --git a/zombie.gd b/zombie.gd
index 2192549..90cdf9a 100644
--- a/zombie.gd
+++ b/zombie.gd
@@ -51,7 +51,7 @@ func _physics_process(delta):
else:
speed.y -= delta * 9.8
- move_and_slide(speed)
+ var _n = move_and_slide(speed)
func getid() -> String:
var id = ""