Switches now have timers

This commit is contained in:
Derek
2024-10-12 18:24:42 -05:00
parent 9731910edd
commit d19bb93791
8 changed files with 99 additions and 63 deletions

11
scripts/pressure_plate.gd Normal file
View File

@@ -0,0 +1,11 @@
extends SwitchBasic
func _on_collision_area_body_entered(body: Node3D) -> void:
if body.is_in_group("weight"):
switched_on = true
SignalBus.emit_signal("switch_changed")
func _on_collision_area_body_exited(body: Node3D) -> void:
if body.is_in_group("weight"):
switched_on = false
SignalBus.emit_signal("switch_changed")

View File

@@ -1,3 +1,4 @@
extends Node
signal switch_changed()
signal switch_timeout()

View File

@@ -1,12 +1,45 @@
extends Node
@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
var switched_on : bool
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
add_to_group("switch")
add_to_group("interact")
switched_on = start_on
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func switch():
if toggle_enabled:
if switched_on == true:
switched_on = false
SignalBus.emit_signal("switch_changed")
else:
switched_on = true
SignalBus.emit_signal("switch_changed")
if timer_enabled:
start_timer()
else:
switched_on = true
SignalBus.emit_signal("switch_changed")
if timer_enabled:
start_timer()
func start_timer():
await get_tree().create_timer(timer_duration).timeout
_on_timer_timeout()
func _on_timer_timeout():
switched_on = false
SignalBus.emit_signal("switch_changed")

View File

@@ -1,40 +1,8 @@
extends Node3D
var switched_on
@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 = start_on
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
extends SwitchBasic
func interact():
if toggle_enabled:
if switched_on == true:
switched_on = false
SignalBus.emit_signal("switch_changed")
else:
switched_on = true
SignalBus.emit_signal("switch_changed")
else:
switched_on = true
SignalBus.emit_signal("switch_changed")
switch()
func _on_static_body_3d_switch_hit() -> void:
if bullet_enabled:
interact()
switch()