Advertisement
pigu_6

VM| Basic Game Time + Night/Day

Nov 24th, 2012
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.65 KB | None | 0 0
  1. #Basic Game Time + Night/Day
  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. #--- Free to use in any project with credit given
  23.  
  24. #---Game Clock---#
  25. #USE_CLOCK to true to display game time clock
  26. #CLOCK_POSITION for position of clock
  27. # 1 = topleft, 2 = topright, 3 = bottomleft, 4 = bottomright
  28. #CLOCK_TOGGLE is any input button available, see the INPUT help file for options
  29. #------#
  30. USE_CLOCK = true
  31. CLOCK_POSITION = 4
  32. CLOCK_TOGGLE = :SHIFT
  33.  
  34. module GameTime
  35. #---Game Time Details---#
  36. #Number of frames in a game minute, 60 frames = 1 second
  37. TIME_COUNT = 60
  38. #Sets whether to tint screen based on game time
  39. USE_TINT = true
  40.  
  41. #Switch to denote day or night time
  42. USE_SWITCH = false
  43. NIGHT_DAY_SWITCH = 1
  44. DAY_TIME_START = 6
  45. NIGHT_TIME_START = 18
  46.  
  47. #True to pause time while not in map or while during a message
  48. PAUSE_IN_COMBAT = false
  49. PAUSE_NOT_IN_MAP = true
  50. PAUSE_IN_MESSAGE = true
  51.  
  52. #Sets time frames of tints by minute count, one day is 1440 minutes
  53. # 0 = 12am, 360 = 6am, 720 = 12pm, 1080 = 6pm etc...
  54. PRESUNRISE_TIME = 240
  55. SUNRISE_TIME = 360
  56. NOONSTART_TIME = 660
  57. NOONEND_TIME = 900
  58. PRESUNSET_TIME = 1080
  59. SUNSET_TIME = 1260
  60. MIDNIGHT_TIME = 60 #Must be greater than 0
  61.  
  62. #Sets custome tints
  63. PRESUNRISE_TONE = Tone.new(-75,-75,0,50)
  64. SUNRISE_TONE = Tone.new(0,0,0,0)
  65. NOONSTART_TONE = Tone.new(45,45,0,-25)
  66. NOONEND_TONE = Tone.new(0,0,0,0)
  67. PRESUNSET_TONE = Tone.new(-50,-50,0,25)
  68. SUNSET_TONE = Tone.new(-75,-100,0,75)
  69. MIDNIGHT_TONE = Tone.new(-125,-125,0,125)
  70.  
  71. #Include the ids of any maps not to be tinted based on time
  72. # Usually reserved for indoor maps
  73. NOTINTMAPS = [2]
  74.  
  75. #Store current time in a variable?
  76. USE_VARIABLE = false
  77. TIME_VARIABLE = 1
  78.  
  79. #---END---#
  80.  
  81. def self.init
  82. $game_time = 0
  83. $game_time_pause_time = false
  84. $game_time_pause_tint = false
  85. end
  86. def self.update
  87. if $game_time_pause_time then return else end
  88. case SceneManager::scene_is?(Scene_Map)
  89. when true
  90. if $game_message.visible == true && PAUSE_IN_MESSAGE then else
  91. $game_time += 1 if Graphics.frame_count % TIME_COUNT == 0 end
  92. when false
  93.  
  94. if !PAUSE_NOT_IN_MAP and !SceneManager::scene_is?(Scene_Battle)
  95. $game_time += 1 if Graphics.frame_count % TIME_COUNT == 0 end
  96. if SceneManager::scene_is?(Scene_Battle) && PAUSE_IN_COMBAT != true
  97. $game_time += 1 if Graphics.frame_count % TIME_COUNT == 0 end
  98. end
  99. if $game_time == 1440 then $game_time = 0 end
  100. $game_variables[TIME_VARIABLE] = $game_time if USE_VARIABLE
  101. update_night_swith if USE_SWITCH
  102. GameTime::tint if $game_time_pause_tint != true
  103. end
  104. def update_night_switch
  105. if hour? > DAY_TIME_START and hour? < NIGHT_TIME_START
  106. $game_switches[NIGHT_DAY_SWITCH] = true unless $game_switches[NIGHT_DAY_SWITCH] == true
  107. else
  108. $game_switches[NIGHT_DAY_SWITCH] = false unless $game_switches[NIGHT_DAY_SWITCH] == false
  109. end
  110. end
  111. def self.hour?
  112. return $game_time / 60
  113. end
  114. def self.minute?
  115. return $game_time % 60
  116. end
  117. def self.time?
  118. meri = "AM"
  119. hour = GameTime::hour?
  120. minute = GameTime::minute?
  121. if hour > 11 then meri = "PM" end
  122. if hour == 0 then hour = 12; meri = "AM" end
  123. if hour > 12 then hour -= 12 end
  124. if hour < 10 then hour = " " + hour.to_s else hour.to_s end
  125. if minute < 10 then minute = "0" + minute.to_s else minute.to_s end
  126. return hour.to_s + ":" + minute.to_s + " " + meri
  127. end
  128. def self.set(number)
  129. $game_time = number if number < 1440
  130. GameTime::tint(0)
  131. end
  132. def self.change(number)
  133. $game_time += number
  134. $game_time -= 1440 if $game_time > 1440
  135. $game_time += 1440 if $game_time < 0
  136. GameTime::tint(0)
  137. end
  138. def self.tint(tint = 60)
  139. if USE_TINT != true then return end
  140. for i in NOTINTMAPS
  141. if $game_map.map_id == i
  142. $game_map.screen.start_tone_change(Tone.new(0,0,0,0),0)
  143. return
  144. end
  145. end
  146. if SceneManager::scene_is?(Scene_Map) then else return end
  147. case $game_time
  148. when PRESUNRISE_TIME .. SUNRISE_TIME
  149. $game_map.screen.start_tone_change(PRESUNRISE_TONE, tint)
  150. when SUNRISE_TIME .. NOONSTART_TIME
  151. $game_map.screen.start_tone_change(SUNRISE_TONE, tint)
  152. when NOONSTART_TIME .. NOONEND_TIME
  153. $game_map.screen.start_tone_change(NOONSTART_TONE, tint)
  154. when NOONEND_TIME .. PRESUNSET_TIME
  155. $game_map.screen.start_tone_change(NOONEND_TONE, tint)
  156. when PRESUNSET_TIME .. SUNSET_TIME
  157. $game_map.screen.start_tone_change(PRESUNSET_TONE, tint)
  158. when SUNSET_TIME .. 1440
  159. $game_map.screen.start_tone_change(SUNSET_TONE, tint)
  160. when 0 .. MIDNIGHT_TIME
  161. $game_map.screen.start_tone_change(SUNSET_TONE, tint)
  162. when MIDNIGHT_TIME .. PRESUNRISE_TIME
  163. $game_map.screen.start_tone_change(MIDNIGHT_TONE, tint)
  164. end
  165. end
  166. def self.pause_time(set)
  167. $game_time_pause_time = set
  168. end
  169. def self.pause_tint(set)
  170. $game_time_pause_tint = set
  171. end
  172. def self.clock(set)
  173. SceneManager.scene.clock_visible?(set)
  174. end
  175.  
  176. class Window_Clock < Window_Base
  177. def initialize
  178. case CLOCK_POSITION
  179. when 1
  180. super(0,0,115,56)
  181. when 2
  182. super(429,0,115,56)
  183. when 3
  184. super(0,360,115,56)
  185. when 4
  186. super(429,360,115,56)
  187. end
  188. self.visible = $game_time_clock_visibility unless $game_time_clock_visibility.nil?
  189. end
  190. def update
  191. self.contents.clear
  192. self.contents.draw_text(0,0,100,24,GameTime::time?)
  193. $game_time_clock_visibility = self.visible
  194. end
  195. end
  196.  
  197. end
  198.  
  199. module DataManager
  200. class << self
  201. alias gametime_msc make_save_contents
  202. alias gametime_esc extract_save_contents
  203. end
  204. def self.make_save_contents
  205. contents = gametime_msc
  206. contents[:gametime] = $game_time
  207. contents
  208. end
  209. def self.extract_save_contents(contents)
  210. gametime_esc(contents)
  211. $game_time = contents[:gametime]
  212. end
  213. end
  214.  
  215.  
  216. class Scene_Map < Scene_Base
  217. alias gametime_post_transfer post_transfer
  218. alias gametime_create_all_windows create_all_windows
  219. alias gametime_update_map update
  220. def post_transfer
  221. GameTime::tint(0)
  222. gametime_post_transfer
  223. end
  224. def create_all_windows
  225. gametime_create_all_windows
  226. @gametimeclock = GameTime::Window_Clock.new if USE_CLOCK
  227. end
  228. def update
  229. gametime_update_map
  230. @gametimeclock.update if @gametimeclock.nil? == false
  231. if Input.trigger?(CLOCK_TOGGLE) and @gametimeclock.nil? == false
  232. @gametimeclock.visible ? @gametimeclock.visible = false : @gametimeclock.visible = true
  233. end
  234. end
  235. def clock_visible?(set)
  236. @gametimeclock.visible = set
  237. end
  238. end
  239.  
  240. class Scene_Base
  241. alias gametime_update update
  242. def update
  243. gametime_update
  244. GameTime::update
  245. end
  246. end
  247.  
  248. GameTime::init
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement