Vlue

Basic Game Time

Aug 5th, 2012
27,829
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Basic Game Time + Night/Day v1.6.2b
  2. #----------#
  3. #Features: Provides a series of functions to set and recall current game time
  4. #          as well customizable tints based on current game time to give the
  5. #          appearance of night and day.
  6. #
  7. #Usage:   Script calls:
  8. #           GameTime::minute?   - returns the current minute
  9. #           GameTime::hour?     - returns the current hour
  10. #           GameTime::set(time) - sets the game time to time, in frames (max:1440)
  11. #           GameTime::change(time) - increments the game time! (can be negative)
  12. #           GameTime::pause_time(set) - stops time for events and stuff, true or false
  13. #           GameTime::pause_tint(set) - time runs, but tints do not update
  14. #           GameTime::clock(set) - sets whether clock is visible or not
  15. #        
  16. #Customization: Set below, in comments.
  17. #
  18. #Examples: GameTime::set(360)
  19. #
  20. #----------#
  21. #-- Script by: V.M of D.T
  22. #
  23. #- Questions or comments can be:
  24. #    given by email: sumptuaryspade@live.ca
  25. #    provided on facebook: http://www.facebook.com/DaimoniousTailsGames
  26. #   All my other scripts and projects can be found here: http://daimonioustails.weebly.com/
  27. #
  28. #--- Free to use in any project, commercial or non-commercial, with credit given
  29. # - - Though a donation's always a nice way to say thank you~ (I also accept actual thank you's)
  30.  
  31. #---Game Clock---#
  32. #USE_CLOCK to true to display game time clock
  33. #CLOCK_POSITION for position of clock
  34. #  1 = topleft, 2 = topright, 3 = bottomleft, 4 = bottomright
  35. #CLOCK_TOGGLE is any input button available, see the INPUT help file for options
  36. #------#
  37. USE_CLOCK       = true
  38. CLOCK_POSITION  = 4
  39. CLOCK_TOGGLE    = :SHIFT
  40.  
  41. module GameTime
  42.   #---Game Time Details---#
  43.   #Number of frames in a game minute, 60 frames = 1 second
  44.   TIME_COUNT      = 60
  45.   #Sets whether to tint screen based on game time
  46.   USE_TINT        = true
  47.  
  48.   #Switch to denote day or night time
  49.   USE_SWITCH = false
  50.   NIGHT_DAY_SWITCH = 1
  51.   DAY_TIME_START = 6
  52.   NIGHT_TIME_START = 18
  53.  
  54.   #True to pause time while not in map or while during a message
  55.   PAUSE_IN_COMBAT  = false
  56.   PAUSE_NOT_IN_MAP = true
  57.   PAUSE_IN_MESSAGE = true
  58.  
  59.   #Sets time frames of tints by minute count, one day is 1440 minutes
  60.   # 0 = 12am, 360 = 6am, 720 = 12pm, 1080 = 6pm  etc...
  61.   PRESUNRISE_TIME = 240
  62.   SUNRISE_TIME    = 360
  63.   NOONSTART_TIME  = 660
  64.   NOONEND_TIME    = 900
  65.   PRESUNSET_TIME  = 1080
  66.   SUNSET_TIME     = 1260
  67.   MIDNIGHT_TIME   = 60  #Must be greater than 0
  68.  
  69.   #Sets custome tints
  70.   PRESUNRISE_TONE = Tone.new(-75,-75,0,50)
  71.   SUNRISE_TONE    = Tone.new(0,0,0,0)
  72.   NOONSTART_TONE  = Tone.new(45,45,0,-25)
  73.   NOONEND_TONE    = Tone.new(0,0,0,0)
  74.   PRESUNSET_TONE  = Tone.new(-50,-50,0,25)
  75.   SUNSET_TONE     = Tone.new(-75,-100,0,75)
  76.   MIDNIGHT_TONE   = Tone.new(-125,-125,0,125)
  77.  
  78.   #Include the ids of any maps not to be tinted based on time
  79.   # Usually reserved for indoor maps
  80.   NOTINTMAPS = [2]
  81.  
  82.   #Store current time in a variable?
  83.   USE_VARIABLE = false
  84.   TIME_VARIABLE = 1
  85.  
  86.   #---END---#
  87.  
  88.   def self.init
  89.     $game_time = 0
  90.     $game_time_pause_time = false
  91.     $game_time_pause_tint = false
  92.   end
  93.   def self.update
  94.     old_time = $game_time
  95.     if $game_time_pause_time then return else end
  96.     case SceneManager::scene_is?(Scene_Map)
  97.     when true
  98.       if $game_message.visible == true && PAUSE_IN_MESSAGE then else
  99.       $game_time += 1 if Graphics.frame_count % TIME_COUNT == 0 end
  100.     when false
  101.  
  102.       if !PAUSE_NOT_IN_MAP and !SceneManager::scene_is?(Scene_Battle)
  103.         $game_time += 1 if Graphics.frame_count % TIME_COUNT == 0 end
  104.       if SceneManager::scene_is?(Scene_Battle) && PAUSE_IN_COMBAT != true
  105.       $game_time += 1 if Graphics.frame_count % TIME_COUNT == 0 end
  106.     end
  107.     if $game_time == 1440 then $game_time = 0 end
  108.     $game_variables[TIME_VARIABLE] = $game_time if USE_VARIABLE
  109.     update_night_switch if USE_SWITCH
  110.     GameTime::tint if $game_time_pause_tint != true
  111.     if old_time != $game_time then $game_map.need_refresh = true end
  112.   end
  113.   def self.update_night_switch
  114.     if hour? > DAY_TIME_START and hour? < NIGHT_TIME_START
  115.       $game_switches[NIGHT_DAY_SWITCH] = true unless $game_switches[NIGHT_DAY_SWITCH] == true
  116.     else
  117.       $game_switches[NIGHT_DAY_SWITCH] = false unless $game_switches[NIGHT_DAY_SWITCH] == false
  118.     end
  119.   end
  120.   def self.hour?
  121.     return $game_time / 60
  122.   end
  123.   def self.minute?
  124.     return $game_time % 60
  125.   end
  126.   def self.time?
  127.     meri = "AM"
  128.     hour = GameTime::hour?
  129.     minute = GameTime::minute?
  130.     if hour > 11 then meri = "PM" end
  131.     if hour == 0 then hour = 12; meri = "AM" end
  132.     if hour > 12 then hour -= 12 end
  133.     if hour < 10 then hour = " " + hour.to_s else hour.to_s end
  134.     if minute < 10 then minute = "0" + minute.to_s else minute.to_s end
  135.     return hour.to_s + ":" + minute.to_s + " " + meri
  136.   end
  137.   def self.set(number)
  138.     $game_time = number if number < 1440
  139.     GameTime::tint(0) if $game_time_pause_tint != true
  140.   end
  141.   def self.change(number)
  142.     $game_time += number
  143.     $game_time -= 1440 if $game_time > 1440
  144.     $game_time += 1440 if $game_time < 0
  145.     GameTime::tint(0) if $game_time_pause_tint != true
  146.   end
  147.   def self.tint(tint = 60)
  148.     if USE_TINT != true then return end
  149.     for i in NOTINTMAPS
  150.       if $game_map.map_id == i
  151.         $game_map.screen.start_tone_change(Tone.new(0,0,0,0),0)
  152.         return
  153.       end
  154.     end
  155.     if SceneManager::scene_is?(Scene_Map) then else return end
  156.     case $game_time
  157.     when PRESUNRISE_TIME .. SUNRISE_TIME
  158.       $game_map.screen.start_tone_change(PRESUNRISE_TONE, tint)
  159.     when SUNRISE_TIME .. NOONSTART_TIME
  160.       $game_map.screen.start_tone_change(SUNRISE_TONE, tint)
  161.     when NOONSTART_TIME .. NOONEND_TIME
  162.       $game_map.screen.start_tone_change(NOONSTART_TONE, tint)
  163.     when NOONEND_TIME .. PRESUNSET_TIME
  164.       $game_map.screen.start_tone_change(NOONEND_TONE, tint)
  165.     when PRESUNSET_TIME .. SUNSET_TIME
  166.       $game_map.screen.start_tone_change(PRESUNSET_TONE, tint)
  167.     when SUNSET_TIME .. 1440
  168.       $game_map.screen.start_tone_change(SUNSET_TONE, tint)
  169.     when 0 .. MIDNIGHT_TIME
  170.       $game_map.screen.start_tone_change(SUNSET_TONE, tint)
  171.     when MIDNIGHT_TIME .. PRESUNRISE_TIME
  172.       $game_map.screen.start_tone_change(MIDNIGHT_TONE, tint)
  173.     end
  174.   end
  175.   def self.pause_time(set)
  176.     $game_time_pause_time = set
  177.   end
  178.   def self.pause_tint(set)
  179.     $game_time_pause_tint = set
  180.   end
  181.   def self.clock(set)
  182.     return unless SceneManager.scene.is_a?(Scene_Map)
  183.     SceneManager.scene.clock_visible?(set)
  184.   end
  185.  
  186.   class Window_Clock < Window_Base
  187.     def initialize
  188.       case CLOCK_POSITION
  189.       when 1
  190.         super(0,0,115,56)
  191.       when 2
  192.         super(Graphics.width-115,0,115,56)
  193.       when 3
  194.         super(0,Graphics.height-56,115,56)
  195.       when 4
  196.         super(Graphics.width-115,Graphics.height-56,115,56)
  197.       end
  198.       self.visible = $game_time_clock_visibility unless $game_time_clock_visibility.nil?
  199.     end
  200.     def update
  201.       self.contents.clear
  202.       self.contents.draw_text(0,0,100,24,GameTime::time?)
  203.       $game_time_clock_visibility = self.visible
  204.     end
  205.   end
  206.  
  207. end
  208.  
  209. GameTime::init
  210.  
  211. module DataManager
  212.   class << self
  213.   alias gametime_msc make_save_contents
  214.   alias gametime_esc extract_save_contents
  215.   end
  216.   def self.make_save_contents
  217.     contents = gametime_msc
  218.     contents[:gametime] = $game_time
  219.     contents
  220.   end
  221.   def self.extract_save_contents(contents)
  222.     gametime_esc(contents)
  223.     $game_time = contents[:gametime]
  224.   end
  225. end
  226.  
  227.  
  228. class Scene_Map < Scene_Base
  229.   alias gametime_post_transfer post_transfer
  230.   alias gametime_create_all_windows create_all_windows
  231.   alias gametime_update_map update
  232.   def post_transfer
  233.     GameTime::tint(0) if $game_time_pause_tint != true
  234.     gametime_post_transfer
  235.   end
  236.   def create_all_windows
  237.     gametime_create_all_windows
  238.     @gametimeclock = GameTime::Window_Clock.new if USE_CLOCK
  239.   end
  240.   def update
  241.     gametime_update_map
  242.     @gametimeclock.update if @gametimeclock.nil? == false
  243.     if Input.trigger?(CLOCK_TOGGLE) and @gametimeclock.nil? == false
  244.       @gametimeclock.visible ? @gametimeclock.visible = false : @gametimeclock.visible = true
  245.     end
  246.   end
  247.   def clock_visible?(set)
  248.     @gametimeclock.visible = set
  249.   end
  250. end
  251.  
  252. class Scene_Base
  253.   alias gametime_update update
  254.   def update
  255.     gametime_update
  256.     GameTime::update
  257.   end
  258. end
RAW Paste Data