Added a game timer and put it on the game manager to handle day end events
This commit is contained in:
1 parent
8d313b8a71
commit
eeb34f9372
4 files changed
+75
-1
No files matched your search
@@ -1,9 +1,21 @@
|
||||
extends Node
|
||||
|
||||
export var time_per_day : float = 600.0
|
||||
|
||||
onready var player = get_tree().get_nodes_in_group("player")[0]
|
||||
onready var day_timer = $"%day_timer"
|
||||
onready var day_timer_text = $"%day_timer_text"
|
||||
|
||||
func _ready():
|
||||
player.connect("starved_to_death", self, "_on_player_starved_to_death")
|
||||
day_timer.wait_time = time_per_day
|
||||
day_timer.start()
|
||||
|
||||
func _process(delta):
|
||||
var time_left : int = day_timer.time_left
|
||||
var minutes : int = time_left / 60
|
||||
var seconds : int = time_left % 60
|
||||
day_timer_text.text = "Time Left: %0*d:%0*d" % [2, minutes, 2, seconds]
|
||||
|
||||
func _on_player_starved_to_death():
|
||||
var node = Dialogic.start("starve")
|
||||
@@ -13,3 +25,16 @@ func _on_player_starved_to_death():
|
||||
yield(node, "timeline_end")
|
||||
get_tree().paused = false
|
||||
get_tree().quit() # go back to main menu when such a thing exists
|
||||
|
||||
func _on_day_timer_timeout():
|
||||
player.health -= 1
|
||||
if player.health <= 0:
|
||||
_on_player_starved_to_death()
|
||||
return
|
||||
var node = Dialogic.start("day_end")
|
||||
node.pause_mode = PAUSE_MODE_PROCESS
|
||||
add_child(node)
|
||||
get_tree().paused = true
|
||||
yield(node, "timeline_end")
|
||||
get_tree().paused = false
|
||||
|
||||
Reference in new issue
Block a user