赞 | 3 |
VIP | 0 |
好人卡 | 39 |
积分 | 1 |
经验 | 101436 |
最后登录 | 2017-9-1 |
在线时间 | 2276 小时 |
Lv1.梦旅人 路人党员
- 梦石
- 0
- 星屑
- 52
- 在线时间
- 2276 小时
- 注册时间
- 2010-12-30
- 帖子
- 3225
|
- Input.module_eval do
- if !@orig_methods
- @orig_methods = {}
- @locks = []
- Input.methods.each{|m|@orig_methods[m] = Input.method(m)}
- ["trigger?", "press?", "repeat?"].each do |m|
- define_method(m) do |k|
- @locks.include?(k) ? false : @orig_methods[m].call(k)
- end
- module_function m
- public m
- end
- define_method('dir4') do
- @locks.include?(k = @orig_methods['dir4'].call) ? 0 : k
- end
- define_method('dir8') do
- k = @orig_methods['dir8'].call
- return 0 if [2, 4, 6, 8].any?{|d|@locks.include?(d) and k == d}
- case k
- when 1
- return 0 if @locks.include?(2) and @locks.include?(4)
- return 4 if @locks.include?(2)
- return 2 if @locks.include?(4)
- when 3
- return 0 if @locks.include?(2) and @locks.include?(6)
- return 6 if @locks.include?(2)
- return 2 if @locks.include?(6)
- when 7
- return 0 if @locks.include?(8) and @locks.include?(4)
- return 4 if @locks.include?(8)
- return 8 if @locks.include?(4)
- when 9
- return 0 if @locks.include?(6) and @locks.include?(8)
- return 8 if @locks.include?(6)
- return 6 if @locks.include?(8)
- end
- return k
- end
- define_method('lock') do |*args|
- @locks |= args
- @locks.sort!
- end
- define_method('unlock') do |*args|
- args.each{|k|@locks.delete(k)}
- end
- module_function :dir4, :dir8, :lock, :unlock
- public :dir4, :dir8, :lock, :unlock
- end
- end
复制代码 上面的插入main之前,下面的是例子,教程范例啥的懒得弄- # 禁用上和右
- Input.lock Input::DOWN, Input::RIGHT
- # 解禁
- Input.unlock Input::DOWN, Input::RIGHT
复制代码 |
评分
-
查看全部评分
|