.            ★.        . blessfrey.me ..          ☆        .

stoplight

game guide

Co-routines give you the power to change the light! Watch how player input disrupts the stoplight's schedule. Push the walk button to skip a phase. Or wait until the phase times out.

This is just a small project to get more comfortable with yields in Godot Engine.

This game was released June 5, 2019.

code

node hierarchy

Screenshot: Godot Engine editor

Main.gd


extends Node

onready var stoplight = $Stoplight

func _ready():
	stoplight.play()

	var result = wait(5, 'green')
	$WalkButton/TextureButton.connect('pressed', result, 'resume', ['interrupted on green'], CONNECT_ONESHOT)
	yield(result, 'completed')

	result = wait(5, 'yellow')
	$WalkButton/TextureButton.connect('pressed', result, 'resume', ['interrupted on yellow'], CONNECT_ONESHOT)
	yield(result, 'completed')
	
	result = wait(5, 'red')
	$WalkButton/TextureButton.connect('pressed', result, 'resume', ['interrupted on red'], CONNECT_ONESHOT)
	yield(result, 'completed')

func wait(time, color):
	print('waiting for: ' + color)
	var result = yield(get_tree().create_timer(time), 'timeout')
	if result:
		print(result)
	stoplight.animation = color
	print('done: ' + color)

func _on_completed():
	print('completed')

func _on_WalkButton_gui_input(event):
	if event is InputEventMouseButton and event.pressed:
		print ("Walk Button not functioning.")

Label.gd


extends Label
var time_start = 0
var time_now = 0

func _ready():
	time_start = OS.get_unix_time()
	set_process(true)

func _process(delta):
	time_now = OS.get_unix_time()
	var elapsed = time_now - time_start
	var minutes = elapsed / 60
	var seconds = elapsed % 60
	var str_elapsed = "%02d" % [seconds]
	text = str(str_elapsed)

Credits

  • coding + art by chimchooree
  • Tools: Godot Engine 3.0.6, Krita
  • Hosting: itch.io
  • Thumbnail Font: Alpha Flowers by Chloe5972