News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

Timer Demo

Started by Kman1011, June 07, 2007, 08:27:47 PM

Previous topic - Next topic

Kman1011

Just thought I would throw this little demo in for any gamers who want to use a timer in thier games

PlayBASIC Code: [Select]
; PROJECT : Timer
; AUTHOR : Kman
; CREATED : 6/7/2007
; EDITED : 6/7/2007
; ---------------------------------------------------------------------
Print "Hit Enter key Anytime..."
Sync
startime=Timer()
Repeat
; Cls 0
savetimesec=(Timer()-startime)/1000
savetimemin=savetimesec/60
savetimehr=savetimemin/60
;SetCursor 0,2
;Print (Timer()-startime)/1000
;Sync
Until EnterKey()=True

time$=Digits$(savetimehr,2)+":"+Digits$(savetimemin,2)+":"+Digits$(savetimesec,2)
Print "Duration of time: "+time$
WaitNoKey
Sync
WaitKey
End




EDIT: Changed code boxes to PBcode boxes
Ahh... Another visitor. Stay awhile....STAY FOREVER!!!...MWA-HA-HA-HA

kevin

#1
 Here's a few functions that convert a timer ticks (milliseconds) into Hours,Minutes,Seconds

PlayBASIC Code: [Select]
   StartTime=Timer()

Do
Cls 0

Ticks=timer()-StartTime

Text 100,100,"Hours/Min/Seconds:"+ConvertTimeToHMS(ticks,0)
Text 100,120,"Seconds/Min/Hours:"+ConvertTimeToHMS(ticks,1)


Text 100,200,"Min/Seconds:"+ConvertTimeToMS(ticks,0)
Text 100,220,"Seconds/Min:"+ConvertTimeToMS(ticks,1)


Sync
loop







` *=---------------------------------------------------------------------=*
` >> Convert Time(millisecondes) to Hours/Mins/Seconds <<
` *=---------------------------------------------------------------------=*
`
` This function will convert a milli seconds timer value into digital
` time format. This version supports Hours/Minutes and Seconds.
`
`
` *=---------------------------------------------------------------------=*


Function ConvertTimeToHMS(ticks,format)

Seconds=ticks/1000
Minutes=mod((Seconds/60),60)
Hours=mod((seconds/3600),24)

Seconds=mod(seconds,60)

h$=Digits$(hours,2)
m$=Digits$(minutes,2)
s$=Digits$(seconds,2)

if format=0
result$=h$+":"+m$+":"+s$
else
result$=s$+":"+m$+":"+h$
endif

EndFunction result$


` *=---------------------------------------------------------------------=*
` >> Convert Timer to Mins/Seconds <<
` *=---------------------------------------------------------------------=*
`
` This function will convert a milli seconds timer value into digital
` time format. This version supports Minutes and Seconds.
`
`
` *=---------------------------------------------------------------------=*


Function ConvertTimeToMS(ticks,format)

Seconds=ticks/1000
Minutes=mod((Seconds/60),60)
Seconds=mod(seconds,60)
m$=digits$(minutes,2)
s$=digits$(seconds,2)

if format=0
result$=m$+":"+s$
else
result$=s$+":"+m$
endif

EndFunction result$





Kman1011

Very Handy Functions :)
Ahh... Another visitor. Stay awhile....STAY FOREVER!!!...MWA-HA-HA-HA