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

Project1

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

[已经过期] 黑白棋脚本与鼠标脚本冲突(好像是以前66做的)

[复制链接]

Lv2.观梦者

梦石
0
星屑
479
在线时间
30 小时
注册时间
2017-5-30
帖子
56
跳转到指定楼层
1
发表于 2017-10-19 02:08:34 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
本帖最后由 樱桃丸子aab 于 2017-10-19 02:34 编辑

这个黑白棋脚本每次下到最后一步,棋盘下满结束计分的时候,如果用鼠标(加了鼠标脚本)点,鼠标脚本都会报错:

执行脚本时发生 NoMethodError。
undefined method 'x' for nil:NilClass


经过研究,确实跟鼠标脚本有冲突,烦请看看原因,我知道很复杂,本人游戏即将制作完成,几乎只剩下这最后一个问题了,实在麻烦了!

黑白棋范例工程如下:
https://rpg.blue/thread-327388-1-1.html

下面分别给出黑白棋脚本和鼠标脚本:

黑白棋脚本1:
  1. #==============================================================================
  2. # ■ Window_Gold
  3. #------------------------------------------------------------------------------
  4. #  显示金钱的窗口。
  5. #==============================================================================

  6. class Window_Heibai < Window_Base
  7.   #--------------------------------------------------------------------------
  8.   # ● 初始化窗口
  9.   #--------------------------------------------------------------------------
  10.   def initialize
  11.     super(480 + 42, 480 - 96 , 118, 96)
  12.     self.contents = Bitmap.new(width - 32, height - 32)
  13.     self.opacity = 160
  14.     refresh
  15.   end
  16.   #--------------------------------------------------------------------------
  17.   # ● 刷新
  18.   #--------------------------------------------------------------------------
  19.   def refresh
  20.     self.contents.clear
  21.     see_the_score
  22.     self.contents.font.color = Color.new(192, 224, 255, 255)
  23.     self.contents.draw_text(0,0,128,32,"白棋:")
  24.     self.contents.draw_text(0,32,128,32,"黑棋:")
  25.     self.contents.font.color = Color.new(255, 255, 128, 255)
  26.     self.contents.draw_text(0,0,80,32,@p1_score.to_s,2)
  27.     self.contents.draw_text(0,32,80,32,@p2_score.to_s,2)
  28.   end
  29.    
  30.   def see_the_score
  31.     @p1_score = 0
  32.     @p2_score = 0
  33.     $p1 = 0
  34.     $p2 = 0
  35.     for id in 1..64
  36.       if get_id_kind(id) == 1
  37.         @p1_score += 1
  38.         $p1 += 1
  39.       end
  40.       if get_id_kind(id) == 2
  41.         @p2_score += 1
  42.         $p2 += 1
  43.       end      
  44.     end
  45.   end
  46.   
  47.   def get_id_tfkey(id, k)
  48.     key = [$game_map.map_id, id, k]
  49.     return $game_self_switches[key]
  50.   end
  51.   
  52.   def get_id_kind(id)
  53.     if get_id_tfkey(id, "A") == true
  54.       return 1
  55.     elsif get_id_tfkey(id, "B") == true
  56.       return 2
  57.     else
  58.       return 0
  59.     end
  60.   end
  61. end
复制代码

黑白棋脚本2:

  1. class Interpreter
  2.   def get_id_tfkey(id, k)
  3.     key = [$game_map.map_id, id, k]
  4.     return $game_self_switches[key]
  5.   end
  6.   
  7.   def get_id_kind(id)
  8.     if get_id_tfkey(id, "A") == true
  9.       return 1
  10.     elsif get_id_tfkey(id, "B") == true
  11.       return 2
  12.     else
  13.       return 0
  14.     end
  15.   end
  16.   
  17.   def def_id_kind(id, tf)
  18.     if tf == 1
  19.       key = [$game_map.map_id, id, "A"]
  20.       $game_self_switches[key] = true
  21.       key = [$game_map.map_id, id, "B"]
  22.       $game_self_switches[key] = false
  23.     else
  24.       key = [$game_map.map_id, id, "B"]
  25.       $game_self_switches[key] = true
  26.       key = [$game_map.map_id, id, "A"]
  27.       $game_self_switches[key] = false
  28.     end
  29.     $game_map.need_refresh = true
  30.   end
  31.   
  32.   #----------------------------------------------------------------
  33.   # 获知走当前的格子能获得的总利润
  34.   #----------------------------------------------------------------
  35.   def get_number(id , whoIam)
  36.     return 0 if get_id_kind(id) != 0
  37.     @all_number = [0,0,0,0,0,0,0,0,0,0,0]
  38.     if (id % 8 != 0)
  39.       get_way_number(whoIam, id + 1, 6)
  40.     end
  41.     if (id % 8 != 1)
  42.       get_way_number(whoIam, id - 1, 4)
  43.     end
  44.     if (id < 57)
  45.       get_way_number(whoIam, id + 8, 2)
  46.     end
  47.     if (id > 8)
  48.       get_way_number(whoIam, id - 8, 8)
  49.     end
  50.     if !(id >= 57 or id % 8 == 1)
  51.       get_way_number(whoIam, id + 7, 1)
  52.     end
  53.     if !(id >= 57 or id % 8 == 0)
  54.       get_way_number(whoIam, id + 9, 3)
  55.     end
  56.     if !(id <= 8 or id % 8 == 1)
  57.       get_way_number(whoIam, id - 9, 7)
  58.     end
  59.     if !(id <= 8 or id % 8 == 0)
  60.       get_way_number(whoIam, id - 7, 9)
  61.     end
  62.     return @all_number[1] + @all_number[2] +@all_number[3] +@all_number[4] +@all_number[6] +@all_number[7] +@all_number[8] +@all_number[9]
  63.   end

  64.   def get_way_number(what_I_need , id, way)
  65.     if get_id_kind(id) != 0 and get_id_kind(id) != what_I_need
  66.       @all_number[way] += 1
  67.       case way
  68.       when 6
  69.         if (id % 8 == 0)
  70.           @all_number[way] = 0
  71.         else
  72.           get_way_number(what_I_need, id + 1, way)
  73.         end
  74.       when 4
  75.         if (id % 8 == 1)
  76.           @all_number[way] = 0
  77.         else
  78.           get_way_number(what_I_need, id - 1, way)
  79.         end
  80.       when 2
  81.         if (id >= 57)
  82.           @all_number[way] = 0
  83.         else
  84.           get_way_number(what_I_need, id + 8, way)
  85.         end   
  86.       when 8
  87.         if (id <= 8)
  88.           @all_number[way] = 0
  89.         else
  90.           get_way_number(what_I_need, id - 8, way)
  91.         end   
  92.       when 1
  93.         if (id >= 57 or id % 8 == 1)
  94.           @all_number[way] = 0
  95.         else
  96.           get_way_number(what_I_need, id + 7, way)
  97.         end  
  98.       when 3
  99.         if (id >= 57 or id % 8 == 0)
  100.           @all_number[way] = 0
  101.         else
  102.           get_way_number(what_I_need, id + 9, way)
  103.         end
  104.       when 7
  105.         if (id <= 8 or id % 8 == 1)
  106.           @all_number[way] = 0
  107.         else
  108.           get_way_number(what_I_need, id - 9, way)
  109.         end
  110.       when 9
  111.         if (id <= 8 or id % 8 == 0)
  112.           @all_number[way] = 0
  113.         else
  114.           get_way_number(what_I_need, id - 7, way)
  115.         end           
  116.       end
  117.       
  118.     elsif get_id_kind(id) == 0
  119.       @all_number[way] = 0
  120.       
  121.     else
  122.       
  123.     end
  124.         
  125.   end

  126.   def confirm_id(id , whoIam)
  127.     return false if get_number(id , whoIam) == 0
  128.     if @all_number[6] != 0
  129.       change_way(whoIam, id + 1, 6)
  130.     end
  131.     if @all_number[4] != 0
  132.       change_way(whoIam, id - 1, 4)
  133.     end
  134.     if @all_number[2] != 0
  135.       change_way(whoIam, id + 8, 2)
  136.     end
  137.     if @all_number[8] != 0
  138.       change_way(whoIam, id - 8, 8)
  139.     end
  140.     if @all_number[1] != 0
  141.       change_way(whoIam, id + 7, 1)
  142.     end
  143.     if @all_number[3] != 0
  144.       change_way(whoIam, id + 9, 3)
  145.     end
  146.     if @all_number[7] != 0
  147.       change_way(whoIam, id - 9, 7)
  148.     end
  149.     if @all_number[9] != 0
  150.       change_way(whoIam, id - 7, 9)
  151.     end
  152.     def_id_kind(id, whoIam)
  153.     case whoIam
  154.     when 1
  155.       $c = check_for_max(2)
  156.     when 2
  157.       $c = check_for_max(1)
  158.     end
  159.     $game_map.need_refresh = true
  160.     $score_win.refresh if $score_win != nil and !$score_win.disposed?
  161.     return true
  162.   end

  163.   def change_way(what_I_need , id, way)
  164.     if get_id_kind(id) != what_I_need
  165.       def_id_kind(id, what_I_need)
  166.       case way
  167.       when 6
  168.           change_way(what_I_need, id + 1, way)
  169.       when 4
  170.           change_way(what_I_need, id - 1, way)
  171.       when 2
  172.           change_way(what_I_need, id + 8, way)
  173.       when 8
  174.           change_way(what_I_need, id - 8, way)
  175.       when 1
  176.           change_way(what_I_need, id + 7, way)
  177.       when 3
  178.           change_way(what_I_need, id + 9, way)  
  179.       when 7
  180.           change_way(what_I_need, id - 9, way)
  181.       when 9
  182.           change_way(what_I_need, id - 7, way)
  183.       end
  184.       
  185.     else
  186.       
  187.     end
  188.         
  189.   end

  190.   def check_for_max(whoIam)
  191.     @hb_array = []

  192.     for id in [1,8,64,57]
  193.       next if get_id_kind(id) != 0
  194.       @hb_array.push ([get_number(id , whoIam) , id])
  195.     end
  196.     if @hb_array[0] != nil and @hb_array[0][0] != 0
  197.       return @hb_array[0][1]
  198.     end

  199.     t = []
  200.     if get_id_kind(1) == whoIam
  201.       t.push (2)
  202.       t.push (9)
  203.     end
  204.     if get_id_kind(8) == whoIam
  205.       t.push (7)
  206.       t.push (16)
  207.     end
  208.     if get_id_kind(57) == whoIam
  209.       t.push (58)
  210.       t.push (49)
  211.     end
  212.     if get_id_kind(64) == whoIam
  213.       t.push (63)
  214.       t.push (56)
  215.     end
  216.     for id in t      
  217.       next if get_id_kind(id) != 0
  218.       @hb_array.push ([get_number(id , whoIam) , id])
  219.     end
  220.     @hb_array.sort!{|b,c| c[0] - b[0]}
  221.     if @hb_array[0] != nil and @hb_array[0][0] != 0
  222.       return @hb_array[0][1]
  223.     end

  224.     for id in [3,4,5,6,59,60,61,62,17,25,33,41,24,32,40,48]
  225.       next if get_id_kind(id) != 0
  226.       @hb_array.push ([get_number(id , whoIam) , id])      
  227.     end
  228.     @hb_array.sort!{|b,c| c[0] - b[0]}
  229.     if @hb_array[0] != nil and @hb_array[0][0] != 0
  230.       if @hb_array[1] != nil and @hb_array[1][0] != 0 and @hb_array[0][0] - @hb_array[1][0] <= 1
  231.         if rand(100) < 20
  232.           return @hb_array[1][1]
  233.         end
  234.       end
  235.       return @hb_array[0][1]
  236.     end     

  237.     for id in [11,12,13,14,18,19,20,21,22,23,26,27,28,29,30,31,
  238.       34,35,36,37,38,39,42,43,44,45,46,47,51,52,53,54]
  239.       next if get_id_kind(id) != 0
  240.       @hb_array.push ([get_number(id , whoIam) , id])
  241.     end
  242.     @hb_array.sort!{|b,c| c[0] - b[0]}
  243.     if @hb_array[0] != nil and @hb_array[0][0] != 0
  244.       if @hb_array[1] != nil and @hb_array[1][0] != 0 and @hb_array[0][0] - @hb_array[1][0] <= 1
  245.         if rand(100) < 20
  246.           return @hb_array[1][1]
  247.         end
  248.       end
  249.       return @hb_array[0][1]
  250.     end      

  251.     for id in 1..64
  252.       next if get_id_kind(id) != 0
  253.       @hb_array.push ([get_number(id , whoIam) , id])
  254.     end
  255.     @hb_array.sort!{|b,c| c[0] - b[0]}
  256.     if @hb_array[0] == nil
  257.       return "game finished"
  258.     elsif @hb_array[0][0] == 0
  259.       enemy = 1
  260.       if whoIam == 1
  261.         enemy = 2
  262.       end
  263.       @hb_array = []
  264.       for id in 1..64
  265.         next if get_id_kind(id) != 0
  266.         @hb_array.push ([get_number(id , enemy) , id])
  267.       end
  268.       @hb_array.sort!{|b,c| c[0] - b[0]}
  269.       if @hb_array[0][0] == 0
  270.         return "game finished"
  271.       else
  272.         return "no where to go"
  273.       end
  274.     else
  275.       return @hb_array[0][1]
  276.     end
  277.   end
  278. end
复制代码

鼠标脚本1:

  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.         if event.list != nil
  40.         for i in 0...event.list.size
  41.           if event.list.size > 0
  42.           if event.list[i].parameters[0] == "Item" #类型判断
  43.             event.flag = 1
  44.           elsif event.list[i].parameters[0] == "Npc" #类型判断
  45.             event.flag = 2
  46.           elsif event.list[i].parameters[0] == "Enemy" #类型判断
  47.             event.flag = 3
  48.           else
  49.             event.flag = 0 if $game_player.get_mouse_sta != 2 #无标志
  50.           end
  51.           return event.flag #返回事件类型标志
  52.           end
  53.         end
  54.         end
  55.       end
  56.     end
  57.     return 0 if $game_player.get_mouse_sta != 2 #如果不是在跟随鼠标状态,则返回无标志
  58.     return $mouse_icon_id #使鼠标图不变化
  59.   end
  60.   #--------------------------------------------------------------------------
  61.   # ● 检查鼠标处是否有事件可以开启
  62.   #--------------------------------------------------------------------------
  63.   def check_event_custom_start(mouse_x, mouse_y)
  64.     for event in $game_map.events.values #循环所有事件检查
  65.       #事件角色图片宽度、高度
  66.       event_width = RPG::Cache.character(event.character_name,event.character_hue).width/4
  67.       event_height = RPG::Cache.character(event.character_name,event.character_hue).height/4
  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, -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)
  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 = 6 if way_y == 0
  78.               elsif way_x == 0
  79.                 p_direction = 2 if way_y == -1
  80.                 p_direction = 8 if way_y == 1
  81.               else
  82.                 p_direction = 4 if way_y == 0
  83.               end
  84.               event.start #开启事件
  85.               return 1, p_direction #返回即将开启事件以及角色朝向
  86.             end
  87.           end
  88.         end
  89.       end
  90.     end
  91.     return 0, 5 #返回不会开启事件以及角色朝向不变
  92.   end
  93.   #--------------------------------------------------------------------------
  94.   # ● 检查鼠标处是否存在自定义事件 for 寻路
  95.   #--------------------------------------------------------------------------
  96.   def check_event_custom_exist(mouse_x, mouse_y)
  97.     for event in $game_map.events.values #循环所有事件检查
  98.       #事件角色图片宽度、高度
  99.       event_width = RPG::Cache.character(event.character_name,event.character_hue).width/4
  100.       event_height = RPG::Cache.character(event.character_name,event.character_hue).height/4
  101.       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
  102.         for i in 0...event.list.size
  103.           return 1, event if ["Item", "Npc"].include?(event.list[i].parameters[0]) #返回存在自定义事件以及事件体
  104.         end
  105.       end
  106.     end
  107.     return 0, event #返回不存在自定义事件,以及事件体
  108.   end
  109. end


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


  113. #==============================================================================
  114. # ● API调用
  115. #==============================================================================
  116. $ShowCursor = Win32API.new("user32", "ShowCursor", 'i', 'l')
  117. $GetCursorPos = Win32API.new("user32", "GetCursorPos", 'p', 'i')
  118. $ScreenToClient = Win32API.new("user32", "ScreenToClient", 'ip', 'i')
  119. $GetActiveWindow = Win32API.new("user32", "GetActiveWindow", nil, 'l')
  120. $Window_HWND = $GetActiveWindow.call
  121. $GetKeyState = Win32API.new("user32", "GetKeyState", 'i', 'i')
  122. module Mouse  
  123. LEFT = 0x01
  124. RIGHT = 0x02

  125. def self.init(sprite = nil)
  126.    $ShowCursor.call(0)
  127.    
  128.    @show_cursor = false
  129.    
  130.    @mouse_sprite = Sprite.new
  131.    @mouse_sprite.z = 99999
  132.    @mouse_sprite.bitmap = Bitmap.new('Graphics/Icons/001-Mouse01.png')

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

  606.    #开始移动
  607.    if @mouse_sta != nil and @mouse_sta == 1 #若鼠标状态为寻路状态
  608.      unless moving? or $game_system.map_interpreter.running? or
  609.             @move_route_forcing or $game_temp.message_window_showing #排除无效情况
  610.        if @paths_id != nil and @paths != nil and @paths_id <= @paths.size #若没有完成路径
  611.          case @paths[@paths_id] #判断路径
  612.          when 6
  613.            @last_move_x = true
  614.            move_right
  615.            @paths_id += 1
  616.            @direction = 6
  617.          when 4
  618.            @last_move_x = true
  619.            move_left
  620.            @paths_id += 1
  621.            @direction = 4
  622.          when 2
  623.            @last_move_x = false
  624.            move_down
  625.            @direction = 2
  626.            @paths_id += 1
  627.          when 8
  628.            @last_move_x = false
  629.            move_up
  630.            @direction = 8
  631.            @paths_id += 1
  632.          end
  633.        end
  634.      end
  635.    elsif @paths != nil and @mouse_sta == 2 #当鼠标状态为跟随,且在移动中
  636.      if Mouse.press?(Mouse::LEFT) #持续按住鼠标
  637.        unless moving? or $game_system.map_interpreter.running? or
  638.               @move_route_forcing or $game_temp.message_window_showing #排除无效情况
  639.          #跟随方向判断并跟随
  640.          if @mtp_x > self.screen_x
  641.            if @mtp_y - self.screen_y > - ( @mtp_x - self.screen_x ) and
  642.               @mtp_y - self.screen_y < @mtp_x - self.screen_x
  643.              move_right
  644.              $mouse_icon_id = 16
  645.              @direction = 6
  646.            end
  647.            if @mtp_y - self.screen_y > @mtp_x - self.screen_x
  648.              move_down
  649.              $mouse_icon_id = 12
  650.              @direction = 2
  651.            end
  652.            if @mtp_y - self.screen_y < - ( @mtp_x - self.screen_x )
  653.              move_up
  654.              $mouse_icon_id = 18
  655.              @direction = 8
  656.            end
  657.          end
  658.          if @mtp_x < self.screen_x
  659.            if @mtp_y - self.screen_y > - ( self.screen_x - @mtp_x ) and
  660.               @mtp_y - self.screen_y < self.screen_x - @mtp_x
  661.              move_left
  662.              $mouse_icon_id = 14
  663.              @direction = 4
  664.            end
  665.            if @mtp_y - self.screen_y > self.screen_x - @mtp_x
  666.              move_down
  667.              $mouse_icon_id = 12
  668.              @direction = 2
  669.            end
  670.            if @mtp_y - self.screen_y < - ( self.screen_x - @mtp_x )
  671.              move_up
  672.              $mouse_icon_id = 18
  673.              @direction = 8
  674.            end
  675.          end
  676.        end
  677.      else #没状态的情况
  678.        $mouse_icon_id = 0
  679.        @mouse_sta = 0
  680.        @paths_id = @paths.size #终止寻路移动
  681.      end
  682.    end
  683. self_update
  684. end
  685. end
  686. Mouse.init
  687. END { Mouse.exit }
复制代码

鼠标脚本2:

  1. #==============================================================================
  2. # ■ Find_Path
  3. #------------------------------------------------------------------------------
  4. #  寻路算法--完整鼠标系统(四方向)专用版
  5. #   By whbm
  6. #==============================================================================
  7. class Find_Path
  8. #--------------------------------------------------------------------------
  9. def initialize  #初始化
  10. @open_list = []
  11. @close_lise = []
  12. @path = []
  13. end  #结束初始化
  14. #--------------------------------------------------------------------------
  15. def fp_passable?(x, y, d, tr_x = -2, tr_y = -2)  #开始判定通行
  16. return false if (tr_x == @unable_xa or
  17.                  tr_x == @unable_xb or
  18.                  tr_y == @unable_ya or
  19.                  tr_y == @unable_yb)
  20. if [2, 4, 6, 8].include?(d)
  21.    if $game_player.passable?(x, y, d)
  22.      return true
  23.    else
  24.      return false
  25.    end
  26. end
  27. end  #结束判定通行
  28. #--------------------------------------------------------------------------
  29. def get_g(now_point)  #开始计算G值
  30. d = now_point[2]
  31. return 0 if d == 5
  32. father_point = get_father_point(now_point)
  33. g = father_point[3] + 10
  34. return g
  35. end  #结束计算G值
  36. #--------------------------------------------------------------------------
  37. def get_h(now_point)  #开始计算H值
  38. now_x = now_point[0]
  39. now_y = now_point[1]
  40. #print @trg_x,now_x,@trg_y,now_y
  41. h = (@trg_x - now_x).abs + (@trg_y - now_y).abs
  42. return h * 10
  43. end  #结束计算H值
  44. #--------------------------------------------------------------------------
  45. def get_f(now_point)  #开始计算F值
  46. f = now_point[3] + now_point[4]
  47. return f
  48. end  #结束计算F值
  49. #--------------------------------------------------------------------------
  50. def get_point(x, y) #取已知坐标点
  51. if @open_list.size != 0
  52.    @open_list.each do |point|
  53.      if point[0] == x and point[1] == y
  54.        return point
  55.        break
  56.      end
  57.    end
  58. end
  59. if @close_list.size != 0
  60.    @close_list.each do |point|
  61.      if point[0] == x and point[1] == y
  62.        return point
  63.        break
  64.      end
  65.    end
  66. end
  67. end  #结束取已知坐标点
  68. #--------------------------------------------------------------------------
  69. def get_father_point(now_point)  #取已知点的父节点
  70. d = now_point[2]
  71. return now_point if d == 5
  72. x = now_point[0] + (d == 6 ? 1 : (d == 4 ? -1 : 0))
  73. y = now_point[1] + (d == 2 ? 1 : (d == 8 ? -1 : 0))
  74. return get_point(x, y)
  75. end  #结束取已知点的父节点
  76. #--------------------------------------------------------------------------
  77. def new_point(x, y, d)  #开始建立新节点
  78. #print x,y,d
  79. point = [x, y, d]
  80. point.push get_g(point)
  81. point.push get_h(point)
  82. point.push get_f(point)
  83. return point
  84. end  #结束建立新节点
  85. #--------------------------------------------------------------------------
  86. def get_direction(self_x, self_y, trg_x, trg_y)
  87.   if trg_x > self_x
  88.     if trg_y - self_y > -  ( trg_x - self_x ) and
  89.       trg_y - self_y < ( trg_x - self_x )
  90.       return 6
  91.     end
  92.     if trg_y - self_y > ( trg_x - self_x )
  93.       return 2
  94.     end
  95.     if trg_y - self_y < - ( trg_x - self_x )
  96.       return 8
  97.     end
  98.   end
  99.   if trg_x < self_x
  100.     if trg_y - self_y > - ( self_x - trg_x ) and
  101.       trg_y - self_y < ( self_x - trg_x )
  102.       return 4
  103.     end
  104.     if trg_y - self_y > ( self_x - trg_x )
  105.       return 2
  106.     end
  107.     if trg_y - self_y < - ( self_x - trg_x )
  108.       return 8
  109.     end
  110.   end
  111. end
  112. #--------------------------------------------------------------------------
  113. def get_d_x_y(x, y, d)
  114.   d_x = x + (d == 6 ? 1 : (d == 4 ? -1 : 0))
  115.   d_y = y + (d == 2 ? 1 : (d == 8 ? -1 : 0))
  116.   return d_x, d_y
  117. end
  118. #--------------------------------------------------------------------------
  119. def find_short_path_other(self_x, self_y, trg_x, trg_y,
  120.                           real_self_x, real_self_y, real_trg_x, real_trg_y)
  121.   @self_x = self_x
  122.   @self_y = self_y
  123.   @now_x = self_x
  124.   @now_y = self_y
  125.   @trg_x = trg_x
  126.   @trg_y = trg_y
  127.   @path = []
  128.   direction = get_direction(real_self_x, real_self_y, real_trg_x, real_trg_y)
  129.   @now_trg_x, @now_trg_y = get_d_x_y(@self_x, @self_y, direction)
  130.   while fp_passable?(@now_x, @now_y, direction)
  131.     @path.push direction
  132.     @now_x = @now_trg_x
  133.     @now_y = @now_trg_y
  134.     @now_trg_x, @now_trg_y = get_d_x_y(@now_x, @now_y, direction)
  135.   end
  136.   return @path
  137. end
  138. #--------------------------------------------------------------------------
  139. def find_short_path(self_x, self_y, trg_x, trg_y,
  140.                     real_self_x, real_self_y, real_trg_x, real_trg_y)  #开始搜索路径
  141.   
  142. return find_short_path_other(self_x, self_y, trg_x, trg_y,
  143.                               real_self_x, real_self_y, real_trg_x, real_trg_y) if not
  144.                   (fp_passable?(trg_x, trg_y + 1, 8) or
  145.                    fp_passable?(trg_x + 1, trg_y, 4) or
  146.                    fp_passable?(trg_x - 1, trg_y, 6) or
  147.                    fp_passable?(trg_x, trg_y - 1, 2)) and @goal_type != 1
  148.                   
  149.                   
  150.   #根据屏幕限定搜索面积..加速
  151. @unable_xa = $game_map.display_x / 128 - 1
  152. @unable_ya = $game_map.display_y / 128 - 1
  153. @unable_xb = $game_map.display_x / 128 + 20
  154. @unable_yb = $game_map.display_y / 128 + 20


  155. @self_x = self_x
  156. @self_y = self_y
  157. @now_x = self_x
  158. @now_y = self_y
  159. @trg_x = trg_x
  160. @trg_y = trg_y
  161. @open_list = []
  162. @close_list = []
  163. #准备搜索
  164. #print @self_x,@self_y
  165. @now_point = new_point(@self_x, @self_y, 5) #令起始点为当前点
  166. @open_list.push @now_point #将当前点加入关闭列表
  167. #开始搜索
  168. begin
  169. loop do
  170.    check_trg = check_around_point(@now_point)
  171.    if check_trg == true
  172.      @path = get_path
  173.      break
  174.    end
  175.    @now_point = get_lowest_f_point
  176.    if @now_point == [] or @now_point == nil
  177.      @path = []
  178.      break
  179.    end
  180. end
  181. rescue Hangup
  182.   retry
  183. end
  184. return @path
  185. end  #结束搜索路径
  186. #--------------------------------------------------------------------------
  187. def find_player_short_path(trg_x, trg_y,
  188.                            real_trg_x, real_trg_y)  #寻找角色的最短路径
  189. self_x = $game_player.x
  190. self_y = $game_player.y
  191. real_self_x = $game_player.screen_x
  192. real_self_y = $game_player.screen_y
  193. @goal_type, event = $game_map.check_event_custom_exist(real_trg_x, real_trg_y)
  194. if @goal_type == 1
  195.    trg_x = event.x
  196.    trg_y = event.y
  197. end
  198. return find_short_path(self_x, self_y, trg_x, trg_y,
  199.                         real_self_x, real_self_y, real_trg_x, real_trg_y)
  200. end  #结束角色的寻找路径
  201. #--------------------------------------------------------------------------
  202. def get_path  #取得最终的路径
  203. path = []
  204. now_point = @open_list[@open_list.size - 1]
  205. path.push(10 - now_point[2])
  206. last_point = now_point
  207. loop do
  208.    now_point = get_father_point(now_point)
  209.    break if now_point[2] == 5
  210.    path.push(10 - now_point[2])
  211. end
  212. return path.reverse
  213. end  #结束取得最终的路径
  214. #--------------------------------------------------------------------------
  215. def get_lowest_f_point  #开始取得最低F值的点
  216. if @open_list == []
  217.    return []
  218. end
  219. last_lowest_f_point = @open_list[0]
  220. @open_list.each do |point|
  221.    last_lowest_f_point = point if point[5] < last_lowest_f_point[5]
  222. end
  223. return last_lowest_f_point
  224. end  #结束取得最低F值点
  225. #--------------------------------------------------------------------------
  226. def check_around_point(point)  #开始检查已知点的八方节点
  227. for d in [1, 2, 3, 4, 6, 7, 8, 9]
  228.    x = point[0] + ((d == 9 or d == 6 or d == 3) ? 1 : ((d == 7 or d == 4 or d == 1) ? -1 : 0))
  229.    y = point[1] + ((d == 1 or d == 2 or d == 3) ? 1 : ((d == 7 or d == 8 or d == 9) ? -1 : 0))
  230.    if in_close_list?(x, y) #在关闭列表中
  231.      next
  232.    elsif in_open_list?(x, y) #在开启列表中
  233.      get_new_g_point = new_point(x, y, 10 - d)
  234.      get_last_g_point = get_point(x, y)
  235.      if get_new_g_point[3] >= get_last_g_point[3]
  236.        next
  237.      else
  238.        #如果改变父节点是新G值更小则确定改变
  239.        @open_list[@open_list.index(get_last_g_point)] = get_new_g_point
  240.      end
  241.    else
  242.      if fp_passable?(point[0], point[1], d, x, y)
  243.        # 如果不在开启列表中、且不在关闭列表中、且通行则添加它到新八周节点
  244.        @open_list.push new_point(x, y, 10 - d)
  245.        #如果将目标点添加到了开启列表中就返回true
  246.        return true if x == @trg_x and y == @trg_y
  247.        return true if @goal_type == 1 and [1, 0, -1].include?(x - @trg_x) and [1, 0, -1].include?(y - @trg_y)
  248.      end
  249.    end
  250. end
  251. #此刻没有找到目标点并将当前点加入关闭列表并在开启列表中删除
  252. @close_list.push point
  253. @open_list.delete(point)
  254. #此刻没找到目标点并返回false
  255. return false
  256. end  #结束计算已知点的八方节点
  257. #--------------------------------------------------------------------------
  258. def in_open_list?(x, y)  #开始检查谋点是否在开启列表中
  259. @open_list.each do |point|
  260.    return true if point[0] == x and point[1] == y
  261. end
  262. return false
  263. end  #结束检查谋点是否在开启列表中
  264. #--------------------------------------------------------------------------
  265. def in_close_list?(x, y)  #开始检查谋点是否在关闭列表中
  266. @close_list.each do |point|
  267.    return true if point[0] == x and point[1] == y
  268. end
  269. return false
  270. end  #结束检查谋点是否在关闭列表中
  271. #--------------------------------------------------------------------------
  272. end
复制代码


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

本版积分规则

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

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

GMT+8, 2024-9-21 16:45

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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