设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 3795|回复: 3
打印 上一主题 下一主题

[原创发布] RGSS1实用"扩展库"

[复制链接]

Lv1.梦旅人

梦石
0
星屑
55
在线时间
323 小时
注册时间
2010-8-21
帖子
666
跳转到指定楼层
1
发表于 2011-4-3 11:21:28 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
本帖最后由 沙漠点灰 于 2011-4-3 11:22 编辑

清单
1.[方便] 随机播放BGM
2.[扩展] 获取mp3文件时间长度 (有bug  ←等于没说)
3.[扩展] Graphics块 模仿 RGSS2部分功能
4.[扩展] Bitmap类   模仿 RGSS2部分功能
5.[美化] 真 窗口移动
6.[美化] 伪 窗口移动
7.[扩展] 子选项窗口(http://rpg.blue/thread-174280-1-1.html)

脚本如下:
1+2 :
  1. #==============================================================================
  2. # ■ Audio
  3. #------------------------------------------------------------------------------
  4. #  随机播放BGM   
  5. #   Audio/BGM/下的文件,RTP什么的不会读...因为涉及到注册表什么的
  6. #   可以读取 C:/Program Files/RPG Maker XP/RGSS/Standard/ 的东西
  7. #        我能做的只有这些了,高手来解决吧
  8. #==============================================================================
  9. def Audio.random_bgm_play
  10.   # 查找根目录下的BGM文件
  11.   list = Dir["Audio/BGM/*"]
  12.   list = list[rand(list.size)]
  13.   v = Game_System.method_defined?("bgm_v") ? $game_system.bgm_v : 80 rescue return
  14.   unless list
  15.     # 根目录下没有BGM时,试图找C:/Program Files/RPG Maker XP/RGSS/Standard/下的文件
  16.     old_dir = Dir.pwd
  17.     Dir.chdir("C:/Program Files/RPG Maker XP/RGSS/Standard/") rescue return Dir.chdir(old_dir)
  18.     list = Dir["Audio/BGM/*"]
  19.     list = list[rand(list.size)]
  20.     Dir.chdir(old_dir)
  21.   end
  22.   # 试图失败时,直接返回
  23.   return unless list
  24.   self.bgm_play(list, v, 100)
  25.   # $game_system 为空时,直接返回
  26.   return unless $game_system
  27.   # 获取文件名,省事,
  28.   $game_system.playing_bgm = RPG::AudioFile.new(File.basename(list),v,100)
  29. end
  30. class Game_System
  31.   def playing_bgm=(bgm)
  32.     @playing_bgm = bgm
  33.   end
  34. end
  35. #--------------------------------------------------------------------------
  36. # ●  获取mp3文件时间长度
  37. #--------------------------------------------------------------------------
  38. def Audio.mp3_length(name)
  39.   @play ||= Win32API.new('winmm.dll', 'mciSendString',%(p p l l), 'l')
  40.   old_dir = Dir.pwd
  41.   Dir.chdir("Audio/BGM/")
  42.   name += ".mp3" if File.extname(name) == ""
  43.   length = " " * 10
  44.   File.rename(name, "temp.mp3")
  45.   @play.call("status temp.mp3 length", length, 512, 0)
  46.   File.rename("temp.mp3", name)
  47.   Dir.chdir(old_dir)
  48.   return length.to_i
  49. end
复制代码
使用方法 脚本置顶
1.Audio.random_bgm_play
2.Audio.mp3_length(name)   name = mp3文件名

3:
  1. #==============================================================================
  2. # ■ Graphics
  3. #------------------------------------------------------------------------------
  4. #  图像模块
  5. #==============================================================================

  6. #--------------------------------------------------------------------------
  7. # ● 更待指定帧数
  8. #--------------------------------------------------------------------------
  9. def Graphics.wait(n)
  10.   n.times{self.update;yield if defined? yield}
  11. end
  12. #--------------------------------------------------------------------------
  13. # ● 获取窗口宽
  14. #--------------------------------------------------------------------------
  15. def Graphics.width
  16.   @width ||= 640
  17. end
  18. #--------------------------------------------------------------------------
  19. # ● 获取窗口高
  20. #--------------------------------------------------------------------------
  21. def Graphics.height
  22.   @height ||= 480
  23. end
  24. #--------------------------------------------------------------------------
  25. # ● 更改窗口大小
  26. #--------------------------------------------------------------------------
  27. def Graphics.resize_screen(width, height)
  28.   @width  ||= 640
  29.   @height ||= 480
  30.   
  31.   游戏ini名=".\\Game.ini"
  32.   val = "\0"*256
  33.   gps = Win32API.new('kernel32', 'GetPrivateProfileString','pppplp', 'l')
  34.   gps.call("Game", "Title", "", val, 256, 游戏ini名)
  35.   val.delete!("\0")
  36.   title = val
  37.   fw = Win32API.new('user32', 'FindWindow', 'pp', 'i')
  38.   hWnd = fw.call("RGSS Player", title)
  39.   swp = Win32API.new('user32', 'SetWindowPos', 'lliiiii', 'i')
  40.   
  41.   pointwds = [0,0,0,0].pack('llll')
  42.   pointcet = [0, 0].pack('ll')

  43.   wdsrect = Win32API.new('user32.dll', 'GetWindowRect', 'lp', 'l')
  44.   client_screen = Win32API.new("user32", "ClientToScreen", 'ip', 'i')
  45.   
  46.   wdsrect.call(hWnd,pointwds)
  47.   client_screen.call(hWnd, pointcet)

  48.   wds = pointwds.unpack('llll')
  49.   cet = pointcet.unpack('ll')

  50.   addw =  wds[2] - wds[0] - @width
  51.   addh =  wds[3] - wds[1] - @height

  52.   x = wds[0] - (width - @width) / 2
  53.   y = wds[1] - (height - @height) / 2
  54.   
  55.   @width  = width
  56.   @height = height
  57.   
  58.   swp.call(hWnd, 0, x, y, @width + addw, @height + addh, 0x20)
  59. end
复制代码
模仿RGSS2清单:
1.等待指定帧数
Graphics.wait(n)
n = 帧数

加上了扩展(代码块)
Graphics.wait(n){...}

比如向左移动一窗口55像素
原来是:
55.times{Graphics.update;窗口.x -= 1}
现在
Graphics.wait(55){窗口.x -= 1}
(好像没区别...?)

2.更改窗口大小
Graphics.resize_screen(width, height)
width = 宽   height 高

3+4:获取窗口宽 高
Graphics.width   Graphics.height

4:(原    ——by 猫哥哥  改    ——by 沙漠.灰(未经过原作者同意,请见谅))
  1. #==============================================================================
  2. # ■ Bitmap
  3. #------------------------------------------------------------------------------
  4. #    位图类    RGSS扩充
  5. #                  原    ——by 猫哥哥
  6. #                  改    ——by 沙漠.灰         
  7. #=============================================================================#

  8. class Bitmap
  9.   #--------------------------------------------------------------------------
  10.   # ● 渐进色彩填充
  11.   #    vertical : 横(竖)填充
  12.   #--------------------------------------------------------------------------
  13.   def gradient_fill_rect(x,y,width,height=false,color1=255,color2=nil,vertical=false,opacity=255)
  14.     # 矩形判断
  15.     if x.is_a?(Rect)
  16.       s1,s2,s3,s4=x.x,x.y,x.width,x.height
  17.       return self.gradient_fill_rect(s1,s2,s3,s4,y,width,height,color1)
  18.     end
  19.     # 渐进步长(step)判断
  20.     vertical == false ? step = width - x : step = height - y;color = color1;color.alpha = opacity
  21.     # 渐进_红
  22.     key_re = Math.sqrt(((color2.red   - color1.red  )/step)**2)
  23.     # 渐进_绿
  24.     key_gr = Math.sqrt(((color2.green - color1.green)/step)**2)
  25.     # 渐进_蓝
  26.     key_bl = Math.sqrt(((color2.blue  - color1.blue )/step)**2)
  27.     # 反渐进方向判断
  28.     key_re *= -1 if color2.red  < color1.red
  29.     key_gr *= -1 if color2.green< color1.green
  30.     key_bl *= -1 if color2.blue < color1.blue
  31.     # 横(竖)填充
  32.     if vertical
  33.         (height-y).times{
  34.           self.fill_rect(x, y, width, 1, color)
  35.           y=y+1;color.red =color.red + key_re
  36.           color.green =color.green + key_gr;color.blue =color.blue + key_bl
  37.          }
  38.     else
  39.       (width-x).times{
  40.           self.fill_rect(x, y, 1, height, color)
  41.           x=x+1;color.red =color.red + key_re
  42.           color.green =color.green + key_gr;color.blue =color.blue + key_bl
  43.       }
  44.     end
  45.   end
  46.   #--------------------------------------------------------------------------
  47.   # ● 清除位图指定地方
  48.   #--------------------------------------------------------------------------   
  49.   def clear_rect(x, y=0,width=0,height=0)
  50.     # 矩形判断
  51.     if x.is_a?(Rect)
  52.       self.fill_rect(x,Color.new(0,0,0,0))
  53.     else
  54.       self.fill_rect(x, y, width, height, Color.new(0,0,0,0))
  55.     end
  56.   end
  57.   #--------------------------------------------------------------------------
  58.   # ● 位图重叠模糊(壳)
  59.   #--------------------------------------------------------------------------
  60.   def fragment_bluring(blur=4,during=3)
  61.     for i in 1..blur
  62.       self.fragment_blur(i)
  63.       self.blt(0, 0, self, self.rect)
  64.       during.times{Graphics.update}   
  65.     end
  66.   end
  67.   #--------------------------------------------------------------------------
  68.   # ● 模糊算法(壳)
  69.   #     times      重做模糊次数
  70.   #     during     经历帧数
  71.   #     blur       分散半径
  72.   #--------------------------------------------------------------------------   
  73.   def blur(times=1,during =1,blur=1)
  74.     times.times{blur_r(blur);during.times{Graphics.update if during >1}}
  75.   end
  76.   #--------------------------------------------------------------------------
  77.   # ● 玻璃(半透明)渐进填充
  78.   #    vertical   横(竖)渐进
  79.   #--------------------------------------------------------------------------   
  80.   def glass_fill_rect(x, y=nil,width=nil,height=false,color1=nil,color2=nil,vertical=false)
  81.     # 矩形判断
  82.     if x.is_a?(Rect)
  83.       s1,s2,s3,s4=x.x,x.y,x.width,x.height
  84.       return self.glass_fill_rect(s1,s2,s3,s4,y,width,height)
  85.     end
  86.     # 生成临时位图
  87.     a1 = Bitmap.new(width, height);a2 = Bitmap.new(width, height)
  88.     # 并填充
  89.     a1.fill_rect(x, y, width, height, color1);a2.fill_rect(x, y, width, height, color2)
  90.     # 横(竖)渐进
  91.     unless vertical
  92.       key =[[255.0/(width - x),255.0].min,1.0].min
  93.       src_rect = Rect.new(x,y,1,height);k = x
  94.       for i in x..width
  95.         self.blt(x, y, a1, src_rect, (width-i)*key)
  96.         self.blt(x, y, a2, src_rect, (i-k)*key)
  97.         x += 1
  98.       end
  99.     else
  100.       key =[[255.0/(height - x),255.0].min,1.0].min
  101.       src_rect = Rect.new(x,y,width,1);k = y
  102.       for i in y..height
  103.         self.blt(x, y, a1, src_rect, (height-i)*key)
  104.         self.blt(x, y, a2, src_rect, (i-k)*key)
  105.         y += 1
  106.       end
  107.     end
  108.     # 释放临时位图
  109.     a1.dispose;a2.dispose
  110.   end
  111.   # 以下方法私有化
  112.   private
  113.   #--------------------------------------------------------------------------
  114.   # ● 位图重叠模糊(执行)
  115.   #--------------------------------------------------------------------------  
  116.   def fragment_blur(radius=6)
  117.     src_bitmap = self;rect = self.rect;key = 255/7
  118.     self.blt(0,0,src_bitmap,rect,key*4)
  119.     self.blt(0,-radius,src_bitmap,rect,key*2)
  120.     self.blt(radius,0,src_bitmap,rect,key*2)
  121.     self.blt(-radius,0,src_bitmap,rect,key*2)
  122.     self.blt(0,radius,src_bitmap,rect,key*2)
  123.     self.blt(radius,-radius,src_bitmap,rect,key*1)
  124.     self.blt(-radius,radius,src_bitmap,rect,key*1)
  125.     self.blt(-radius,-radius,src_bitmap,rect,key*1)
  126.     self.blt(radius,radius,src_bitmap,rect,key*1)
  127.   end
  128.   #--------------------------------------------------------------------------
  129.   # ● 模糊算法(执行)
  130.   #      radius          分散半径
  131.   #      p.s. 写得好乱...和我有的一拼,不过好多废代码....
  132.   #--------------------------------------------------------------------------  
  133.   def blur_r(radius = 2)
  134.     # 分散半径值修正
  135.     radius = [radius,1].max
  136.     src_bitmap = self
  137.     rect = self.rect
  138.    
  139.     ta_l = 1+radius*2
  140.     ta = Table.new(ta_l,ta_l)  #过滤器
  141.    
  142.     ta_l.times{|i|ta_l.times{|j|ta[i,j] = 1}}
  143.     ta[((ta.xsize+1)/2)-1,((ta.xsize+1)/2)-1] = 2**(1+radius)
  144.     main = ta[((ta.xsize+1)/2)-1,((ta.xsize+1)/2)-1]#找到中心点
  145.     nn = 2;j = ((ta.xsize+1)/2)-1;line =[]#主干道
  146.    
  147.     for i in 0..((ta.xsize+1)/2)-2
  148.       ta[i,j] = nn
  149.       ta[j,i] = nn
  150.       ta[ta.xsize-1-i,j] = nn
  151.       ta[j,ta.xsize-1-i] = nn
  152.       line.push ta[i,((ta.xsize+1)/2)-1]
  153.       nn *= 2
  154.     end
  155.    
  156.     for j in 0...line.size
  157.        for i in 0..((ta.xsize+1)/2)-2
  158.         line[j] = line[j]/2
  159.         break if line[j] == 1
  160.         ta[((ta.xsize+1)/2)-2-i ,j           ] = line[j]
  161.         ta[((ta.xsize+1)/2)+i   ,j           ] = line[j]
  162.         ta[((ta.xsize+1)/2)-2-i ,ta.xsize-1-j] = line[j]
  163.         ta[((ta.xsize+1)/2)+i   ,ta.xsize-1-j] = line[j]
  164.       end
  165.     end
  166.    
  167.     key_a = [];key_p = main
  168.     for i in 1..main
  169.       if key_p == 1
  170.         key_a << main
  171.         break
  172.       else
  173.       key_p /= 2
  174.       key_a << key_p
  175.       end
  176.     end
  177.     key_k = 0
  178.     for i in 0...key_a.size
  179.       key_k += key_a[i]
  180.     end
  181.     key = [255.0/key_k,1].max
  182.     for i in 0...ta.xsize
  183.       for j in 0...ta.ysize
  184.         # 值的修正
  185.         key_main = [[key*ta[i,j],255].min,1].max
  186.         self.blt(i-(((ta.xsize+1)/2)-1),j-(((ta.xsize+1)/2)-1),self,rect,key_main)
  187.       end
  188.     end
  189.   end

  190. end  
复制代码
清单 :
1.渐进色彩填充
参考RMVX Help

2.清除位图指定地方
同上

3.位图重叠模糊(不知道名字对不对...)
位图.fragment_bluring
参考 模糊算法

4.模糊算法
参考RMVX Help

5.玻璃(半透明)渐进填充
位图.glass_fill_rect(XXXXXXXXXXXXXXXX)
参考 渐进色彩填充

五.
  1. #==============================================================================
  2. # ■ Window
  3. #------------------------------------------------------------------------------
  4. #  游戏中全部窗口的超级类。
  5. #==============================================================================

  6. class Window
  7.   #--------------------------------------------------------------------------
  8.   # ● X 坐标
  9.   #--------------------------------------------------------------------------
  10.   alias isa_dust_x x
  11.   def x
  12.     @true_x ||= self.isa_dust_x.to_f
  13.     return @true_x
  14.   end
  15.   alias isa_dust_x= x=
  16.   def x=(new_x)
  17.     @true_x = new_x.to_f
  18.     self.isa_dust_x = @true_x
  19.   end
  20.   #--------------------------------------------------------------------------
  21.   # ● Y 坐标
  22.   #--------------------------------------------------------------------------
  23.   alias isa_dust_y y
  24.   def y
  25.     @true_y ||= self.isa_dust_y.to_f
  26.     return @true_y
  27.   end
  28.   alias isa_dust_y= y=
  29.   def y=(new_y)
  30.     @true_y = new_y.to_f
  31.     self.isa_dust_y = @true_y
  32.   end
  33. end
复制代码
上面代码置顶
  1. #==============================================================================
  2. # ■ Window_Base
  3. #------------------------------------------------------------------------------
  4. #  游戏中全部窗口的超级类。
  5. #==============================================================================

  6. class Window_Base < Window
  7.   #--------------------------------------------------------------------------
  8.   # ● 初始化
  9.   #--------------------------------------------------------------------------
  10.   alias isa_dust_initialize initialize
  11.   def initialize(*a)
  12.     isa_dust_initialize(*a)
  13.     @move_count = 0
  14.     @move_to_x  = 0
  15.     @move_to_y  = 0
  16.   end
  17.   #--------------------------------------------------------------------------
  18.   # ● 真 移动
  19.   #--------------------------------------------------------------------------
  20.   def move_to(x,y,count)
  21.     @move_to_x = x
  22.     @move_to_y = y
  23.     @move_count= count
  24.   end
  25.   #--------------------------------------------------------------------------
  26.   # ● 刷新
  27.   #--------------------------------------------------------------------------
  28.   alias isa_dust_update update
  29.   def update
  30.     isa_dust_update
  31.     # 移动完毕时,直接返回
  32.     return if @move_count <= 0
  33.     self.x += (@move_to_x - self.x)/@move_count.to_f
  34.     self.y += (@move_to_y - self.y)/@move_count.to_f
  35.     @move_count -= 1
  36.   end
  37. end
复制代码
上面代码插到Main前Window_Base后

用法:
窗口.move_to(x坐标,y坐标,帧数)
注.必须调用update方法,帧数(默认)40帧1秒(不同于事件的图片移动)

例:(用上面的等待指定帧数)

窗口.move_to(600,0,100)
Graphics.wait(100){窗口.update}

100帧让叫窗口的窗口对象移动到 600,0 处

六.代码如下
  1. class Window_Base < Window
  2.   #--------------------------------------------------------------------------
  3.   # ● 伪 移动
  4.   #--------------------------------------------------------------------------
  5.   def not_really_move(d="right")
  6.     d == "right" ? d = 1 : d = -1
  7.     self.x        += d * 5
  8.     self.ox       += d * 5
  9.     self.width    -= d * 5
  10.     self.opacity  += d * 15
  11.     self.contents_opacity += d * 15
  12.   end
  13. end
复制代码
这个是纯美化功能,动态淡出淡入
一般先初始化(必须是17)
17.times{@folder_window.not_really_move("left ")}
Graphics.wait(17){@folder_window.not_really_move("right")}

场景最后释放前
Graphics.wait(17){@folder_window.not_really_move("left ")}

具体例子见:http://rpg.blue/thread-174282-1-1.html

七.略

打字好辛苦~~

点评

简单一点的模糊 应该是 算准比例 然后 blt = =bb  发表于 2011-4-9 11:24
>>猛戳>>MetalSagaR游戏主页<<这里<<
欢迎提供您的意见
头像被屏蔽

Lv1.梦旅人 (禁止发言)

梦石
0
星屑
50
在线时间
31 小时
注册时间
2011-3-2
帖子
122
2
发表于 2011-4-3 11:58:19 | 只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
签名被屏蔽
回复 支持 反对

使用道具 举报

Lv3.寻梦者

酱油的

梦石
0
星屑
970
在线时间
2161 小时
注册时间
2007-12-22
帖子
3271

贵宾

3
发表于 2011-4-3 13:55:41 | 只看该作者
其實用RGSS2來模仿RGSS1比相反更方便

点评

那是肯定的....貌似RGSS2只删除几个方法,RGSS2的Bitmap的放射型模糊很赞...哎...继续学习算法  发表于 2011-4-3 14:06
不做頭像做簽名,看我囧冏有神(多謝山人有情提供 )
回复 支持 反对

使用道具 举报

Lv2.观梦者

虚構歪曲

梦石
0
星屑
309
在线时间
1194 小时
注册时间
2010-12-18
帖子
3928

贵宾

4
发表于 2011-4-3 13:56:50 | 只看该作者
渐进色彩填充……
血槽有望了……
回复 支持 反对

使用道具 举报

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

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-5-14 05:32

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表