Progress Bar, which does timer, and as player manages to hit milestones the timer goes up

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By yeeshu06
:warning: Old Version Published before Godot 3 was released.

Good day,

I want to make a progress bar, which countsdown time (eg: 15-20 seconds), and as the player hits milestones, the time increases in the bar. How can i achieve this using progress bar. Please help, or suggest your way. Thanks a ton.

:bust_in_silhouette: Reply From: avencherus

Perhaps something like this?

extends ProgressBar

var timer = Timer.new()

export (float, 0.0, 100.0, .1) var start_time = 15.0
export (float, 0.0, 100.0, .1) var end_time   = 20.0

func _ready():
	
	timer.set_timer_process_mode(Timer.TIMER_PROCESS_FIXED)
	timer.set_wait_time(end_time - start_time)
	timer.set_one_shot(true)
	timer.connect("timeout", self, "gameover")
	
	add_child(timer)
	timer.start()

	set_fixed_process(true)
	
func gameover():
	print("GAME OVER - TIME RAN OUT")
	set_fixed_process(false)
	
var t = 1

func _fixed_process(delta): # Print testing
	
	if(t >= 1):
		t -= 1
		print(timer.get_time_left())
		
	t += delta
		
const ADDITIONAL_TIME = 3.0

func _on_Button_pressed(): # Button for testing
	
	# Must get time before stopping timer.
	var new_time = timer.get_time_left() + ADDITIONAL_TIME
	
	timer.stop()
	timer.set_wait_time(new_time)
	timer.start()