retrace/Global/Daytime.gd

33 lines
552 B
GDScript

extends Node
#const _max: int = 1440 # 24 hour + 60 mins
const _max: int = 1440
const WORK_TIME = _max * 0.3
const SLEEP_TIME = _max * 0.6
var _time: float setget _set_time, get_time
var increase_per_second: float = 5.0
signal respawn
func _set_time (new_time: float):
_time = new_time
func get_time () -> float:
return _time
func get_max () -> int:
return _max
func _process (delta: float) -> void:
# continually increases daytime
_set_time(_time + increase_per_second * delta)
if _time >= _max:
_time = 0
emit_signal("respawn")