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

Project1

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

[RMVX发布] 简易鼠标输入

[复制链接]

Lv1.梦旅人

梦石
0
星屑
50
在线时间
158 小时
注册时间
2011-3-13
帖子
71
跳转到指定楼层
1
发表于 2011-6-19 15:45:50 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
本帖最后由 小⑨ 于 2011-6-19 16:26 编辑
  1. #===============================================================================
  2. # ■ [VX]简易鼠标输入
  3. #    [VX]EasyMouseInput
  4. #-------------------------------------------------------------------------------
  5. #    click?          :返回是否左键单击
  6. #    rightClick?     :返回是否右键单击
  7. #    down?           :返回是否左键单击
  8. #    rightDown?      :返回是否左键单击
  9. #    getX            :返回鼠标的画面X坐标
  10. #    getY            :返回鼠标的画面Y坐标
  11. #    getDragRect     :返回鼠标拖动形成的方框,格式为Rect
  12. #    26~39行为设定,请根据游戏实际情况更改
  13. #-------------------------------------------------------------------------------
  14. #    更新作者: ⑨
  15. #    许可协议: FSL
  16. #===============================================================================
  17. $fscript = {} if $fscript == nil
  18. $fscript["EasyMouseInput"] = "1.0.0000"

  19. #-------------------------------------------------------------------------------
  20. # ▼ 通用配置模块
  21. #-------------------------------------------------------------------------------

  22. module FSL
  23.   module EasyMouseConfig
  24.     #窗口大小,不用修改
  25.     WINDOW_X = Graphics.width
  26.     WINDOW_Y = Graphics.height
  27.    
  28.     #鼠标左键和右键点击的SE
  29.     CLICK_AUDIO_PATH = "Audio/SE/Cursor"
  30.     R_CLICK_AUDIO_PATH = nil
  31.     #鼠标是否限制在窗口中不能移动
  32.     MOUSE_IN_RECT = true
  33.    
  34.     #用图片代替鼠标指针
  35.     SHOW_MOUSE_IMAGE = true
  36.     #鼠标图形路径
  37.     MOUSE_IMAGE_PATH = "Graphics/MouseImage/"
  38.   end
  39. end

  40. # API =========================================================================
  41. $show_cursor = Win32API.new("user32", "ShowCursor", 'i', 'l')
  42. $get_cursor_pos = Win32API.new("user32", "GetCursorPos", 'p', 'i')
  43. $screen_to_client = Win32API.new("user32", "ScreenToClient", 'ip', 'i')
  44. $get_active_window = Win32API.new("user32", "GetActiveWindow", nil, 'l')
  45. $screen_to_client = Win32API.new("user32", "ScreenToClient", 'lp', 'l')
  46. $clip_cursor = Win32API.new("user32", "ClipCursor", 'p', 'l')
  47. $get_async_key_state = Win32API.new("user32", "GetAsyncKeyState", 'l', 'i')
  48. $hwnd = $get_active_window.call()
  49. #==============================================================================
  50. # ■ Mouse
  51. #------------------------------------------------------------------------------
  52. #  处理响应鼠标的模块
  53. #==============================================================================

  54. module Mouse
  55.   include (FSL::EasyMouseConfig)
  56.   attr_accessor:mouseX
  57.   attr_accessor:mouseY
  58.   attr_accessor:click
  59.   attr_accessor:rightClick
  60.   attr_accessor:downFlag
  61.   attr_accessor:rightDownFlag
  62.   attr_accessor:dragRect
  63.   attr_accessor:dragRect_x_1
  64.   attr_accessor:dragRect_x_2
  65.   attr_accessor:dragRect_y_1
  66.   attr_accessor:dragRect_y_2
  67.   $show_cursor.call(0) if SHOW_MOUSE_IMAGE  
  68.   #--------------------------------------------------------------------------
  69.   # ● 刷新
  70.   #--------------------------------------------------------------------------
  71.   def self.update
  72.     getMouseLocation
  73.     setMouseRect if FSL::EasyMouseConfig::MOUSE_IN_RECT
  74.     @click = mouseClickJudge
  75.     @rightClick = mouseRightClickJudge
  76.   end
  77.   #--------------------------------------------------------------------------
  78.   # ● 判断鼠标左键点击
  79.   #--------------------------------------------------------------------------
  80.   def self.click?
  81.     return @click
  82.   end
  83.   #--------------------------------------------------------------------------
  84.   # ● 判断鼠标右键点击
  85.   #--------------------------------------------------------------------------
  86.   def self.rightClick?
  87.     return @rightClick
  88.   end
  89.   #--------------------------------------------------------------------------
  90.   # ● 判断鼠标左键正按下
  91.   #--------------------------------------------------------------------------
  92.   def self.down?
  93.     if @downFlag == 1
  94.       return true
  95.     else
  96.       return false
  97.     end
  98.   end
  99.   #--------------------------------------------------------------------------
  100.   # ● 判断鼠标右键正按下
  101.   #--------------------------------------------------------------------------
  102.   def self.rightDown?
  103.     if @rightDownFlag == 1
  104.       return true
  105.     else
  106.       return false
  107.     end
  108.   end
  109.   #--------------------------------------------------------------------------
  110.   # ● 获取鼠标X
  111.   #--------------------------------------------------------------------------
  112.   def self.getX
  113.     return @mouseX
  114.   end
  115.   #--------------------------------------------------------------------------
  116.   # ● 获取鼠标Y
  117.   #--------------------------------------------------------------------------
  118.   def self.getY
  119.     return @mouseY
  120.   end
  121.   #--------------------------------------------------------------------------
  122.   # ● 获取鼠标拖动矩形
  123.   #--------------------------------------------------------------------------
  124.   def self.getDragRect
  125.     return dragRect
  126.   end
  127.   #--------------------------------------------------------------------------
  128.   # ● 单击鼠标
  129.   #--------------------------------------------------------------------------
  130.   def self.mouseClickJudge
  131.     result = $get_async_key_state.call(0x01)
  132.    
  133.     if @downFlag == 0 && result != 0
  134.       @dragRect_x_1 = @mouseX
  135.       @dragRect_y_1 = @mouseY
  136.       @dragRect = Rect.new(0, 0, 0, 0)
  137.     end
  138.     if @downFlag == 1 && result == 0
  139.       @dragRect_x_2 = @mouseX
  140.       @dragRect_y_2 = @mouseY
  141.       setDragRect
  142.     end
  143.    
  144.     if @downFlag == 1 && result != 0
  145.       return false
  146.     end
  147.     if result != 0
  148.       @downFlag = 1
  149.       Audio.se_play(CLICK_AUDIO_PATH) if CLICK_AUDIO_PATH != nil
  150.       return true
  151.     else
  152.       @downFlag = 0
  153.       return false
  154.     end
  155.   end
  156.   #--------------------------------------------------------------------------
  157.   # ● 右击鼠标
  158.   #--------------------------------------------------------------------------
  159.   def self.mouseRightClickJudge
  160.     result = $get_async_key_state.call(0x02)
  161.     if @rightDownFlag == 1 && result != 0
  162.       return false
  163.     end
  164.     if result != 0
  165.       @rightDownFlag = 1
  166.       Audio.se_play(R_CLICK_AUDIO_PATH) if R_CLICK_AUDIO_PATH != nil
  167.       return true
  168.     else
  169.       @rightDownFlag = 0
  170.       return false
  171.     end
  172.   end
  173.   #--------------------------------------------------------------------------
  174.   # ● 把鼠标限制在窗口中
  175.   #--------------------------------------------------------------------------
  176.   def self.setMouseRect
  177.     w = [0, 0].pack("ll")
  178.     $screen_to_client.call($hwnd, w)
  179.     w = w.unpack("ll")
  180.     x = w[0]
  181.     y = w[1]
  182.     $clip_cursor.call([-x, -y, -x+WINDOW_X, -y+WINDOW_Y].pack('llll'))
  183.   end
  184.   #--------------------------------------------------------------------------
  185.   # ● 获取鼠标在屏幕中的位置
  186.   #--------------------------------------------------------------------------
  187.   def self.getMouseLocation
  188.     c = [0, 0]
  189.     c = c.pack("ll")
  190.     $get_cursor_pos.call(c)
  191.     c = c.unpack("ll")
  192.     w = [0, 0].pack("ll")
  193.     $screen_to_client.call($hwnd, w)
  194.     w = w.unpack("ll")
  195.     @mouseX = c[0] + w[0]
  196.     @mouseY = c[1] + w[1]
  197.   end
  198.   #--------------------------------------------------------------------------
  199.   # ● 获取鼠标拖动的矩形
  200.   #--------------------------------------------------------------------------
  201.   def self.setDragRect
  202.     @dragRect = Rect.new(0, 0, 0, 0)
  203.     if @dragRect_x_1 >= @dragRect_x_2
  204.       @dragRect.x = @dragRect_x_2
  205.       @dragRect.width = @dragRect_x_1 - @dragRect_x_2
  206.     else
  207.       @dragRect.x = @dragRect_x_1
  208.       @dragRect.width = @dragRect_x_2 - @dragRect_x_1
  209.     end
  210.     if @dragRect_y_1 >= @dragRect_y_2
  211.       @dragRect.y = @dragRect_y_2
  212.       @dragRect.height = @dragRect_y_1 - @dragRect_y_2
  213.     else
  214.       @dragRect.y = @dragRect_y_1
  215.       @dragRect.height = @dragRect_y_2 - @dragRect_y_1
  216.     end
  217.   end
  218. end

  219. #==============================================================================
  220. # ■ Scene_Base
  221. #------------------------------------------------------------------------------
  222. #  游戏中全部画面的超级类。
  223. #==============================================================================
  224. class Scene_Base
  225.   include (FSL::EasyMouseConfig)
  226.   def start
  227.     if SHOW_MOUSE_IMAGE
  228.       @mouse_sprite = Sprite.new
  229.       @mouse_bitmap_1 = Bitmap.new(MOUSE_IMAGE_PATH + "Mouse_1")
  230.       @mouse_bitmap_2 = Bitmap.new(MOUSE_IMAGE_PATH + "Mouse_2")
  231.       @mouse_sprite.bitmap = @mouse_bitmap_1
  232.       @mouseBitmapIndex = 1
  233.       @mouse_sprite.z = 10000
  234.     end
  235.   end
  236.   
  237.   def terminate
  238.     if SHOW_MOUSE_IMAGE
  239.       @mouse_sprite.dispose
  240.       @mouse_sprite.bitmap.dispose
  241.     end
  242.   end
  243.   #--------------------------------------------------------------------------
  244.   # ● 刷新
  245.   #--------------------------------------------------------------------------
  246.   def update
  247.     Mouse.update
  248.     if SHOW_MOUSE_IMAGE
  249.       @mouse_sprite.x = Mouse.getX
  250.       @mouse_sprite.y = Mouse.getY
  251.       if Mouse.down? && @mouseBitmapIndex == 1
  252.         @mouse_sprite.bitmap = @mouse_bitmap_2
  253.         @mouseBitmapIndex = 2
  254.       end
  255.       if Mouse.down? == false && @mouseBitmapIndex == 2
  256.         @mouse_sprite.bitmap = @mouse_bitmap_1
  257.         @mouseBitmapIndex = 1
  258.       end
  259.     end
  260.   end
  261. end

复制代码
总之,大概是比较适合小游戏的东西吧,一点都没有加配合RPG的东西= =……
就当Input用吧= =||

下面是范例
MouseTestReal.rar (281.9 KB, 下载次数: 621)

点评

其实我无法理解'传统观念'的具体含义,下次见面再争辩吧。(点评漏字了  发表于 2011-6-21 13:54
> <  发表于 2011-6-21 09:47

评分

参与人数 2星屑 +60 收起 理由
fux2 + 40 违规内容
忧雪の伤 + 20 其实我无法理解'传统观念'的具体含义,下.

查看全部评分


游戏发布帖戳图进入> <

Lv1.梦旅人

梦石
0
星屑
50
在线时间
426 小时
注册时间
2011-2-25
帖子
126
2
发表于 2011-8-21 20:13:32 | 只看该作者
鼠标罢工,只能移动 选择无效

点评

这个本来就是这样的吧 =-= 这个只是一个输入方法 窗口需要你自己改的 - -  发表于 2011-8-22 13:55
回复 支持 反对

使用道具 举报

头像被屏蔽

Lv1.梦旅人 (禁止发言)

梦石
0
星屑
50
在线时间
0 小时
注册时间
2006-8-15
帖子
75
3
发表于 2011-8-22 13:46:35 | 只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-4-28 23:50

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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