Skip to content

Commit

Permalink
Kill player on time out (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinigami92 authored Nov 20, 2023
1 parent 4bc2cde commit c9321af
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/hud/time_left_indicator/time_left_indicator.gd
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
class_name TimeLeftIndicator
extends Label

signal time_left_ended

## The time in seconds that the player has to complete the level.
@export var time: int = 300

@onready var timer: Timer = $Timer


func _ready() -> void:
timer.timeout.connect(_on_timer_timeout)


func _process(_delta: float) -> void:
text = "%02d:%02d" % [floor(timer.time_left / 60), int(timer.time_left) % 60]


func _on_player_hub_player_exited() -> void:
timer.start(300)
timer.start(time)
visible = true


func _on_player_hub_player_entered() -> void:
timer.stop()
visible = false


func _on_timer_timeout() -> void:
time_left_ended.emit()
7 changes: 7 additions & 0 deletions src/player/player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,10 @@ func take_hit(body: Node2D) -> void:

if health <= 0:
died.emit(self)


func _on_time_left_indicator_time_left_ended() -> void:
# Insta-kill player, if time runs out
# TODO @Shinigami92 2023-11-20: This will trigger something like a sandstorm
# or similar later on
died.emit(self)
1 change: 1 addition & 0 deletions src/world/world.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,4 @@ script = ExtResource("11_akep3")
[connection signal="player_exited" from="PlayerHub" to="OuterWorldChunkGen" method="_on_player_hub_player_exited"]
[connection signal="player_exited" from="PlayerHub" to="Player/Camera2D/TimeLeftIndicator" method="_on_player_hub_player_exited"]
[connection signal="died" from="Player" to="PlayerHub" method="_on_player_died"]
[connection signal="time_left_ended" from="Player/Camera2D/TimeLeftIndicator" to="Player" method="_on_time_left_indicator_time_left_ended"]

0 comments on commit c9321af

Please sign in to comment.