BAIT Community Project (thread 2)

Miscellaneous Forums/Blitz Showcase/BAIT Community Project (thread 2)

Clock.bb (Adapt as required):

; Data declarations

Const ClockX = 350
Const ClockY = 30

Global MinutesLeft    = 0
Global SecondsLeft    = 10
Global LastTimeChange = MilliSecs()

Function UpdateClock()

	; Counts the clock down to 0

	If LastTimeChange + 1000 < MilliSecs()
	
		If SecondsLeft > 0
		
			SecondsLeft = SecondsLeft - 1
		
		Else
		
			If MinutesLeft > 0
			
				MinutesLeft = MinutesLeft - 1
				SecondsLeft = 59
			
			EndIf
		
		EndIf
		
		LastTimeChange = MilliSecs()
	
	EndIf

End Function

Function DisplayClock()

	; Displays the clock at the set position

	If SecondsLeft >= 10
	
		Text ClockX, ClockY, MinutesLeft + ":"  + SecondsLeft 
	
	Else
	
		Text ClockX, ClockY, MinutesLeft + ":0" + SecondsLeft
	
	EndIf

End Function

; Test Harness

SetBuffer BackBuffer()

While Not KeyHit(1)

	Cls
	
		UpdateClock()
		DisplayClock()

	Flip

Wend


Ryan