Project1
标题:
关于地图上按键盘来开启开关和状态的脚本
[打印本页]
作者:
dorx2010
时间:
2015-9-14 17:01
标题:
关于地图上按键盘来开启开关和状态的脚本
小弟的想法是,在地图上按"R"键来开启或关闭"开关1"
"开关1"开启时,主角同时附加"状态1",,关闭时,主角解除"状态1",
希望大大可以帮忙><希望是脚本,,因为用纯事件会使游戏很卡吧{:2_270:}
作者:
taroxd
时间:
2015-9-14 17:01
本帖最后由 taroxd 于 2015-9-14 20:47 编辑
[pre lang="ruby"]
module Keyboard
API = Win32API.new('user32', 'GetAsyncKeyState', 'I', 'I')
# 以按键码为键,连续按下的帧数为值的 hash
@states = Hash.new { |h, k| h[k] = 0 }
def self.update
@states.each_key do |key|
@states[key] = API.call(key) < 0 ? @states[key] + 1 : 0
end
end
def self.clear
@states.clear
end
def self.trigger?(key)
@states[key] == 1
end
end
class Scene_Map
alias_method :ub_20150914, :update_basic
def update_basic
ub_20150914
Keyboard.update
return unless Keyboard.trigger? 'R'.ord
s = $game_switches
if s[1]
s[1] = false
$game_party.members.each { |actor| actor.remove_state 1 }
else
s[1] = true
$game_party.members.each { |actor| actor.add_state 1 }
end
end
end
[/pre]
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X5.0