Project1

标题: 鼠标放在人物身上,人物变亮 [打印本页]

作者: 逍遥仙诚    时间: 2011-10-16 11:08
标题: 鼠标放在人物身上,人物变亮
本帖最后由 逍遥仙诚 于 2011-10-16 11:12 编辑
  1. #==============================================================================
  2. # ■ 完整鼠标系统(四方向)
  3. #------------------------------------------------------------------------------
  4. #  使用时务必配合专用寻路算法
  5. #   By whbm
  6. #==============================================================================
  7. #下面做一下介绍与使用说明:
  8. #    在屏幕上单击鼠标的时候,会自动进行寻路,这里为了速度更快并且为了进行迷
  9. #宫时的难度寻路被限定在当时的屏幕内部。(否则玩家直接点到终点,呵呵....知道
  10. #后果了吧)
  11. #    在角色移动过程中再次单击鼠标(即双击)并在单击第二次鼠标的时候不松手,
  12. #角色将会跟随鼠标方向移动。(这个应该好理解,不用多说吧)当角色贴着欲被启动
  13. #的事件的时候,单击NPC即可启动事件。若未贴着,将会产生自动寻路到NPC附近的某
  14. #点,那时在单击NPC即可。
  15. #    当鼠标停在某些事件上时候会发现有不同的图标,设置方法为:宝箱事件请在事
  16. #件的执行内容中添加 注释,注释内容为 Item 注意大小写。NPC事件请在事件的执行
  17. #内容中添加 注释注释内容为 NPC 注意大小写。若不箱改变某事件的图标,则不要写
  18. #那两个注释。
  19. #    当把脚本转到您工程的时候千万别忘了那个寻路用的脚本。
  20. #==============================================================================
  21. class Game_Event
  22.   attr_accessor :flag
  23. end
  24. #==============================================================================
  25. # ■ Game_Map
  26. #------------------------------------------------------------------------------
  27. #  处理地图的类。包含卷动以及可以通行的判断功能。
  28. # 本类的实例请参考 $game_map 。
  29. #==============================================================================
  30. class Game_Map
  31.   #--------------------------------------------------------------------------
  32.   # ● 检查鼠标处是否有自定义的事件并返回类型
  33.   #--------------------------------------------------------------------------
  34.   def check_event_custom(mouse_x, mouse_y)
  35.     for event in $game_map.events.values #循环所有事件检查
  36.       event_width = RPG::Cache.character(event.character_name,event.character_hue).width / 4
  37.       event_height = RPG::Cache.character(event.character_name,event.character_hue).height / 4
  38.       if mouse_x > event.screen_x - event_width / 2 and mouse_x < event.screen_x + event_width / 2 and mouse_y + 32 > event.screen_y + 32 - event_height and mouse_y + 32 < event.screen_y + 32
  39.         for i in 0...event.list.size
  40.           if event.list[i].parameters[0] == "Item" #类型判断
  41.             event.flag = 1
  42.           elsif event.list[i].parameters[0] == "Npc" #类型判断
  43.             event.flag = 2
  44.           else
  45.             event.flag = 0 if $game_player.get_mouse_sta != 2 #无标志
  46.           end
  47.           return event.flag #返回事件类型标志
  48.         end
  49.       end
  50.     end
  51.     return 0 if $game_player.get_mouse_sta != 2 #如果不是在跟随鼠标状态,则返回无标志
  52.     return $mouse_icon_id #使鼠标图不变化
  53.   end
  54.   #--------------------------------------------------------------------------
  55.   # ● 检查鼠标处是否有事件可以开启
  56.   #--------------------------------------------------------------------------
  57.   def check_event_custom_start(mouse_x, mouse_y)
  58.     for event in $game_map.events.values #循环所有事件检查
  59.       #事件角色图片宽度、高度
  60.       event_width = RPG::Cache.character(event.character_name,event.character_hue).width/4
  61.       event_height = RPG::Cache.character(event.character_name,event.character_hue).height/4
  62.       #判断是否鼠标在事件上
  63.       if mouse_x > event.screen_x - event_width / 2 and mouse_x < event.screen_x + event_width / 2 and mouse_y + 32 > event.screen_y + 32 - event_height and mouse_y + 32 < event.screen_y + 32
  64.         way_x = $game_player.x - event.x
  65.         way_y = $game_player.y - event.y
  66.         if ([1, -1].include?($game_player.x-event.x) and $game_player.y-event.y == 0) or ([1, -1].include?($game_player.y-event.y) and $game_player.x-event.x == 0)
  67.           for i in 0...event.list.size
  68.             if ["Item","Npc"].include?(event.list[i].parameters[0]) #当事件属于自定义事件
  69.               #判断主角朝向
  70.               if way_x == -1
  71.                 p_direction = 6 if way_y == 0
  72.               elsif way_x == 0
  73.                 p_direction = 2 if way_y == -1
  74.                 p_direction = 8 if way_y == 1
  75.               else
  76.                 p_direction = 4 if way_y == 0
  77.               end
  78.               event.start #开启事件
  79.               return 1, p_direction #返回即将开启事件以及角色朝向
  80.             end
  81.           end
  82.         end
  83.       end
  84.     end
  85.     return 0, 5 #返回不会开启事件以及角色朝向不变
  86.   end
  87.   #--------------------------------------------------------------------------
  88.   # ● 检查鼠标处是否存在自定义事件 for 寻路
  89.   #--------------------------------------------------------------------------
  90.   def check_event_custom_exist(mouse_x, mouse_y)
  91.     for event in $game_map.events.values #循环所有事件检查
  92.       #事件角色图片宽度、高度
  93.       event_width = RPG::Cache.character(event.character_name,event.character_hue).width/4
  94.       event_height = RPG::Cache.character(event.character_name,event.character_hue).height/4
  95.       if mouse_x > event.screen_x - event_width / 2 and mouse_x < event.screen_x + event_width / 2 and mouse_y + 32 > event.screen_y + 32 - event_height and mouse_y + 32 < event.screen_y + 32
  96.         for i in 0...event.list.size
  97.           return 1, event if ["Item", "Npc"].include?(event.list[i].parameters[0]) #返回存在自定义事件以及事件体
  98.         end
  99.       end
  100.     end
  101.     return 0, event #返回不存在自定义事件,以及事件体
  102.   end
  103. end


  104. #=================以下两个用来调整战斗时的手感问题,可以自己试试。
  105. $敌人选框扩大 = 20
  106. $角色选框扩大 = 30


  107. #==============================================================================
  108. # ● API调用
  109. #==============================================================================
  110. $ShowCursor = Win32API.new("user32", "ShowCursor", 'i', 'l')
  111. $GetCursorPos = Win32API.new("user32", "GetCursorPos", 'p', 'i')
  112. $ScreenToClient = Win32API.new("user32", "ScreenToClient", 'ip', 'i')
  113. $GetActiveWindow = Win32API.new("user32", "GetActiveWindow", nil, 'l')
  114. $Window_HWND = $GetActiveWindow.call
  115. $GetKeyState = Win32API.new("user32", "GetKeyState", 'i', 'i')
  116. module Mouse  
  117. LEFT = 0x01
  118. RIGHT = 0x02

  119. def self.init(sprite = nil)
  120.    $ShowCursor.call(0)
  121.    
  122.    @show_cursor = false

  123.    @mouse_ani_viewport = Viewport.new(0,0,640,480)
  124.    @mouse_ani_viewport.z = 1
  125.    @mouse_ani = RPG::Sprite.new(@mouse_ani_viewport)
  126.    @mouse_ani.z = 1
  127.    
  128.    @mouse_sprite = Sprite.new
  129.    @mouse_sprite.z = 99999
  130.    @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/鼠标')
  131.    
  132.    $data_animations = load_data("Data/Animations.rxdata")
  133.    @mouse_wait_count = $data_animations[211].frame_max * 2
  134.    @mouse_wait = 0
  135.    @b = 1
  136.    
  137.    @left_press = false
  138.    @right_press = false
  139.    @left_trigger = false
  140.    @right_trigger = false
  141.    @left_repeat = false
  142.    @right_repeat = false
  143.    @click_lock = false
  144.    
  145.    update
  146. end
  147. def self.exit
  148.    @mouse_sprite.bitmap.dispose
  149.    @mouse_sprite.dispose
  150.    @mouse_ani.dispose
  151.    @show_cursor = true
  152.    $ShowCursor.call(1)
  153. end
  154. def self.mouse_debug
  155.    return @mouse_debug.bitmap
  156. end
  157.   #.........................................................................
  158. def self.set_ani(x, y)
  159.    @ani_x = x
  160.    @ani_y = y
  161.    x -= $game_map.display_x / 4
  162.    y -= $game_map.display_y / 4
  163.    @mouse_ani.x, @mouse_ani.y = x, y
  164.    @mouse_ani.animation($data_animations[211],true)
  165.    @mouse_wait = @mouse_wait_count
  166. end
  167. def self.update_ani
  168.    if @mouse_wait > 0
  169.      x = @ani_x
  170.      y = @ani_y
  171.      x -= $game_map.display_x / 4
  172.      y -= $game_map.display_y / 4
  173.      @mouse_ani.x, @mouse_ani.y = x, y
  174.      @mouse_ani.update
  175.      @mouse_wait -= 1
  176.    end
  177. end

  178. def self.update
  179.   # $game_system.map_interpreter.running? ? @mouse_sprite.bitmap = Bitmap.new("对话时候的图标")
  180.    # @mouse_sprite.bitmap = Bitmap.new("平常的图标")
  181.     update_ani
  182.    left_down = $GetKeyState.call(0x01)
  183.    right_down = $GetKeyState.call(0x02)
  184.    if Graphics.frame_count * 3 / Graphics.frame_rate != @total_sec
  185.      @total_sec = Graphics.frame_count * 3 / Graphics.frame_rate
  186.      @a = !@a
  187.    end
  188.   
  189.    if $scene.is_a?(Scene_Map) == false
  190.      $mouse_icon_id = 0
  191.    end
  192.    if $mouse_icon_id != $mouse_icon_id_last
  193.      case $mouse_icon_id
  194.      when 1
  195.        if @a
  196.          @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/GetItem1')
  197.        else
  198.          @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/GetItem2')
  199.        end
  200.      when 2
  201.        if @a
  202.          @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/TalkTo1')
  203.        else
  204.          @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/TalkTo2')
  205.        end
  206. =begin
  207.      when 11
  208.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/Mouse_LOWER_LEFT')
  209.      when 12
  210.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/Mouse_DOWN')
  211.      when 13
  212.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/Mouse_LOWER_RIGHT')
  213.      when 14
  214.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/Mouse_LEFT')
  215.      when 16
  216.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/Mouse_RIGHT')
  217.      when 17
  218.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/Mouse_UPPER_LEFT')
  219.      when 18
  220.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/Mouse_UP')
  221.      when 19
  222.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/Mouse_UPPER_RIGHT')
  223. =end
  224.      when 0
  225. #       $game_system.map_interpreter.running? ? @mouse_sprite.bitmap = Bitmap.new("Graphics/Icons/鼠标")
  226.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/鼠标')
  227.      end
  228.      $mouse_icon_id_last = $mouse_icon_id
  229.    end
  230.    @click_lock = false
  231.    mouse_x, mouse_y = self.get_mouse_pos
  232.    if @mouse_sprite != nil
  233.      @mouse_sprite.x = mouse_x
  234.      @mouse_sprite.y = mouse_y
  235.    end
  236.    if left_down[7] == 1
  237.      @left_repeat = (not @left_repeat)
  238.      @left_trigger = (not @left_press)
  239.      @left_press = true
  240.    else
  241.      @left_press = false
  242.      @left_trigger = false
  243.      @left_repeat = false
  244.    end
  245.    if right_down[7] == 1
  246.      @right_repeat = (not @right_repeat)
  247.      @right_trigger = (not @right_press)
  248.      @right_press = true
  249.    else
  250.      @right_press = false
  251.      @right_trigger = false
  252.      @right_repeat = false
  253.    end
  254. end
  255. def self.get_mouse_pos
  256.    point_var = [0, 0].pack('ll')
  257.    if $GetCursorPos.call(point_var) != 0
  258.      if $ScreenToClient.call($Window_HWND, point_var) != 0
  259.        x, y = point_var.unpack('ll')
  260.        if (x < 0) or (x > 10000) then x = 0 end
  261.        if (y < 0) or (y > 10000) then y = 0 end
  262.        if x > 640 then x = 640 end
  263.        if y > 480 then y = 480 end
  264.        return x, y
  265.      else
  266.        return 0, 0
  267.      end
  268.    else
  269.      return 0, 0
  270.    end
  271. end
  272. def self.press?(mouse_code)
  273.    if mouse_code == LEFT
  274.      if @click_lock
  275.        return false
  276.      else
  277.        return @left_press
  278.      end
  279.    elsif mouse_code == RIGHT
  280.      return @right_press
  281.    else
  282.      return false
  283.    end
  284. end
  285. def self.trigger?(mouse_code)
  286.    if mouse_code == LEFT
  287.      if @click_lock
  288.        return false
  289.      else
  290.        return @left_trigger
  291.      end
  292.    elsif mouse_code == RIGHT
  293.      return @right_trigger
  294.    else
  295.      return false
  296.    end
  297. end
  298. def self.repeat?(mouse_code)
  299.    if mouse_code == LEFT
  300.      if @click_lock
  301.        return false
  302.      else
  303.        return @left_repeat
  304.      end
  305.    elsif mouse_code == RIGHT
  306.      return @right_repeat
  307.    else
  308.      return false
  309.    end
  310. end
  311. def self.click_lock?
  312.    return @click_lock
  313. end
  314. def self.click_lock
  315.    @click_lock = true
  316. end
  317. def self.click_unlock
  318.    @click_lock = false
  319. end
  320. end
  321. module Input
  322. if @self_update == nil
  323.    @self_update = method('update')
  324.    @self_press = method('press?')
  325.    @self_trigger = method('trigger?')
  326.    @self_repeat = method('repeat?')
  327. end
  328. def self.update
  329.    @self_update.call
  330.    Mouse.update
  331. end
  332. def self.press?(key_code)
  333.    if @self_press.call(key_code)
  334.      return true
  335.    end
  336.    if key_code == C
  337.      return Mouse.press?(Mouse::LEFT)
  338.    elsif key_code == B
  339.      return Mouse.press?(Mouse::RIGHT)
  340.    else
  341.      return @self_press.call(key_code)
  342.    end
  343. end
  344. def self.trigger?(key_code)
  345.    if @self_trigger.call(key_code)
  346.      return true
  347.    end
  348.    if key_code == C
  349.      return Mouse.trigger?(Mouse::LEFT)
  350.    elsif key_code == B
  351.      return Mouse.trigger?(Mouse::RIGHT)
  352.    else
  353.      return @self_trigger.call(key_code)
  354.    end
  355. end
  356. def self.repeat?(key_code)
  357.    if @self_repeat.call(key_code)
  358.      return true
  359.    end
  360.    if key_code == C
  361.      return Mouse.repeat?(Mouse::LEFT)
  362.    elsif key_code == B
  363.      return Mouse.repeat?(Mouse::RIGHT)
  364.    else
  365.      return @self_repeat.call(key_code)
  366.    end
  367. end
  368. end
  369. class Window_Selectable
  370. if @self_alias == nil
  371.    alias self_update update
  372.    @self_alias = true
  373. end
  374. def update
  375.    self_update
  376.    if self.active and @item_max > 0
  377.      index_var = @index
  378.      tp_index = @index
  379.      mouse_x, mouse_y = Mouse.get_mouse_pos
  380.      mouse_not_in_rect = true
  381.      for i in 0...@item_max
  382.        @index = i
  383.        update_cursor_rect
  384.        top_x = self.cursor_rect.x + self.x + 16
  385.        top_y = self.cursor_rect.y + self.y + 16
  386.        bottom_x = top_x + self.cursor_rect.width
  387.        bottom_y = top_y + self.cursor_rect.height
  388.        if (mouse_x > top_x) and (mouse_y > top_y) and
  389.           (mouse_x < bottom_x) and (mouse_y < bottom_y)
  390.          mouse_not_in_rect = false
  391.          if tp_index != @index
  392.            tp_index = @index
  393.            $game_system.se_play($data_system.cursor_se)
  394.          end
  395.          break
  396.        end
  397.      end
  398.      if mouse_not_in_rect
  399.        @index = index_var
  400.        update_cursor_rect
  401.        Mouse.click_lock
  402.      else
  403.        Mouse.click_unlock               
  404.      end
  405.    end
  406. end
  407. end
  408. =begin
  409. class Window_Selectable_Minny
  410.   if @self_alias == nil
  411.     alias self_update update
  412.     @self_alias = true
  413.   end
  414.   def update
  415.     #self.cursor_rect.empty
  416.     self_update
  417.     if self.active and @item_max > 0
  418.       index_var = @index
  419.       tp_index = @index
  420.       mouse_x, mouse_y = Mouse.get_mouse_pos
  421.       mouse_not_in_rect = true
  422.       for i in 0...@item_max
  423.         @index = i
  424.         update_cursor_rect
  425.         top_x = self.cursor_rect.x + self.x + 16
  426.         top_y = self.cursor_rect.y + self.y + 16
  427.         bottom_x = top_x + self.cursor_rect.width
  428.         bottom_y = top_y + self.cursor_rect.height
  429.         if (mouse_x > top_x) and (mouse_y > top_y) and
  430.            (mouse_x < bottom_x) and (mouse_y < bottom_y)
  431.           mouse_not_in_rect = false
  432.           if tp_index != @index
  433.             tp_index = @index
  434.             $game_system.se_play($data_system.cursor_se)
  435.           end
  436.           break
  437.         end
  438.       end
  439.       if mouse_not_in_rect
  440.         @index = index_var
  441.         update_cursor_rect
  442.         Mouse.click_lock
  443.       else
  444.         Mouse.click_unlock               
  445.       end
  446.     end
  447.   end
  448. end
  449. =end
  450. class Window_NameInput
  451. if @self_alias == nil
  452.    alias self_update update
  453.    @self_alias = true
  454. end
  455. def update
  456.    self_update
  457.    if self.active
  458.      index_var = @index
  459.      mouse_x, mouse_y = Mouse.get_mouse_pos
  460.      mouse_not_in_rect = true
  461.      for i in (0...CHARACTER_TABLE.size).to_a.push(180)
  462.        @index = i
  463.        update_cursor_rect
  464.        top_x = self.cursor_rect.x + self.x + 16
  465.        top_y = self.cursor_rect.y + self.y + 16
  466.        bottom_x = top_x + self.cursor_rect.width
  467.        bottom_y = top_y + self.cursor_rect.height
  468.        if (mouse_x > top_x) and (mouse_y > top_y) and
  469.           (mouse_x < bottom_x) and (mouse_y < bottom_y)
  470.          mouse_not_in_rect = false
  471.          break
  472.        end
  473.      end
  474.      if mouse_not_in_rect
  475.        @index = index_var
  476.        update_cursor_rect
  477.        Mouse.click_lock
  478.      else
  479.        Mouse.click_unlock
  480.      end
  481.    end
  482. end
  483. end
  484. class Window_InputNumber
  485. if @self_alias == nil
  486.    alias self_update update
  487.    @self_alias = true
  488. end
  489. def update
  490.    self_update
  491.    mouse_x, mouse_y = Mouse.get_mouse_pos
  492.    if self.active and @digits_max > 0
  493.      index_var = @index
  494.      mouse_not_in_rect = true
  495.      for i in 0...@digits_max
  496.        @index = i
  497.        update_cursor_rect
  498.        top_x = self.cursor_rect.x + self.x + 16
  499.        bottom_x = top_x + self.cursor_rect.width
  500.        if (mouse_x > top_x) and (mouse_x < bottom_x)
  501.          mouse_not_in_rect = false
  502.          break
  503.        end
  504.      end
  505.      if mouse_not_in_rect
  506.        @index = index_var
  507.        update_cursor_rect
  508.        Mouse.click_lock
  509.      else
  510.        Mouse.click_unlock
  511.      end
  512.    end
  513.    if @last_mouse_y == nil
  514.      @last_mouse_y = mouse_y
  515.    end
  516.    check_pos = (@last_mouse_y - mouse_y).abs
  517.    if check_pos > 10
  518.      $game_system.se_play($data_system.cursor_se)
  519.      place = 10 ** (@digits_max - 1 - @index)
  520.      n = @number / place % 10
  521.      @number -= n * place
  522.      n = (n + 1) % 10 if mouse_y < @last_mouse_y
  523.      n = (n + 9) % 10 if mouse_y > @last_mouse_y
  524.      @number += n * place
  525.      refresh
  526.      @last_mouse_y = mouse_y
  527.    end
  528. end
  529. end
  530. class Scene_File
  531. if @self_alias == nil
  532.    alias self_update update
  533.    @self_alias = true
  534. end
  535. def update
  536.    mouse_x, mouse_y = Mouse.get_mouse_pos
  537.    Mouse.click_lock
  538.    idx = 0
  539.    for i in @savefile_windows
  540.      top_x = i.x + 16
  541.      top_y = i.y + 16
  542.      bottom_x = top_x + i.width
  543.      bottom_y = top_y + i.height
  544.      if (mouse_x > top_x) and (mouse_y > top_y) and
  545.         (mouse_x < bottom_x) and (mouse_y < bottom_y)
  546.        i.selected = true
  547.        if @file_index != idx
  548.          @file_index = idx
  549.          $game_system.se_play($data_system.cursor_se)
  550.        end            
  551.        Mouse.click_unlock
  552.      else
  553.        i.selected = false
  554.      end
  555.      idx += 1
  556.    end
  557.    self_update
  558. end
  559. end
  560. class Arrow_Enemy
  561. if @self_alias == nil
  562.    alias self_update update
  563.    @self_alias = true
  564. end
  565. def update
  566.    mouse_x, mouse_y = Mouse.get_mouse_pos
  567.    idx = 0
  568.    for i in $game_troop.enemies do
  569.      if i.exist?
  570.        top_x = i.screen_x - self.ox
  571.        top_y = i.screen_y - self.oy
  572.        bottom_x = top_x + self.src_rect.width
  573.        bottom_y = top_y + self.src_rect.height
  574.        if (mouse_x > top_x - $敌人选框扩大) and (mouse_y > top_y - $敌人选框扩大) and
  575.           (mouse_x < bottom_x + $敌人选框扩大) and (mouse_y < bottom_y + $敌人选框扩大)
  576.          if @index != idx
  577.            $game_system.se_play($data_system.cursor_se)
  578.            @index = idx
  579.          end
  580.        end
  581.      end
  582.      idx += 1
  583.    end
  584.    self_update
  585. end
  586. end
  587. class Arrow_Actor
  588. if @self_alias == nil
  589.    alias self_update update
  590.    @self_alias = true
  591. end
  592. def update
  593.    mouse_x, mouse_y = Mouse.get_mouse_pos
  594.    idx = 0
  595.    for i in $game_party.actors do
  596.      if i.exist?
  597.        top_x = i.screen_x - self.ox
  598.        top_y = i.screen_y - self.oy
  599.        bottom_x = top_x + self.src_rect.width
  600.        bottom_y = top_y + self.src_rect.height
  601.        if (mouse_x > top_x - $角色选框扩大) and (mouse_y > top_y - $角色选框扩大) and
  602.           (mouse_x < bottom_x + $角色选框扩大) and (mouse_y < bottom_y + $角色选框扩大)
  603.          if @index != idx
  604.            $game_system.se_play($data_system.cursor_se)
  605.            @index = idx
  606.          end
  607.        end
  608.      end
  609.      idx += 1
  610.    end
  611.    self_update
  612. end
  613. end
  614. #==============================================================================
  615. # ■ Game_Player
  616. #------------------------------------------------------------------------------
  617. #  处理主角的类。事件启动的判定、以及地图的滚动等功能。
  618. # 本类的实例请参考 $game_player。
  619. #   鼠标控制角色的主程序
  620. #==============================================================================
  621. class Game_Player
  622. if @self_alias == nil
  623.    alias self_update update
  624.    @self_alias = true
  625. end
  626. #--------------------------------------------------------------------------
  627. # ● 得到鼠标的状态
  628. #--------------------------------------------------------------------------
  629. def get_mouse_sta
  630.    return @mouse_sta
  631. end
  632. #--------------------------------------------------------------------------
  633. # ● 完整鼠标系统
  634. #--------------------------------------------------------------------------
  635.   #--------------------------------------------------------------------------
  636. # ● 完整鼠标系统
  637. #--------------------------------------------------------------------------
  638. def update
  639.    mouse_x, mouse_y = Mouse.get_mouse_pos
  640.    @mtp_x = mouse_x
  641.    @mtp_y = mouse_y
  642.    # 地图界面按扭操作系统★★★★★★★★★★★★★★★★★★★★★
  643.    # 操作提示
  644.    if @mtp_x >= 140 and @mtp_x <= 155 and @mtp_y >= 16 and @mtp_y <= 41
  645.      $game_screen.pictures[44].show("!选框", 0, 0, 0, 100.0, 100.0, 255, 0)
  646.      if Input.trigger?(Input::C)
  647.        $game_system.se_play($data_system.decision_se); $game_screen.pictures[44].erase
  648.        $scene = Scene_Menu.new      
  649.       end
  650.    else
  651.      $game_screen.pictures[44].erase
  652.    end
  653. # 物品按扭
  654.    if @mtp_x >= 128 and @mtp_x <= 143 and @mtp_y >= 0 and @mtp_y <= 14
  655.      $game_screen.pictures[43].show("选框", 0, 128, 0, 100.0, 100.0, 255, 0)
  656.      if Input.trigger?(Input::C)
  657.        $game_system.se_play($data_system.decision_se); $game_screen.pictures[43].erase
  658.        $scene = Scene_Item.new
  659.       end
  660.    else
  661.      $game_screen.pictures[43].erase
  662.    end
  663. # 存挡按扭
  664.    if @mtp_x >= 124 and @mtp_x <= 138 and @mtp_y >= 15 and @mtp_y <= 27
  665.      $game_screen.pictures[42].show("选框", 0, 124, 14, 100.0, 100.0, 255, 0)
  666.      if Input.trigger?(Input::C)
  667.        $game_system.se_play($data_system.decision_se); $game_screen.pictures[42].erase
  668.        $scene = Scene_Save.new
  669.       end
  670.    else
  671.      $game_screen.pictures[42].erase
  672.    end
  673.     if @mtp_x >= 118 and @mtp_x <= 133 and @mtp_y >= 28 and @mtp_y <= 43
  674.      $game_screen.pictures[41].show("选框", 0, 118, 28, 100.0, 100.0, 255, 0)
  675.      if Input.trigger?(Input::C)
  676.        $game_system.se_play($data_system.decision_se); $game_screen.pictures[41].erase
  677.        $scene = Scene_End.new
  678.       end
  679.    else
  680.      $game_screen.pictures[41].erase
  681.    end
  682.    #------------------------------------------------------
  683.    unless $game_system.map_interpreter.running? and @mouse_sta == 2 #鼠标状态不为跟随状态
  684.      #得到鼠标图标方向
  685.      $mouse_icon_id = $game_map.check_event_custom(mouse_x,mouse_y)  if not [11, 12, 13, 14, 16, 17, 18, 19].include?($mouse_icon_id)
  686.    else
  687.      #令鼠标图标为正常
  688.      $mouse_icon_id = 0 if @mouse_sta != 2
  689.    end
  690.    
  691.    #单击鼠标时进行判断寻路或跟随
  692.    if Mouse.trigger?(Mouse::LEFT) #当点击鼠标时
  693.      unless $game_system.map_interpreter.running? or
  694.             @move_route_forcing or $game_temp.message_window_showing #各种无效情况的排除
  695.        #初始化
  696.        @mouse_sta = 1
  697.        p_direction = 5
  698.        #检查鼠标处能否开启事件
  699.        event_start,p_direction = $game_map.check_event_custom_start(mouse_x, mouse_y)
  700.        #若在移动中再次点击鼠标左键(即双击左键),则改鼠标状态为跟随状态
  701.        @mouse_sta = 2 if @paths_id != nil and @paths_id != @paths.size
  702.        if @mouse_sta != 2
  703.          #鼠标状态不为跟随状态则取数据并初始化路径
  704.          trg_x = (mouse_x + $game_map.display_x / 4) / 32
  705.          trg_y = (mouse_y + $game_map.display_y / 4) / 32
  706.          @paths = []
  707.          @paths_id = 0
  708.          if event_start == 0 #若不能开启事件
  709.            if trg_x != $game_player.x or trg_y != $game_player.y #若目标不为自身则开始寻路
  710.              Mouse.set_ani(mouse_x + $game_map.display_x / 4, mouse_y + $game_map.display_y / 4)
  711.              find_path = Find_Path.new
  712.              @paths = find_path.find_player_short_path(trg_x, trg_y, @mtp_x, @mtp_y)
  713.            end
  714.          else #若能开启事件则改变角色朝向
  715.            @direction = p_direction
  716.          end
  717.        end
  718.      end
  719.    end

  720.    #开始移动
  721.    if @mouse_sta != nil and @mouse_sta == 1 #若鼠标状态为寻路状态
  722.      unless moving? or $game_system.map_interpreter.running? or
  723.             @move_route_forcing or $game_temp.message_window_showing #排除无效情况
  724.        if @paths_id != nil and @paths != nil and @paths_id <= @paths.size #若没有完成路径
  725.          case @paths[@paths_id] #判断路径
  726.          when 6
  727.            @last_move_x = true
  728.            move_right
  729.            @paths_id += 1
  730.            @direction = 6
  731.          when 4
  732.            @last_move_x = true
  733.            move_left
  734.            @paths_id += 1
  735.            @direction = 4
  736.          when 2
  737.            @last_move_x = false
  738.            move_down
  739.            @direction = 2
  740.            @paths_id += 1
  741.          when 8
  742.            @last_move_x = false
  743.            move_up
  744.            @direction = 8
  745.            @paths_id += 1
  746.          end
  747.        end
  748.      end
  749.    elsif @paths != nil and @mouse_sta == 2 #当鼠标状态为跟随,且在移动中
  750.      if Mouse.press?(Mouse::LEFT) #持续按住鼠标
  751.        unless moving? or $game_system.map_interpreter.running? or
  752.               @move_route_forcing or $game_temp.message_window_showing #排除无效情况
  753.          #跟随方向判断并跟随
  754.          if @mtp_x > self.screen_x
  755.            if @mtp_y - self.screen_y > - ( @mtp_x - self.screen_x ) and
  756.               @mtp_y - self.screen_y < @mtp_x - self.screen_x
  757.              move_right
  758.              $mouse_icon_id = 16
  759.              @direction = 6
  760.            end
  761.            if @mtp_y - self.screen_y > @mtp_x - self.screen_x
  762.              move_down
  763.              $mouse_icon_id = 12
  764.              @direction = 2
  765.            end
  766.            if @mtp_y - self.screen_y < - ( @mtp_x - self.screen_x )
  767.              move_up
  768.              $mouse_icon_id = 18
  769.              @direction = 8
  770.            end
  771.          end
  772.          if @mtp_x < self.screen_x
  773.            if @mtp_y - self.screen_y > - ( self.screen_x - @mtp_x ) and
  774.               @mtp_y - self.screen_y < self.screen_x - @mtp_x
  775.              move_left
  776.              $mouse_icon_id = 14
  777.              @direction = 4
  778.            end
  779.            if @mtp_y - self.screen_y > self.screen_x - @mtp_x
  780.              move_down
  781.              $mouse_icon_id = 12
  782.              @direction = 2
  783.            end
  784.            if @mtp_y - self.screen_y < - ( self.screen_x - @mtp_x )
  785.              move_up
  786.              $mouse_icon_id = 18
  787.              @direction = 8
  788.            end
  789.          end
  790.        end
  791.      else #没状态的情况
  792.        $mouse_icon_id = 0
  793.        @mouse_sta = 0
  794.        @paths_id = @paths.size #终止寻路移动
  795.      end
  796.    end
  797. self_update
  798. end
  799. end
  800. Mouse.init
  801. END { Mouse.exit }
复制代码
求高人指点Rt下面是一张我做的游戏图如果加上那个效果我相信画面会更和谐 dsu_plus_rewardpost_czw
作者: 黑舞嗜    时间: 2011-10-16 11:27
直接用这个吧XD

http://rpg.blue/forum.php?mod=vi ... =%E9%BC%A0%E6%A0%87
作者: 御宅酱    时间: 2011-10-16 11:29
楼主好强大{:nm_5:}




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1