Project1

标题: 求八方向鼠标脚本对应的寻路脚本 [打印本页]

作者: Fan723    时间: 2015-7-7 22:47
标题: 求八方向鼠标脚本对应的寻路脚本
代码复制
  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. #==============================================================================
  26. # ■ Game_Map
  27. #------------------------------------------------------------------------------
  28. #  处理地图的类。包含卷动以及可以通行的判断功能。
  29. # 本类的实例请参考 $game_map 。
  30. #==============================================================================
  31. class Game_Map
  32.   def show_rate(event)
  33.     return 1
  34.   end
  35.   #--------------------------------------------------------------------------
  36.   # ● 检查鼠标处是否有自定义的事件并返回类型
  37.   #--------------------------------------------------------------------------
  38.   def check_event_custom(mouse_x, mouse_y)
  39.     for event in $game_map.events.values #循环所有事件检查
  40.       rate =  show_rate(event)
  41.       event_width = (RPG::Cache.character(event.character_name,event.character_hue).width / $c3_每一步的帧数) * rate
  42.       event_height = (RPG::Cache.character(event.character_name,event.character_hue).height / 8) * rate
  43.       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
  44.         for i in 0...event.list.size
  45.           if event.list[i].parameters[0] == "Item" #类型判断
  46.             event.flag = 1
  47.           elsif event.list[i].parameters[0] == "Npc" #类型判断
  48.             event.flag = 2
  49.           else
  50.             event.flag = 0 if $game_player.get_mouse_sta != 2 #无标志
  51.           end
  52.           return event.flag #返回事件类型标志
  53.         end
  54.       end
  55.     end
  56.     return 0 if $game_player.get_mouse_sta != 2 #如果不是在跟随鼠标状态,则返回无标志
  57.     return $mouse_icon_id #使鼠标图不变化
  58.   end
  59.   #--------------------------------------------------------------------------
  60.   # ● 检查鼠标处是否有事件可以开启
  61.   #--------------------------------------------------------------------------
  62.   def check_event_custom_start(mouse_x, mouse_y)
  63.     for event in $game_map.events.values #循环所有事件检查
  64.       #事件角色图片宽度、高度
  65.       rate =  show_rate(event)
  66.       event_width = (RPG::Cache.character(event.character_name,event.character_hue).width / $c3_每一步的帧数) * rate
  67.       event_height = (RPG::Cache.character(event.character_name,event.character_hue).height / 8) * rate
  68.       #判断是否鼠标在事件上
  69.       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
  70.         way_x = $game_player.x - event.x
  71.         way_y = $game_player.y - event.y
  72.         if [1,0,-1].include?($game_player.x-event.x) and [1,0,-1].include?($game_player.y-event.y)
  73.           for i in 0...event.list.size
  74.             if ["Item","Npc"].include?(event.list[i].parameters[0]) #当事件属于自定义事件
  75.               #判断主角朝向
  76.               if way_x == -1
  77.                 p_direction = 3 if way_y == -1
  78.                 p_direction = 6 if way_y == 0
  79.                 p_direction = 9 if way_y == 1
  80.               elsif way_x == 0
  81.                 p_direction = 2 if way_y == -1
  82.                 p_direction = 8 if way_y == 1
  83.               else
  84.                 p_direction = 1 if way_y == -1
  85.                 p_direction = 4 if way_y == 0
  86.                 p_direction = 7 if way_y == 1
  87.               end
  88.               event.start #开启事件
  89.               return 1, p_direction #返回即将开启事件以及角色朝向
  90.             end
  91.           end
  92.         end
  93.       end
  94.     end
  95.     return 0, 5 #返回不会开启事件以及角色朝向不变
  96.   end
  97.   #--------------------------------------------------------------------------
  98.   # ● 检查鼠标处是否存在自定义事件 for 寻路
  99.   #--------------------------------------------------------------------------
  100.   def check_event_custom_exist(mouse_x, mouse_y)
  101.     for event in $game_map.events.values #循环所有事件检查
  102.       #事件角色图片宽度、高度
  103.       rate =  show_rate(event)
  104.       event_width = (RPG::Cache.character(event.character_name,event.character_hue).width / $c3_每一步的帧数) * rate
  105.       event_height = (RPG::Cache.character(event.character_name,event.character_hue).height / 8) * rate
  106.       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
  107.         for i in 0...event.list.size
  108.           return 1, event if ["Item", "Npc"].include?(event.list[i].parameters[0]) #返回存在自定义事件以及事件体
  109.         end
  110.       end
  111.     end
  112.     return 0, event #返回不存在自定义事件,以及事件体
  113.   end
  114. end
  115. #=================以下两个用来调整战斗时的手感问题,可以自己试试。
  116. $敌人选框扩大 = 20
  117. $角色选框扩大 = 30
  118.  
  119.  
  120. #==============================================================================
  121. # ● API调用
  122. #==============================================================================
  123. $ShowCursor = Win32API.new("user32", "ShowCursor", 'i', 'l')
  124. $GetCursorPos = Win32API.new("user32", "GetCursorPos", 'p', 'i')
  125. $ScreenToClient = Win32API.new("user32", "ScreenToClient", 'ip', 'i')
  126. $GetActiveWindow = Win32API.new("user32", "GetActiveWindow", nil, 'l')
  127. $Window_HWND = $GetActiveWindow.call
  128. $GetKeyState = Win32API.new("user32", "GetKeyState", 'i', 'i')
  129. module Mouse  
  130. LEFT = 0x01
  131. RIGHT = 0x02
  132.  
  133. def self.init(sprite = nil)
  134.    $ShowCursor.call(0)
  135.  
  136.    @show_cursor = false
  137.  
  138.    @mouse_sprite = Sprite.new
  139.    @mouse_sprite.z = 99999
  140.    @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/木剑')
  141.  
  142.    @left_press = false
  143.    @right_press = false
  144.    @left_trigger = false
  145.    @right_trigger = false
  146.    @left_repeat = false
  147.    @right_repeat = false
  148.    @click_lock = false
  149.  
  150.    update
  151. end
  152. def self.exit
  153.    @mouse_sprite.bitmap.dispose
  154.    @mouse_sprite.dispose
  155.    @show_cursor = true
  156.    $ShowCursor.call(1)
  157. end
  158. def self.mouse_debug
  159.    return @mouse_debug.bitmap
  160. end
  161. def self.update
  162.    left_down = $GetKeyState.call(0x01)
  163.    right_down = $GetKeyState.call(0x02)
  164.    if Graphics.frame_count * 3 / Graphics.frame_rate != @total_sec
  165.      @total_sec = Graphics.frame_count * 3 / Graphics.frame_rate
  166.      @a = !@a
  167.    end
  168.    if $scene.is_a?(Scene_Map) == false
  169.      $mouse_icon_id = 0
  170.    end
  171.    if $mouse_icon_id != $mouse_icon_id_last
  172.      case $mouse_icon_id
  173.      when 1
  174.        if @a
  175.          @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/GetItem1')
  176.        else
  177.          @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/GetItem2')
  178.        end
  179.      when 2
  180.        if @a
  181.          @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/TalkTo1')
  182.        else
  183.          @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/TalkTo2')
  184.        end
  185.      when 11
  186.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/Mouse_LOWER_LEFT')
  187.      when 12
  188.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/Mouse_DOWN')
  189.      when 13
  190.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/Mouse_LOWER_RIGHT')
  191.      when 14
  192.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/Mouse_LEFT')
  193.      when 16
  194.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/Mouse_RIGHT')
  195.      when 17
  196.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/Mouse_UPPER_LEFT')
  197.      when 18
  198.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/Mouse_UP')
  199.      when 19
  200.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/Mouse_UPPER_RIGHT')
  201.      when 0
  202.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/木剑')
  203.      end
  204.      $mouse_icon_id_last = $mouse_icon_id
  205.    end
  206.    @click_lock = false
  207.    mouse_x, mouse_y = self.get_mouse_pos
  208.    if @mouse_sprite != nil
  209.      @mouse_sprite.x = mouse_x
  210.      @mouse_sprite.y = mouse_y
  211.    end
  212.    if left_down[7] == 1
  213.      @left_repeat = (not @left_repeat)
  214.      @left_trigger = (not @left_press)
  215.      @left_press = true
  216.    else
  217.      @left_press = false
  218.      @left_trigger = false
  219.      @left_repeat = false
  220.    end
  221.    if right_down[7] == 1
  222.      @right_repeat = (not @right_repeat)
  223.      @right_trigger = (not @right_press)
  224.      @right_press = true
  225.    else
  226.      @right_press = false
  227.      @right_trigger = false
  228.      @right_repeat = false
  229.    end
  230. end
  231. def self.get_mouse_pos
  232.    point_var = [0, 0].pack('ll')
  233.    if $GetCursorPos.call(point_var) != 0
  234.      if $ScreenToClient.call($Window_HWND, point_var) != 0
  235.        x, y = point_var.unpack('ll')
  236.        if (x < 0) or (x > 10000) then x = 0 end
  237.        if (y < 0) or (y > 10000) then y = 0 end
  238.        if x > 640 then x = 640 end
  239.        if y > 480 then y = 480 end
  240.        return x, y
  241.      else
  242.        return 0, 0
  243.      end
  244.    else
  245.      return 0, 0
  246.    end
  247. end
  248. def self.press?(mouse_code)
  249.    if mouse_code == LEFT
  250.      if @click_lock
  251.        return false
  252.      else
  253.        return @left_press
  254.      end
  255.    elsif mouse_code == RIGHT
  256.      return @right_press
  257.    else
  258.      return false
  259.    end
  260. end
  261. def self.trigger?(mouse_code)
  262.    if mouse_code == LEFT
  263.      if @click_lock
  264.        return false
  265.      else
  266.        return @left_trigger
  267.      end
  268.    elsif mouse_code == RIGHT
  269.      return @right_trigger
  270.    else
  271.      return false
  272.    end
  273. end
  274. def self.repeat?(mouse_code)
  275.    if mouse_code == LEFT
  276.      if @click_lock
  277.        return false
  278.      else
  279.        return @left_repeat
  280.      end
  281.    elsif mouse_code == RIGHT
  282.      return @right_repeat
  283.    else
  284.      return false
  285.    end
  286. end
  287. def self.click_lock?
  288.    return @click_lock
  289. end
  290. def self.click_lock
  291.    @click_lock = true
  292. end
  293. def self.click_unlock
  294.    @click_lock = false
  295. end
  296. end
  297. module Input
  298. if @self_update == nil
  299.    @self_update = method('update')
  300.    @self_press = method('press?')
  301.    @self_trigger = method('trigger?')
  302.    @self_repeat = method('repeat?')
  303. end
  304. def self.update
  305.    @self_update.call
  306.    Mouse.update
  307. end
  308. def self.press?(key_code)
  309.    if @self_press.call(key_code)
  310.      return true
  311.    end
  312.    if key_code == C
  313.      return Mouse.press?(Mouse::LEFT)
  314.    elsif key_code == B
  315.      return Mouse.press?(Mouse::RIGHT)
  316.    else
  317.      return @self_press.call(key_code)
  318.    end
  319. end
  320. def self.trigger?(key_code)
  321.    if @self_trigger.call(key_code)
  322.      return true
  323.    end
  324.    if key_code == C
  325.      return Mouse.trigger?(Mouse::LEFT)
  326.    elsif key_code == B
  327.      return Mouse.trigger?(Mouse::RIGHT)
  328.    else
  329.      return @self_trigger.call(key_code)
  330.    end
  331. end
  332. def self.repeat?(key_code)
  333.    if @self_repeat.call(key_code)
  334.      return true
  335.    end
  336.    if key_code == C
  337.      return Mouse.repeat?(Mouse::LEFT)
  338.    elsif key_code == B
  339.      return Mouse.repeat?(Mouse::RIGHT)
  340.    else
  341.      return @self_repeat.call(key_code)
  342.    end
  343. end
  344. end
  345. class Window_Selectable
  346. if @self_alias == nil
  347.    alias self_update update
  348.    @self_alias = true
  349. end
  350. def update
  351.    self_update
  352.    if self.active and @item_max > 0
  353.      index_var = @index
  354.      tp_index = @index
  355.      mouse_x, mouse_y = Mouse.get_mouse_pos
  356.      mouse_not_in_rect = true
  357.      for i in 0...@item_max
  358.        @index = i
  359.        update_cursor_rect
  360.        top_x = self.cursor_rect.x + self.x + 16
  361.        top_y = self.cursor_rect.y + self.y + 16
  362.        bottom_x = top_x + self.cursor_rect.width
  363.        bottom_y = top_y + self.cursor_rect.height
  364.        if (mouse_x > top_x) and (mouse_y > top_y) and
  365.           (mouse_x < bottom_x) and (mouse_y < bottom_y)
  366.          mouse_not_in_rect = false
  367.          if tp_index != @index
  368.            tp_index = @index
  369.            $game_system.se_play($data_system.cursor_se)
  370.          end
  371.          break
  372.        end
  373.      end
  374.      if mouse_not_in_rect
  375.        @index = index_var
  376.        update_cursor_rect
  377.        Mouse.click_lock
  378.      else
  379.        Mouse.click_unlock               
  380.      end
  381.    end
  382. end
  383. end
  384. class Window_NameInput
  385. if @self_alias == nil
  386.    alias self_update update
  387.    @self_alias = true
  388. end
  389. def update
  390.    self_update
  391.    if self.active
  392.      index_var = @index
  393.      mouse_x, mouse_y = Mouse.get_mouse_pos
  394.      mouse_not_in_rect = true
  395.      for i in (0...CHARACTER_TABLE.size).to_a.push(180)
  396.        @index = i
  397.        update_cursor_rect
  398.        top_x = self.cursor_rect.x + self.x + 16
  399.        top_y = self.cursor_rect.y + self.y + 16
  400.        bottom_x = top_x + self.cursor_rect.width
  401.        bottom_y = top_y + self.cursor_rect.height
  402.        if (mouse_x > top_x) and (mouse_y > top_y) and
  403.           (mouse_x < bottom_x) and (mouse_y < bottom_y)
  404.          mouse_not_in_rect = false
  405.          break
  406.        end
  407.      end
  408.      if mouse_not_in_rect
  409.        @index = index_var
  410.        update_cursor_rect
  411.        Mouse.click_lock
  412.      else
  413.        Mouse.click_unlock
  414.      end
  415.    end
  416. end
  417. end
  418. class Window_InputNumber
  419. if @self_alias == nil
  420.    alias self_update update
  421.    @self_alias = true
  422. end
  423. def update
  424.    self_update
  425.    mouse_x, mouse_y = Mouse.get_mouse_pos
  426.    if self.active and @digits_max > 0
  427.      index_var = @index
  428.      mouse_not_in_rect = true
  429.      for i in 0...@digits_max
  430.        @index = i
  431.        update_cursor_rect
  432.        top_x = self.cursor_rect.x + self.x + 16
  433.        bottom_x = top_x + self.cursor_rect.width
  434.        if (mouse_x > top_x) and (mouse_x < bottom_x)
  435.          mouse_not_in_rect = false
  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.    if @last_mouse_y == nil
  448.      @last_mouse_y = mouse_y
  449.    end
  450.    check_pos = (@last_mouse_y - mouse_y).abs
  451.    if check_pos > 10
  452.      $game_system.se_play($data_system.cursor_se)
  453.      place = 10 ** (@digits_max - 1 - @index)
  454.      n = @number / place % 10
  455.      @number -= n * place
  456.      n = (n + 1) % 10 if mouse_y < @last_mouse_y
  457.      n = (n + 9) % 10 if mouse_y > @last_mouse_y
  458.      @number += n * place
  459.      refresh
  460.      @last_mouse_y = mouse_y
  461.    end
  462. end
  463. end
  464. class Scene_File
  465. if @self_alias == nil
  466.    alias self_update update
  467.    @self_alias = true
  468. end
  469. def update
  470.    mouse_x, mouse_y = Mouse.get_mouse_pos
  471.    Mouse.click_lock
  472.    idx = 0
  473.    for i in @savefile_windows
  474.      top_x = i.x + 16
  475.      top_y = i.y + 16
  476.      bottom_x = top_x + i.width
  477.      bottom_y = top_y + i.height
  478.      if (mouse_x > top_x) and (mouse_y > top_y) and
  479.         (mouse_x < bottom_x) and (mouse_y < bottom_y)
  480.        i.selected = true
  481.        if @file_index != idx
  482.          @file_index = idx
  483.          $game_system.se_play($data_system.cursor_se)
  484.        end            
  485.        Mouse.click_unlock
  486.      else
  487.        i.selected = false
  488.      end
  489.      idx += 1
  490.    end
  491.    self_update
  492. end
  493. end
  494. class Arrow_Enemy
  495. if @self_alias == nil
  496.    alias self_update update
  497.    @self_alias = true
  498. end
  499. def update
  500.    mouse_x, mouse_y = Mouse.get_mouse_pos
  501.    idx = 0
  502.    for i in $game_troop.enemies do
  503.      if i.exist?
  504.        top_x = i.screen_x - self.ox
  505.        top_y = i.screen_y - self.oy
  506.        bottom_x = top_x + self.src_rect.width
  507.        bottom_y = top_y + self.src_rect.height
  508.        if (mouse_x > top_x - $敌人选框扩大) and (mouse_y > top_y - $敌人选框扩大) and
  509.           (mouse_x < bottom_x + $敌人选框扩大) and (mouse_y < bottom_y + $敌人选框扩大)
  510.          if @index != idx
  511.            $game_system.se_play($data_system.cursor_se)
  512.            @index = idx
  513.          end
  514.        end
  515.      end
  516.      idx += 1
  517.    end
  518.    self_update
  519. end
  520. end
  521. class Arrow_Actor
  522. if @self_alias == nil
  523.    alias self_update update
  524.    @self_alias = true
  525. end
  526. def update
  527.    mouse_x, mouse_y = Mouse.get_mouse_pos
  528.    idx = 0
  529.    for i in $game_party.actors do
  530.      if i.exist?
  531.        top_x = i.screen_x - self.ox
  532.        top_y = i.screen_y - self.oy
  533.        bottom_x = top_x + self.src_rect.width
  534.        bottom_y = top_y + self.src_rect.height
  535.        if (mouse_x > top_x - $角色选框扩大) and (mouse_y > top_y - $角色选框扩大) and
  536.           (mouse_x < bottom_x + $角色选框扩大) and (mouse_y < bottom_y + $角色选框扩大)
  537.          if @index != idx
  538.            $game_system.se_play($data_system.cursor_se)
  539.            @index = idx
  540.          end
  541.        end
  542.      end
  543.      idx += 1
  544.    end
  545.    self_update
  546. end
  547. end
  548. #==============================================================================
  549. # ■ Game_Player
  550. #------------------------------------------------------------------------------
  551. #  处理主角的类。事件启动的判定、以及地图的滚动等功能。
  552. # 本类的实例请参考 $game_player。
  553. #   鼠标控制角色的主程序
  554. #==============================================================================
  555. class Game_Player
  556. if @self_alias == nil
  557.    alias self_update update
  558.    @self_alias = true
  559. end
  560. #--------------------------------------------------------------------------
  561. # ● 得到鼠标的状态
  562. #--------------------------------------------------------------------------
  563. def get_mouse_sta
  564.    return @mouse_sta
  565. end
  566. #--------------------------------------------------------------------------
  567. # ● 完整鼠标系统
  568. #--------------------------------------------------------------------------
  569. def update
  570.    mouse_x, mouse_y = Mouse.get_mouse_pos
  571.    @mtp_x = mouse_x
  572.    @mtp_y = mouse_y
  573.    unless $game_system.map_interpreter.running? and @mouse_sta == 2 #鼠标状态不为跟随状态
  574.      #得到鼠标图标方向
  575.      $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)
  576.    else
  577.      #令鼠标图标为正常
  578.      $mouse_icon_id = 0 if @mouse_sta != 2
  579.    end
  580.  
  581.    #单击鼠标时进行判断寻路或跟随
  582.    if Mouse.trigger?(Mouse::LEFT) #当点击鼠标时
  583.      unless $game_system.map_interpreter.running? or
  584.             @move_route_forcing or $game_temp.message_window_showing #各种无效情况的排除
  585.        #初始化
  586.        @mouse_sta = 1
  587.        p_direction = 5
  588.        #检查鼠标处能否开启事件
  589.        event_start,p_direction = $game_map.check_event_custom_start(mouse_x, mouse_y)
  590.        #若在移动中再次点击鼠标左键(即双击左键),则改鼠标状态为跟随状态
  591.        @mouse_sta = 2 if @paths_id != nil and @paths_id != @paths.size
  592.        if @mouse_sta != 2
  593.          #鼠标状态不为跟随状态则取数据并初始化路径
  594.          trg_x = (mouse_x + $game_map.display_x / 4) / 32
  595.          trg_y = (mouse_y + $game_map.display_y / 4) / 32
  596.          @paths = []
  597.          @paths_id = 0
  598.          if event_start == 0 #若不能开启事件
  599.            if trg_x != $game_player.x or trg_y != $game_player.y #若目标不为自身则开始寻路
  600.              find_path = Find_Path.new
  601.              @paths = find_path.find_player_short_path(trg_x, trg_y, @mtp_x, @mtp_y)
  602.            end
  603.          else #若能开启事件则改变角色朝向
  604.            @direction = p_direction
  605.          end
  606.        end
  607.      end
  608.    end
  609.  
  610.    #开始移动
  611.    if @mouse_sta != nil and @mouse_sta == 1 #若鼠标状态为寻路状态
  612.      unless moving? or $game_system.map_interpreter.running? or
  613.             @move_route_forcing or $game_temp.message_window_showing #排除无效情况
  614.        if @paths_id != nil and @paths != nil and @paths_id <= @paths.size #若没有完成路径
  615.          case @paths[@paths_id] #判断路径
  616.          when 6
  617.            @last_move_x = true
  618.            move_right
  619.            @paths_id += 1
  620.            @direction = 6
  621.          when 4
  622.            @last_move_x = true
  623.            move_left
  624.            @paths_id += 1
  625.            @direction = 4
  626.          when 2
  627.            @last_move_x = false
  628.            move_down
  629.            @direction = 2
  630.            @paths_id += 1
  631.          when 8
  632.            @last_move_x = false
  633.            move_up
  634.            @direction = 8
  635.            @paths_id += 1
  636.          #斜四方向
  637.          when 1
  638.            @last_move_x = false
  639.            move_lower_left
  640.            @direction = 1
  641.            @paths_id += 1
  642.          when 3
  643.            @last_move_x = false
  644.            move_lower_right
  645.            @direction = 3
  646.            @paths_id += 1
  647.          when 7
  648.            @last_move_x = false
  649.            move_upper_left
  650.            @direction = 7
  651.            @paths_id += 1
  652.          when 9
  653.            @last_move_x = false
  654.            move_upper_right
  655.            @direction = 9
  656.            @paths_id += 1
  657.          end
  658.        end
  659.      end
  660.    elsif @paths != nil and @mouse_sta == 2 #当鼠标状态为跟随,且在移动中
  661.      if Mouse.press?(Mouse::LEFT) #持续按住鼠标
  662.        unless moving? or $game_system.map_interpreter.running? or
  663.               @move_route_forcing or $game_temp.message_window_showing #排除无效情况
  664.          #跟随方向判断并跟随
  665.          rate =  $game_map.show_rate(self)
  666.          width = (RPG::Cache.character(self.character_name,self.character_hue).width / $c3_每一步的帧数) * rate
  667.          height = (RPG::Cache.character(self.character_name,self.character_hue).height / 8) * rate
  668.          self_ox = (self.screen_x - width / 2 + self.screen_x + width / 2) / 2
  669.          self_oy = (self.screen_y - height + self.screen_y) / 2
  670.          #self_ox = self.screen_x
  671.          #self_oy = self.screen_y
  672.          if (@mtp_x - self_ox)*(@mtp_x - self_ox) + (@mtp_y - self_oy)*(@mtp_y - self_oy) >= 961
  673.            if @mtp_x > self_ox
  674.              if self_oy - @mtp_y < 0.4 * (@mtp_x - self_ox) and
  675.                 @mtp_y - self_oy < 0.4 * (@mtp_x - self_ox)
  676.                move_right
  677.                $mouse_icon_id = 16
  678.                @direction = 6
  679.              end
  680.              if @mtp_y - self_oy > - 0.4 * ( self_ox - @mtp_x ) and
  681.                 @mtp_y - self_oy < - 2.4 * ( self_ox - @mtp_x )
  682.                move_lower_right
  683.                $mouse_icon_id = 13
  684.                @direction = 3
  685.              end
  686.              if @mtp_y - self_oy < 0.4 * ( self_ox - @mtp_x ) and
  687.                 @mtp_y - self_oy > 2.4 * ( self_ox - @mtp_x )
  688.                move_upper_right
  689.                $mouse_icon_id = 19
  690.                @direction = 9
  691.              end
  692.              if @mtp_y - self_oy > 2.4 * ( @mtp_x - self_ox )
  693.                move_down
  694.                $mouse_icon_id = 12
  695.                @direction = 2
  696.              end
  697.              if @mtp_y - self_oy < - 2.4 * ( @mtp_x - self_ox )
  698.                move_up
  699.                $mouse_icon_id = 18
  700.                @direction = 8
  701.              end
  702.            end
  703.            if @mtp_x < self_ox
  704.              if @mtp_y - self_oy > - 0.4 * ( self_ox - @mtp_x ) and
  705.                 @mtp_y - self_oy < 0.4 * ( self_ox - @mtp_x )
  706.                move_left
  707.                $mouse_icon_id = 14
  708.                @direction = 4
  709.              end
  710.              if @mtp_y - self_oy > 0.4 * ( self_ox - @mtp_x ) and
  711.                 @mtp_y - self_oy < 2.4 * ( self_ox - @mtp_x )
  712.                move_lower_left
  713.                $mouse_icon_id = 11
  714.                @direction = 1
  715.              end
  716.              if @mtp_y - self_oy < - 0.4 * ( self_ox - @mtp_x ) and
  717.                 @mtp_y - self_oy > - 2.4 * ( self_ox - @mtp_x )
  718.                move_upper_left
  719.                $mouse_icon_id = 17
  720.                @direction = 7
  721.              end
  722.              if @mtp_y - self_oy > 2.4 * ( self_ox - @mtp_x )
  723.                move_down
  724.                $mouse_icon_id = 12
  725.                @direction = 2
  726.              end
  727.              if @mtp_y - self_oy < - 2.4 * ( self_ox - @mtp_x )
  728.                move_up
  729.                $mouse_icon_id = 18
  730.                @direction = 8
  731.              end
  732.            end
  733.          end
  734.            #...................................................................
  735.            if @mtp_x > self_ox
  736.              if @mtp_y - self_oy > - 0.4 * ( @mtp_x - self_ox ) and
  737.                 @mtp_y - self_oy < 0.4 * ( @mtp_x - self_ox )
  738.                $mouse_icon_id = 16
  739.                @direction = 6
  740.              end
  741.              if @mtp_y - self_oy > 0.4 * ( @mtp_x - self_ox ) and
  742.                @mtp_y - self_oy < 2.4 * ( @mtp_x - self_ox )
  743.                $mouse_icon_id = 13
  744.                @direction = 3
  745.              end
  746.              if @mtp_y - self_oy < - 0.4 * ( @mtp_x - self_ox ) and
  747.                @mtp_y - self_oy > - 2.4 * ( @mtp_x - self_ox )
  748.                $mouse_icon_id = 19
  749.                @direction = 9
  750.              end
  751.              if @mtp_y - self_oy > 2.4 * ( @mtp_x - self_ox )
  752.                $mouse_icon_id = 12
  753.                @direction = 2
  754.              end
  755.              if @mtp_y - self_oy < - 2.4 * ( @mtp_x - self_ox )
  756.                $mouse_icon_id = 18
  757.                @direction = 8
  758.              end
  759.            end
  760.            if @mtp_x < self_ox
  761.              if @mtp_y - self_oy > - 0.4 * ( self_ox - @mtp_x ) and
  762.                 @mtp_y - self_oy < 0.4 * ( self_ox - @mtp_x )
  763.                $mouse_icon_id = 14
  764.                @direction = 4
  765.              end
  766.              if @mtp_y - self_oy > 0.4 * ( self_ox - @mtp_x ) and
  767.                 @mtp_y - self_oy < 2.4 * ( self_ox - @mtp_x )
  768.                $mouse_icon_id = 11
  769.                @direction = 1
  770.              end
  771.              if @mtp_y - self_oy < - 0.4 * ( self_ox - @mtp_x ) and
  772.                 @mtp_y - self_oy > - 2.4 * ( self_ox - @mtp_x )
  773.                $mouse_icon_id = 17
  774.                @direction = 7
  775.              end
  776.              if @mtp_y - self_oy > 2.4 * ( self_ox - @mtp_x )
  777.                $mouse_icon_id = 12
  778.                @direction = 2
  779.              end
  780.              if @mtp_y - self_oy < - 2.4 * ( self_ox - @mtp_x )
  781.                $mouse_icon_id = 18
  782.                @direction = 8
  783.              end
  784.            end
  785.            #...................................................................
  786.        end
  787.      else #没状态的情况
  788.        $mouse_icon_id = 0
  789.        @mouse_sta = 0
  790.        @paths_id = @paths.size #终止寻路移动
  791.      end
  792.    end
  793.    self_update
  794. end
  795. end
  796. Mouse.init
  797. END { Mouse.exit }

作者: kuerlulu    时间: 2015-7-8 14:11
https://rpg.blue/thread-321278-1-1.html
https://rpg.blue/thread-254033-1-1.html
作者: Fan723    时间: 2015-7-8 21:37
谢谢!这两个帖子我都看过了,可是解决不了问题,出现同样错误:

作者: 妖精蕾贝卡    时间: 2015-7-8 22:17
完整鼠标系统(八方向).zip (526.39 KB, 下载次数: 123)
這個範例應該可以參考一下。
作者: Fan723    时间: 2015-7-8 22:35
非常感谢!总算还没发现报错!




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