extends Control

var time: float;
var secs_previous: int;
var dead: bool = false

func _ready():
    reset()

func _process(delta):
    if !dead:
        time += delta
    var secs_raw: int = int(time) % 60;
    if secs_raw != secs_previous:
        secs_previous = secs_raw
        var secs: String = str(int(time) % 60);
        var mins: String = str(int(time / 60.0));
        if mins.length() == 1:
            mins = "0" + mins;
        if secs.length() == 1:
            secs = "0" + secs;
        $Label.set_text("%s:%s" % [mins, secs]);

func stop():
    dead = true

func reset():
    time = 0.0
    secs_previous = -1
    dead = false
