feux synchronisés!
This commit is contained in:
@@ -1,31 +1,33 @@
|
|||||||
extends Node2D
|
extends Node2D
|
||||||
class_name LightSemaphore
|
class_name LightSemaphore
|
||||||
|
|
||||||
@export var dependantSemaphore : LightSemaphore = null
|
@export var synchronizedSemaphore : LightSemaphore = null
|
||||||
@export var hasOwnTimerEnabled = true
|
@export var hasOwnTimerEnabled = true
|
||||||
@onready var lights := [$Sempahore/green, $Sempahore/yellow, $Sempahore/red ];
|
@onready var lights := [$Sempahore/green, $Sempahore/yellow, $Sempahore/red ];
|
||||||
|
@export var waitTicks := [5, 1, 6];
|
||||||
@export var light = 0;
|
@export var light = 0;
|
||||||
|
var tickCounter = 0
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
$brakeZone.get_child(1).disabled = !light;
|
$brakeZone.get_child(1).disabled = !light;
|
||||||
for i in range (lights.size()):
|
for i in range (lights.size()):
|
||||||
lights[i].visible = i == light
|
lights[i].visible = i == light
|
||||||
|
$Timer.wait_time = 1;
|
||||||
|
|
||||||
func change_light():
|
func tick():
|
||||||
light += 1;
|
tickCounter+=1
|
||||||
if light > 2:
|
if tickCounter == waitTicks[light]:
|
||||||
light = 0;
|
light += 1;
|
||||||
|
if light > 2:
|
||||||
|
light = 0;
|
||||||
|
tickCounter = 0;
|
||||||
$brakeZone.get_child(1).disabled = !light;
|
$brakeZone.get_child(1).disabled = !light;
|
||||||
for i in range (lights.size()):
|
for i in range (lights.size()):
|
||||||
lights[i].visible = i == light
|
lights[i].visible = i == light
|
||||||
|
if synchronizedSemaphore:
|
||||||
|
synchronizedSemaphore.tick();
|
||||||
|
|
||||||
func _on_timer_timeout() -> void:
|
func _on_timer_timeout() -> void:
|
||||||
if hasOwnTimerEnabled:
|
if hasOwnTimerEnabled:
|
||||||
if light == 0:
|
|
||||||
$Timer.wait_time = 1;
|
|
||||||
else:
|
|
||||||
$Timer.wait_time = 5;
|
|
||||||
$Timer.start()
|
$Timer.start()
|
||||||
change_light();
|
tick();
|
||||||
if dependantSemaphore:
|
|
||||||
dependantSemaphore.change_light();
|
|
||||||
|
|||||||
Reference in New Issue
Block a user