#==============================================================================
# Timer Plus
#==============================================================================
# Author : OriginalWij
# Version : 1.0
#==============================================================================
#==============================================================================
# NOTE: The newest version is the ONLY supported version!
#
# v1.0
# - Initial release
#==============================================================================
#==============================================================================
# Script/Script Event Command calls:
#
# $game_system.timer_x ......... get/set X coordinate [default = 4]
# $game_system.timer_y ......... get/set Y coordinate [default = 4]
# $game_system.timer_visible ... get/set visibility [default = true]
# $game_system.timer_bar ....... get/set bar enable [default = false]
# $game_system.timer_color1 .... get/set bar color 1 [default = dark_red]
# $game_system.timer_color2 .... get/set bar color 2 [default = lite_red]
# $game_system.timer_window .... get/set window enable [default = false]
#
# NOTE1: all of the above must be set BEFORE the timer is started
# NOTE2: all of the above DO NOT reset automatically (static unless altered)
# NOTE3: dark_red = Color.new(128, 0, 0); lite_red = Color.new(255, 0, 0)
#==============================================================================
#==============================================================================
# Config
#==============================================================================
module OW_TP
# Play BGS when timer is almost done?
BGS = true
# Time left on timer when BGS starts [in seconds] (when BGS = true)
B_MAX = 15
# BGS to play when timer is at or below B_MAX (when BGS = true)
B_SOUND = "Clock"
B_VOLUME = 80
B_PITCH = 100
# Change timer text color when timer is almost done?
CLR = true
# Time left on timer when color change starts [in seconds] (when CLR = true)
C_MAX = 30
# Color to change text to when timer is at or below C_MAX (when CLR = true)
C_CLR = Color.new(255, 0, 0)
# Play buzzer when timer reaches zero?
BUZZ = true
# SE to play when timer reaches zero? (when BUZZ = true)
BZ_SOUND = "Buzzer1"
BZ_VOLUME = 100
BZ_PITCH = 60
# Stop timer when timer reaches zero? (same as the Stop Timer event command)
STOP = true
end
#==============================================================================
# Game_System
#==============================================================================
class Game_System
#--------------------------------------------------------------------------
# Public Instance Variables (New)
#--------------------------------------------------------------------------
attr_accessor :timer_bar
attr_accessor :timer_window
attr_accessor :timer_max
attr_accessor :timer_visible
attr_accessor :timer_x
attr_accessor :timer_y
attr_accessor :timer_color1
attr_accessor :timer_color2
#--------------------------------------------------------------------------
# Initialize (Mod)
#--------------------------------------------------------------------------
alias ow_timerplus_game_system_initialize initialize unless $@
def initialize
ow_timerplus_game_system_initialize
@timer_bar = @timer_window = false
@timer_visible = true
@timer_max = 0
@timer_x = @timer_y = 4
@timer_color1 = Color.new(128, 0, 0)
@timer_color2 = Color.new(255, 0, 0)
end
#--------------------------------------------------------------------------
# Update (Rewrite)
#--------------------------------------------------------------------------
def update
if @timer_working and @timer > 0
@timer -= 1
Audio.bgs_stop if OW_TP::BGS and @timer < 3
if @timer == 0
@timer_max = 0
@timer_working = false if OW_TP::STOP
$game_temp.next_scene = "map" if $game_temp.in_battle
end
end
end
end
#==============================================================================
# Game_Interpreter
#==============================================================================
class Game_Interpreter
#--------------------------------------------------------------------------
# Control Timer (Rewrite)
#--------------------------------------------------------------------------
def command_124
if @params[0] == 0 # Start
$game_system.timer = (@params[1] + 1) * Graphics.frame_rate
$game_system.timer_max = $game_system.timer
$game_system.timer_working = true
end
if @params[0] == 1 # Stop
$game_system.timer_working = false
$game_system.timer = $game_system.timer_max = 0
end
return true
end
end
#==============================================================================
# Sprite_Timer
#==============================================================================
class Sprite_Timer < Sprite
#--------------------------------------------------------------------------
# Initialize (Rewrite)
#--------------------------------------------------------------------------
def initialize(viewport)
super(viewport)
self.bitmap = Bitmap.new(88, 48)
self.bitmap.font.size = 32
offset = $game_system.timer_window ? 16 : 0
self.x = $game_system.timer_x + offset
self.y = $game_system.timer_y + offset
self.y -= 12 if !$game_system.timer_bar and $game_system.timer_window
self.z = 200
update
end
#--------------------------------------------------------------------------
# Update (Rewrite)
#--------------------------------------------------------------------------
def update
super
self.visible = ($game_system.timer_working and $game_system.timer_visible)
return unless self.visible
if @window != $game_system.timer_window or @bar != $game_system.timer_bar
@window = $game_system.timer_window
@bar = $game_system.timer_bar
offset = $game_system.timer_window ? 16 : 0
self.x = $game_system.timer_x + offset
self.y = $game_system.timer_y + offset
self.y -= 12 if !$game_system.timer_bar and $game_system.timer_window
end
if $game_system.timer / Graphics.frame_rate != @total_sec
@total_sec = $game_system.timer / Graphics.frame_rate
self.bitmap.clear
if OW_TP::BUZZ and @total_sec / 60 == 0 and @total_sec % 60 == 0
filename = "Audio/SE/" + OW_TP::BZ_SOUND
Audio.se_play(filename, OW_TP::BZ_VOLUME, OW_TP::BZ_PITCH)
end
if OW_TP::BGS and @total_sec / 60 == 0 and @total_sec % 60 <= OW_TP::B_MAX
if RPG::BGS.last.name != OW_TP::B_SOUND
filename = "Audio/BGS/" + OW_TP::B_SOUND
Audio.bgs_play(filename, OW_TP::B_VOLUME, OW_TP::B_PITCH)
RPG::BGS.last.name = OW_TP::B_SOUND
end
end
if OW_TP::CLR and @total_sec / 60 == 0 and @total_sec % 60 <= OW_TP::C_MAX
self.bitmap.font.color = OW_TP::C_CLR
else
self.bitmap.font.color = Color.new(255, 255, 255)
end
draw_timer_gauge if $game_system.timer_bar
if @total_sec / 60 > 0
text = sprintf("%01d:%02d", @total_sec / 60, @total_sec % 60)
else
text = sprintf(":%02d", @total_sec % 60)
end
self.bitmap.draw_text(self.bitmap.rect, text, 1)
end
end
#--------------------------------------------------------------------------
# Draw Timer Gauge (New)
#--------------------------------------------------------------------------
def draw_timer_gauge
w = self.bitmap.width
gw = (w - 4) * $game_system.timer / $game_system.timer_max
color1 = $game_system.timer_color1
color2 = $game_system.timer_color2
self.bitmap.fill_rect(0, 0, w, 10, Color.new(0, 0, 0))
self.bitmap.fill_rect(1, 1, w - 2, 8, Color.new(255, 255, 255))
self.bitmap.fill_rect(2, 2, w - 4, 6, Color.new(0, 0, 0))
return if @total_sec % 60 == 0 and @total_sec / 60 == 0
self.bitmap.gradient_fill_rect(2, 2, gw, 6, color1, color2)
end
end
#==============================================================================
# Scene_Map
#==============================================================================
class Scene_Map < Scene_Base
#--------------------------------------------------------------------------
# Update (Mod)
#--------------------------------------------------------------------------
alias ow_timerplus_scene_map_update update unless $@
def update
ow_timerplus_scene_map_update
unless @timer_window.nil?
@timer_window.update
@timer_window.visible = $game_system.timer_visible
end
unless $game_message.visible
if $game_system.timer_window and $game_system.timer_working and
@timer_window.nil?
h = $game_system.timer_bar ? 68 : 58
x = $game_system.timer_x
y = $game_system.timer_y
@timer_window = Window_Base.new(x, y, 120, h)
@timer_window.z = 49
@timer_window.visible = $game_system.timer_visible
end
if (!$game_system.timer_window or !$game_system.timer_working or
@gs_bar != $game_system.timer_bar) and !@timer_window.nil?
@gs_bar = $game_system.timer_bar
@timer_window.dispose
@timer_window = nil
end
end
end
end