From f9243b4b81ef59b88f21e0faedfa436606d0233e Mon Sep 17 00:00:00 2001 From: Thomas Date: Wed, 26 Feb 2025 18:14:46 +0100 Subject: [PATCH] =?UTF-8?q?feux=20synchronis=C3=A9s!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- urban_furnitures/semaphores/semaphore.gd | 26 +++++++++++++----------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/urban_furnitures/semaphores/semaphore.gd b/urban_furnitures/semaphores/semaphore.gd index fd0f9d3..51faa00 100644 --- a/urban_furnitures/semaphores/semaphore.gd +++ b/urban_furnitures/semaphores/semaphore.gd @@ -1,31 +1,33 @@ extends Node2D class_name LightSemaphore -@export var dependantSemaphore : LightSemaphore = null +@export var synchronizedSemaphore : LightSemaphore = null @export var hasOwnTimerEnabled = true @onready var lights := [$Sempahore/green, $Sempahore/yellow, $Sempahore/red ]; +@export var waitTicks := [5, 1, 6]; @export var light = 0; +var tickCounter = 0 func _ready() -> void: $brakeZone.get_child(1).disabled = !light; for i in range (lights.size()): lights[i].visible = i == light + $Timer.wait_time = 1; -func change_light(): - light += 1; - if light > 2: - light = 0; +func tick(): + tickCounter+=1 + if tickCounter == waitTicks[light]: + light += 1; + if light > 2: + light = 0; + tickCounter = 0; $brakeZone.get_child(1).disabled = !light; for i in range (lights.size()): lights[i].visible = i == light + if synchronizedSemaphore: + synchronizedSemaphore.tick(); func _on_timer_timeout() -> void: if hasOwnTimerEnabled: - if light == 0: - $Timer.wait_time = 1; - else: - $Timer.wait_time = 5; $Timer.start() - change_light(); - if dependantSemaphore: - dependantSemaphore.change_light(); + tick();