#==============================================================================
# ** Sprite_Timer
#------------------------------------------------------------------------------
# This sprite is used to display the timer.It observes the $game_system
# class and automatically changes sprite conditions.
#==============================================================================
class Sprite_Timer < Sprite
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super
self.bitmap = Bitmap.new(120, 20)
self.bitmap.font.name = "Arial"
self.bitmap.font.size = 15
self.x = 620 - self.bitmap.width
self.y = 0
self.z = 2000
@flicker = true
if $game_variables[CURRENT_GAME_DAY] < INTIALIZE_GAME_DAY
$game_variables[CURRENT_GAME_DAY] = INTIALIZE_GAME_DAY
end
update
end
#--------------------------------------------------------------------------
# * Dispose
#--------------------------------------------------------------------------
def dispose
if self.bitmap != nil
self.bitmap.dispose
end
super
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
super
# Set timer to visible if working
if $game_switches[INVISIBLE_TIMER_SWITCH] == true
self.visible = false
else
self.visible = true
end
if $game_variables[NEW_HOUR] != 0 and
$game_variables[NEW_HOUR] != $game_variables[HOUR_VARIABLE]
$game_system.timer = $game_variables[NEW_HOUR] * 2400
if $game_system.timer > 57600
$game_system.timer % 57600
$game_variables[CURRENT_GAME_DAY] += 1
end
$game_variables[NEW_HOUR] = 0
end
# If timer needs to be redrawn
if $game_system.timer / Graphics.frame_rate != @total_sec and $game_system.timer_working
# Clear window contents
self.bitmap.clear
# Calculate total number of seconds
@total_sec = $game_system.timer / Graphics.frame_rate
# Make a string for displaying the timer
case $game_variables[HOUR_VARIABLE]
when 0,1,2,3,4,5,18,19,20,21,22,23,24
moon_and_sun = RPG::Cache.picture("Moon")
cw = moon_and_sun.width
ch = moon_and_sun.height
rect = Rect.new(0, 0, cw, ch)
when 6,7,8,9,10,11,12,13,14,15,16,17
moon_and_sun = RPG::Cache.picture("Sun")
cw = moon_and_sun.width
ch = moon_and_sun.height
rect = Rect.new(0, 0, cw, ch)
end
if $game_variables[HOUR_VARIABLE] > 24
moon_and_sun = RPG::Cache.picture("Moon")
cw = moon_and_sun.width
ch = moon_and_sun.height
rect = Rect.new(0, 0, cw, ch)
end
if AM_AND_PM == true
if $game_variables[HOUR_VARIABLE] > 12
min = (@total_sec - 720) / 60
sec = @total_sec % 60
else
min = @total_sec / 60
sec = @total_sec % 60
end
if $game_variables[HOUR_VARIABLE] > 11 and $game_variables[HOUR_VARIABLE] != 24
setting = "PM"
else
setting = "AM"
end
if FLICKERCOLON == true and @flicker == false
text = sprintf("%02d %02d " + setting, min, sec)
@flicker = true
else
text = sprintf("%02d:%02d " + setting, min, sec)
if FLICKERCOLON == true
@flicker = false
end
end
else
min = @total_sec / 60
sec = @total_sec % 60
text = sprintf("%02d:%02d", min, sec)
end
if $game_variables[HOUR_VARIABLE] > 12 and AM_AND_PM == true
$game_variables[HOUR_VARIABLE] = min + 12
else
$game_variables[HOUR_VARIABLE] = min
end
$sec = sec
# Draw timer
rect2 = Rect.new(1, 1, 120, 20)
self.bitmap.font.color.set(0, 0, 0)
self.bitmap.draw_text(rect2, text, 1)
self.bitmap.font.color.set(255, 255, 255)
self.bitmap.draw_text(self.bitmap.rect, text, 1)
self.bitmap.blt(90, 0, moon_and_sun, rect)
end
end
end