Skip to content

Instantly share code, notes, and snippets.

@rutan
Created March 31, 2013 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rutan/5280501 to your computer and use it in GitHub Desktop.
Save rutan/5280501 to your computer and use it in GitHub Desktop.
【RGSS3】高速Input.repeat?さん for RGSS3
# coding: utf-8
#===============================================================================
# ■ 高速Input.repeat?さん for RGSS3
#-------------------------------------------------------------------------------
# 2012/01/02 Ru/むっくRu
#-------------------------------------------------------------------------------
# Input.repeat?の認識間隔を高速化します
# (※設定次第で低速にもできるよ!)
#
# ● 以下のメソッドが追加されます
# Input.repeatEx?(key) …… 高速版Input.repeat?
#
# ● 以下のメソッドが変更されます
# Input.repeat?(key) …… 高速になります
#
#-------------------------------------------------------------------------------
# 【問題点など】
# 設定項目の説明文がひどい
#-------------------------------------------------------------------------------
# 【更新履歴】
# 2012/01/02 ベーススクリプト使用時にそちら側にも反映できるように機能拡張
# 2011/12/25 起動直後にエラーすることがあるのを修正
# 2011/12/21 VX版を移植ぶっぱ
#-------------------------------------------------------------------------------
#===============================================================================
# ● 設定項目
#==============================================================================
module HZM_VXA
module InputRepeatEx
# repeatの1回目から2回目のウェイト時間
# (ピッ!ピピピピピピ…… のピッ!からピピピ……までの時間)
WAIT1 = 20
# repeatの2回目以降のウェイト時間
# (ピ!ピピピピピピ…… のピピピの間の時間)
WAIT2 = 1
# デフォルトのInput.repeat?を高速repeatで置き換えるか?
REPLACE_REPEAT_FLAG = true
end
end
#===============================================================================
# ↑   ここまで設定   ↑
# ↓ 以下、スクリプト部 ↓
#===============================================================================
module HZM_VXA
module InputRepeatEx
LIST = [:DOWN, :LEFT, :RIGHT, :UP, :A, :B, :C, :X, :Y, :Z, :L, :R, :SHIFT, :CTRL, :ALT, :F5, :F6, :F7, :F8, :F9]
end
end
module Input
@hzm_vxa_inputrepeatex_repeatex_cnt = {}
@hzm_vxa_inputrepeatex_repeatex_flag = {}
HZM_VXA::InputRepeatEx::LIST.each do |key|
@hzm_vxa_inputrepeatex_repeatex_cnt[key] = 0
@hzm_vxa_inputrepeatex_repeatex_flag[key] = false
end
end
class << Input
#-----------------------------------------------------------------------------
# ● 更新(エイリアス)
#-----------------------------------------------------------------------------
alias hzm_vxa_inputrepeatex_update update
def update
hzm_vxa_inputrepeatex_update
HZM_VXA::InputRepeatEx::LIST.each do |key|
if trigger?(key)
@hzm_vxa_inputrepeatex_repeatex_cnt[key] = HZM_VXA::InputRepeatEx::WAIT1
@hzm_vxa_inputrepeatex_repeatex_flag[key] = true
elsif press?(key)
if @hzm_vxa_inputrepeatex_repeatex_cnt[key] <= 0
@hzm_vxa_inputrepeatex_repeatex_cnt[key] = HZM_VXA::InputRepeatEx::WAIT2
@hzm_vxa_inputrepeatex_repeatex_flag[key] = true
else
@hzm_vxa_inputrepeatex_repeatex_cnt[key] -= 1
@hzm_vxa_inputrepeatex_repeatex_flag[key] = false
end
else
@hzm_vxa_inputrepeatex_repeatex_cnt[key] = 0
@hzm_vxa_inputrepeatex_repeatex_flag[key] = false
end
end
end
#-----------------------------------------------------------------------------
# ● 高速repeat
#-----------------------------------------------------------------------------
def repeatEx?(key)
@hzm_vxa_inputrepeatex_repeatex_flag[key]
end
#-----------------------------------------------------------------------------
# ● repeat?(再定義)
#-----------------------------------------------------------------------------
if HZM_VXA::InputRepeatEx::REPLACE_REPEAT_FLAG
def repeat?(key)
repeatEx?(key)
end
end
end
# ベーススクリプト導入時はそちらにもrepeatExを対応
if defined?(HZM_VXA::Input)
module HZM_VXA
module Input
def self.wait1
HZM_VXA::InputRepeatEx::WAIT1
end
def self.wait2
HZM_VXA::InputRepeatEx::WAIT2
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment