Location Earth, (I Think)
Home
About Us
Contact Us
Links
Home
GTA Style RealTime
Complete with 7 day counter.
 
Have you ever wanted GTA Style RealTime like in the Picture on the Right?
 
Using this code below will automatically give you this 24 Hour Clock System, But my version also come complete with a 7 Day Counter so you can also tell what day of the week it is.
 
How to use this?
Simple copy the code from the panel below to DarkBasic and Press F5 for a working Example, If you do deside to use this system then combine it with a Bitmap Font for a better and more GTA Style look, Remember to save the Time and Date during a save game though so when your player returns the Time setting can then be Restored. 
 
If you do use this in your game then try connecting the Ambiant Lighting to the Clock, So at Night it will automatically get darker, and then lighter in the morning, I think thats a good effect myself as it automatically adds somethink to your game...
 

` RealTime Functions
`
` By Michael Mihalyfi
` MSon648@Hotmail.com
`
` SetRealTime(Day,Hour,Minute) - Place this at the Start of your Programme to Set the Time
` UpdateRealTime()             - Place this at the Start of your Loop
` Get24HourTime()              - Get the Time in 24 Hour format as a String, Ie: Text 10,10,Get24HourTime()
` GetDay()                     - Get the Day as a String, Ie: Text 10,20,GetDay()
` RealTime.Update              - 1 Indicates if An Update was Made, Ie: 1 Minute Has Passed
` RealTimeSpeed                - Sets the Speed of the Time..., (Default = 1000, Ie: 1 Second)
`
` ----------------------------------------------------------------------------------------------


Sync On
Sync Rate
0

SetRealTime(1,6,0)

Do : Cls : UpdateRealTime()

If RealTime.Update = 1
` Code can Go here...
EndIf

Text 10,10,Get24HourTime()
Text 10,20,GetDay()
Sync : Loop

` RealTime Functions ----------------------------------------------------------------------------------------------
FUNCTION
SetRealTime(Day,Hour,Minute)
   GOSUB SetupRealTime
         RealTime.Day       = Day
         RealTime.Hour      = Hour
         RealTime.Minute    = Minute
         RealTime.RealTimer = TIMER()
         RealTime.Update    = 1


ENDFUNCTION
FUNCTION
UpdateRealTime()
      IF RealTime.RealTimer + RealTimeSpeed <= TIMER()
         RealTime.RealTimer = TIMER()
         RealTime.Minute    = RealTime.Minute + 1
      IF RealTime.Minute    = 60 THEN RealTime.Minute = 0 : RealTime.Hour = RealTime.Hour + 1
      IF RealTime.Hour      = 25 THEN RealTime.Hour   = 0 : RealTime.Day  = RealTime.Day  + 1
      IF RealTime.Day       = 8  THEN RealTime.Day    = 1
         RealTime.Update    = 1
    ELSE RealTime.Update    = 0
         ENDIF

ENDFUNCTION
FUNCTION
Get24HourTime()
      IF RealTime.Hour   < 10 THEN Hour$   = "0" + STR$(RealTime.Hour  ) ELSE Hour$   = STR$(RealTime.Hour  )
      IF RealTime.Minute < 10 THEN Minute$ = "0" + STR$(RealTime.Minute) ELSE Minute$ = STR$(RealTime.Minute)
         Time$ = Hour$ + ":" + Minute$

ENDFUNCTION Time$
FUNCTION GetDay()
      IF RealTime.Day = 1 THEN EXITFUNCTION "Monday"
      IF RealTime.Day = 2 THEN EXITFUNCTION "Tuesday"
      IF RealTime.Day = 3 THEN EXITFUNCTION "Wednesday"
      IF RealTime.Day = 4 THEN EXITFUNCTION "Thursday"
      IF RealTime.Day = 5 THEN EXITFUNCTION "Friday"
      IF RealTime.Day = 6 THEN EXITFUNCTION "Saturday"
      IF RealTime.Day = 7 THEN EXITFUNCTION "Sunday"


ENDFUNCTION ""
` ----------------------------------------------------------------------------------------------

SetupRealTime: TYPE System_Type_RealTime
                    Day       AS INTEGER
                    Hour      AS INTEGER
                    Minute    AS INTEGER
                    Update    AS INTEGER
                    RealTimer AS INTEGER
                    ENDTYPE

             GLOBAL RealTime      AS System_Type_RealTime
             GLOBAL RealTimeSpeed AS INTEGER
                    RealTimeSpeed = 1000
                    RETURN