03-08-2008, 05:21 AM
Timer Rewrite
Introduction
This script allows you to turn your timer display on/off, it allows you to change the opacity of the timer, it allows you to used fixed positioning e.g. Top Left, Bottom Right etc and it also allows you to set an exact position on the screen for it to appear, along with being able to change it's exact font size and font type.
Features
TIMER DISPLAY SWITCH
FIXED POSITIONING
UNIVERSAL POSITIONING
OPACITY CONTROL
CHANGE FONT SIZE & TYPE
Script
Add this script above Main.
Code:
#==============================================================================
# ** Game_System
#------------------------------------------------------------------------------
# This class handles system-related data. Also manages vehicles and BGM, etc.
# The instance of this class is referenced by $game_system.
#==============================================================================
class Game_System
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :timer # timer
attr_accessor :timer_working # timer working flag
attr_accessor :timer_position # timer screen position
attr_accessor :timer_posx # timer position x axis
attr_accessor :timer_posy # timer position y axis
attr_accessor :timer_opacity # timer opacity
attr_accessor :timer_fonttype # timer font type
attr_accessor :timer_fontsize # timer font size
attr_accessor :save_disabled # save forbidden
attr_accessor :menu_disabled # menu forbidden
attr_accessor :encounter_disabled # encounter forbidden
attr_accessor :save_count # save count
attr_accessor :version_id # game version ID
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
@timer = 0
@timer_working = false
@timer_position = 1
@timer_opacity = 255
@timer_posx = 0
@timer_posy = 0
@timer_fonttype = "Arial"
@timer_fontsize = 32
@save_disabled = false
@menu_disabled = false
@encounter_disabled = false
@save_count = 0
@version_id = 0
end
#--------------------------------------------------------------------------
# * Get Battle BGM
#--------------------------------------------------------------------------
def battle_bgm
if @battle_bgm == nil
return $data_system.battle_bgm
else
return @battle_bgm
end
end
#--------------------------------------------------------------------------
# * Set Battle BGM
# battle_bgm : new battle BGM
#--------------------------------------------------------------------------
def battle_bgm=(battle_bgm)
@battle_bgm = battle_bgm
end
#--------------------------------------------------------------------------
# * Get Battle End ME
#--------------------------------------------------------------------------
def battle_end_me
if @battle_end_me == nil
return $data_system.battle_end_me
else
return @battle_end_me
end
end
#--------------------------------------------------------------------------
# * Set Battle End ME
# battle_end_me : new battle end ME
#--------------------------------------------------------------------------
def battle_end_me=(battle_end_me)
@battle_end_me = battle_end_me
end
#--------------------------------------------------------------------------
# * Get Position of Timer
#--------------------------------------------------------------------------
def timer_position
return @timer_position
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
if @timer_working and @timer > 0
@timer -= 1
if @timer == 0 and $game_temp.in_battle # If the timer 0 in battle
$game_temp.next_scene = "map" # interrupt the battle
end
end
end
end
#==============================================================================
# ** Sprite_Timer
#------------------------------------------------------------------------------
# This sprite is used to display the timer. It observes the $game_system
# and automatically changes sprite conditions.
#==============================================================================
class Sprite_Timer < Sprite
#--------------------------------------------------------------------------
# * Object Initialization
# viewport : viewport
#--------------------------------------------------------------------------
def initialize(viewport)
super(viewport)
self.bitmap = Bitmap.new(88, 48)
self.bitmap.font.name = $game_system.timer_fonttype
self.bitmap.font.size = $game_system.timer_fontsize
@timer_position = $game_system.timer_position
self.x = 544
self.y = 0
self.z = 200
update
end
#--------------------------------------------------------------------------
# * Dispose
#--------------------------------------------------------------------------
def dispose
self.bitmap.dispose
super
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
case @timer_position
when 0 # Top Left
self.x = 85 - self.bitmap.width
self.y = 0
when 1 # Top Right
self.x = 544 - self.bitmap.width
self.y = 0
when 2 # Bottom Left
self.x = 85 - self.bitmap.width
self.y = 370
when 3 # Bottom Right
self.x = 544 - self.bitmap.width
self.y = 370
when 4 # Custom
self.x = $game_system.timer_posx
self.y = $game_system.timer_posy
end
super
self.visible = $game_system.timer_working
self.bitmap.font.name = $game_system.timer_fonttype
self.bitmap.font.size = $game_system.timer_fontsize
if $game_switches[1] == false
self.opacity = $game_system.timer_opacity
else
self.opacity = 0
end
if $game_system.timer / Graphics.frame_rate != @total_sec
self.bitmap.clear
@timer_position = $game_system.timer_position
@total_sec = $game_system.timer / Graphics.frame_rate
min = @total_sec / 60
sec = @total_sec % 60
text = sprintf("%02d:%02d", min, sec)
self.bitmap.font.color.set(255, 255, 255)
self.bitmap.draw_text(self.bitmap.rect, text, 1)
end
end
end
Credits
Kurisu aka Slipper for helping me point out my mistake :yellowkiss: