# 技能公式范例:
# Taroxd::QTE.set { b.add_state 1 }; a.atk * 4 - b.def * 2
module Taroxd end
class << Taroxd::QTE = Object.new
WAITING = 60 # 执行 set 到触发时间的帧数
SCREEN_WAITING = WAITING + 60 # 执行 set 时画面等待的帧数
TOLERENCE = 1 # 准许误差的帧数
# key 为 nil 时表示没有 QTE 设置
# when_triggered: QTE 触发时执行的脚本
def set(key = :C, &when_triggered)
@frame = WAITING
@key = key
@when_triggered = when_triggered
end
def update
return unless @key
@frame -= 1
return terminate if @frame < -TOLERENCE
trigger if hit? && @frame.abs <= TOLERENCE
end
def pos
@key && 1 - @frame.fdiv(WAITING)
end
private
def hit?
Input.trigger?(@key)
end
def trigger
@when_triggered.call
terminate
end
def terminate
@key = nil
end
end
# 技能公式范例:
# Taroxd::QTE.set { b.add_state 1 }; a.atk * 4 - b.def * 2
module Taroxd end
class << Taroxd::QTE = Object.new
WAITING = 60 # 执行 set 到触发时间的帧数
SCREEN_WAITING = WAITING + 60 # 执行 set 时画面等待的帧数
TOLERENCE = 1 # 准许误差的帧数
# key 为 nil 时表示没有 QTE 设置
# when_triggered: QTE 触发时执行的脚本
def set(key = :C, &when_triggered)
@frame = WAITING
@key = key
@when_triggered = when_triggered
end
def update
return unless @key
@frame -= 1
return terminate if @frame < -TOLERENCE
trigger if hit? && @frame.abs <= TOLERENCE
end
def pos
@key && 1 - @frame.fdiv(WAITING)
end
private
def hit?
Input.trigger?(@key)
end
def trigger
@when_triggered.call
terminate
end
def terminate
@key = nil
end
end