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

Project1

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

[已经解决] 我这个脚本如何寻路,请高手修改,我的是四方向行走图

[复制链接]

Lv1.梦旅人

梦石
0
星屑
50
在线时间
83 小时
注册时间
2011-3-21
帖子
119
跳转到指定楼层
1
发表于 2012-4-22 11:54:50 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 eve592370698 于 2012-4-27 09:37 编辑
  1. ==============================================================================
  2. # 本脚本来自[url]www.66RPG.com[/url],使用和转载请保留此信息
  3. #==============================================================================

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


  7. #==============================================================================
  8. # API调用
  9. #==============================================================================
  10. $ShowCursor = Win32API.new("user32", "ShowCursor", 'i', 'l')
  11. $GetCursorPos = Win32API.new("user32", "GetCursorPos", 'p', 'i')
  12. $ScreenToClient = Win32API.new("user32", "ScreenToClient", 'ip', 'i')
  13. $GetActiveWindow = Win32API.new("user32", "GetActiveWindow", nil, 'l')
  14. $Window_HWND = $GetActiveWindow.call
  15. $GetKeyState = Win32API.new("user32", "GetKeyState", 'i', 'i')
  16. #$FindWindow = Win32API.new("user32", "FindWindow", 'pp', 'i')
  17. #$HookStart  = Win32API.new("mouse_hook.dll", "HookStart", 'i', nil)
  18. #$HookEnd  = Win32API.new("mouse_hook.dll", "HookEnd", nil, nil)
  19. #$GetMouseStatus  = Win32API.new("mouse_hook.dll", "GetMouseStatus", 'i', 'i')
  20. #$Window_HWND = $FindWindow.call(nil, 'mousetry')

  21. module Mouse  
  22.   LEFT = 0x01
  23.   RIGHT = 0x02
  24.   attr_accessor :sbxx
  25.   attr_accessor :sbxy

  26.   def self.init(sprite = nil)
  27. #   $HookStart.call($Window_HWND)
  28.     $ShowCursor.call(0)
  29.    
  30.     @show_cursor = false
  31.    
  32.     @mouse_sprite = Sprite.new
  33.     @mouse_sprite.z = 99999
  34.     @sbxx = 0
  35.     @sbxy = 0
  36.     @mouse_sprite.bitmap = Bitmap.new('data/Base/shubiao.png')
  37.     #@mouse_sprite.bitmap.fill_rect(Rect.new(0, 0, 32, 32), Color.new(0, 0, 0))

  38.     @left_press = false
  39.     @right_press = false
  40.     @left_trigger = false
  41.     @right_trigger = false
  42.     @left_repeat = false
  43.     @right_repeat = false
  44.     @click_lock = false
  45.    
  46.     update
  47.   end
  48.   def self.exit
  49.     @mouse_sprite.bitmap.dispose
  50.     @mouse_sprite.dispose
  51.     @show_cursor = true
  52. #    $HookEnd.call
  53.     $ShowCursor.call(1)
  54.   end
  55.   def self.mouse_debug
  56.     return @mouse_debug.bitmap
  57.   end
  58.   def self.update
  59.     left_down = $GetKeyState.call(0x01)
  60.     right_down = $GetKeyState.call(0x02)
  61.    
  62.     @click_lock = false
  63.     mouse_x, mouse_y = self.get_mouse_pos
  64.     if @mouse_sprite != nil
  65.       @mouse_sprite.x = mouse_x
  66.       @mouse_sprite.y = mouse_y
  67.       @sbxx = mouse_x
  68.       @sbxy = mouse_y
  69.     end
  70.     if left_down[7] == 1
  71.       @left_repeat = (not @left_repeat)
  72.       @left_trigger = (not @left_press)
  73.       @left_press = true
  74.     else
  75.       @left_press = false
  76.       @left_trigger = false
  77.       @left_repeat = false
  78.     end
  79.     if right_down[7] == 1
  80.       @right_repeat = (not @right_repeat)
  81.       @right_trigger = (not @right_press)
  82.       @right_press = true
  83.     else
  84.       @right_press = false
  85.       @right_trigger = false
  86.       @right_repeat = false
  87.     end
  88.   end
  89.   def self.get_mouse_pos
  90.     point_var = [0, 0].pack('ll')
  91.     if $GetCursorPos.call(point_var) != 0
  92.       if $ScreenToClient.call($Window_HWND, point_var) != 0
  93.         x, y = point_var.unpack('ll')
  94.         if (x < 0) or (x > 10000) then x = 0 end
  95.         if (y < 0) or (y > 10000) then y = 0 end
  96.         if x > 640 then x = 640 end
  97.         if y > 480 then y = 480 end
  98.         return x, y
  99.       else
  100.         return 0, 0
  101.       end
  102.     else
  103.       return 0, 0
  104.     end
  105.   end
  106.   def self.press?(mouse_code)
  107.     if mouse_code == LEFT
  108.       if @click_lock
  109.         return false
  110.       else
  111.         return @left_press
  112.       end
  113.     elsif mouse_code == RIGHT
  114.       return @right_press
  115.     else
  116.       return false
  117.     end
  118.   end
  119.   def self.trigger?(mouse_code)
  120.     if mouse_code == LEFT
  121.       if @click_lock
  122.         return false
  123.       else
  124.         return @left_trigger
  125.       end
  126.     elsif mouse_code == RIGHT
  127.       return @right_trigger
  128.     else
  129.       return false
  130.     end
  131.   end
  132.   def self.repeat?(mouse_code)
  133.     if mouse_code == LEFT
  134.       if @click_lock
  135.         return false
  136.       else
  137.         return @left_repeat
  138.       end
  139.     elsif mouse_code == RIGHT
  140.       return @right_repeat
  141.     else
  142.       return false
  143.     end
  144.   end
  145.   def self.click_lock?
  146.     return @click_lock
  147.   end
  148.   def self.click_lock
  149.     @click_lock = true
  150.   end
  151.   def self.click_unlock
  152.     @click_lock = false
  153.   end
  154. end
  155. module Input
  156.   if @self_update == nil
  157.     @self_update = method('update')
  158.     @self_press = method('press?')
  159.     @self_trigger = method('trigger?')
  160.     @self_repeat = method('repeat?')
  161.   end
  162.   def self.update
  163.     @self_update.call
  164.     Mouse.update
  165.   end
  166.   def self.press?(key_code)
  167.     if @self_press.call(key_code)
  168.       return true
  169.     end
  170.     if key_code == C
  171.       return Mouse.press?(Mouse::LEFT)
  172.     elsif key_code == B
  173.       return Mouse.press?(Mouse::RIGHT)
  174.     else
  175.       return @self_press.call(key_code)
  176.     end
  177.   end
  178.   def self.trigger?(key_code)
  179.     if @self_trigger.call(key_code)
  180.       return true
  181.     end
  182.     if key_code == C
  183.       return Mouse.trigger?(Mouse::LEFT)
  184.     elsif key_code == B
  185.       return Mouse.trigger?(Mouse::RIGHT)
  186.     else
  187.       return @self_trigger.call(key_code)
  188.     end
  189.   end
  190.   def self.repeat?(key_code)
  191.     if @self_repeat.call(key_code)
  192.       return true
  193.     end
  194.     if key_code == C
  195.       return Mouse.repeat?(Mouse::LEFT)
  196.     elsif key_code == B
  197.       return Mouse.repeat?(Mouse::RIGHT)
  198.     else
  199.       return @self_repeat.call(key_code)
  200.     end
  201.   end
  202. end
  203. class Window_Selectable
  204.   if @self_alias == nil
  205.     alias self_update update
  206.     @self_alias = true
  207.   end
  208.   def update
  209.     #self.cursor_rect.empty
  210.     self_update
  211.     if self.active and @item_max > 0
  212.       index_var = @index
  213.       tp_index = @index
  214.       mouse_x, mouse_y = Mouse.get_mouse_pos
  215.       mouse_not_in_rect = true
  216.       for i in 0...@item_max
  217.         @index = i
  218.         update_cursor_rect
  219.         top_x = self.cursor_rect.x + self.x + 16
  220.         top_y = self.cursor_rect.y + self.y + 16
  221.         bottom_x = top_x + self.cursor_rect.width
  222.         bottom_y = top_y + self.cursor_rect.height
  223.         if (mouse_x > top_x) and (mouse_y > top_y) and
  224.            (mouse_x < bottom_x) and (mouse_y < bottom_y)
  225.           mouse_not_in_rect = false
  226.           if tp_index != @index
  227.             tp_index = @index
  228.             $game_system.se_play($data_system.cursor_se)
  229.           end
  230.           break
  231.         end
  232.       end
  233.       if mouse_not_in_rect
  234.         @index = index_var
  235.         update_cursor_rect
  236.         Mouse.click_lock
  237.       else
  238.         Mouse.click_unlock               
  239.       end
  240.     end
  241.   end
  242. end
  243. class Window_NameInput
  244.   if @self_alias == nil
  245.     alias self_update update
  246.     @self_alias = true
  247.   end
  248.   def update
  249.     #self.cursor_rect.empty
  250.     self_update
  251.     if self.active
  252.       index_var = @index
  253.       mouse_x, mouse_y = Mouse.get_mouse_pos
  254.       mouse_not_in_rect = true
  255.       for i in (0...CHARACTER_TABLE.size).to_a.push(180)
  256.         @index = i
  257.         update_cursor_rect
  258.         top_x = self.cursor_rect.x + self.x + 16
  259.         top_y = self.cursor_rect.y + self.y + 16
  260.         bottom_x = top_x + self.cursor_rect.width
  261.         bottom_y = top_y + self.cursor_rect.height
  262.         #
  263.         if (mouse_x > top_x) and (mouse_y > top_y) and
  264.            (mouse_x < bottom_x) and (mouse_y < bottom_y)
  265.           mouse_not_in_rect = false
  266.           break
  267.         end
  268.       end
  269.       if mouse_not_in_rect
  270.         @index = index_var
  271.         update_cursor_rect
  272.         Mouse.click_lock
  273.       else
  274.         Mouse.click_unlock
  275.       end
  276.     end
  277.   end
  278. end
  279. class Window_InputNumber
  280.   if @self_alias == nil
  281.     alias self_update update
  282.     @self_alias = true
  283.   end
  284.   def update
  285.     #self.cursor_rect.empty
  286.     self_update
  287.     mouse_x, mouse_y = Mouse.get_mouse_pos
  288.     if self.active and @digits_max > 0
  289.       index_var = @index
  290.       mouse_not_in_rect = true
  291.       for i in 0...@digits_max
  292.         @index = i
  293.         update_cursor_rect
  294.         top_x = self.cursor_rect.x + self.x + 16
  295.         bottom_x = top_x + self.cursor_rect.width
  296.         #
  297.         if (mouse_x > top_x) and (mouse_x < bottom_x)
  298.           mouse_not_in_rect = false
  299.           break
  300.         end
  301.       end
  302.       if mouse_not_in_rect
  303.         @index = index_var
  304.         update_cursor_rect
  305.         Mouse.click_lock
  306.       else
  307.         Mouse.click_unlock
  308.       end
  309.     end
  310.     if @last_mouse_y == nil
  311.       @last_mouse_y = mouse_y
  312.     end
  313.     check_pos = (@last_mouse_y - mouse_y).abs
  314.     if check_pos > 10
  315.       $game_system.se_play($data_system.cursor_se)
  316.       place = 10 ** (@digits_max - 1 - @index)
  317.       n = @number / place % 10
  318.       @number -= n * place
  319.       n = (n + 1) % 10 if mouse_y < @last_mouse_y
  320.       n = (n + 9) % 10 if mouse_y > @last_mouse_y
  321.       @number += n * place
  322.       refresh
  323.       @last_mouse_y = mouse_y
  324.     end
  325.   end
  326. end
  327. class Scene_File
  328.   if @self_alias == nil
  329.     alias self_update update
  330.     @self_alias = true
  331.   end
  332.   def update
  333.     mouse_x, mouse_y = Mouse.get_mouse_pos
  334.     Mouse.click_lock
  335.     idx = 0
  336.     for i in @savefile_windows
  337.       top_x = i.x + 16
  338.       top_y = i.y + 16
  339.       bottom_x = top_x + i.width
  340.       bottom_y = top_y + i.height
  341.       if (mouse_x > top_x) and (mouse_y > top_y) and
  342.          (mouse_x < bottom_x) and (mouse_y < bottom_y)
  343.         i.selected = true
  344.         if @file_index != idx
  345.           @file_index = idx
  346.           $game_system.se_play($data_system.cursor_se)
  347.         end            
  348.         Mouse.click_unlock
  349.       else
  350.         i.selected = false
  351.       end
  352.       idx += 1
  353.     end
  354.     self_update
  355.   end
  356. end
  357. class Game_Player
  358.   if @self_alias == nil
  359.     alias self_update update
  360.     @self_alias = true
  361.   end
  362.   def update
  363.     mouse_x, mouse_y = Mouse.get_mouse_pos

  364.     if @last_move_x == nil
  365.       @last_move_x = false
  366.     end
  367.     if Mouse.press?(Mouse::LEFT)
  368.       last_moving = moving?
  369.       last_direction = @direction
  370.       unless moving? or $game_system.map_interpreter.running? or
  371.              @move_route_forcing or $game_temp.message_window_showing
  372.         last_x = @x
  373.         if @last_move_x
  374.           @last_move_x = false
  375.         elsif mouse_x > screen_x + 16
  376.       #    move_right
  377.         elsif mouse_x < screen_x - 16
  378.     #      move_left
  379.         end
  380.         last_y = @y
  381.         if last_x != @x
  382.           @last_move_x = true
  383.         elsif mouse_y > screen_y
  384.          # move_down
  385.         elsif mouse_y < screen_y - 32
  386.          # move_up
  387.         end
  388.         if last_y != @y
  389.           @last_move_x = false
  390.         elsif not @last_move_x
  391.           case last_direction
  392.           when 2
  393.       #      turn_down
  394.           when 4
  395.     #        turn_left
  396.           when 6
  397.      #       turn_right
  398.           when 8
  399.        #     turn_up
  400.           end
  401.         end
  402.       end
  403.     end
  404.     self_update
  405.   end
  406. end
  407. Mouse.init
  408. END { Mouse.exit }




  409. #==============================================================================
  410. # 本脚本来自[url]www.66RPG.com[/url],使用和转载请保留此信息
  411. #==============================================================================
复制代码

点评

给您本月最后期限,下个月可要统一处理了!  发表于 2012-4-27 09:38
你发上来的是鼠标脚本,不是寻路脚本  发表于 2012-4-22 12:20

Lv2.观梦者

梦石
0
星屑
687
在线时间
791 小时
注册时间
2011-10-20
帖子
2394

开拓者

2
发表于 2012-4-22 12:09:10 | 只看该作者
用A*,然后算
回复

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-10-1 23:45

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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