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

Project1

 找回密码
 注册会员
搜索
查看: 18871|回复: 39

[原创发布] 真·RMXP分辨率拓展

[复制链接]

Lv3.寻梦者

梦石
0
星屑
3710
在线时间
1960 小时
注册时间
2013-1-3
帖子
9525
发表于 2014-4-26 06:03:52 | 显示全部楼层 |阅读模式

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

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

x
本帖最后由 紫英晓狼1130 于 2015-6-21 18:59 编辑

介绍
这是一直想要的一个功能,在今天终于实现了
脚本主要来源于癫狂侠客的DKRM,自己稍作修改
所有的窗口类没有改动,使用前请注意
范例里默认的窗口大小是800*600,当然可以改动
取消全屏已经修改,同时Enter键也可以使用
分辨率越大,FPS降得越快,这不可避免
有什么不懂的,欢迎大家向我提问,谢谢
经测试,该方法仍有缺漏

图片
未标题-1.jpg

下载
真·RMXP分辨率拓展.rar (779.6 KB, 下载次数: 2254)

点评

不能全屏  发表于 2016-12-1 23:05
更新了我的问题。。哪里能修改天气加强脚本精灵的width和height。。viewport吗?如果lz能帮忙解决私人赠送1~2v。。  发表于 2014-4-26 19:00

评分

参与人数 1星屑 +20 收起 理由
日月星辰 + 20 精品文章

查看全部评分

《宿愿·寻剑篇》正式版已经发布!快去看看!点击进入论坛发布贴

Lv2.观梦者

梦石
0
星屑
319
在线时间
890 小时
注册时间
2009-10-12
帖子
1829
发表于 2014-4-26 08:29:55 | 显示全部楼层
本帖最后由 日月星辰 于 2014-4-26 09:07 编辑

lz。。为什么除了禁止全屏键。。连enter键业禁止了。。。我只能按c进入游戏=~=

呃。。enter变成space了怎么、、我还是要enter~

点评

主楼enter已修复  发表于 2014-4-26 18:19
回复 支持 反对

使用道具 举报

Lv6.析梦学徒

Fuzzy Ginkgo
Taciturn Knight

梦石
0
星屑
59775
在线时间
1933 小时
注册时间
2010-6-26
帖子
1605

烫烫烫开拓者

发表于 2014-4-26 10:43:33 | 显示全部楼层
哎,原来只是自己写了一个 Tilemap。我还以为终于有人把内置 Tilemap 黑掉了……
我的言论只代表我个人的观点,不代表雇主及/或任何第三方的立场。
Opinions expressed are solely my own and do not express the views or opinions of my employer and/or any third parties.
捐赠 | GitHub
回复 支持 反对

使用道具 举报

Lv2.观梦者

梦石
0
星屑
319
在线时间
890 小时
注册时间
2009-10-12
帖子
1829
发表于 2014-4-26 17:23:35 | 显示全部楼层
本帖最后由 日月星辰 于 2014-4-26 18:59 编辑

屏幕截图(54).png

天气脚本.rar (789.74 KB, 下载次数: 292)
回复 支持 反对

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
7921
在线时间
1049 小时
注册时间
2012-4-3
帖子
1271

开拓者

发表于 2014-4-27 03:54:48 手机端发表。 | 显示全部楼层
窗口扩大,帧率下降很明显的,这样就不适用互动性强烈的游戏了。
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
3710
在线时间
1960 小时
注册时间
2013-1-3
帖子
9525
 楼主| 发表于 2014-4-27 17:15:35 | 显示全部楼层
本帖最后由 紫英晓狼1130 于 2014-4-27 17:18 编辑
日月星辰 发表于 2014-4-26 17:23
800*600不明显 看截图我是1024*576

已更新附件。。加入的天气脚本很想使用。。但需要修改=~= ...


昨天论坛太慢,就没去看
真·RMXP分辨率拓展.rar (789.96 KB, 下载次数: 553)

点评

好顶赞 谢谢  发表于 2014-4-27 17:24
《宿愿·寻剑篇》正式版已经发布!快去看看!点击进入论坛发布贴
回复 支持 反对

使用道具 举报

Lv2.观梦者

梦石
0
星屑
319
在线时间
890 小时
注册时间
2009-10-12
帖子
1829
发表于 2014-4-27 17:19:16 | 显示全部楼层
紫英晓狼1130 发表于 2014-4-27 17:15
昨天论坛太慢,就没去看

已转账2vip
回复 支持 反对

使用道具 举报

Lv3.寻梦者

○赛

梦石
0
星屑
1249
在线时间
1276 小时
注册时间
2013-1-22
帖子
2246

贵宾

发表于 2014-4-27 17:26:48 | 显示全部楼层
恩。。支持鼠标脚本吗?

点评

支持  发表于 2014-4-27 17:54
回复 支持 反对

使用道具 举报

Lv2.观梦者

梦石
0
星屑
432
在线时间
4175 小时
注册时间
2010-6-26
帖子
6474
发表于 2014-4-27 19:48:23 | 显示全部楼层
Im剑侠客 发表于 2014-4-27 03:54
窗口扩大,帧率下降很明显的,这样就不适用互动性强烈的游戏了。

癫狂侠客的这种方案,使用像河流、海水那样动态自动元件会掉帧,但是不会因为事件过多而掉帧。
@不是马甲 的优化方案正好相反……
潜水,专心忙活三次元工作了……
回复 支持 反对

使用道具 举报

Lv3.寻梦者

○赛

梦石
0
星屑
1249
在线时间
1276 小时
注册时间
2013-1-22
帖子
2246

贵宾

发表于 2014-4-30 20:05:24 | 显示全部楼层
依旧无法兼容鼠标系统…………
能否尝试一下?
这是我的鼠标脚本:
  1. #========================================================================
  2. # 本脚本来自www.66RPG.com,使用和转载请保留此信息
  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.   def self.init(sprite = nil)
  25.     #   $HookStart.call($Window_HWND)
  26.     $ShowCursor.call(0)
  27.    
  28.     @show_cursor = false
  29.    
  30.     @mouse_sprite = Sprite.new
  31.     @mouse_sprite.z = 99999
  32.     @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/001-Weapon01.png')
  33.     #@mouse_sprite.bitmap.fill_rect(Rect.new(0, 0, 32, 32), Color.new(0, 0, 0))
  34.     @left_press = false
  35.     @right_press = false
  36.     @left_trigger = false
  37.     @right_trigger = false
  38.     @left_repeat = false
  39.     @right_repeat = false
  40.     @click_lock = false
  41.    
  42.     update
  43.   end
  44.   def self.exit
  45.     @mouse_sprite.bitmap.dispose
  46.     @mouse_sprite.dispose
  47.     @show_cursor = true
  48.     #    $HookEnd.call
  49.     $ShowCursor.call(1)
  50.   end
  51.   def self.mouse_debug
  52.     return @mouse_debug.bitmap
  53.   end
  54.   def self.update
  55.     left_down = $GetKeyState.call(0x01)
  56.     right_down = $GetKeyState.call(0x02)
  57.    
  58.     @click_lock = false
  59.     mouse_x, mouse_y = self.get_mouse_pos
  60.     if @mouse_sprite != nil
  61.       @mouse_sprite.x = mouse_x
  62.       @mouse_sprite.y = mouse_y
  63.     end
  64.     if left_down[7] == 1
  65.       @left_repeat = (not @left_repeat)
  66.       @left_trigger = (not @left_press)
  67.       @left_press = true
  68.     else
  69.       @left_press = false
  70.       @left_trigger = false
  71.       @left_repeat = false
  72.     end
  73.     if right_down[7] == 1
  74.       @right_repeat = (not @right_repeat)
  75.       @right_trigger = (not @right_press)
  76.       @right_press = true
  77.     else
  78.       @right_press = false
  79.       @right_trigger = false
  80.       @right_repeat = false
  81.     end
  82.   end
  83.   def self.get_mouse_pos
  84.     point_var = [0, 0].pack('ll')
  85.     if $GetCursorPos.call(point_var) != 0
  86.       if $ScreenToClient.call($Window_HWND, point_var) != 0
  87.         x, y = point_var.unpack('ll')
  88.         if (x < 0) or (x > 10000) then x = 0 end
  89.         if (y < 0) or (y > 10000) then y = 0 end
  90.         if x > 1024 then x = 704 end
  91.         if y > 1024 then y = 704 end
  92.         return x, y
  93.       else
  94.         return 0, 0
  95.       end
  96.     else
  97.       return 0, 0
  98.     end
  99.   end
  100.   def self.press?(mouse_code)
  101.     if mouse_code == LEFT
  102.       if @click_lock
  103.         return false
  104.       else
  105.         return @left_press
  106.       end
  107.     elsif mouse_code == RIGHT
  108.       return @right_press
  109.     else
  110.       return false
  111.     end
  112.   end
  113.   def self.trigger?(mouse_code)
  114.     if mouse_code == LEFT
  115.       if @click_lock
  116.         return false
  117.       else
  118.         return @left_trigger
  119.       end
  120.     elsif mouse_code == RIGHT
  121.       return @right_trigger
  122.     else
  123.       return false
  124.     end
  125.   end
  126.   def self.repeat?(mouse_code)
  127.     if mouse_code == LEFT
  128.       if @click_lock
  129.         return false
  130.       else
  131.         return @left_repeat
  132.       end
  133.     elsif mouse_code == RIGHT
  134.       return @right_repeat
  135.     else
  136.       return false
  137.     end
  138.   end
  139.   def self.click_lock?
  140.     return @click_lock
  141.   end
  142.   def self.click_lock
  143.     @click_lock = true
  144.   end
  145.   def self.click_unlock
  146.     @click_lock = false
  147.   end
  148. end
  149. module Input
  150.   if @self_update == nil
  151.     @self_update = method('update')
  152.     @self_press = method('press?')
  153.     @self_trigger = method('trigger?')
  154.     @self_repeat = method('repeat?')
  155.   end
  156.   def self.update
  157.     @self_update.call
  158.     Mouse.update
  159.   end
  160.   def self.press?(key_code)
  161.     if @self_press.call(key_code)
  162.       return true
  163.     end
  164.     if key_code == C
  165.       return Mouse.press?(Mouse::LEFT)
  166.     elsif key_code == B
  167.       return Mouse.press?(Mouse::RIGHT)
  168.     else
  169.       return @self_press.call(key_code)
  170.     end
  171.   end
  172.   def self.trigger?(key_code)
  173.     if @self_trigger.call(key_code)
  174.       return true
  175.     end
  176.     if key_code == C
  177.       return Mouse.trigger?(Mouse::LEFT)
  178.     elsif key_code == B
  179.       return Mouse.trigger?(Mouse::RIGHT)
  180.     else
  181.       return @self_trigger.call(key_code)
  182.     end
  183.   end
  184.   def self.repeat?(key_code)
  185.     if @self_repeat.call(key_code)
  186.       return true
  187.     end
  188.     if key_code == C
  189.       return Mouse.repeat?(Mouse::LEFT)
  190.     elsif key_code == B
  191.       return Mouse.repeat?(Mouse::RIGHT)
  192.     else
  193.       return @self_repeat.call(key_code)
  194.     end
  195.   end
  196. end
  197. class Window_Selectable
  198.   if @self_alias == nil
  199.     alias self_update update
  200.     @self_alias = true
  201.   end
  202.   def update
  203.     #self.cursor_rect.empty
  204.     self_update
  205.     if self.active and @item_max > 0
  206.       index_var = @index
  207.       tp_index = @index
  208.       mouse_x, mouse_y = Mouse.get_mouse_pos
  209.       mouse_not_in_rect = true
  210.       for i in 0...@item_max
  211.         [url=home.php?mod=space&uid=370741]@Index[/url] = i
  212.         update_cursor_rect
  213.         top_x = self.cursor_rect.x + self.x + 16
  214.         top_y = self.cursor_rect.y + self.y + 16
  215.         bottom_x = top_x + self.cursor_rect.width
  216.         bottom_y = top_y + self.cursor_rect.height
  217.         if (mouse_x > top_x) and (mouse_y > top_y) and
  218.             (mouse_x < bottom_x) and (mouse_y < bottom_y)
  219.           mouse_not_in_rect = false
  220.           if tp_index != @index
  221.             tp_index = @index
  222.             $game_system.se_play($data_system.cursor_se)
  223.           end
  224.           break
  225.         end
  226.       end
  227.       if mouse_not_in_rect
  228.         @index = index_var
  229.         update_cursor_rect
  230.         Mouse.click_lock
  231.       else
  232.         Mouse.click_unlock               
  233.       end
  234.     end
  235.   end
  236. end
  237. class Window_NameInput
  238.   if @self_alias == nil
  239.     alias self_update update
  240.     @self_alias = true
  241.   end
  242.   def update
  243.     #self.cursor_rect.empty
  244.     self_update
  245.     if self.active
  246.       index_var = @index
  247.       mouse_x, mouse_y = Mouse.get_mouse_pos
  248.       mouse_not_in_rect = true
  249.       for i in (0...CHARACTER_TABLE.size).to_a.push(180)
  250.         @index = i
  251.         update_cursor_rect
  252.         top_x = self.cursor_rect.x + self.x + 16
  253.         top_y = self.cursor_rect.y + self.y + 16
  254.         bottom_x = top_x + self.cursor_rect.width
  255.         bottom_y = top_y + self.cursor_rect.height
  256.         #
  257.         if (mouse_x > top_x) and (mouse_y > top_y) and
  258.             (mouse_x < bottom_x) and (mouse_y < bottom_y)
  259.           mouse_not_in_rect = false
  260.           break
  261.         end
  262.       end
  263.       if mouse_not_in_rect
  264.         @index = index_var
  265.         update_cursor_rect
  266.         Mouse.click_lock
  267.       else
  268.         Mouse.click_unlock
  269.       end
  270.     end
  271.   end
  272. end
  273. class Window_InputNumber
  274.   if @self_alias == nil
  275.     alias self_update update
  276.     @self_alias = true
  277.   end
  278.   def update
  279.     #self.cursor_rect.empty
  280.     self_update
  281.     mouse_x, mouse_y = Mouse.get_mouse_pos
  282.     if self.active and @digits_max > 0
  283.       index_var = @index
  284.       mouse_not_in_rect = true
  285.       for i in 0...@digits_max
  286.         @index = i
  287.         update_cursor_rect
  288.         top_x = self.cursor_rect.x + self.x + 16
  289.         bottom_x = top_x + self.cursor_rect.width
  290.         #
  291.         if (mouse_x > top_x) and (mouse_x < bottom_x)
  292.           mouse_not_in_rect = false
  293.           break
  294.         end
  295.       end
  296.       if mouse_not_in_rect
  297.         @index = index_var
  298.         update_cursor_rect
  299.         Mouse.click_lock
  300.       else
  301.         Mouse.click_unlock
  302.       end
  303.     end
  304.     if @last_mouse_y == nil
  305.       @last_mouse_y = mouse_y
  306.     end
  307.     check_pos = (@last_mouse_y - mouse_y).abs
  308.     if check_pos > 10
  309.       $game_system.se_play($data_system.cursor_se)
  310.       place = 10 ** (@digits_max - 1 - @index)
  311.       n = [url=home.php?mod=space&uid=27178]@Number[/url] / place % 10
  312.       @number -= n * place
  313.       n = (n + 1) % 10 if mouse_y < @last_mouse_y
  314.       n = (n + 9) % 10 if mouse_y > @last_mouse_y
  315.       @number += n * place
  316.       refresh
  317.       @last_mouse_y = mouse_y
  318.     end
  319.   end
  320. end
  321. class Scene_File
  322.   if @self_alias == nil
  323.     alias self_update update
  324.     @self_alias = true
  325.   end
  326.   def update
  327.     mouse_x, mouse_y = Mouse.get_mouse_pos
  328.     Mouse.click_lock
  329.     idx = 0
  330.     for i in @savefile_windows
  331.       top_x = i.x + 16
  332.       top_y = i.y + 16
  333.       bottom_x = top_x + i.width
  334.       bottom_y = top_y + i.height
  335.       if (mouse_x > top_x) and (mouse_y > top_y) and
  336.           (mouse_x < bottom_x) and (mouse_y < bottom_y)
  337.         i.selected = true
  338.         if @file_index != idx
  339.           @file_index = idx
  340.           $game_system.se_play($data_system.cursor_se)
  341.         end            
  342.         Mouse.click_unlock
  343.       else
  344.         i.selected = false
  345.       end
  346.       idx += 1
  347.     end
  348.     self_update
  349.   end
  350. end
  351. class Arrow_Enemy
  352.   if @self_alias == nil
  353.     alias self_update update
  354.     @self_alias = true
  355.   end
  356.   def update
  357.     mouse_x, mouse_y = Mouse.get_mouse_pos
  358.     idx = 0
  359.     for i in $game_troop.enemies do
  360.       if i.exist?
  361.         top_x = i.screen_x - self.ox
  362.         top_y = i.screen_y - self.oy
  363.         bottom_x = top_x + self.src_rect.width
  364.         bottom_y = top_y + self.src_rect.height
  365.         if (mouse_x > top_x - $敌人选框扩大) and (mouse_y > top_y - $敌人选框扩大) and
  366.             (mouse_x < bottom_x + $敌人选框扩大) and (mouse_y < bottom_y + $敌人选框扩大)
  367.           if @index != idx
  368.             $game_system.se_play($data_system.cursor_se)
  369.             @index = idx
  370.           end
  371.         end
  372.       end
  373.       idx += 1
  374.     end
  375.     self_update
  376.   end
  377. end
  378. class Arrow_Actor
  379.   if @self_alias == nil
  380.     alias self_update update
  381.     @self_alias = true
  382.   end
  383.   def update
  384.     mouse_x, mouse_y = Mouse.get_mouse_pos
  385.     idx = 0
  386.     for i in $game_party.actors do
  387.       if i.exist?
  388.         top_x = i.screen_x - self.ox
  389.         top_y = i.screen_y - self.oy
  390.         bottom_x = top_x + self.src_rect.width
  391.         bottom_y = top_y + self.src_rect.height
  392.         if (mouse_x > top_x - $角色选框扩大) and (mouse_y > top_y - $角色选框扩大) and
  393.             (mouse_x < bottom_x + $角色选框扩大) and (mouse_y < bottom_y + $角色选框扩大)
  394.           if @index != idx
  395.             $game_system.se_play($data_system.cursor_se)
  396.             @index = idx
  397.           end
  398.         end
  399.       end
  400.       idx += 1
  401.     end
  402.     self_update
  403.   end
  404. end
  405. class Game_Player
  406.   if @self_alias == nil
  407.     alias self_update update
  408.     @self_alias = true
  409.   end
  410.   def update
  411.     mouse_x, mouse_y = Mouse.get_mouse_pos
  412.     if @last_move_x == nil
  413.       @last_move_x = false
  414.     end
  415.     if Mouse.press?(Mouse::LEFT)
  416.       last_moving = moving?
  417.       last_direction = @direction
  418.       unless moving? or $game_system.map_interpreter.running? or
  419.           @move_route_forcing or $game_temp.message_window_showing
  420.         last_x = @x
  421.         if @last_move_x
  422.           @last_move_x = false
  423.         elsif mouse_x > screen_x + 16
  424.           move_right
  425.         elsif mouse_x < screen_x - 16
  426.           move_left
  427.         end
  428.         last_y = @y
  429.         if last_x != @x
  430.           @last_move_x = true
  431.         elsif mouse_y > screen_y
  432.           move_down
  433.         elsif mouse_y < screen_y - 32
  434.           move_up
  435.         end
  436.         if last_y != @y
  437.           @last_move_x = false
  438.         elsif not @last_move_x
  439.           case last_direction
  440.           when 2
  441.             turn_down
  442.           when 4
  443.             turn_left
  444.           when 6
  445.             turn_right
  446.           when 8
  447.             turn_up
  448.           end
  449.         end
  450.       end
  451.     end
  452.     self_update
  453.   end
  454. end
  455. Mouse.init
  456. END { Mouse.exit }
  457. #====================================================================
  458. # 本脚本来自www.66RPG.com,使用和转载请保留此信息
  459. #====================================================================
复制代码
  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.    
  124.    @mouse_sprite = Sprite.new
  125.    @mouse_sprite.z = 99999
  126.    @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/001-Weapon01.png')

  127.    @left_press = false
  128.    @right_press = false
  129.    @left_trigger = false
  130.    @right_trigger = false
  131.    @left_repeat = false
  132.    @right_repeat = false
  133.    @click_lock = false
  134.    
  135.    update
  136. end
  137. def self.exit
  138.    @mouse_sprite.bitmap.dispose
  139.    @mouse_sprite.dispose
  140.    @show_cursor = true
  141.    $ShowCursor.call(1)
  142. end
  143. def self.mouse_debug
  144.    return @mouse_debug.bitmap
  145. end
  146. def self.update
  147.    left_down = $GetKeyState.call(0x01)
  148.    right_down = $GetKeyState.call(0x02)
  149.    if Graphics.frame_count * 3 / Graphics.frame_rate != @total_sec
  150.      @total_sec = Graphics.frame_count * 3 / Graphics.frame_rate
  151.      @a = !@a
  152.    end
  153.    if $scene.is_a?(Scene_Map) == false
  154.      $mouse_icon_id = 0
  155.    end
  156. =begin   
  157. if $mouse_icon_id != $mouse_icon_id_last
  158.    case $mouse_icon_id
  159.    when 1
  160.      if @a
  161.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/GetItem1')
  162.      else
  163.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/GetItem2')
  164.      end
  165.    when 2
  166.      if @a
  167.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/TalkTo1')
  168.      else
  169.        @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/TalkTo2')
  170.      end
  171.    when 11
  172.      @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/Mouse_LOWER_LEFT')
  173.    when 12
  174.      @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/Mouse_DOWN')
  175.    when 13
  176.      @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/Mouse_LOWER_RIGHT')
  177.    when 14
  178.      @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/Mouse_LEFT')
  179.    when 16
  180.      @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/Mouse_RIGHT')
  181.    when 17
  182.      @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/Mouse_UPPER_LEFT')
  183.    when 18
  184.      @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/Mouse_UP')
  185.    when 19
  186.      @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/Mouse_UPPER_RIGHT')
  187.    when 0
  188.      @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/鼠标1')
  189.    end
  190.   
  191.      $mouse_icon_id_last = $mouse_icon_id
  192.    end
  193. =end   
  194.    @click_lock = false
  195.    mouse_x, mouse_y = self.get_mouse_pos
  196.    if @mouse_sprite != nil
  197.      @mouse_sprite.x = mouse_x
  198.      @mouse_sprite.y = mouse_y
  199.    end
  200.    if left_down[7] == 1
  201.      @left_repeat = (not @left_repeat)
  202.      @left_trigger = (not @left_press)
  203.      @left_press = true
  204.    else
  205.      @left_press = false
  206.      @left_trigger = false
  207.      @left_repeat = false
  208.    end
  209.    if right_down[7] == 1
  210.      @right_repeat = (not @right_repeat)
  211.      @right_trigger = (not @right_press)
  212.      @right_press = true
  213.    else
  214.      @right_press = false
  215.      @right_trigger = false
  216.      @right_repeat = false
  217.    end
  218. end
  219. def self.get_mouse_pos
  220.    point_var = [0, 0].pack('ll')
  221.    if $GetCursorPos.call(point_var) != 0
  222.      if $ScreenToClient.call($Window_HWND, point_var) != 0
  223.        x, y = point_var.unpack('ll')
  224.        if (x < 0) or (x > 10000) then x = 0 end
  225.        if (y < 0) or (y > 10000) then y = 0 end
  226.        if x > 1024 then x = 1024 end
  227.        if y > 704 then y = 704 end
  228.        return x, y
  229.      else
  230.        return 0, 0
  231.      end
  232.    else
  233.      return 0, 0
  234.    end
  235. end
  236. def self.press?(mouse_code)
  237.    if mouse_code == LEFT
  238.      if @click_lock
  239.        return false
  240.      else
  241.        return @left_press
  242.      end
  243.    elsif mouse_code == RIGHT
  244.      return @right_press
  245.    else
  246.      return false
  247.    end
  248. end
  249. def self.trigger?(mouse_code)
  250.    if mouse_code == LEFT
  251.      if @click_lock
  252.        return false
  253.      else
  254.        return @left_trigger
  255.      end
  256.    elsif mouse_code == RIGHT
  257.      return @right_trigger
  258.    else
  259.      return false
  260.    end
  261. end
  262. def self.repeat?(mouse_code)
  263.    if mouse_code == LEFT
  264.      if @click_lock
  265.        return false
  266.      else
  267.        return @left_repeat
  268.      end
  269.    elsif mouse_code == RIGHT
  270.      return @right_repeat
  271.    else
  272.      return false
  273.    end
  274. end
  275. def self.click_lock?
  276.    return @click_lock
  277. end
  278. def self.click_lock
  279.    @click_lock = true
  280. end
  281. def self.click_unlock
  282.    @click_lock = false
  283. end
  284. end
  285. module Input
  286. if @self_update == nil
  287.    @self_update = method('update')
  288.    @self_press = method('press?')
  289.    @self_trigger = method('trigger?')
  290.    @self_repeat = method('repeat?')
  291. end
  292. def self.update
  293.    @self_update.call
  294.    Mouse.update
  295. end
  296. def self.press?(key_code)
  297.    if @self_press.call(key_code)
  298.      return true
  299.    end
  300.    if key_code == C
  301.      return Mouse.press?(Mouse::LEFT)
  302.    elsif key_code == B
  303.      return Mouse.press?(Mouse::RIGHT)
  304.    else
  305.      return @self_press.call(key_code)
  306.    end
  307. end
  308. def self.trigger?(key_code)
  309.    if @self_trigger.call(key_code)
  310.      return true
  311.    end
  312.    if key_code == C
  313.      return Mouse.trigger?(Mouse::LEFT)
  314.    elsif key_code == B
  315.      return Mouse.trigger?(Mouse::RIGHT)
  316.    else
  317.      return @self_trigger.call(key_code)
  318.    end
  319. end
  320. def self.repeat?(key_code)
  321.    if @self_repeat.call(key_code)
  322.      return true
  323.    end
  324.    if key_code == C
  325.      return Mouse.repeat?(Mouse::LEFT)
  326.    elsif key_code == B
  327.      return Mouse.repeat?(Mouse::RIGHT)
  328.    else
  329.      return @self_repeat.call(key_code)
  330.    end
  331. end
  332. end
  333. class Window_Selectable
  334. if @self_alias == nil
  335.    alias self_update update
  336.    @self_alias = true
  337. end
  338. def update
  339.    self_update
  340.    if self.active and @item_max > 0
  341.      index_var = @index
  342.      tp_index = @index
  343.      mouse_x, mouse_y = Mouse.get_mouse_pos
  344.      mouse_not_in_rect = true
  345.      for i in 0...@item_max
  346.        @index = i
  347.        update_cursor_rect
  348.        top_x = self.cursor_rect.x + self.x + 16
  349.        top_y = self.cursor_rect.y + self.y + 16
  350.        bottom_x = top_x + self.cursor_rect.width
  351.        bottom_y = top_y + self.cursor_rect.height
  352.        if (mouse_x > top_x) and (mouse_y > top_y) and
  353.           (mouse_x < bottom_x) and (mouse_y < bottom_y)
  354.          mouse_not_in_rect = false
  355.          if tp_index != @index
  356.            tp_index = @index
  357.            $game_system.se_play($data_system.cursor_se)
  358.          end
  359.          break
  360.        end
  361.      end
  362.      if mouse_not_in_rect
  363.        @index = index_var
  364.        update_cursor_rect
  365.        Mouse.click_lock
  366.      else
  367.        Mouse.click_unlock               
  368.      end
  369.    end
  370. end
  371. end
  372. class Window_NameInput
  373. if @self_alias == nil
  374.    alias self_update update
  375.    @self_alias = true
  376. end
  377. def update
  378.    self_update
  379.    if self.active
  380.      index_var = @index
  381.      mouse_x, mouse_y = Mouse.get_mouse_pos
  382.      mouse_not_in_rect = true
  383.      for i in (0...CHARACTER_TABLE.size).to_a.push(180)
  384.        @index = i
  385.        update_cursor_rect
  386.        top_x = self.cursor_rect.x + self.x + 16
  387.        top_y = self.cursor_rect.y + self.y + 16
  388.        bottom_x = top_x + self.cursor_rect.width
  389.        bottom_y = top_y + self.cursor_rect.height
  390.        if (mouse_x > top_x) and (mouse_y > top_y) and
  391.           (mouse_x < bottom_x) and (mouse_y < bottom_y)
  392.          mouse_not_in_rect = false
  393.          break
  394.        end
  395.      end
  396.      if mouse_not_in_rect
  397.        @index = index_var
  398.        update_cursor_rect
  399.        Mouse.click_lock
  400.      else
  401.        Mouse.click_unlock
  402.      end
  403.    end
  404. end
  405. end
  406. class Window_InputNumber
  407. if @self_alias == nil
  408.    alias self_update update
  409.    @self_alias = true
  410. end
  411. def update
  412.    self_update
  413.    mouse_x, mouse_y = Mouse.get_mouse_pos
  414.    if self.active and @digits_max > 0
  415.      index_var = @index
  416.      mouse_not_in_rect = true
  417.      for i in 0...@digits_max
  418.        @index = i
  419.        update_cursor_rect
  420.        top_x = self.cursor_rect.x + self.x + 16
  421.        bottom_x = top_x + self.cursor_rect.width
  422.        if (mouse_x > top_x) and (mouse_x < bottom_x)
  423.          mouse_not_in_rect = false
  424.          break
  425.        end
  426.      end
  427.      if mouse_not_in_rect
  428.        @index = index_var
  429.        update_cursor_rect
  430.        Mouse.click_lock
  431.      else
  432.        Mouse.click_unlock
  433.      end
  434.    end
  435.    if @last_mouse_y == nil
  436.      @last_mouse_y = mouse_y
  437.    end
  438.    check_pos = (@last_mouse_y - mouse_y).abs
  439.    if check_pos > 10
  440.      $game_system.se_play($data_system.cursor_se)
  441.      place = 10 ** (@digits_max - 1 - @index)
  442.      n = @number / place % 10
  443.      @number -= n * place
  444.      n = (n + 1) % 10 if mouse_y < @last_mouse_y
  445.      n = (n + 9) % 10 if mouse_y > @last_mouse_y
  446.      @number += n * place
  447.      refresh
  448.      @last_mouse_y = mouse_y
  449.    end
  450. end
  451. end
  452. class Scene_File
  453. if @self_alias == nil
  454.    alias self_update update
  455.    @self_alias = true
  456. end
  457. def update
  458.    mouse_x, mouse_y = Mouse.get_mouse_pos
  459.    Mouse.click_lock
  460.    idx = 0
  461.    for i in @savefile_windows
  462.      top_x = i.x + 16
  463.      top_y = i.y + 16
  464.      bottom_x = top_x + i.width
  465.      bottom_y = top_y + i.height
  466.      if (mouse_x > top_x) and (mouse_y > top_y) and
  467.         (mouse_x < bottom_x) and (mouse_y < bottom_y)
  468.        i.selected = true
  469.        if @file_index != idx
  470.          @file_index = idx
  471.          $game_system.se_play($data_system.cursor_se)
  472.        end            
  473.        Mouse.click_unlock
  474.      else
  475.        i.selected = false
  476.      end
  477.      idx += 1
  478.    end
  479.    self_update
  480. end
  481. end
  482. class Arrow_Enemy
  483. if @self_alias == nil
  484.    alias self_update update
  485.    @self_alias = true
  486. end
  487. def update
  488.    mouse_x, mouse_y = Mouse.get_mouse_pos
  489.    idx = 0
  490.    for i in $game_troop.enemies do
  491.      if i.exist?
  492.        top_x = i.screen_x - self.ox
  493.        top_y = i.screen_y - self.oy
  494.        bottom_x = top_x + self.src_rect.width
  495.        bottom_y = top_y + self.src_rect.height
  496.        if (mouse_x > top_x - $敌人选框扩大) and (mouse_y > top_y - $敌人选框扩大) and
  497.           (mouse_x < bottom_x + $敌人选框扩大) and (mouse_y < bottom_y + $敌人选框扩大)
  498.          if @index != idx
  499.            $game_system.se_play($data_system.cursor_se)
  500.            @index = idx
  501.          end
  502.        end
  503.      end
  504.      idx += 1
  505.    end
  506.    self_update
  507. end
  508. end
  509. class Arrow_Actor
  510. if @self_alias == nil
  511.    alias self_update update
  512.    @self_alias = true
  513. end
  514. def update
  515.    mouse_x, mouse_y = Mouse.get_mouse_pos
  516.    idx = 0
  517.    for i in $game_party.actors do
  518.      if i.exist?
  519.        top_x = i.screen_x - self.ox
  520.        top_y = i.screen_y - self.oy
  521.        bottom_x = top_x + self.src_rect.width
  522.        bottom_y = top_y + self.src_rect.height
  523.        if (mouse_x > top_x - $角色选框扩大) and (mouse_y > top_y - $角色选框扩大) and
  524.           (mouse_x < bottom_x + $角色选框扩大) and (mouse_y < bottom_y + $角色选框扩大)
  525.          if @index != idx
  526.            $game_system.se_play($data_system.cursor_se)
  527.            @index = idx
  528.          end
  529.        end
  530.      end
  531.      idx += 1
  532.    end
  533.    self_update
  534. end
  535. end
  536. #==============================================================================
  537. # ■ Game_Player
  538. #------------------------------------------------------------------------------
  539. #  处理主角的类。事件启动的判定、以及地图的滚动等功能。
  540. # 本类的实例请参考 $game_player。
  541. #   鼠标控制角色的主程序
  542. #==============================================================================
  543. class Game_Player
  544. if @self_alias == nil
  545.    alias self_update update
  546.    @self_alias = true
  547. end
  548. #--------------------------------------------------------------------------
  549. # ● 得到鼠标的状态
  550. #--------------------------------------------------------------------------
  551. def get_mouse_sta
  552.    return @mouse_sta
  553. end
  554. #--------------------------------------------------------------------------
  555. # ● 完整鼠标系统
  556. #--------------------------------------------------------------------------
  557. def update
  558.    mouse_x, mouse_y = Mouse.get_mouse_pos
  559.    @mtp_x = mouse_x
  560.    @mtp_y = mouse_y
  561.    unless $game_system.map_interpreter.running? and @mouse_sta == 2 #鼠标状态不为跟随状态
  562.      #得到鼠标图标方向
  563.      $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)
  564.    else
  565.      #令鼠标图标为正常
  566.      $mouse_icon_id = 0 if @mouse_sta != 2
  567.    end
  568.    
  569.    #单击鼠标时进行判断寻路或跟随
  570.    if Mouse.trigger?(Mouse::LEFT) #当点击鼠标时
  571.      unless $game_system.map_interpreter.running? or
  572.             @move_route_forcing or $game_temp.message_window_showing #各种无效情况的排除
  573.        #初始化
  574.        @mouse_sta = 1
  575.        p_direction = 5
  576.        #检查鼠标处能否开启事件
  577.        event_start,p_direction = $game_map.check_event_custom_start(mouse_x, mouse_y)
  578.        #若在移动中再次点击鼠标左键(即双击左键),则改鼠标状态为跟随状态
  579.        @mouse_sta = 2 if @paths_id != nil and @paths_id != @paths.size
  580.        if @mouse_sta != 2
  581.          #鼠标状态不为跟随状态则取数据并初始化路径
  582.          trg_x = (mouse_x + $game_map.display_x / 4) / 32
  583.          trg_y = (mouse_y + $game_map.display_y / 4) / 32
  584.          @paths = []
  585.          @paths_id = 0
  586.          if event_start == 0 #若不能开启事件
  587.            if trg_x != $game_player.x or trg_y != $game_player.y #若目标不为自身则开始寻路
  588.              find_path = Find_Path.new
  589.              @paths = find_path.find_player_short_path(trg_x, trg_y, @mtp_x, @mtp_y)
  590.            end
  591.          else #若能开启事件则改变角色朝向
  592.            @direction = p_direction
  593.          end
  594.        end
  595.      end
  596.    end

  597.    #开始移动
  598.    if @mouse_sta != nil and @mouse_sta == 1 #若鼠标状态为寻路状态
  599.      unless moving? or $game_system.map_interpreter.running? or
  600.             @move_route_forcing or $game_temp.message_window_showing #排除无效情况
  601.        if @paths_id != nil and @paths != nil and @paths_id <= @paths.size #若没有完成路径
  602.          case @paths[@paths_id] #判断路径
  603.          when 6
  604.            @last_move_x = true
  605.            move_right
  606.            @paths_id += 1
  607.            @direction = 6
  608.          when 4
  609.            @last_move_x = true
  610.            move_left
  611.            @paths_id += 1
  612.            @direction = 4
  613.          when 2
  614.            @last_move_x = false
  615.            move_down
  616.            @direction = 2
  617.            @paths_id += 1
  618.          when 8
  619.            @last_move_x = false
  620.            move_up
  621.            @direction = 8
  622.            @paths_id += 1
  623.          end
  624.        end
  625.      end
  626.    elsif @paths != nil and @mouse_sta == 2 #当鼠标状态为跟随,且在移动中
  627.      if Mouse.press?(Mouse::LEFT) #持续按住鼠标
  628.        unless moving? or $game_system.map_interpreter.running? or
  629.               @move_route_forcing or $game_temp.message_window_showing #排除无效情况
  630.          #跟随方向判断并跟随
  631.          if @mtp_x > self.screen_x
  632.            if @mtp_y - self.screen_y > - ( @mtp_x - self.screen_x ) and
  633.               @mtp_y - self.screen_y < @mtp_x - self.screen_x
  634.              move_right
  635.              $mouse_icon_id = 16
  636.              @direction = 6
  637.            end
  638.            if @mtp_y - self.screen_y > @mtp_x - self.screen_x
  639.              move_down
  640.              $mouse_icon_id = 12
  641.              @direction = 2
  642.            end
  643.            if @mtp_y - self.screen_y < - ( @mtp_x - self.screen_x )
  644.              move_up
  645.              $mouse_icon_id = 18
  646.              @direction = 8
  647.            end
  648.          end
  649.          if @mtp_x < self.screen_x
  650.            if @mtp_y - self.screen_y > - ( self.screen_x - @mtp_x ) and
  651.               @mtp_y - self.screen_y < self.screen_x - @mtp_x
  652.              move_left
  653.              $mouse_icon_id = 14
  654.              @direction = 4
  655.            end
  656.            if @mtp_y - self.screen_y > self.screen_x - @mtp_x
  657.              move_down
  658.              $mouse_icon_id = 12
  659.              @direction = 2
  660.            end
  661.            if @mtp_y - self.screen_y < - ( self.screen_x - @mtp_x )
  662.              move_up
  663.              $mouse_icon_id = 18
  664.              @direction = 8
  665.            end
  666.          end
  667.        end
  668.      else #没状态的情况
  669.        $mouse_icon_id = 0
  670.        @mouse_sta = 0
  671.        @paths_id = @paths.size #终止寻路移动
  672.      end
  673.    end
  674. self_update
  675. end
  676. end
  677. Mouse.init
  678. END { Mouse.exit }
  679. #==============================================================================
  680. # ■ Find_Path
  681. #------------------------------------------------------------------------------
  682. #  寻路算法--完整鼠标系统(四方向)专用版
  683. #   By whbm
  684. #==============================================================================
  685. class Find_Path
  686. #--------------------------------------------------------------------------
  687. def initialize  #初始化
  688. @open_list = []
  689. @close_lise = []
  690. @path = []
  691. end  #结束初始化
  692. #--------------------------------------------------------------------------
  693. def fp_passable?(x, y, d, tr_x = -2, tr_y = -2)  #开始判定通行
  694. return false if (tr_x == @unable_xa or
  695.                  tr_x == @unable_xb or
  696.                  tr_y == @unable_ya or
  697.                  tr_y == @unable_yb)
  698. if [2, 4, 6, 8].include?(d)
  699.    if $game_player.passable?(x, y, d)
  700.      return true
  701.    else
  702.      return false
  703.    end
  704. end
  705. end  #结束判定通行
  706. #--------------------------------------------------------------------------
  707. def get_g(now_point)  #开始计算G值
  708. d = now_point[2]
  709. return 0 if d == 5
  710. father_point = get_father_point(now_point)
  711. g = father_point[3] + 10
  712. return g
  713. end  #结束计算G值
  714. #--------------------------------------------------------------------------
  715. def get_h(now_point)  #开始计算H值
  716. now_x = now_point[0]
  717. now_y = now_point[1]
  718. #print @trg_x,now_x,@trg_y,now_y
  719. h = (@trg_x - now_x).abs + (@trg_y - now_y).abs
  720. return h * 10
  721. end  #结束计算H值
  722. #--------------------------------------------------------------------------
  723. def get_f(now_point)  #开始计算F值
  724. f = now_point[3] + now_point[4]
  725. return f
  726. end  #结束计算F值
  727. #--------------------------------------------------------------------------
  728. def get_point(x, y) #取已知坐标点
  729. if @open_list.size != 0
  730.    @open_list.each do |point|
  731.      if point[0] == x and point[1] == y
  732.        return point
  733.        break
  734.      end
  735.    end
  736. end
  737. if @close_list.size != 0
  738.    @close_list.each do |point|
  739.      if point[0] == x and point[1] == y
  740.        return point
  741.        break
  742.      end
  743.    end
  744. end
  745. end  #结束取已知坐标点
  746. #--------------------------------------------------------------------------
  747. def get_father_point(now_point)  #取已知点的父节点
  748. d = now_point[2]
  749. return now_point if d == 5
  750. x = now_point[0] + (d == 6 ? 1 : (d == 4 ? -1 : 0))
  751. y = now_point[1] + (d == 2 ? 1 : (d == 8 ? -1 : 0))
  752. return get_point(x, y)
  753. end  #结束取已知点的父节点
  754. #--------------------------------------------------------------------------
  755. def new_point(x, y, d)  #开始建立新节点
  756. #print x,y,d
  757. point = [x, y, d]
  758. point.push get_g(point)
  759. point.push get_h(point)
  760. point.push get_f(point)
  761. return point
  762. end  #结束建立新节点
  763. #--------------------------------------------------------------------------
  764. def get_direction(self_x, self_y, trg_x, trg_y)
  765.   if trg_x > self_x
  766.     if trg_y - self_y > -  ( trg_x - self_x ) and
  767.       trg_y - self_y < ( trg_x - self_x )
  768.       return 6
  769.     end
  770.     if trg_y - self_y > ( trg_x - self_x )
  771.       return 2
  772.     end
  773.     if trg_y - self_y < - ( trg_x - self_x )
  774.       return 8
  775.     end
  776.   end
  777.   if trg_x < self_x
  778.     if trg_y - self_y > - ( self_x - trg_x ) and
  779.       trg_y - self_y < ( self_x - trg_x )
  780.       return 4
  781.     end
  782.     if trg_y - self_y > ( self_x - trg_x )
  783.       return 2
  784.     end
  785.     if trg_y - self_y < - ( self_x - trg_x )
  786.       return 8
  787.     end
  788.   end
  789. end
  790. #--------------------------------------------------------------------------
  791. def get_d_x_y(x, y, d)
  792.   d_x = x + (d == 6 ? 1 : (d == 4 ? -1 : 0))
  793.   d_y = y + (d == 2 ? 1 : (d == 8 ? -1 : 0))
  794.   return d_x, d_y
  795. end
  796. #--------------------------------------------------------------------------
  797. def find_short_path_other(self_x, self_y, trg_x, trg_y,
  798.                           real_self_x, real_self_y, real_trg_x, real_trg_y)
  799.   @self_x = self_x
  800.   @self_y = self_y
  801.   @now_x = self_x
  802.   @now_y = self_y
  803.   @trg_x = trg_x
  804.   @trg_y = trg_y
  805.   @path = []
  806.   direction = get_direction(real_self_x, real_self_y, real_trg_x, real_trg_y)
  807.   @now_trg_x, @now_trg_y = get_d_x_y(@self_x, @self_y, direction)
  808.   while fp_passable?(@now_x, @now_y, direction)
  809.     @path.push direction
  810.     @now_x = @now_trg_x
  811.     @now_y = @now_trg_y
  812.     @now_trg_x, @now_trg_y = get_d_x_y(@now_x, @now_y, direction)
  813.   end
  814.   return @path
  815. end
  816. #--------------------------------------------------------------------------
  817. def find_short_path(self_x, self_y, trg_x, trg_y,
  818.                     real_self_x, real_self_y, real_trg_x, real_trg_y)  #开始搜索路径
  819.   
  820. return find_short_path_other(self_x, self_y, trg_x, trg_y,
  821.                               real_self_x, real_self_y, real_trg_x, real_trg_y) if not
  822.                   (fp_passable?(trg_x, trg_y + 1, 8) or
  823.                    fp_passable?(trg_x + 1, trg_y, 4) or
  824.                    fp_passable?(trg_x - 1, trg_y, 6) or
  825.                    fp_passable?(trg_x, trg_y - 1, 2)) and @goal_type != 1
  826.                   
  827.                   
  828.   #根据屏幕限定搜索面积..加速
  829. @unable_xa = $game_map.display_x / 128 - 1
  830. @unable_ya = $game_map.display_y / 128 - 1
  831. @unable_xb = $game_map.display_x / 128 + 20
  832. @unable_yb = $game_map.display_y / 128 + 20


  833. @self_x = self_x
  834. @self_y = self_y
  835. @now_x = self_x
  836. @now_y = self_y
  837. @trg_x = trg_x
  838. @trg_y = trg_y
  839. @open_list = []
  840. @close_list = []
  841. #准备搜索
  842. #print @self_x,@self_y
  843. @now_point = new_point(@self_x, @self_y, 5) #令起始点为当前点
  844. @open_list.push @now_point #将当前点加入关闭列表
  845. #开始搜索
  846. begin
  847. loop do
  848.    check_trg = check_around_point(@now_point)
  849.    if check_trg == true
  850.      @path = get_path
  851.      break
  852.    end
  853.    @now_point = get_lowest_f_point
  854.    if @now_point == [] or @now_point == nil
  855.      @path = []
  856.      break
  857.    end
  858. end
  859. rescue Hangup
  860.   retry
  861. end
  862. return @path
  863. end  #结束搜索路径
  864. #--------------------------------------------------------------------------
  865. def find_player_short_path(trg_x, trg_y,
  866.                            real_trg_x, real_trg_y)  #寻找角色的最短路径
  867. self_x = $game_player.x
  868. self_y = $game_player.y
  869. real_self_x = $game_player.screen_x
  870. real_self_y = $game_player.screen_y
  871. @goal_type, event = $game_map.check_event_custom_exist(real_trg_x, real_trg_y)
  872. if @goal_type == 1
  873.    trg_x = event.x
  874.    trg_y = event.y
  875. end
  876. return find_short_path(self_x, self_y, trg_x, trg_y,
  877.                         real_self_x, real_self_y, real_trg_x, real_trg_y)
  878. end  #结束角色的寻找路径
  879. #--------------------------------------------------------------------------
  880. def get_path  #取得最终的路径
  881. path = []
  882. now_point = @open_list[@open_list.size - 1]
  883. path.push(10 - now_point[2])
  884. last_point = now_point
  885. loop do
  886.    now_point = get_father_point(now_point)
  887.    break if now_point[2] == 5
  888.    path.push(10 - now_point[2])
  889. end
  890. return path.reverse
  891. end  #结束取得最终的路径
  892. #--------------------------------------------------------------------------
  893. def get_lowest_f_point  #开始取得最低F值的点
  894. if @open_list == []
  895.    return []
  896. end
  897. last_lowest_f_point = @open_list[0]
  898. @open_list.each do |point|
  899.    last_lowest_f_point = point if point[5] < last_lowest_f_point[5]
  900. end
  901. return last_lowest_f_point
  902. end  #结束取得最低F值点
  903. #--------------------------------------------------------------------------
  904. def check_around_point(point)  #开始检查已知点的八方节点
  905. for d in [1, 2, 3, 4, 6, 7, 8, 9]
  906.    x = point[0] + ((d == 9 or d == 6 or d == 3) ? 1 : ((d == 7 or d == 4 or d == 1) ? -1 : 0))
  907.    y = point[1] + ((d == 1 or d == 2 or d == 3) ? 1 : ((d == 7 or d == 8 or d == 9) ? -1 : 0))
  908.    if in_close_list?(x, y) #在关闭列表中
  909.      next
  910.    elsif in_open_list?(x, y) #在开启列表中
  911.      get_new_g_point = new_point(x, y, 10 - d)
  912.      get_last_g_point = get_point(x, y)
  913.      if get_new_g_point[3] >= get_last_g_point[3]
  914.        next
  915.      else
  916.        #如果改变父节点是新G值更小则确定改变
  917.        @open_list[@open_list.index(get_last_g_point)] = get_new_g_point
  918.      end
  919.    else
  920.      if fp_passable?(point[0], point[1], d, x, y)
  921.        # 如果不在开启列表中、且不在关闭列表中、且通行则添加它到新八周节点
  922.        @open_list.push new_point(x, y, 10 - d)
  923.        #如果将目标点添加到了开启列表中就返回true
  924.        return true if x == @trg_x and y == @trg_y
  925.        return true if @goal_type == 1 and [1, 0, -1].include?(x - @trg_x) and [1, 0, -1].include?(y - @trg_y)
  926.      end
  927.    end
  928. end
  929. #此刻没有找到目标点并将当前点加入关闭列表并在开启列表中删除
  930. @close_list.push point
  931. @open_list.delete(point)
  932. #此刻没找到目标点并返回false
  933. return false
  934. end  #结束计算已知点的八方节点
  935. #--------------------------------------------------------------------------
  936. def in_open_list?(x, y)  #开始检查谋点是否在开启列表中
  937. @open_list.each do |point|
  938.    return true if point[0] == x and point[1] == y
  939. end
  940. return false
  941. end  #结束检查谋点是否在开启列表中
  942. #--------------------------------------------------------------------------
  943. def in_close_list?(x, y)  #开始检查谋点是否在关闭列表中
  944. @close_list.each do |point|
  945.    return true if point[0] == x and point[1] == y
  946. end
  947. return false
  948. end  #结束检查谋点是否在关闭列表中
  949. #--------------------------------------------------------------------------
  950. end
复制代码
如果可以的话愿意送上10vip.
回复 支持 0 反对 1

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-3-28 19:31

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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