#===============================================================================
# ~* Sprite_Timer (Critical) *~
#-------------------------------------------------------------------------------
# Written by: Kain Nobel
# Version: 0.5
# Last Update: 5/13/2008
# Date Created: 10/17/2008
#===============================================================================
TimerCriticalSwitch = 1
#===============================================================================
# INSTRUCTIONS:
# This is just an enhanced version of Sprite_Timer default class, with a few
# small changes I decided to make to it. Now it not only displays minutes and
# seconds in the string, but also milli-seconds... yes, a fraction of a second,
# and it updates in real time too! (Provided your computer isn't fucked!)
# Lastly, it detects the total set time vs current time, and sets a caution
# and critical color when the timer reaches a certain point, such as 1/2 or 3/4
# the set time.
#-------------------------------------------------------------------------------
class Sprite_Timer < Sprite
#------------------------
# * Object Initialization
#------------------------
def initialize
super
# Variable used to determine timer critical
@critical = -1
self.bitmap = Bitmap.new(120, 48)
self.bitmap.font.name = "Arial"
self.bitmap.font.size = 32
self.x = 380 - self.bitmap.width
self.y = 0
self.z = 500
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
self.visible = $game_system.timer_working
# If Timer needs to be withdrawn
self.bitmap.clear
# Get @total_sec value
@total_sec = $game_system.timer / Graphics.frame_rate
frac = $game_system.timer % Graphics.frame_rate
sec_fraction = frac.to_f / Graphics.frame_rate.to_f
sec_fraction *= 100
min = @total_sec / 100
sec = @total_sec % 60
# Send min, sec, millisec info to a string.
text = sprintf("%02d:%02d", sec, sec_fraction)
# If Critical is equal or less than 0, set to @total_sec / 2
if $game_switches[TimerCriticalSwitch] == true
# Auto-Set critical time to 1/2 timer set time
if @critical == -1
@critical = (@total_sec / 2)
end
# If @total_sec is more than (Timer Setting / 2) ?
if @total_sec >= @critical
self.bitmap.font.color.set(204, 224, 240)
# If @total_sec is equal to or more than (Timer Setting / 4) ?
elsif @total_sec >= (@critical / 2)
self.bitmap.font.color.set(255, 200, 0)
else
# @total_sec is less than Timer Critcal Variable!
self.bitmap.font.color.set(255, 0, 0)
end
else
# Switch is off, automatically set to default color
self.bitmap.font.color.set(204, 224, 240)
end
# Draw the timer value from string 'text'
self.bitmap.draw_text(self.bitmap.rect, text, 1)
end
end