UnderwareDESIGN

PlayBASIC => Resources => Source Codes => Topic started by: Kman1011 on June 07, 2007, 08:27:47 PM

Title: Timer Demo
Post by: Kman1011 on June 07, 2007, 08:27:47 PM
Just thought I would throw this little demo in for any gamers who want to use a timer in thier games

[pbcode]
; 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
[/pbcode]


EDIT: Changed code boxes to PBcode boxes
Title: Re: Timer Demo
Post by: kevin on June 16, 2007, 03:09:52 PM
 Here's a few functions that convert a timer ticks (milliseconds) into Hours,Minutes,Seconds

[pbcode]

   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$



[/pbcode]
Title: Re: Timer Demo
Post by: Kman1011 on June 17, 2007, 07:55:01 PM
Very Handy Functions :)