查看: 3244|回复: 5

[原创发布] 【脚写脚本】移动对话窗口信息

[复制链接]
梦石
10
星屑
39550
在线时间
1919 小时
注册时间
2010-11-14
回帖
3214

R考场第七期纪念奖

发表于 2020-4-20 11:24:13 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
本帖最后由 KB.Driver 于 2020-4-20 11:25 编辑

11.gif
使用方向键可以造成对话窗口会动的感觉。

需要先插入上面这段脚本
点我

[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]

评分

参与人数 1赞 +1 收起 理由
PLeaseS + 1 塞糖

查看全部评分

用头画头像,用脚写脚本
梦石
0
星屑
11809
在线时间
623 小时
注册时间
2016-8-25
回帖
1340

R考场第七期纪念奖

发表于 2020-4-20 11:52:56 | 显示全部楼层
tqltql
不过这个脚本能用在什么地方呢

点评

你可以下载了把Window_Message改成Window_Base,然后在initialize和initialize_ugoku_calendar99后面加(*args)  发表于 2020-4-20 12:21
回复

使用道具 举报

老鹰

梦石
40
星屑
37812
在线时间
7091 小时
注册时间
2012-5-26
回帖
3297

极短24评委极短23参与极短22参与极短21评委老司机慢点开短篇十吟唱者组别冠军开拓者剧作品鉴家

发表于 2020-4-20 12:38:09 | 显示全部楼层
有点鬼畜hhhhh
实际上这个需要结合 对话框宽高扩展,默认只有4行也就左右移动有点用
但是这么多字其实看起来很累,而且绘制也会卡(如果一口气绘制完的话)

评分

参与人数 1赞 +1 收起 理由
chanszeman1018 + 1 我很赞同

查看全部评分

回复

使用道具 举报

梦石
0
星屑
11809
在线时间
623 小时
注册时间
2016-8-25
回帖
1340

R考场第七期纪念奖

发表于 2020-4-20 14:20:02 | 显示全部楼层
把对话框扩大
说不定可以做地图
回复

使用道具 举报

梦石
2
星屑
6767
在线时间
501 小时
注册时间
2018-3-23
回帖
487

R考场第七期银奖

发表于 2020-4-20 18:48:36 | 显示全部楼层
仿佛看出了缓动的效果……
总之膜(guan)拜(shui)日历大佬!
祝好。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部