- 累计送礼:
- 0 个
- 累计收礼:
- 0 个
TA的每日心情 | 开心 昨天 18:01 |
---|
签到天数: 114 天 连续签到: 4 天 [LV.6]常住居民II

管理员
  
- VIP
- 6
- 卡币
- 10632
- OK点
- 16
- 推广点
- 0
- 同能卷
- 0
- 积分
- 13401


|
清单
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 = list[rand(list.size)] v = Game_System.method_defined?("bgm_v") ? $game_system.bgm_v : 80 rescue return unless 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[rand(list.size)] Dir.chdir(old_dir) end # 试图失败时,直接返回 return unless list self.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_System def playing_bgm=(bgm) @playing_bgm = bgm endend#--------------------------------------------------------------------------# ● 获取mp3文件时间长度#--------------------------------------------------------------------------def Audio.mp3_length(name) @play ||= Win32API.new('winmm.dll', 'mciSendString',%(p p l l), 'l') old_dir = Dir.pwd Dir.chdir("Audio/BGM/") name += ".mp3" if File.extname(name) == "" length = " " * 10 File.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"*256 gps = Win32API.new('kernel32', 'GetPrivateProfileString','pppplp', 'l') gps.call("Game", "Title", "", val, 256, 游戏ini名) val.delete!("\0") title = val fw = Win32API.new('user32', 'FindWindow', 'pp', 'i') hWnd = fw.call("RGSS Player", title) swp = Win32API.new('user32', 'SetWindowPos', 'lliiiii', 'i') pointwds = [0,0,0,0].pack('llll') pointcet = [0, 0].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[2] - wds[0] - @width addh = wds[3] - wds[1] - @height x = wds[0] - (width - @width) / 2 y = wds[1] - (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 沙漠.灰(未经过原作者同意,请见谅))[code]#==============================================================================# ■ 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 } end end #-------------------------------------------------------------------------- # ● 清除位图指定地方 #-------------------------------------------------------------------------- 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)) end end #-------------------------------------------------------------------------- # ● 位图重叠模糊(壳) #-------------------------------------------------------------------------- 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} end end #-------------------------------------------------------------------------- # ● 模糊算法(壳) # 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 =[[255.0/(width - x),255.0].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 =[[255.0/(height - x),255.0].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.dispose end # 以下方法私有化 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 = [radius,1].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[i,j] = 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[i,j] = nn ta[j,i] = nn ta[ta.xsize-1-i,j] = nn ta[j,ta.xsize-1-i] = nn line.push ta[i,((ta.xsize+1)/2)-1] nn *= 2 end for j in 0...line.size for i in 0..((ta.xsize+1)/2)-2 line[j] = line[j]/2 break if line[j] == 1 ta[((ta.xsize+1)/2)-2-i ,j ] = line[j] ta[((ta.xsize+1)/2)+i ,j ] = line[j] ta[((ta.xsize+1)/2)-2-i ,ta.xsize-1-j] = line[j] ta[((ta.xsize+1)/2)+i ,ta.xsize-1-j] = line[j] end end key_a = [];key_p = main for i in 1..main if key_p == 1 key_a |
|