| 赞 | 274 |
| VIP | |
| 好人卡 | |
| 积分 | 496 |
| 经验 | |
| 最后登录 | 2024-6-21 |
| 在线时间 | 1919 小时 |
- 梦石
- 10
- 星屑
- 39550
- 在线时间
- 1919 小时
- 注册时间
- 2010-11-14
- 回帖
- 3214

|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有账号?注册会员
×
本帖最后由 KB.Driver 于 2020-4-20 11:25 编辑
使用方向键可以造成对话窗口会动的感觉。
需要先插入上面这段脚本
点我
[pre lang="ruby"]# This is a tweening library for Ruby. It has no dependencies, but was
# designed with Gosu in mind.
# This is mostly an implementation of Robert Penner's easing equations
# More information on the equations can be found here:
# http://www.robertpenner.com/easing/
#
# UziMonkey <michael.c.morin@gmail.com>
class Tween
attr_reader :easer
attr_accessor :done
attr_accessor :start
attr_accessor :finish
def initialize(start, finish, easer, duration)
@start, @finish = start, finish
@easer, @duration = easer, duration
unless @start.is_a? Enumerable
@start = [@start]
end
unless @finish.is_a? Enumerable
@finish = [@finish]
end
@time = 0.0
@done = false
end
def update(delta = 1)
@time += delta
if @time > @duration
@time = @duration
@done = true
elsif @time <= 0
@time = 0.0
end
end
def rewind
@time = 0.0
@done = false
end
def [](idx)
@easer.ease(
@time,
@start[idx],
(@finish[idx] - @start[idx]),
@duration
)
end
def progress
@time / @duration
end
def value; self[0]; end
def x; self[0]; end
def y; self[1]; end
def z; self[2]; end
# In the following ease methods:
# st = start
# t = time
# d = duration
# ch = change
# I know, these are quite messy. I don't know 100% what's going on in many
# of them, but they're translated from Penner's ActionScript code which was
# uncommented and rather indecipherable.
module Linear
def self.ease(t, st, ch, d)
ch * t / d + st
end
end
module Sine
module In
def self.ease(t, st, ch, d)
-ch * Math.cos(t / d * (Math::PI / 2)) + ch + st
end
end
module Out
def self.ease(t, st, ch, d)
ch * Math.sin(t / d * (Math::PI / 2)) + st
end
end
module InOut
def self.ease(t, st, ch, d)
-ch / 2 * (Math.cos(Math::PI * t / d) - 1) + st
end
end
end
module Circ
module In
def self.ease(t, st, ch, d)
-ch * (Math.sqrt(1 - (t/d) * t/d) - 1) + st
end
end
module Out
def self.ease(t, st, ch, d)
t = t/d - 1
ch * Math.sqrt(1 - t * t) + st
end
end
module InOut
def self.ease(t, st, ch, d)
if (t /= d/2.0) < 1
return -ch / 2 * (Math.sqrt(1 - t*t) - 1) + st
else
return ch / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1) + st
end
end
end
end
module Bounce
module Out
def self.ease(t, st, ch, d)
if (t /= d) < (1/2.75)
ch * (7.5625 * t * t) + st
elsif t < (2 / 2.75)
ch * (7.5625 * (t -= (1.5 / 2.75)) * t + 0.75) + st
elsif t < (2.5 / 2.75)
ch * (7.5625 * (t -= (2.25 / 2.75)) * t + 0.9375) + st
else
ch * (7.5625 * (t -= (2.625 / 2.75)) * t + 0.984375) + st
end
end
end
module In
def self.ease(t, st, ch, d)
ch - Tween::Bounce::Out.ease(d-t, 0, ch, d) + st
end
end
module InOut
def self.ease(t, st, ch, d)
if t < d/2.0
Tween::Bounce::In.ease(t*2.0, 0, ch, d) * 0.5 + st
else
Tween::Bounce::Out.ease(t*2.0 - d, 0, ch, d) * 0.5 + ch * 0.5 + st
end
end
end
end
module Back
module In
def self.ease(t, st, ch, d, s=1.70158)
ch * (t/=d) * t * ((s+1) * t - s) + st
end
end
module Out
def self.ease(t, st, ch, d, s=1.70158)
ch * ((t=t/d-1) * t * ((s+1) * t + s) + 1) + st
end
end
module InOut
def self.ease(t, st, ch, d, s=1.70158)
if (t /= d/2.0) < 1
ch / 2.0 * (t * t * (((s *= (1.525)) + 1) * t - s)) + st
else
ch / 2.0 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + st
end
end
end
end
module Cubic
module In
def self.ease(t, st, ch, d)
ch * (t /= d) * t * t + st
end
end
module Out
def self.ease(t, st, ch, d)
ch * ((t = t / d.to_f - 1) * t * t + 1) + st
end
end
module InOut
def self.ease(t, st, ch, d)
if (t /= d / 2.0) < 1
ch / 2.0 * t * t * t + st
else
ch / 2.0 * ((t -= 2) * t * t + 2) + st
end
end
end
end
module Expo
module In
def self.ease(t, st, ch, d)
if t == 0
st
else
ch * (2 ** (10 * (t / d.to_f - 1))) + st
end
end
end
module Out
def self.ease(t, st, ch, d)
if t == d
st + ch
else
ch * (-(2 ** (-10 * t / d.to_f)) + 1) + st
end
end
end
module InOut
def self.ease(t, st, ch, d)
if t == 0
st
elsif t == d
st + ch
elsif (t /= d / 2.0) < 1
ch / 2.0 * (2 ** (10 * (t - 1))) + st
else
ch / 2.0 * (-(2 ** (-10 * (t -= 1))) + 2) + st
end
end
end
end
module Quad
module In
def self.ease(t, st, ch, d)
ch * (t /= d.to_f) * t + st
end
end
module Out
def self.ease(t, st, ch, d)
-ch * (t /= d.to_f) * (t - 2) + st
end
end
module InOut
def self.ease(t, st, ch, d)
if (t /= d / 2.0) < 1
ch / 2.0 * t * t + st
else
-ch / 2.0 * ((t -= 1) * (t - 2) - 1) + st
end
end
end
end
module Quart
module In
def self.ease(t, st, ch, d)
ch * (t /= d.to_f) * t * t * t + st
end
end
module Out
def self.ease(t, st, ch, d)
-ch * ((t = t / d.to_f - 1) * t * t * t - 1) + st
end
end
module InOut
def self.ease(t, st, ch, d)
if (t /= d / 2.0) < 1
ch / 2.0 * t * t * t * t + st
else
-ch / 2.0 * ((t -= 2) * t * t * t - 2) + st
end
end
end
end
module Quint
module In
def self.ease(t, st, ch, d)
ch * (t /= d.to_f) * t * t * t * t + st
end
end
module Out
def self.ease(t, st, ch, d)
ch * ((t = t / d.to_f - 1) * t * t *t * t + 1) + st
end
end
module InOut
def self.ease(t, st, ch, d)
if (t /= d / 2.0) < 1
ch / 2.0 * t * t *t * t * t + st
else
ch / 2.0 * ((t -= 2) * t * t * t * t + 2) + st
end
end
end
end
module Elastic
module In
def self.ease(t, st, ch, d, a = 5, p = 0)
s = 0
if t == 0
return st
elsif (t /= d.to_f) >= 1
return st + ch
end
p = d * 0.3 if p == 0
if (a == 0) || (a < ch.abs)
a = ch
s = p / 4.0
else
s = p / (2 * Math::PI) * Math.asin(ch / a.to_f)
end
-(a * (2 ** (10 * (t -= 1))) * Math.sin( (t * d - s) * (2 * Math::PI) / p)) + st
end
end
module Out
def self.ease(t, st, ch, d, a = 0.1, p = 0)
s = 0
if t == 0
return st
elsif (t /= d.to_f) >= 1
return st + ch
end
p = d * 0.3 if p == 0
if (a == 0) || (a < ch.abs)
a = ch
s = p / 4.0
else
s = p / (2 * Math::PI) * Math.asin(ch / a.to_f)
end
a * (2 ** (-10 * t)) * Math.sin((t * d - s) * (2 * Math::PI) / p.to_f) + ch + st
end
end
end
# This is mostly for use by demo.rb
EASERS = [
Linear,
Sine::In,
Sine::Out,
Sine::InOut,
Circ::In,
Circ::Out,
Circ::InOut,
Bounce::Out,
Bounce::In,
Bounce::InOut,
Back::In,
Back::Out,
Back::InOut,
Cubic::In,
Cubic::Out,
Cubic::InOut,
Expo::In,
Expo::Out,
Expo::InOut,
Quad::In,
Quad::Out,
Quad::InOut,
Quart::In,
Quart::Out,
Quart::InOut,
Quint::In,
Quint::Out,
Quint::InOut,
Elastic::In,
Elastic::Out
]
end[/pre]
脚本本体:
[pre lang="ruby"]#encoding:utf-8
##
# Ugoku
# author: Calendar99
#
# use arrow keys to make your message window ugokemasu.
##
class Window_Message
dur = 15
power = 90
tw = ->(ab, inout) { "Tween.new(#{ab}, Tween::Cubic::#{inout}, #{dur})" }
expo_tws = "->(a, b) { [(#{tw['a, b','Out']}), (#{tw['b, a' ,'In']})] }"
{
:down => [:oy, "->(ox, oy) { (#{expo_tws})[oy, oy - #{power}] }"],
:up => [:oy, "->(ox, oy) { (#{expo_tws})[oy, oy + #{power}] }"],
:right => [:ox, "->(ox, oy) { (#{expo_tws})[ox, ox - #{power}] }"],
:left => [:ox, "->(ox, oy) { (#{expo_tws})[ox, ox + #{power}] }"],
}.each {|meth, (attr, tws)|
class_eval %{
def ugoku_#{meth}
if @#{attr}_tweens.empty?
@#{attr}_tweens += (#{tws}).call(ox, oy)
else
@#{attr}_tweens.shift until @#{attr}_tweens.size == 1
@#{attr}_tweens.unshift (#{tws}).call(ox, oy)[0]
@#{attr}_tweens[1].start[0] = @#{attr}_tweens[0].finish[0]
@#{attr}_tweens[1].rewind
end
end
}
}
alias initialize_ugoku_calendar99 initialize
def initialize
initialize_ugoku_calendar99
@ox_tweens = []
@oy_tweens = []
end
alias update_ugoku_calendar99 update
def update
process_ugoku
update_ugoku
update_ugoku_calendar99
end
def process_ugoku
return unless active && open?
ugoku_down if Input.trigger?(:DOWN)
ugoku_up if Input.trigger?(:UP)
ugoku_right if Input.trigger?(:RIGHT)
ugoku_left if Input.trigger?(:LEFT)
end
upd = ->(param) {
%{
unless @#{param}_tweens.empty?
if @#{param}_tweens[0].done
@#{param}_tweens.shift
end
if tw = @#{param}_tweens[0]
tw.update
self.#{param} = tw.value
end
end
}
}
class_eval %{
def update_ugoku
#{upd['ox']}
#{upd['oy']}
end
}
end[/pre] |
评分
-
查看全部评分
|