#============================================================================== # ■ Numset #------------------------------------------------------------------------------ #  定数全般のモジュールです。 #============================================================================== module Numset TIMER_NAME = "timer" # タイマー画像の名称 TIMER_COLOR = Color.new(255, 255, 255) # タイマーの文字色 TIMER_FONT = "Arial Black" # タイマーのフォント TIMER_WIDTH = 16 # 文字タイマーの幅 TEXT_SIZE = 32 # 一文字のサイズ end #============================================================================== # ■ Game_System #------------------------------------------------------------------------------ #  システム周りのデータを扱うクラスです。BGM などの管理も行います。このクラス # のインスタンスは $game_system で参照されます。 #============================================================================== class Game_System #-------------------------------------------------------------------------- # ● 公開インスタンス変数 #-------------------------------------------------------------------------- attr_accessor :timer_mode # タイマーの強化状態 attr_accessor :timer_visible # タイマーの可視状態 #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- alias :timer_initialize :initialize def initialize timer_initialize @timer_mode = true @timer_visible = true end #-------------------------------------------------------------------------- # ● フレーム更新 #-------------------------------------------------------------------------- def update # タイマーを 1 減らす if @timer_working == true and @timer > 0 @timer -= 1 # リバース状態ではタイマーを 1 増やす elsif @timer_working == "reverse" @timer += 1 end end end #============================================================================== # ■ Sprite_Timer #------------------------------------------------------------------------------ #  タイマー表示用のスプライトです。$game_system を監視し、スプライトの状態を # 自動的に変化させます。 #============================================================================== class Sprite_Timer < Sprite #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize super begin @bitmap = RPG::Cache.windowskin(Numset::TIMER_NAME) self.bitmap = Bitmap.new(@bitmap.width, @bitmap.height) @width = @bitmap.width / 11 @height = @bitmap.height # ファイルがない場合の処理 rescue Errno::ENOENT @width = Numset::TIMER_WIDTH @height = @width * 2 self.bitmap = Bitmap.new(@width * 11, @height) @bitmap = Bitmap.new(@width * 11, @height) rect = Rect.new(0, 0, @width, @height) for i in 0..9 @bitmap.blt(@width * i, 0, RPG::Cache.text(@width, @height, i.to_s, Numset::TIMER_COLOR, Numset::TEXT_SIZE, Numset::TIMER_FONT), rect) end @bitmap.blt(@width * 10, 0, RPG::Cache.text(@width, @height, ":", Numset::TIMER_COLOR, Numset::TEXT_SIZE, Numset::TIMER_FONT), rect) end self.x = 636 - self.bitmap.width self.y = 4 self.z = 500 update end #-------------------------------------------------------------------------- # ● フレーム更新 #-------------------------------------------------------------------------- def update super # タイマー作動中、かつ可視状態なら可視に設定 unless $game_system.timer_working or not $game_system.timer_visible self.visible = false else self.visible = true end # タイマーを再描画する必要がある場合 if $game_system.timer_mode or ($game_system.timer / Graphics.frame_rate) != @total_sec # ウィンドウ内容をクリア self.bitmap.clear # トータル秒数を計算(整数化) @total_sec = ($game_system.timer * 100 / Graphics.frame_rate) # タイマー表示用の文字列を作成 text = "" if (@total_sec / 6000) >= 60 hour = @total_sec / 360000 text += sprintf("% 2d:", hour) end min = (@total_sec / 6000) % 60 sec = (@total_sec / 100) % 60 text += sprintf("%02d:%02d", min, sec) if $game_system.timer_mode sec_m = @total_sec % 100 text += sprintf(":%02d", sec_m) end # タイマーを描画 text = text.split(//) i = text.size rect = Rect.new(0, 0, @width, @height) for draw in text rect.x = select(draw) self.bitmap.blt(self.bitmap.width - i * @width, 0, @bitmap, rect) i -= 1 end end end #-------------------------------------------------------------------------- # ● 文字の決定 #-------------------------------------------------------------------------- def select(text) if text == ":" return 10 * @width else num = text.to_i return num * @width end end end #============================================================================== # ■ Interpreter #------------------------------------------------------------------------------ #  イベントコマンドを実行するインタプリタです。このクラスは Game_System クラ # スや Game_Event クラスの内部で使用されます。 #============================================================================== class Interpreter #-------------------------------------------------------------------------- # ● 注釈イベントの実行 #-------------------------------------------------------------------------- if self.class.method_defined?("command_108") alias :timer_command_108 :command_108 def command_108 if @parameters[0] == "タイマーの増加" $game_system.timer_working = "reverse" return true end if @parameters[0] == "タイマーの一時停止" $game_system.timer_working = "stop" return true end if @parameters[0] == "タイマーの強化" $game_system.timer_mode = true return true end if @parameters[0] == "タイマーの強化中止" $game_system.timer_mode = false return true end if @parameters[0] == "タイマーの可視" $game_system.timer_visible = true return true end if @parameters[0] == "タイマーの不可視" $game_system.timer_visible = false return true end timer_command_108 end end #-------------------------------------------------------------------------- # ● タイマーの操作 #-------------------------------------------------------------------------- def command_124 # 始動の場合 if @parameters[0] == 0 $game_system.timer = @parameters[1] * Graphics.frame_rate $game_system.timer_working = true end # 停止の場合 if @parameters[0] == 1 $game_system.timer_working = false $game_system.timer = 0 end # 継続 return true end end