Project1
标题: 我已丧心病狂! [打印本页]
作者: 余烬之中 时间: 2014-3-9 11:31
标题: 我已丧心病狂!
本帖最后由 余烬之中 于 2014-3-9 15:23 编辑
写脚本的时候常常需要动态移动窗口,每次都要重来很烦的有木有!
于是提高可重用性………………这个不是重点!
这是做好后用来测试的东西 莫名其妙戳中了笑点
@晴兰 @taroxd @无脑之人
附 操作方法:
脚本
module Smomo
module Kit
@@register = {
dynamical_move: []
} # @@register
module_function
def register
@@register
end
end # Smomo::Kit
module_function
def dynamical_move(aim, x = :x, y = :y)
reg = Smomo::Kit.register[:dynamical_move]
id = aim.object_id
return reg[id] if reg[id]
reg[id] = Object.new
# class << reg[id]
class << reg[id]
attr_accessor :moving,:ox,:oy,:ax,:ay,:x,:y,:aim_id,:duration,:rx,:ry
# moveto
def moveto(tx, ty, duration)
unless moving
a = ObjectSpace._id2ref(@aim_id)
@ox, @oy = a.send(@x), a.send(@y)
@ax, @ay = tx, ty
@rx, @ry = *[@ox, @oy].collect(&:to_f)
@duration = duration
@moving = true
end
_moveto
end
# _moveto
def _moveto
a = ObjectSpace._id2ref(@aim_id)
@rx += (@ax - @ox).to_f / @duration
@ry += (@ay - @oy).to_f / @duration
a.instance_eval %!
self.#{@x} = #{@rx}
self.#{@y} = #{@ry}
!
stop if (@rx - @ax).to_i == 0 && (@ry - @ay).to_i == 0
end
# stop
define_method(:stop){@moving = false}
# apos
define_method(:apos){[@ax, @ay]}
# opos
define_method(:opos){[@ox, @oy]}
end # class << reg[id]
reg[id].moving, reg[id].x, reg[id].y, reg[id].aim_id = false, x, y, id
reg[id]
end # dynamical_move
end # Smomo
module Smomo
module Kit
@@register = {
dynamical_move: []
} # @@register
module_function
def register
@@register
end
end # Smomo::Kit
module_function
def dynamical_move(aim, x = :x, y = :y)
reg = Smomo::Kit.register[:dynamical_move]
id = aim.object_id
return reg[id] if reg[id]
reg[id] = Object.new
# class << reg[id]
class << reg[id]
attr_accessor :moving,:ox,:oy,:ax,:ay,:x,:y,:aim_id,:duration,:rx,:ry
# moveto
def moveto(tx, ty, duration)
unless moving
a = ObjectSpace._id2ref(@aim_id)
@ox, @oy = a.send(@x), a.send(@y)
@ax, @ay = tx, ty
@rx, @ry = *[@ox, @oy].collect(&:to_f)
@duration = duration
@moving = true
end
_moveto
end
# _moveto
def _moveto
a = ObjectSpace._id2ref(@aim_id)
@rx += (@ax - @ox).to_f / @duration
@ry += (@ay - @oy).to_f / @duration
a.instance_eval %!
self.#{@x} = #{@rx}
self.#{@y} = #{@ry}
!
stop if (@rx - @ax).to_i == 0 && (@ry - @ay).to_i == 0
end
# stop
define_method(:stop){@moving = false}
# apos
define_method(:apos){[@ax, @ay]}
# opos
define_method(:opos){[@ox, @oy]}
end # class << reg[id]
reg[id].moving, reg[id].x, reg[id].y, reg[id].aim_id = false, x, y, id
reg[id]
end # dynamical_move
end # Smomo
测试脚本
def test
$adasdasdaf ||= []
ssssssss = $adasdasdaf.size
$adasdasdaf[ssssssss] = Window_Base.new(424 * rand, 206 * rand, 120, 210)
class << $adasdasdaf[ssssssss]
alias :old_update :update
def update
Smomo.dynamical_move(self).moveto(424 * rand, 206 * rand, 60 * rand)
old_update
end
end
$adasdasdaf[ssssssss + 1] = Window_Base.new(394 * rand, 356 * rand, 150, 60)
class << $adasdasdaf[ssssssss + 1]
alias :old_update :update
def update
Smomo.dynamical_move(self).moveto(394 * rand, 356 * rand, 30 * rand)
old_update
end
end
$game_variables[1] += 1
end
class Scene_Map
alias :woyisangxinbingkuang :update
def update
woyisangxinbingkuang
$adasdasdaf.each_with_index{|w, i|
w.disposed? ? [$adasdasdaf[i] = nil, $adasdasdaf.compact!] : w.update
} if $adasdasdaf
end
end
def test
$adasdasdaf ||= []
ssssssss = $adasdasdaf.size
$adasdasdaf[ssssssss] = Window_Base.new(424 * rand, 206 * rand, 120, 210)
class << $adasdasdaf[ssssssss]
alias :old_update :update
def update
Smomo.dynamical_move(self).moveto(424 * rand, 206 * rand, 60 * rand)
old_update
end
end
$adasdasdaf[ssssssss + 1] = Window_Base.new(394 * rand, 356 * rand, 150, 60)
class << $adasdasdaf[ssssssss + 1]
alias :old_update :update
def update
Smomo.dynamical_move(self).moveto(394 * rand, 356 * rand, 30 * rand)
old_update
end
end
$game_variables[1] += 1
end
class Scene_Map
alias :woyisangxinbingkuang :update
def update
woyisangxinbingkuang
$adasdasdaf.each_with_index{|w, i|
w.disposed? ? [$adasdasdaf[i] = nil, $adasdasdaf.compact!] : w.update
} if $adasdasdaf
end
end
然后在地图上新建事件 事件内容为执行脚本
【test】
然后进入游戏按空格疯狂地触发事件~~
当然 既然disable了…………
作者: 失落迷白 时间: 2014-3-9 11:38
程序猿经常把自己弄得面目狰狞,然后又经常被自己做得逗笑
作者: 紫英晓狼1130 时间: 2014-3-9 12:49
所以直接加大窗口,移动图片
作者: 弗雷德 时间: 2014-3-9 12:52
还是会美工好,可以通过图片用一些傻B的方式来弥补俺脚本上的不足
作者: 无脑之人 时间: 2014-3-9 13:20
【程序猿的冷笑话系列么……
不开GC就会爆内存,不做死就不会死你怎么就是不明白www
作者: 美丽晨露 时间: 2014-3-9 13:38
我很好奇那个击破数是用来作什么用的
作者: 正太君 时间: 2014-3-9 13:46
$adasdasdaf 这个命名很棒
欢迎光临 Project1 (https://rpg.blue/) |
Powered by Discuz! X3.1 |