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

Project1

 找回密码
 注册会员
搜索

RPGVX -> RGE 兼容层【用RGE来运行VX工程】(2011-6-18更新)

查看数: 5713 | 评论数: 16 | 收藏 2
关灯 | 提示:支持键盘翻页<-左 右->
    组图打开中,请稍候......
发布时间: 2011-6-6 08:35

正文摘要:

#============================================================================== # ★ RGE -> RPGVX 兼容层 #------------------------------------------------------------------------------ # 提供RGSS2内置 ...

回复

零度 发表于 2011-7-20 19:31:44
有buy没处说,冒着被扣分的危险还是提交吧,想用点评的  但点评中只出现了一小部分文字,多余文字被系统屏蔽了?
在选择 新的游戏 后 标题换面并没有一下转到游戏地图(就是能控制小人在地图上来回跑的页面) 而是 文字消失了 延缓了一下才 转到开始页面

点评

好吧 ,我out了。。。  发表于 2011-7-20 19:41
好吧 ,我out  发表于 2011-7-20 19:41
发布区随便挖坟,不扣分= =  发表于 2011-7-20 19:36
zh99998 发表于 2011-6-18 18:03:55
6-18更新,感谢一箭烂YiJL 更新内容见顶楼

点评

其实还是有不完美的地方的 例如 选择 新的开始 后 会出现类似卡的问题(文字消失了,但没转到游戏地图上,也就是有延缓)  发表于 2011-7-20 19:25
一箭烂YiJL 发表于 2011-6-13 19:42:37
连个帖,发布完成了的(话说zh你的头像....):
  1. #==============================================================================
  2. # ■ Graphics
  3. #------------------------------------------------------------------------------
  4. #  进行有关全体图像处理的模块。
  5. #   RGE 的 Graphics.snap_to_bitmap。(RGE版)
  6. #==============================================================================
  7. module Graphics
  8.   #--------------------------------------------------------------------------
  9.   # ● API 函数
  10.   #--------------------------------------------------------------------------
  11.   CreateDC = Win32API.new("gdi32", "CreateDC", "pppl", "l")
  12.   CreateCompatibleBitmap = Win32API.new("gdi32", "CreateCompatibleBitmap", "lll", "l")
  13.   CreateCompatibleDC = Win32API.new("gdi32", "CreateCompatibleDC", "l", "l")
  14.   SelectObject = Win32API.new("gdi32", "SelectObject", "ll", "l")
  15.   BitBlt = Win32API.new("gdi32", "BitBlt", "lllllllll", "l")
  16.   GetBitmapBits = Win32API.new("gdi32", "GetBitmapBits", "llp", "l")
  17.   ScreenToClient = Win32API.new("user32", "ScreenToClient", "ip", "i")
  18.   DeleteDC = Win32API.new("gdi32", "DeleteDC", "l", "l")
  19.   DeleteObject = Win32API.new("gdi32", "DeleteObject", "l", "l")
  20.   HWnd = Win32API.new("user32", "GetActiveWindow", nil, 'l').call
  21.   DwCount = (Frame.width * Frame.height * 4)# * 2
  22.   #--------------------------------------------------------------------------
  23.   # ● 值
  24.   #--------------------------------------------------------------------------
  25.   @@lpBits = "\000" * DwCount
  26.   SRCCOPY = 0xCC0020
  27.   #--------------------------------------------------------------------------
  28.   # ● snap_to_bitmap (RGE版)
  29.   #--------------------------------------------------------------------------
  30.   def self.snap_to_bitmap
  31.     hScrDC = CreateDC.call("DISPLAY", "", "", 0)
  32.     hMemDC = CreateCompatibleDC.call(hScrDC)
  33.     hBitmap = CreateCompatibleBitmap.call(hScrDC, width, height)
  34.     hOldBitmap = SelectObject.call(hMemDC, hBitmap)
  35.     win_pos = "\0\0\0\0\0\0\0\0"
  36.     ScreenToClient.call(HWnd, win_pos)
  37.     win_pos = win_pos.unpack("LL")
  38.     BitBlt.call(hMemDC, win_pos[0], win_pos[1], width*2, height*2, hScrDC, 0, 0, SRCCOPY)
  39.     hBitmap2 = SelectObject.call(hMemDC, hOldBitmap)
  40.     GetBitmapBits.call(hBitmap2, DwCount, @@lpBits)
  41.     # 释放所有东西
  42.     DeleteDC.call(hScrDC)
  43.     DeleteDC.call(hMemDC)
  44.     DeleteObject.call(hBitmap)
  45.     DeleteObject.call(hOldBitmap)
  46.     DeleteObject.call(hBitmap2)
  47.     rgbs = @@lpBits
  48.     len = width * 4
  49.     for y in 0...height
  50.       break if 2 * y >= height - 1
  51.       nth1 = y * len
  52.       nth2 = (height - 1 - y) * len
  53.       tStr = rgbs[nth1,len]
  54.       rgbs[nth1, len] = rgbs[nth2, len]
  55.       rgbs[nth2, len] = tStr
  56.     end
  57.     size = 54 + Frame.width * Frame.height * 4
  58.     chunk1 = "BM" + [size].pack("L") + "\0\0\0\0\x36\0\0\0"
  59.     chunk2 = "\x28\0\0\0" + [Frame.width, Frame.height].pack("L2") +
  60.     "\1\0\x20\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  61.     rgbs = chunk1 + chunk2 + rgbs
  62.     bitmap = Bitmap.mem_new(rgbs.maddr, rgbs.size)
  63.     return bitmap
  64.   end
  65. end
复制代码

评分

参与人数 1星屑 +600 收起 理由
zh99998 + 600 thanks

查看全部评分

一箭烂YiJL 发表于 2011-6-11 16:40:11
david50407 发表于 2011-6-11 16:27
自己刻的Shadow 应该VX一样Bitmap#blur

其实 @default_shadow 应否用类变量呢?(貌似会省下一些内存...不知道= =)
Bitmap 貌似是这个:
  1. http://rpg.blue/article-40940.html
复制代码
是吗?

Bitmap.mem_new 不知为啥会出错,看 12 楼那个无误获取字符串内存地址的办法,
我(Vista)出错,RGE::BaseError   Create bitmap error with(Address:0x???????, Length:905216),
脚本如下(呼叫zh来看= =):
  1. #==============================================================================
  2. # ■ Graphics
  3. #------------------------------------------------------------------------------
  4. #  进行有关全体图像处理的模块。
  5. #   RGE 的 Graphics.snap_to_bitmap。(和 XP 版有分别)
  6. #==============================================================================
  7. module Graphics
  8.   #--------------------------------------------------------------------------
  9.   # ● API 函数
  10.   #--------------------------------------------------------------------------
  11.   CreateDC = Win32API.new("gdi32", "CreateDC", "pppl", "l")
  12.   CreateCompatibleBitmap = Win32API.new("gdi32", "CreateCompatibleBitmap", "lll", "l")
  13.   CreateCompatibleDC = Win32API.new("gdi32", "CreateCompatibleDC", "l", "l")
  14.   SelectObject = Win32API.new("gdi32", "SelectObject", "ll", "l")
  15.   BitBlt = Win32API.new("gdi32", "BitBlt", "lllllllll", "l")
  16.   GetBitmapBits = Win32API.new("gdi32", "GetBitmapBits", "llp", "l")
  17.   ScreenToClient = Win32API.new("user32", "ScreenToClient", "ip", "i")
  18.   DeleteDC = Win32API.new("gdi32", "DeleteDC", "l", "l")
  19.   DeleteObject = Win32API.new("gdi32", "DeleteObject", "l", "l")
  20.   SRCCOPY = 0xCC0020
  21.   RtlMoveMemory_pi = Win32API.new("kernel32", "RtlMoveMemory", "pii", "i")
  22.   HWnd = Win32API.new("user32", "GetActiveWindow", nil, 'l').call
  23.   DwCount = (Frame.width * Frame.height * 4)# * 2
  24.   @@lpBits = "\000" * DwCount
  25.   #--------------------------------------------------------------------------
  26.   # ● snap_to_bitmap (RGE版)
  27.   #--------------------------------------------------------------------------
  28.   def self.snap_to_bitmap
  29.     hScrDC = CreateDC.call("DISPLAY", "", "", 0)
  30.     hMemDC = CreateCompatibleDC.call(hScrDC)
  31.     hBitmap = CreateCompatibleBitmap.call(hScrDC, width, height)
  32.     hOldBitmap = SelectObject.call(hMemDC, hBitmap)
  33.     win_pos = "\0\0\0\0\0\0\0\0"
  34.     ScreenToClient.call(HWnd, win_pos)
  35.     win_pos = win_pos.unpack("LL")
  36.     BitBlt.call(hMemDC, win_pos[0], win_pos[1], width*2, height*2, hScrDC, 0, 0, SRCCOPY)
  37.     hBitmap2 = SelectObject.call(hMemDC, hOldBitmap)
  38.     GetBitmapBits.call(hBitmap2, DwCount, @@lpBits)
  39.     # 释放所有东西
  40.     DeleteDC.call(hScrDC)
  41.     DeleteDC.call(hMemDC)
  42.     DeleteObject.call(hBitmap)
  43.     DeleteObject.call(hOldBitmap)
  44.     DeleteObject.call(hBitmap2)
  45.     rgbs = @@lpBits
  46.     len = width * 4
  47.     for y in 0...height
  48.       break if 2 * y >= height - 1
  49.       nth1 = y * len
  50.       nth2 = (height - 1 - y) * len
  51.       tStr = rgbs[nth1,len]
  52.       rgbs[nth1, len] = rgbs[nth2, len]
  53.       rgbs[nth2, len] = tStr
  54.     end
  55.     # 找 String 的内存地址
  56.     rgbs_address = "xxxx"    # 分配指针 4 个字节
  57.     RtlMoveMemory_pi.call(rgbs_address, rgbs.object_id * 2 + 12, 4)
  58.     rgbs_address = rgbs_address.unpack("L")[0]
  59.     bitmap = Bitmap.mem_new(rgbs_address, Frame.width * Frame.height * 4)
  60.     return bitmap
  61.   end
  62. end
复制代码

点评

blur是之前用的 已经忘记是哪位大神写的了  发表于 2011-6-11 22:16
嗯@default_shadow是应该用@@才对  发表于 2011-6-11 22:16
david50407 发表于 2011-6-11 16:27:57
zh99998 发表于 2011-6-11 14:42
首先感谢您认真看我的帖子并进行修改

1. DLL那个方式我也表示很不爽...所以也没塞进RGE文件夹里而是丢在 ...

自己刻的Shadow 应该VX一样
  1. class Font
  2.   #設定預設值
  3.   @default_shadow = true
  4.   @shadow = @default_shadow
  5.   def default_shadow
  6.     @default_shadow = true if @default_shadow == nil
  7.     return @default_shadow
  8.   end
  9.   def default_shadow=(shadow)
  10.     @default_shadow = shadow
  11.   end
  12.   def shadow
  13.     @shadow = self.default_shadow if @shadow == nil
  14.     return @shadow
  15.   end
  16.   def shadow=(shadow)
  17.     @shadow = shadow
  18.   end
  19. end

  20. class Bitmap
  21.   if $bitmap_drawtext_wrote == nil
  22.     alias old_draw_text draw_text
  23.     $bitmap_drawtext_wrote = true
  24.   end
  25.   def draw_text(*args)
  26.     shadow = false
  27.     shadow = true if (self.font.shadow == true)
  28.     if args.size < 4
  29.       args[2] = 0 if args.size == 2
  30.       if shadow == true
  31.         args[0].x += 1
  32.         args[0].y += 1
  33.         color = Color.new(self.font.color.red, self.font.color.green, self.font.color.blue, self.font.color.alpha)
  34.         self.font.color.set(0, 0, 0, self.font.color.alpha)
  35.         old_draw_text(args[0], args[1], args[2])
  36.         args[0].x -= 1
  37.         args[0].y -= 1
  38.         self.font.color = color
  39.       end
  40.       old_draw_text(args[0], args[1], args[2])
  41.     else
  42.       self.font.shadow = false
  43.       args[5] = 0 if args.size == 5
  44.       if shadow == true
  45.         args[0] += 1
  46.         args[1] += 1
  47.         color = Color.new(self.font.color.red, self.font.color.green, self.font.color.blue, self.font.color.alpha)
  48.         self.font.color.set(0, 0, 0, self.font.color.alpha)
  49.         old_draw_text(args[0], args[1], args[2], args[3], args[4], args[5])
  50.         args[0] -= 1
  51.         args[1] -= 1
  52.         self.font.color = color
  53.       end
  54.       old_draw_text(args[0], args[1], args[2], args[3], args[4], args[5])
  55.       self.font.shadow = true
  56.     end
  57.   end
  58. end
复制代码
Bitmap#blur
  1. #===============================================================#
  2. #   ●RGSS2_bitmap_xp ver 1.02
  3. #===============================================================#
  4. class Bitmap
  5.    
  6. def blur(times=1,during =1,blur=1)
  7.    #blur(重做模糊次数,经历帧数,分散半径)
  8.    for i in 1..times
  9.      blur_r(blur)
  10.      for j in 1..during
  11.        Graphics.update if i > 1 and during >1
  12.      end     
  13.    end   
  14. end
  15. #----------------------------------------------------------------
  16. def blur_r(radius = 2)
  17.     #blur_r(分散半径)
  18.     radius = 1 if radius <= 1 or radius == nil #值的修正
  19.     src_bitmap = self
  20.     rect = self.rect
  21.    
  22.     ta_l = 1+radius*2
  23.     ta = Table.new(ta_l,ta_l)  #过滤器

  24.     for i in 0..ta_l-1
  25.       for j in 0..ta_l-1
  26.         ta[i,j] = 1
  27.       end
  28.     end

  29.       ta[((ta.xsize+1)/2)-1,((ta.xsize+1)/2)-1] = 2**(1+radius)
  30.       main = ta[((ta.xsize+1)/2)-1,((ta.xsize+1)/2)-1]#找到中心点

  31.       nn = 2;j = ((ta.xsize+1)/2)-1;line =[]#主干道
  32.       for i in 0..((ta.xsize+1)/2)-2
  33.         ta[i,j] = nn
  34.         ta[j,i] = nn
  35.         ta[ta.xsize-1-i,j] = nn
  36.         ta[j,ta.xsize-1-i] = nn
  37.         line.push ta[i,((ta.xsize+1)/2)-1]
  38.         nn = nn * 2
  39.       end
  40.    
  41.     for j in 0..line.size-1
  42.        for i in 0..((ta.xsize+1)/2)-2
  43.         line[j] = line[j]/2
  44.         if line[j] == 1
  45.           break
  46.         else
  47.           ta[((ta.xsize+1)/2)-2-i,j] = line[j]
  48.           ta[((ta.xsize+1)/2)+i,j] = line[j]
  49.           ta[((ta.xsize+1)/2)-2-i,ta.xsize-1-j] = line[j]
  50.           ta[((ta.xsize+1)/2)+i,ta.xsize-1-j] = line[j]
  51.         end
  52.       end
  53.     end
  54.     key_a = [];key_p = main
  55.     for i in 1..main
  56.       if key_p == 1
  57.         key_a.push main
  58.         break
  59.       else
  60.       key_p = key_p/2
  61.       key_a.push key_p
  62.       end
  63.     end
  64.     key_k = 0
  65.     for i in 0..key_a.size-1
  66.       key_k = key_k + key_a[i]
  67.     end
  68.     key = 255/key_k
  69.     key = 1 if key <= 0  #值的修正

  70.    for i in 0..ta.xsize-1
  71.         for j in 0..ta.ysize-1
  72.             key_main = key*ta[i,j]
  73.             key_main = 255 if key_main > 255 ; key_main = 1 if key_main < 0  #值的修正
  74.             self.blt(i-(((ta.xsize+1)/2)-1),j-(((ta.xsize+1)/2)-1),src_bitmap,rect,key_main)
  75.         end
  76.     end
  77.   end
  78. end  
复制代码
一箭烂YiJL 发表于 2011-6-11 15:23:31
zh99998 发表于 2011-6-11 14:42
首先感谢您认真看我的帖子并进行修改

1. DLL那个方式我也表示很不爽...所以也没塞进RGE文件夹里而是丢在 ...

表示用字符串的方法之后读取有点问题= =,用 RtlMoveMemory 来取内存的,
先是有关这个函数的用法:http://rpg.blue/blog-115768-8486.html(前部分)

然后我偶尔发现了它的指针位置是 object_id * 2 偏移 12 的,比如:
  1. RtlMoveMemory_pi = Win32API.new("kernel32", "RtlMoveMemory", "pii", "i")
  2. zh = "zh99998"
  3. address = "xxxx"
  4. RtlMoveMemory_pi.call(address, zh.object_id * 2 + 12, address.size)
  5. address = address.unpack("L")[0]   # 这个就是内存位置的开头
  6. buff = " " * zh.size               # 将成为 "zh99998" 的复制本
  7. RtlMoveMemory_pi.call(buff, address, zh.size)
  8. p buff
复制代码
但是一旦用了在 Bitmap.mem_new 出错,我也不知道为啥~...这个加载办法我还是第一次尝试的。

点评

还有 RTP 哪里有 ABC 键?  发表于 2011-6-11 15:24
zh99998 发表于 2011-6-11 14:42:19
一箭烂YiJL 发表于 2011-6-11 13:56
最初我是常驻VX,于是我放出几个我写的出来:
1. zh,我电脑那个 dll 无效...= =RGE 的 Bitmap 结构特殊, ...

首先感谢您认真看我的帖子并进行修改

1. DLL那个方式我也表示很不爽...所以也没塞进RGE文件夹里而是丢在外面,准备换的,你这个帮了我大忙了
不过RGE还有个Bitmap.mem_new可以直接从内存地址读bitmap,然后字符串里也有个获取内存地址的方法,如果可能的话试试不使用临时文件?

2.字体阴影我挂了一个XP的,效果可以,只是跟VX不完全相同就是了

3.thanks

4.修正按键的话,ABC应该读注册表的,所有RMVX游戏共用那一套,读注册表的函数在RTP那个里面有,可以用一下
一箭烂YiJL 发表于 2011-6-11 13:56:32
最初我是常驻VX,于是我放出几个我写的出来:
1. zh,我电脑那个 dll 无效...= =RGE 的 Bitmap 结构特殊,不能用<高速Marshal Bitmap>,所以我改:
  1. #==============================================================================
  2. # ■ Graphics
  3. #------------------------------------------------------------------------------
  4. #  进行有关全体图像处理的模块。
  5. #   RGE 的 Graphics.snap_to_bitmap。(和 XP 版有分别)
  6. #==============================================================================
  7. module Graphics
  8.   #--------------------------------------------------------------------------
  9.   # ● API 函数
  10.   #--------------------------------------------------------------------------
  11.   CreateDC = Win32API.new("gdi32", "CreateDC", "pppl", "l")
  12.   CreateCompatibleBitmap = Win32API.new("gdi32", "CreateCompatibleBitmap", "lll", "l")
  13.   CreateCompatibleDC = Win32API.new("gdi32", "CreateCompatibleDC", "l", "l")
  14.   SelectObject = Win32API.new("gdi32", "SelectObject", "ll", "l")
  15.   BitBlt = Win32API.new("gdi32", "BitBlt", "lllllllll", "l")
  16.   GetBitmapBits = Win32API.new("gdi32", "GetBitmapBits", "llp", "l")
  17.   ScreenToClient = Win32API.new("user32", "ScreenToClient", "ip", "i")
  18.   DeleteDC = Win32API.new("gdi32", "DeleteDC", "l", "l")
  19.   DeleteObject = Win32API.new("gdi32", "DeleteObject", "l", "l")
  20.   SRCCOPY = 0xCC0020
  21.   RtlMoveMemory = Win32API.new("kernel32", "RtlMoveMemory", "ipi", "i")
  22.   RtlMoveMemory_pi = Win32API.new("kernel32", "RtlMoveMemory", "pii", "i")
  23.   HWnd = Win32API.new("user32", "GetActiveWindow", nil, 'l').call
  24.   DwCount = (Frame.width * Frame.height * 4)# * 2
  25.   @@lpBits = "\000" * DwCount
  26.   #--------------------------------------------------------------------------
  27.   # ● snap_to_bitmap (RGE版)
  28.   #--------------------------------------------------------------------------
  29.   def self.snap_to_bitmap
  30.     hScrDC = CreateDC.call("DISPLAY", "", "", 0)
  31.     hMemDC = CreateCompatibleDC.call(hScrDC)
  32.     hBitmap = CreateCompatibleBitmap.call(hScrDC, width, height)
  33.     hOldBitmap = SelectObject.call(hMemDC, hBitmap)
  34.     win_pos = "\0\0\0\0\0\0\0\0"
  35.     ScreenToClient.call(HWnd, win_pos)
  36.     win_pos = win_pos.unpack("LL")
  37.     BitBlt.call(hMemDC, win_pos[0], win_pos[1], width*2, height*2, hScrDC, 0, 0, SRCCOPY)
  38.     hBitmap2 = SelectObject.call(hMemDC, hOldBitmap)
  39.     GetBitmapBits.call(hBitmap2, DwCount, @@lpBits)
  40.     # 释放所有东西
  41.     DeleteDC.call(hScrDC)
  42.     DeleteDC.call(hMemDC)
  43.     DeleteObject.call(hBitmap)
  44.     DeleteObject.call(hOldBitmap)
  45.     DeleteObject.call(hBitmap2)
  46.     rgbs = @@lpBits
  47.     len = width * 4
  48.     for y in 0...height
  49.       break if 2 * y >= height - 1
  50.       nth1 = y * len
  51.       nth2 = (height - 1 - y) * len
  52.       tStr = rgbs[nth1,len]
  53.       rgbs[nth1, len] = rgbs[nth2, len]
  54.       rgbs[nth2, len] = tStr
  55.     end
  56.     # 写 bmp 档案
  57.     length = Frame.width * Frame.height
  58.     file = File.open("cache.bmp", "wb")
  59.     size = 54 + Frame.width * Frame.height * 4
  60.     chunk1 = "BM" + [size].pack("L") + "\0\0\0\0\x36\0\0\0"
  61.     chunk2 = "\x28\0\0\0" + [Frame.width, Frame.height].pack("L2") +
  62.     "\1\0\x20\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  63.     file.write(chunk1 + chunk2 + rgbs)
  64.     file.close
  65.     # 读取以及删掉档案
  66.     bitmap = Bitmap.new("cache.bmp")
  67.     File.delete("cache.bmp")
  68.     return bitmap
  69.   end
  70. end
复制代码
Font 的阴影还没下手,绘画阴影方面主要交给Bitmap了。Font:
  1. #==============================================================================
  2. # ■ Font
  3. #------------------------------------------------------------------------------
  4. #  兼容 RGE 而修改的 Font
  5. #==============================================================================
  6. class Font
  7.   #--------------------------------------------------------------------------
  8.   # ● 类变量
  9.   #--------------------------------------------------------------------------
  10.   @@default_shadow = true
  11.   #--------------------------------------------------------------------------
  12.   # ● 对象初始化
  13.   #--------------------------------------------------------------------------
  14.   alias font_init initialize
  15.   def initialize
  16.     font_init
  17.     @shadow = @@default_shadow
  18.   end
  19.   #--------------------------------------------------------------------------
  20.   # ● default_shadow
  21.   #--------------------------------------------------------------------------
  22.   def self.default_shadow
  23.     return @@default_shadow
  24.   end
  25.   #--------------------------------------------------------------------------
  26.   # ● default_shadow=
  27.   #--------------------------------------------------------------------------
  28.   def self.default_shadow=(bool)
  29.     return if bool != true or bool != false
  30.     @@default_shadow = bool
  31.   end
  32.   #--------------------------------------------------------------------------
  33.   # ● shadow
  34.   #--------------------------------------------------------------------------
  35.   def shadow
  36.     return @shadow
  37.   end
  38.   #--------------------------------------------------------------------------
  39.   # ● shadow=
  40.   #--------------------------------------------------------------------------
  41.   def shadow=(bool)
  42.     return if bool != true or bool != false
  43.     @shadow = bool
  44.   end
  45. end
复制代码
3.你那个clear_rect没有照顾clear_rect(x, y, width, height) 这种参数形式,还有字体阴影交给Bitmap:
  1. #==============================================================================
  2. # ■ Bitmap
  3. #------------------------------------------------------------------------------
  4. #   兼容 RGE 而修改的 Bitmap
  5. #==============================================================================
  6. class Bitmap
  7.   #--------------------------------------------------------------------------
  8.   # ● 填满渐变色彩 (RGSS2)
  9.   #--------------------------------------------------------------------------
  10.   def gradient_fill_rect(*arg)
  11.     arg = *arg
  12.     case arg[0]
  13.     when Rect
  14.       x = arg[0].x
  15.       y = arg[0].y
  16.       width = arg[0].width
  17.       height = arg[0].height
  18.       color1 = arg[1]
  19.       color2 = arg[2]
  20.       vertical = arg[3]
  21.     else
  22.       x = arg[0]
  23.       y = arg[1]
  24.       width = arg[2]
  25.       height = arg[3]
  26.       color1 = arg[4]
  27.       color2 = arg[5]
  28.       vertical = arg[6]
  29.     end
  30.     vertical = false if vertical.nil?
  31.     vertical == false ? step = width : step = height
  32.     color = color1;step += 0.0
  33.     key_re = (color2.red - color1.red) / step
  34.     key_gr = (color2.green - color1.green) / step
  35.     key_bl = (color2.blue - color1.blue) / step
  36.     red = color.red;green = color.green;blue = color.blue
  37.     x -= 1 unless vertical
  38.     y -= 1 if vertical
  39.     if vertical
  40.       for i in 0...height
  41.         y += 1
  42.         red += key_re;green += key_gr;blue += key_bl
  43.         color.red = red.to_i;color.green = green.to_i;color.blue = blue.to_i
  44.         self.fill_rect(x, y, width, 1, color)
  45.       end
  46.     else
  47.       for i in 0...width
  48.         x += 1
  49.         red += key_re;green += key_gr;blue += key_bl
  50.         color.red = red.to_i;color.green = green.to_i;color.blue = blue.to_i
  51.         self.fill_rect(x, y, 1, height, color)
  52.       end
  53.     end
  54.   end
  55.   #--------------------------------------------------------------------------
  56.   # ● clear_rect (RGSS2)
  57.   #--------------------------------------------------------------------------
  58.   def clear_rect(*arg)
  59.     arg = *arg
  60.     case arg
  61.     when Rect
  62.       x = arg.x
  63.       y = arg.y
  64.       width = arg.width
  65.       height = arg.height
  66.     else
  67.       x = arg[0]
  68.       y = arg[1]
  69.       width = arg[2]
  70.       height = arg[3]
  71.     end
  72.     self.fill_rect(x, y, width, height, Color.new(0, 0, 0, 0))
  73.   end
  74.   #--------------------------------------------------------------------------
  75.   # ● draw_text (RGSS2)
  76.   #--------------------------------------------------------------------------
  77.   alias shadow_draw_text draw_text
  78.   def draw_text(*arg)
  79.     arg = *arg
  80.     case arg[0]
  81.     when Rect
  82.       x = arg[0].x
  83.       y = arg[0].y
  84.       width = arg[0].width
  85.       height = arg[0].height
  86.       str = arg[1]
  87.       align = arg[2]
  88.     else
  89.       x = arg[0]
  90.       y = arg[1]
  91.       width = arg[2]
  92.       height = arg[3]
  93.       str = arg[4]
  94.       align = arg[5]
  95.     end
  96.     align = 0 if align.nil?
  97.     ocolor = self.font.color.clone
  98.     self.font.color = Color.new(0, 0, 0, 128)
  99.     if self.font.shadow
  100.       shadow_draw_text(x + 0.5, y + 0.5, width, height, str, align)
  101.     end
  102.     self.font.color = ocolor
  103.     shadow_draw_text(x, y, width, height, str, align)
  104.   end
  105. end
复制代码
4.发现 Input 的按键和 VX 的有错,于是重写了:
  1. #==============================================================================
  2. # ■ Input
  3. #------------------------------------------------------------------------------
  4. #   RGE 本身的 Input 按键表和 VX 的按键有重复的严重问题。
  5. #   以后设定键盘就来这里了
  6. #==============================================================================
  7. module Input
  8.   #--------------------------------------------------------------------------
  9.   # ● KEY 可以自己设定 (根据键盘虚拟词表)
  10.   #--------------------------------------------------------------------------
  11.   LEFT  = [0x25, 0x64]
  12.   RIGHT = [0x27, 0x66]
  13.   UP    = [0x26, 0x68]
  14.   DOWN  = [0x28, 0x62]
  15.   
  16.   C = [0x5A, 0x0D, 0x20]
  17.   B = [0x58, 0x60, 0x1B]
  18.   A = [0x10]
  19.   X = [0x41]
  20.   Y = [0x53]
  21.   Z = [0x44]
  22.   L = [0x51]
  23.   R = [0x57]
  24.   
  25.   Ctrl = [0x11]
  26.   Alt  = [0x12]
  27.   
  28.   F5 = [0x74]
  29.   F6 = [0x75]
  30.   F7 = [0x76]
  31.   F8 = [0x77]
  32.   F9 = [0x78]
  33.   #--------------------------------------------------------------------------
  34.   # ● 实例变量
  35.   #--------------------------------------------------------------------------
  36.   @Key_Repeat = {}
  37.   @Key_Trigger = {}
  38.   module_function
  39.   #--------------------------------------------------------------------------
  40.   # ● 按住?
  41.   #--------------------------------------------------------------------------
  42.   def press?(keys)
  43.     return_list = []
  44.     keys = [keys] if keys.is_a?(Numeric)
  45.     for key in keys
  46.       return_list.push KBoard::GetKeyState.call(key) & 0x8000 > 0
  47.     end
  48.     return true if return_list.include?(true)
  49.     return false
  50.   end
  51.   #--------------------------------------------------------------------------
  52.   # ● 持续被按住?
  53.   #--------------------------------------------------------------------------
  54.   def repeat?(keys)
  55.     return_list = []
  56.     keys = [keys] if keys.is_a?(Numeric)
  57.     for key in keys
  58.       if @Key_Repeat[key] != nil
  59.         return_list.push @Key_Repeat[key]
  60.         next
  61.       end
  62.       @Key_Repeat[key] = KBoard.repeat?(key)
  63.       return_list.push @Key_Repeat[key]
  64.     end
  65.     return true if return_list.include?(true)
  66.     return false
  67.   end
  68.   #--------------------------------------------------------------------------
  69.   # ● 按下?
  70.   #--------------------------------------------------------------------------
  71.   def trigger?(keys)
  72.     return_list = []
  73.     keys = [keys] if keys.is_a?(Numeric)
  74.     for key in keys
  75.       if @Key_Trigger[key] != nil
  76.         return_list.push @Key_Trigger[key]
  77.         next
  78.       end
  79.       @Key_Trigger[key] = KBoard.trigger?(key)
  80.       return_list.push @Key_Trigger[key]
  81.     end
  82.     return true if return_list.include?(true)
  83.     return false
  84.   end
  85.   #==============================================================================
  86.   # ■ KBoard
  87.   #==============================================================================
  88.   module KBoard
  89.     #--------------------------------------------------------------------------
  90.     # ● 实例变量
  91.     #--------------------------------------------------------------------------
  92.     @Key_Hash = {}
  93.     @Key_Repeat = {}
  94.    
  95.     GetKeyState = Win32API.new("user32","GetAsyncKeyState","i","i")
  96.     #--------------------------------------------------------------------------
  97.     # ● 持续被按住?
  98.     #--------------------------------------------------------------------------
  99.     def self.repeat?(key)
  100.       result = GetKeyState.call(key) & 0x8000
  101.       if result > 0
  102.         if @Key_Repeat[key].nil?
  103.           @Key_Repeat[key] = 0
  104.           return true
  105.         end
  106.         @Key_Repeat[key] += 1
  107.       else
  108.         @Key_Repeat[key] = nil
  109.         @Key_Hash[key] = 0
  110.       end
  111.       if !@Key_Repeat[key].nil? and @Key_Repeat[key] > 4 # 4乃准确数字
  112.         @Key_Repeat[key] = 0
  113.         return true
  114.       else
  115.         return false
  116.       end
  117.     end
  118.     #--------------------------------------------------------------------------
  119.     # ● 按下?
  120.     #--------------------------------------------------------------------------
  121.     def self.trigger?(rkey)
  122.       result = GetKeyState.call(rkey) & 0x8000
  123.       return false if @Key_Hash[rkey] and result > 0
  124.       @Key_Hash[rkey] = (result > 0 ? true : false)
  125.       return @Key_Hash[rkey]
  126.     end
  127.   end
  128. end
  129. #==============================================================================
  130. # ■ Input
  131. #------------------------------------------------------------------------------
  132. #   目的是为了加快 update 的速度
  133. #==============================================================================
  134. class << Input
  135.   #--------------------------------------------------------------------------
  136.   # ● 更新?
  137.   #--------------------------------------------------------------------------
  138.   alias old_update update
  139.   def update
  140.     old_update
  141.     @Key_Repeat.clear
  142.     @Key_Trigger.clear
  143.   end
  144. end
复制代码

评分

参与人数 2星屑 +264 收起 理由
david50407 + 132 我最多也寫了Shadow而已
zh99998 + 132 感谢

查看全部评分

路过的小白 发表于 2011-6-7 15:36:55
路过,支持大萌娘- -
拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

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

GMT+8, 2024-11-25 07:38

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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