Project1

标题: 计步器 [打印本页]

作者: taroxd    时间: 2014-5-21 15:56
标题: 计步器
使用方法:使用以下事件脚本

start_pedometer 1
将变量1设置为计步器,以后每走一步变量1的值+1

start_pedometer 2, 3
将变量2设置为计步器,并初始化为3

stop_pedometer 3
停止变量3的计步

stop_pedometer
停止所有变量的计步

RUBY 代码复制
  1. #--------------------------------------------------------------------------
  2. # ● require Taroxd基础设置
  3. #--------------------------------------------------------------------------
  4. class Game_Party < Game_Unit
  5.   #--------------------------------------------------------------------------
  6.   # ● 初始化
  7.   #--------------------------------------------------------------------------
  8.   def_after(:initialize) { @pedometer = [] }
  9.   #--------------------------------------------------------------------------
  10.   # ● 开始计步器
  11.   #--------------------------------------------------------------------------
  12.   def start_pedometer(var_id, count = nil)
  13.     @pedometer << var_id unless @pedometer.include?(var_id)
  14.     $game_variables[var_id] = count if count
  15.   end
  16.   #--------------------------------------------------------------------------
  17.   # ● 停止计步器
  18.   #--------------------------------------------------------------------------
  19.   def stop_pedometer(var_id = nil)
  20.     var_id ? @pedometer.delete(var_id) : @pedometer.clear
  21.   end
  22.   #--------------------------------------------------------------------------
  23.   # ● 计步
  24.   #--------------------------------------------------------------------------
  25.   def_after :on_player_walk do
  26.     @pedometer.each {|var_id| $game_variables[var_id] += 1 }
  27.   end
  28. end
  29.  
  30. class Game_Interpreter
  31.   #--------------------------------------------------------------------------
  32.   # ● 开始
  33.   #--------------------------------------------------------------------------
  34.   def start_pedometer(var_id, count = nil)
  35.     $game_party.start_pedometer(var_id, count)
  36.   end
  37.   #--------------------------------------------------------------------------
  38.   # ● 停止
  39.   #--------------------------------------------------------------------------
  40.   def stop_pedometer(var_id = nil)
  41.     $game_party.stop_pedometer(var_id)
  42.   end
  43. end





欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1