Added override switch

This commit is contained in:
derek
2024-10-14 10:14:07 -05:00
parent d19bb93791
commit 735a48b21d
7 changed files with 78 additions and 136 deletions

Binary file not shown.

Binary file not shown.

File diff suppressed because one or more lines are too long

View File

@@ -1,34 +1,41 @@
extends Node extends Node
@export var door : Node @export var door : Node
@export var switches = []
var switches = []
var switch_override : Node
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready() -> void: func _ready() -> void:
#Connect to signal bus
SignalBus.switch_changed.connect(_on_switch_changed) SignalBus.switch_changed.connect(_on_switch_changed)
#Collect child switches
for i in self.get_children(): for i in self.get_children():
if i.is_in_group("switch"): if i.is_in_group("switch"):
if i.is_in_group("switch_override"):
switch_override = i
else:
switches.append(i) switches.append(i)
print(switches)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func _on_switch_changed() -> void: func _on_switch_changed() -> void:
var switches_needed = switches.size() var switches_needed = switches.size()
var switches_on = 0 var switches_on = 0
for i in switches: for i in switches:
if i.switched_on: if i.switched_on:
switches_on += 1 switches_on += 1
print("switches on " + str(switches_on))
if switches_on == switches_needed: #First check override switch and open or close door
if switch_override.switched_on:
if door.door_open == false:
door.open()
else:
if door.door_open == true:
door.close()
#Otherwise follow standard switches
elif switches_on >= switches_needed:
if door.door_open == false: if door.door_open == false:
door.open() door.open()
else: else:

View File

@@ -39,6 +39,7 @@ interact="interactable objects"
switch="" switch=""
scene_rigidbody="" scene_rigidbody=""
weight="" weight=""
switch_override=""
[input] [input]

View File

@@ -13,10 +13,6 @@ func _ready() -> void:
else: else:
close() close()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func open(): func open():
door_open = true door_open = true
anim_player.play("open") anim_player.play("open")

View File

@@ -0,0 +1,13 @@
extends SwitchBasic
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
add_to_group("switch_override")
func interact():
switch()
func _on_static_body_3d_switch_hit() -> void:
if bullet_enabled:
switch()