diff --git a/assets/blockout_2.tscn b/assets/blockout_2.tscn index fa03467..453001b 100644 --- a/assets/blockout_2.tscn +++ b/assets/blockout_2.tscn @@ -633,13 +633,12 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.016016, 0.0225029, -0.01923 script = ExtResource("1_sbpvn") player = NodePath("Player") money = 50 -start_health = 10 +start_health = 5 gun_1 = ExtResource("2_fn4vb") health_drop_enabled = false [node name="Player" parent="." instance=ExtResource("9_3usor")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 39.6989, 19.155, 65.5954) -AUDIO = false [node name="WorldEnvironment" type="WorldEnvironment" parent="."] environment = SubResource("Environment_b2qms") diff --git a/assets/revolver_1.tscn b/assets/revolver_1.tscn index 590252a..633d2d4 100644 --- a/assets/revolver_1.tscn +++ b/assets/revolver_1.tscn @@ -1202,6 +1202,7 @@ target_position = Vector3(0, 0, -0.1) [node name="SpotLight3D" type="SpotLight3D" parent="revolver1" index="5"] transform = Transform3D(-4.37114e-08, -1, 0, 1, -4.37115e-08, 0, 0, 0, 1, 0, 0, -1.94881) +visible = false light_color = Color(0.965385, 0.844179, 0.572893, 1) light_energy = 10.0 light_projector = ExtResource("3_q41fl") diff --git a/levels/blockout_3.tscn b/levels/blockout_3.tscn index 45b747f..f561691 100644 --- a/levels/blockout_3.tscn +++ b/levels/blockout_3.tscn @@ -441,10 +441,9 @@ skeleton = NodePath("") transform = Transform3D(2, 0, 0, 0, 2, 0, 0, 0, 2, 8.80225, 0.0994795, 14.6317) jump_amount = 30 -[node name="Door1" type="Node" parent="." node_paths=PackedStringArray("door", "switch")] +[node name="Door1" type="Node" parent="." node_paths=PackedStringArray("door")] script = ExtResource("11_wstss") door = NodePath("Door") -switch = NodePath("switch") [node name="Door" type="MeshInstance3D" parent="Door1" node_paths=PackedStringArray("anim_player")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 4.27403, -20.1043) @@ -462,7 +461,7 @@ libraries = { "": SubResource("AnimationLibrary_66q6k") } -[node name="switch" parent="Door1" instance=ExtResource("10_lktr8")] +[node name="switch" parent="Door1" groups=["interact"] instance=ExtResource("10_lktr8")] transform = Transform3D(1.655, 0, 0, 0, 1.655, 0, 0, 0, 1.655, 18.839, 24.696, 0) skeleton = NodePath("../..") script = ExtResource("12_yaq57") @@ -473,4 +472,30 @@ script = ExtResource("13_v1s63") [node name="CollisionShape3D" type="CollisionShape3D" parent="Door1/switch/StaticBody3D"] shape = SubResource("SphereShape3D_vyys8") +[node name="switch2" parent="Door1" groups=["interact"] instance=ExtResource("10_lktr8")] +transform = Transform3D(1.655, 0, 0, 0, 1.655, 0, 0, 0, 1.655, 2.06374, 11.8273, -19.0215) +skeleton = NodePath("../..") +script = ExtResource("12_yaq57") + +[node name="StaticBody3D" type="StaticBody3D" parent="Door1/switch2" groups=["interact", "switch"]] +script = ExtResource("13_v1s63") + +[node name="CollisionShape3D" type="CollisionShape3D" parent="Door1/switch2/StaticBody3D"] +shape = SubResource("SphereShape3D_vyys8") + +[node name="switch3" parent="Door1" groups=["interact"] instance=ExtResource("10_lktr8")] +transform = Transform3D(1.655, 0, 0, 0, 1.655, 0, 0, 0, 1.655, 5.3251, 0.640042, -17.4136) +skeleton = NodePath("../..") +script = ExtResource("12_yaq57") + +[node name="StaticBody3D" type="StaticBody3D" parent="Door1/switch3" groups=["interact", "switch"]] +script = ExtResource("13_v1s63") + +[node name="CollisionShape3D" type="CollisionShape3D" parent="Door1/switch3/StaticBody3D"] +shape = SubResource("SphereShape3D_vyys8") + [connection signal="switch_hit" from="Door1/switch/StaticBody3D" to="Door1/switch" method="_on_static_body_3d_switch_hit"] +[connection signal="switch_hit" from="Door1/switch2/StaticBody3D" to="Door1/switch2" method="_on_static_body_3d_switch_hit"] +[connection signal="switch_on" from="Door1/switch3" to="Door1" method="_on_switch_3_switch_on"] +[connection signal="switch_on" from="Door1/switch3" to="Door1/switch3" method="_on_switch_on"] +[connection signal="switch_hit" from="Door1/switch3/StaticBody3D" to="Door1/switch3" method="_on_static_body_3d_switch_hit"] diff --git a/levels/switchcontroller.gd b/levels/switchcontroller.gd index 761d317..18f0a28 100644 --- a/levels/switchcontroller.gd +++ b/levels/switchcontroller.gd @@ -1,13 +1,36 @@ extends Node @export var door : Node -@export var switch : Node +@export var switches = [] + # Called when the node enters the scene tree for the first time. func _ready() -> void: - pass + + SignalBus.switch_changed.connect(_on_switch_changed) + + for i in self.get_children(): + if i.is_in_group("switch"): + switches.append(i) + + print(switches) # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta: float) -> void: - if switch.switched_on: - door.state_change(switch.switched_on) + pass + + +func _on_switch_changed() -> void: + var switches_needed = switches.size() + var switches_on = 0 + for i in switches: + if i.switched_on: + switches_on += 1 + print("switches on " + str(switches_on)) + + if switches_on == switches_needed: + if door.door_open == false: + door.open() + else: + if door.door_open == true: + door.close() diff --git a/project.godot b/project.godot index ac026e2..15bdfa3 100644 --- a/project.godot +++ b/project.godot @@ -15,6 +15,10 @@ run/main_scene="res://levels/blockout_3.tscn" config/features=PackedStringArray("4.3", "Forward Plus") config/icon="res://icon.svg" +[autoload] + +SignalBus="*res://scripts/signal_bus.gd" + [display] window/size/mode=3 diff --git a/scripts/signal_bus.gd b/scripts/signal_bus.gd new file mode 100644 index 0000000..e01c1d2 --- /dev/null +++ b/scripts/signal_bus.gd @@ -0,0 +1,3 @@ +extends Node + +signal switch_changed() diff --git a/scripts/switch_interactandshoot.gd b/scripts/switch_interactandshoot.gd index fdd32f9..df66cbd 100644 --- a/scripts/switch_interactandshoot.gd +++ b/scripts/switch_interactandshoot.gd @@ -2,18 +2,20 @@ extends Node3D var switched_on -@export var default_setting : bool = false +@export var start_on : bool = false @export var toggle_enabled : bool = false @export var bullet_enabled : bool = true @export var timer_enabled : bool = false @export var timer_duration : float = 2.0 +signal switch_on() +signal switch_off() # Called when the node enters the scene tree for the first time. func _ready() -> void: add_to_group("switch") add_to_group("interact") - switched_on = default_setting + switched_on = start_on # Called every frame. 'delta' is the elapsed time since the previous frame. @@ -21,27 +23,18 @@ func _process(delta: float) -> void: pass func interact(): - print("switch hit") if toggle_enabled: - if switched_on: + if switched_on == true: switched_on = false + SignalBus.emit_signal("switch_changed") else: switched_on = true + SignalBus.emit_signal("switch_changed") else: - print("switched on") switched_on = true + SignalBus.emit_signal("switch_changed") func _on_static_body_3d_switch_hit() -> void: if bullet_enabled: - print("switch hit") - if toggle_enabled: - if switched_on: - switched_on = false - else: - print("switched on") - switched_on = true - else: - print("switched on") - switched_on = true - + interact()