RGSS1实用"扩展库"
清单1.[方便] 随机播放BGM
2.[扩展] 获取mp3文件时间长度 (有bug←等于没说)
3.[扩展] Graphics块 模仿 RGSS2部分功能
4.[扩展] Bitmap类 模仿 RGSS2部分功能
5.[美化] 真 窗口移动
6.[美化] 伪 窗口移动
7.[扩展] 子选项窗口(http://rpg.blue/thread-174280-1-1.html)
脚本如下:
1+2 :#==============================================================================# ■ Audio #------------------------------------------------------------------------------# 随机播放BGM # Audio/BGM/下的文件,RTP什么的不会读...因为涉及到注册表什么的# 可以读取 C:/Program Files/RPG Maker XP/RGSS/Standard/ 的东西# 我能做的只有这些了,高手来解决吧#==============================================================================def Audio.random_bgm_play# 查找根目录下的BGM文件list = Dir["Audio/BGM/*"]list = listv = Game_System.method_defined?("bgm_v") ? $game_system.bgm_v : 80 rescue returnunless list # 根目录下没有BGM时,试图找C:/Program Files/RPG Maker XP/RGSS/Standard/下的文件 old_dir = Dir.pwd Dir.chdir("C:/Program Files/RPG Maker XP/RGSS/Standard/") rescue return Dir.chdir(old_dir) list = Dir["Audio/BGM/*"] list = list Dir.chdir(old_dir)end# 试图失败时,直接返回return unless listself.bgm_play(list, v, 100)# $game_system 为空时,直接返回return unless $game_system# 获取文件名,省事,$game_system.playing_bgm = RPG::AudioFile.new(File.basename(list),v,100)endclass Game_Systemdef playing_bgm=(bgm) @playing_bgm = bgmendend#--------------------------------------------------------------------------# ● 获取mp3文件时间长度#--------------------------------------------------------------------------def Audio.mp3_length(name)@play ||= Win32API.new('winmm.dll', 'mciSendString',%(p p l l), 'l')old_dir = Dir.pwdDir.chdir("Audio/BGM/")name += ".mp3" if File.extname(name) == ""length = " " * 10File.rename(name, "temp.mp3")@play.call("status temp.mp3 length", length, 512, 0)File.rename("temp.mp3", name)Dir.chdir(old_dir)return length.to_iend复制代码使用方法 脚本置顶
1.Audio.random_bgm_play
2.Audio.mp3_length(name) name = mp3文件名
3:#==============================================================================# ■ Graphics #------------------------------------------------------------------------------# 图像模块#==============================================================================#--------------------------------------------------------------------------# ● 更待指定帧数 #--------------------------------------------------------------------------def Graphics.wait(n)n.times{self.update;yield if defined? yield}end#--------------------------------------------------------------------------# ● 获取窗口宽#--------------------------------------------------------------------------def Graphics.width@width ||= 640end#--------------------------------------------------------------------------# ● 获取窗口高#--------------------------------------------------------------------------def Graphics.height@height ||= 480end#--------------------------------------------------------------------------# ● 更改窗口大小#--------------------------------------------------------------------------def Graphics.resize_screen(width, height)@width||= 640@height ||= 480 游戏ini名=".\\Game.ini"val = "\0"*256gps = Win32API.new('kernel32', 'GetPrivateProfileString','pppplp', 'l')gps.call("Game", "Title", "", val, 256, 游戏ini名)val.delete!("\0")title = valfw = Win32API.new('user32', 'FindWindow', 'pp', 'i')hWnd = fw.call("RGSS Player", title)swp = Win32API.new('user32', 'SetWindowPos', 'lliiiii', 'i') pointwds = .pack('llll')pointcet = .pack('ll')wdsrect = Win32API.new('user32.dll', 'GetWindowRect', 'lp', 'l')client_screen = Win32API.new("user32", "ClientToScreen", 'ip', 'i') wdsrect.call(hWnd,pointwds)client_screen.call(hWnd, pointcet)wds = pointwds.unpack('llll')cet = pointcet.unpack('ll')addw =wds - wds - @widthaddh =wds - wds - @heightx = wds - (width - @width) / 2y = wds - (height - @height) / 2 @width= width@height = height swp.call(hWnd, 0, x, y, @width + addw, @height + addh, 0x20) 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 沙漠.灰(未经过原作者同意,请见谅))#==============================================================================# ■ Bitmap#------------------------------------------------------------------------------# 位图类 RGSS扩充# 原 ——by 猫哥哥# 改 ——by 沙漠.灰 #=============================================================================#class Bitmap#--------------------------------------------------------------------------# ● 渐进色彩填充# vertical : 横(竖)填充#--------------------------------------------------------------------------def gradient_fill_rect(x,y,width,height=false,color1=255,color2=nil,vertical=false,opacity=255) # 矩形判断 if x.is_a?(Rect) s1,s2,s3,s4=x.x,x.y,x.width,x.height return self.gradient_fill_rect(s1,s2,s3,s4,y,width,height,color1) end # 渐进步长(step)判断 vertical == false ? step = width - x : step = height - y;color = color1;color.alpha = opacity # 渐进_红 key_re = Math.sqrt(((color2.red - color1.red)/step)**2) # 渐进_绿 key_gr = Math.sqrt(((color2.green - color1.green)/step)**2) # 渐进_蓝 key_bl = Math.sqrt(((color2.blue- color1.blue )/step)**2) # 反渐进方向判断 key_re *= -1 if color2.red< color1.red key_gr *= -1 if color2.green< color1.green key_bl *= -1 if color2.blue < color1.blue # 横(竖)填充 if vertical (height-y).times{ self.fill_rect(x, y, width, 1, color) y=y+1;color.red =color.red + key_re color.green =color.green + key_gr;color.blue =color.blue + key_bl } else (width-x).times{ self.fill_rect(x, y, 1, height, color) x=x+1;color.red =color.red + key_re color.green =color.green + key_gr;color.blue =color.blue + key_bl } endend#--------------------------------------------------------------------------# ● 清除位图指定地方#-------------------------------------------------------------------------- def clear_rect(x, y=0,width=0,height=0) # 矩形判断 if x.is_a?(Rect) self.fill_rect(x,Color.new(0,0,0,0)) else self.fill_rect(x, y, width, height, Color.new(0,0,0,0)) endend#--------------------------------------------------------------------------# ● 位图重叠模糊(壳)#-------------------------------------------------------------------------- def fragment_bluring(blur=4,during=3) for i in 1..blur self.fragment_blur(i) self.blt(0, 0, self, self.rect) during.times{Graphics.update} endend#--------------------------------------------------------------------------# ● 模糊算法(壳)# times 重做模糊次数# during 经历帧数# blur 分散半径#-------------------------------------------------------------------------- def blur(times=1,during =1,blur=1) times.times{blur_r(blur);during.times{Graphics.update if during >1}} end#--------------------------------------------------------------------------# ● 玻璃(半透明)渐进填充# vertical 横(竖)渐进#-------------------------------------------------------------------------- def glass_fill_rect(x, y=nil,width=nil,height=false,color1=nil,color2=nil,vertical=false) # 矩形判断 if x.is_a?(Rect) s1,s2,s3,s4=x.x,x.y,x.width,x.height return self.glass_fill_rect(s1,s2,s3,s4,y,width,height) end # 生成临时位图 a1 = Bitmap.new(width, height);a2 = Bitmap.new(width, height) # 并填充 a1.fill_rect(x, y, width, height, color1);a2.fill_rect(x, y, width, height, color2) # 横(竖)渐进 unless vertical key =[.min,1.0].min src_rect = Rect.new(x,y,1,height);k = x for i in x..width self.blt(x, y, a1, src_rect, (width-i)*key) self.blt(x, y, a2, src_rect, (i-k)*key) x += 1 end else key =[.min,1.0].min src_rect = Rect.new(x,y,width,1);k = y for i in y..height self.blt(x, y, a1, src_rect, (height-i)*key) self.blt(x, y, a2, src_rect, (i-k)*key) y += 1 end end # 释放临时位图 a1.dispose;a2.disposeend# 以下方法私有化private#--------------------------------------------------------------------------# ● 位图重叠模糊(执行)#-------------------------------------------------------------------------- def fragment_blur(radius=6) src_bitmap = self;rect = self.rect;key = 255/7 self.blt(0,0,src_bitmap,rect,key*4) self.blt(0,-radius,src_bitmap,rect,key*2) self.blt(radius,0,src_bitmap,rect,key*2) self.blt(-radius,0,src_bitmap,rect,key*2) self.blt(0,radius,src_bitmap,rect,key*2) self.blt(radius,-radius,src_bitmap,rect,key*1) self.blt(-radius,radius,src_bitmap,rect,key*1) self.blt(-radius,-radius,src_bitmap,rect,key*1) self.blt(radius,radius,src_bitmap,rect,key*1)end#--------------------------------------------------------------------------# ● 模糊算法(执行)# radius 分散半径# p.s. 写得好乱...和我有的一拼,不过好多废代码....#-------------------------------------------------------------------------- def blur_r(radius = 2) # 分散半径值修正 radius = .max src_bitmap = self rect = self.rect ta_l = 1+radius*2 ta = Table.new(ta_l,ta_l)#过滤器 ta_l.times{|i|ta_l.times{|j|ta = 1}} ta[((ta.xsize+1)/2)-1,((ta.xsize+1)/2)-1] = 2**(1+radius) main = ta[((ta.xsize+1)/2)-1,((ta.xsize+1)/2)-1]#找到中心点 nn = 2;j = ((ta.xsize+1)/2)-1;line =[]#主干道 for i in 0..((ta.xsize+1)/2)-2 ta = nn ta = nn ta = nn ta = nn line.push ta nn *= 2 end for j in 0...line.size for i in 0..((ta.xsize+1)/2)-2 line = line/2 break if line == 1 ta[((ta.xsize+1)/2)-2-i ,j ] = line ta[((ta.xsize+1)/2)+i ,j ] = line ta[((ta.xsize+1)/2)-2-i ,ta.xsize-1-j] = line ta[((ta.xsize+1)/2)+i ,ta.xsize-1-j] = line end end key_a = [];key_p = main for i in 1..main if key_p == 1 key_a
页:
[1]