| 
 
| 赞 | 0 |  
| VIP | 15 |  
| 好人卡 | 4 |  
| 积分 | 1 |  
| 经验 | 4165 |  
| 最后登录 | 2016-4-5 |  
| 在线时间 | 158 小时 |  
 Lv1.梦旅人 
	梦石0 星屑50 在线时间158 小时注册时间2011-3-13帖子71 | 
| 
本帖最后由 小⑨ 于 2011-6-19 16:26 编辑
x
加入我们,或者,欢迎回来。您需要 登录 才可以下载或查看,没有帐号?注册会员  
 总之,大概是比较适合小游戏的东西吧,一点都没有加配合RPG的东西= =……复制代码#===============================================================================
# ■ [VX]简易鼠标输入
#    [VX]EasyMouseInput
#-------------------------------------------------------------------------------
#    click?          :返回是否左键单击
#    rightClick?     :返回是否右键单击
#    down?           :返回是否左键单击
#    rightDown?      :返回是否左键单击
#    getX            :返回鼠标的画面X坐标
#    getY            :返回鼠标的画面Y坐标
#    getDragRect     :返回鼠标拖动形成的方框,格式为Rect
#    26~39行为设定,请根据游戏实际情况更改
#-------------------------------------------------------------------------------
#    更新作者: ⑨
#    许可协议: FSL
#===============================================================================
$fscript = {} if $fscript == nil
$fscript["EasyMouseInput"] = "1.0.0000"
#-------------------------------------------------------------------------------
# ▼ 通用配置模块
#-------------------------------------------------------------------------------
module FSL
  module EasyMouseConfig
    #窗口大小,不用修改
    WINDOW_X = Graphics.width
    WINDOW_Y = Graphics.height
    
    #鼠标左键和右键点击的SE
    CLICK_AUDIO_PATH = "Audio/SE/Cursor"
    R_CLICK_AUDIO_PATH = nil
    #鼠标是否限制在窗口中不能移动
    MOUSE_IN_RECT = true
    
    #用图片代替鼠标指针
    SHOW_MOUSE_IMAGE = true
    #鼠标图形路径
    MOUSE_IMAGE_PATH = "Graphics/MouseImage/"
  end
end
# API =========================================================================
$show_cursor = Win32API.new("user32", "ShowCursor", 'i', 'l')
$get_cursor_pos = Win32API.new("user32", "GetCursorPos", 'p', 'i')
$screen_to_client = Win32API.new("user32", "ScreenToClient", 'ip', 'i')
$get_active_window = Win32API.new("user32", "GetActiveWindow", nil, 'l')
$screen_to_client = Win32API.new("user32", "ScreenToClient", 'lp', 'l')
$clip_cursor = Win32API.new("user32", "ClipCursor", 'p', 'l')
$get_async_key_state = Win32API.new("user32", "GetAsyncKeyState", 'l', 'i')
$hwnd = $get_active_window.call()
#==============================================================================
# ■ Mouse
#------------------------------------------------------------------------------
#  处理响应鼠标的模块
#==============================================================================
module Mouse
  include (FSL::EasyMouseConfig)
  attr_accessor:mouseX
  attr_accessor:mouseY
  attr_accessor:click
  attr_accessor:rightClick
  attr_accessor:downFlag
  attr_accessor:rightDownFlag
  attr_accessor:dragRect
  attr_accessor:dragRect_x_1
  attr_accessor:dragRect_x_2
  attr_accessor:dragRect_y_1
  attr_accessor:dragRect_y_2
  $show_cursor.call(0) if SHOW_MOUSE_IMAGE  
  #--------------------------------------------------------------------------
  # ● 刷新
  #--------------------------------------------------------------------------
  def self.update
    getMouseLocation
    setMouseRect if FSL::EasyMouseConfig::MOUSE_IN_RECT
    @click = mouseClickJudge
    @rightClick = mouseRightClickJudge
  end
  #--------------------------------------------------------------------------
  # ● 判断鼠标左键点击
  #--------------------------------------------------------------------------
  def self.click?
    return @click
  end
  #--------------------------------------------------------------------------
  # ● 判断鼠标右键点击
  #--------------------------------------------------------------------------
  def self.rightClick?
    return @rightClick
  end
  #--------------------------------------------------------------------------
  # ● 判断鼠标左键正按下
  #--------------------------------------------------------------------------
  def self.down?
    if @downFlag == 1
      return true
    else
      return false
    end
  end
  #--------------------------------------------------------------------------
  # ● 判断鼠标右键正按下
  #--------------------------------------------------------------------------
  def self.rightDown?
    if @rightDownFlag == 1
      return true
    else
      return false
    end
  end
  #--------------------------------------------------------------------------
  # ● 获取鼠标X
  #--------------------------------------------------------------------------
  def self.getX
    return @mouseX
  end
  #--------------------------------------------------------------------------
  # ● 获取鼠标Y
  #--------------------------------------------------------------------------
  def self.getY
    return @mouseY
  end
  #--------------------------------------------------------------------------
  # ● 获取鼠标拖动矩形
  #--------------------------------------------------------------------------
  def self.getDragRect
    return dragRect
  end
  #--------------------------------------------------------------------------
  # ● 单击鼠标
  #--------------------------------------------------------------------------
  def self.mouseClickJudge
    result = $get_async_key_state.call(0x01)
    
    if @downFlag == 0 && result != 0
      @dragRect_x_1 = @mouseX
      @dragRect_y_1 = @mouseY
      @dragRect = Rect.new(0, 0, 0, 0)
    end
    if @downFlag == 1 && result == 0
      @dragRect_x_2 = @mouseX
      @dragRect_y_2 = @mouseY
      setDragRect
    end
    
    if @downFlag == 1 && result != 0
      return false
    end
    if result != 0
      @downFlag = 1
      Audio.se_play(CLICK_AUDIO_PATH) if CLICK_AUDIO_PATH != nil
      return true
    else
      @downFlag = 0
      return false
    end
  end
  #--------------------------------------------------------------------------
  # ● 右击鼠标
  #--------------------------------------------------------------------------
  def self.mouseRightClickJudge
    result = $get_async_key_state.call(0x02)
    if @rightDownFlag == 1 && result != 0
      return false
    end
    if result != 0
      @rightDownFlag = 1
      Audio.se_play(R_CLICK_AUDIO_PATH) if R_CLICK_AUDIO_PATH != nil
      return true
    else
      @rightDownFlag = 0
      return false
    end
  end
  #--------------------------------------------------------------------------
  # ● 把鼠标限制在窗口中
  #--------------------------------------------------------------------------
  def self.setMouseRect
    w = [0, 0].pack("ll")
    $screen_to_client.call($hwnd, w)
    w = w.unpack("ll")
    x = w[0]
    y = w[1]
    $clip_cursor.call([-x, -y, -x+WINDOW_X, -y+WINDOW_Y].pack('llll'))
  end
  #--------------------------------------------------------------------------
  # ● 获取鼠标在屏幕中的位置
  #--------------------------------------------------------------------------
  def self.getMouseLocation
    c = [0, 0]
    c = c.pack("ll")
    $get_cursor_pos.call(c)
    c = c.unpack("ll")
    w = [0, 0].pack("ll")
    $screen_to_client.call($hwnd, w)
    w = w.unpack("ll")
    @mouseX = c[0] + w[0]
    @mouseY = c[1] + w[1]
  end
  #--------------------------------------------------------------------------
  # ● 获取鼠标拖动的矩形
  #--------------------------------------------------------------------------
  def self.setDragRect
    @dragRect = Rect.new(0, 0, 0, 0)
    if @dragRect_x_1 >= @dragRect_x_2
      @dragRect.x = @dragRect_x_2
      @dragRect.width = @dragRect_x_1 - @dragRect_x_2
    else
      @dragRect.x = @dragRect_x_1
      @dragRect.width = @dragRect_x_2 - @dragRect_x_1
    end
    if @dragRect_y_1 >= @dragRect_y_2
      @dragRect.y = @dragRect_y_2
      @dragRect.height = @dragRect_y_1 - @dragRect_y_2
    else
      @dragRect.y = @dragRect_y_1
      @dragRect.height = @dragRect_y_2 - @dragRect_y_1
    end
  end
end
#==============================================================================
# ■ Scene_Base
#------------------------------------------------------------------------------
#  游戏中全部画面的超级类。
#==============================================================================
class Scene_Base
  include (FSL::EasyMouseConfig)
  def start
    if SHOW_MOUSE_IMAGE
      @mouse_sprite = Sprite.new
      @mouse_bitmap_1 = Bitmap.new(MOUSE_IMAGE_PATH + "Mouse_1")
      @mouse_bitmap_2 = Bitmap.new(MOUSE_IMAGE_PATH + "Mouse_2")
      @mouse_sprite.bitmap = @mouse_bitmap_1
      @mouseBitmapIndex = 1
      @mouse_sprite.z = 10000
    end
  end
  
  def terminate
    if SHOW_MOUSE_IMAGE
      @mouse_sprite.dispose
      @mouse_sprite.bitmap.dispose
    end
  end
  #--------------------------------------------------------------------------
  # ● 刷新
  #--------------------------------------------------------------------------
  def update
    Mouse.update
    if SHOW_MOUSE_IMAGE
      @mouse_sprite.x = Mouse.getX
      @mouse_sprite.y = Mouse.getY
      if Mouse.down? && @mouseBitmapIndex == 1
        @mouse_sprite.bitmap = @mouse_bitmap_2
        @mouseBitmapIndex = 2
      end
      if Mouse.down? == false && @mouseBitmapIndex == 2
        @mouse_sprite.bitmap = @mouse_bitmap_1
        @mouseBitmapIndex = 1
      end
    end
  end
end
就当Input用吧= =||
 
 下面是范例
 
  MouseTestReal.rar
(281.9 KB, 下载次数: 621) | 
 评分
查看全部评分
 |