#==============================================================================
# ■ CLD99::Timer
#------------------------------------------------------------------------------
# 除了标题界面,所有界面都生效的计时器。
# 在此进行计时器的设置。
#==============================================================================
module CLD99
module Timer
SCENE_NO_TIMER = [Scene_Title,Scene_Gameover]
# 进入此场景,计时器将自动停止。
# 默认:[Scene_Title, Scene_Gameover]
GAME_OVER_SWITCH = 0
# 计时器为0时立刻结束游戏?
# -1 禁止 0 允许 正整数 检查对应编号开关
end
end
#==============================================================================
# ■ Scene_Base
#------------------------------------------------------------------------------
# 游戏中所有 Scene 类(场景类)的父类
#==============================================================================
class Scene_Base
#--------------------------------------------------------------------------
# ● 开始处理
#--------------------------------------------------------------------------
alias start_for_timer start
def start
start_for_timer
need_timer_scene? ? make_timer : stop_timer
puts "need_timer_scene?=#{need_timer_scene?}"
end
#--------------------------------------------------------------------------
# ● 生成计时器
#--------------------------------------------------------------------------
def make_timer
if $game_timer && make_timer_scene?
@viewport99 = Viewport.new
@viewport99.z = 201
@timer_sprite = Sprite_Timer.new(@viewport99)
end
end
#--------------------------------------------------------------------------
# ● 停止计时器
#--------------------------------------------------------------------------
def stop_timer
$game_timer.stop if $game_timer
end
#--------------------------------------------------------------------------
# ● 消除计时器
#--------------------------------------------------------------------------
alias terminate_for_timer terminate
def terminate
terminate_for_timer
@timer_sprite.dispose if @timer_sprite
end
#--------------------------------------------------------------------------
# ● 更新计时器
#--------------------------------------------------------------------------
alias update_for_timer update
def update
update_for_timer
if @timer_sprite && make_timer_scene?
$game_timer.update
@timer_sprite.update
end
end
#--------------------------------------------------------------------------
# ● 是否需要计时器
#--------------------------------------------------------------------------
def need_timer_scene?
!CLD99::Timer::SCENE_NO_TIMER.include?(SceneManager.scene.class)
end
#--------------------------------------------------------------------------
# ● 是否需要额外添加计时器
#--------------------------------------------------------------------------
def make_timer_scene?
![Scene_Map,Scene_Battle].include?(SceneManager.scene.class)
end
end
#==============================================================================
# ■ Game_Timer
#------------------------------------------------------------------------------
# 计时器。本类的实例请参考 $game_timer 。
#==============================================================================
class Game_Timer
include CLD99::Timer
#--------------------------------------------------------------------------
# ● 计时器为 0 时的处理
#--------------------------------------------------------------------------
alias on_expire_for_timer on_expire
def on_expire
on_expire_for_timer
on_expire_gameover
end
#--------------------------------------------------------------------------
# ● 计时器为 0 时是否结束游戏
#--------------------------------------------------------------------------
def on_expire_gameover
case GAME_OVER_SWITCH
when -1
return
when 0
SceneManager.goto(Scene_Gameover)
else
SceneManager.goto(Scene_Gameover) if $game_switches[GAME_OVER_SWITCH]
end
end
end