幻想森林

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1602|回复: 1

[RMXP] 我用把方向鼠标脚本开始的时候不能选择

[复制链接]

38

主题

129

帖子

1151

积分

⑥精研

无既空,空既色

积分
1151
发表于 2010-2-1 22:50:56 | 显示全部楼层 |阅读模式
我用把方向脚本,但是刚开始的时候鼠标不能选择只能按确定,就是说鼠标脚本在开头进入游戏的时候不能选择开始或结束只能用键盘选择,有什么方法可以解决吗?这是我的开头脚本
  1. #==============================================================================
  2. # ■ Scene_Title
  3. #------------------------------------------------------------------------------
  4. #  处理标题画面的类。
  5. #==============================================================================
  6. class Scene_Title
  7.   Start_Map_ID = 1 #——新手指导地图编号
  8.   Start_X = 5 #——坐标
  9.   Start_Y = 5 #——坐标
  10.   #--------------------------------------------------------------------------
  11.   # ● 主处理
  12.   #--------------------------------------------------------------------------
  13.   def main
  14.     # 战斗测试的情况下
  15.     if $BTEST
  16.       battle_test
  17.       return
  18.     end
  19.     # 载入数据库
  20.     $data_actors        = load_data("Data/Actors.rxdata")
  21.     $data_classes       = load_data("Data/Classes.rxdata")
  22.     $data_skills        = load_data("Data/Skills.rxdata")
  23.     $data_items         = load_data("Data/Items.rxdata")
  24.     $data_weapons       = load_data("Data/Weapons.rxdata")
  25.     $data_armors        = load_data("Data/Armors.rxdata")
  26.     $data_enemies       = load_data("Data/Enemies.rxdata")
  27.     $data_troops        = load_data("Data/Troops.rxdata")
  28.     $data_states        = load_data("Data/States.rxdata")
  29.     $data_animations    = load_data("Data/Animations.rxdata")
  30.     $data_tilesets      = load_data("Data/Tilesets.rxdata")
  31.     $data_common_events = load_data("Data/CommonEvents.rxdata")
  32.     $data_system        = load_data("Data/System.rxdata")
  33.     # 生成系统对像
  34.     $game_system = Game_System.new
  35.     # 进入事件显示LOGO,如果您不想在调试时总是显示LOGO就加上下一行中注释部分
  36.     if $show_logo # and !$DEBUG
  37.       # 设置标记变量保证下次回到标题画面不会再显示片头
  38.       $show_logo = false
  39.       # 重置测量游戏时间用的画面计数器
  40.       Graphics.frame_count = 0
  41.       # 生成各种游戏对像
  42.       $game_temp          = Game_Temp.new
  43.       $game_system        = Game_System.new
  44.       $game_switches      = Game_Switches.new
  45.       $game_variables     = Game_Variables.new
  46.       $game_self_switches = Game_SelfSwitches.new
  47.       $game_screen        = Game_Screen.new
  48.       $game_actors        = Game_Actors.new
  49.       $game_party         = Game_Party.new
  50.       $game_troop         = Game_Troop.new
  51.       $game_map           = Game_Map.new
  52.       $game_player        = Game_Player.new
  53.       # 设置初期同伴位置
  54.       $game_party.setup_starting_members
  55.       # 设置初期位置的地图
  56.       $game_map.setup($data_system.start_map_id)
  57.       # 主角向初期位置移动
  58.       $game_player.moveto($data_system.start_x, $data_system.start_y)
  59.       # 刷新主角
  60.       $game_player.refresh
  61.       # 执行地图设置的 BGM 与 BGS 的自动切换
  62.       $game_map.autoplay
  63.       # 刷新地图 (执行并行事件)
  64.       $game_map.update
  65.       # 与真正的新游戏唯一不同就是将变量1设置一个标记值(暂用8764)
  66.       $game_variables[1]=8764
  67.       # 主角暂时是不能显示出来的……
  68.       $game_player.transparent = true
  69.       # 切换地图画面
  70.       $scene = Scene_Map.new
  71.     # 否则是默认显示标题画面
  72.     else
  73.       # 生成标题图形
  74.       #==============================================================================
  75. # 本脚本来自[url]www.66RPG.com[/url],使用和转载请保留此信息
  76. #==============================================================================
  77.     # 生成标题图形
  78.     @sprite = [Sprite.new]
  79.     for i in 0..8
  80.       @sprite[i] = Sprite.new
  81.       @sprite[i].opacity = 0
  82.     end
  83.     @sprite[0].bitmap = RPG::Cache.title($data_system.title_name)
  84.     @sprite[0].opacity = 0
  85.     #开始游戏的图片
  86.     @sprite[1].bitmap = Bitmap.new("Graphics/Pictures/11.png")
  87.     @sprite[2].bitmap = Bitmap.new("Graphics/Pictures/12.png")
  88.     #继续游戏的图片
  89.     @sprite[3].bitmap = Bitmap.new("Graphics/Pictures/21.png")
  90.     @sprite[4].bitmap = Bitmap.new("Graphics/Pictures/22.png")
  91.     #新手指导
  92.     @sprite[5].bitmap = Bitmap.new("Graphics/Pictures/41.png")
  93.     @sprite[6].bitmap = Bitmap.new("Graphics/Pictures/42.png")
  94.     #结束游戏的图片
  95.     @sprite[7].bitmap = Bitmap.new("Graphics/Pictures/31.png")
  96.     @sprite[8].bitmap = Bitmap.new("Graphics/Pictures/32.png")
  97.     #图片位置
  98.     for i in 1..8
  99.       x=80
  100.       y=(i+1)/2*60+120
  101.       @sprite[i].x =x
  102.       @sprite[i].y =y
  103.     end
  104.     @continue_enabled = false
  105.     for i in 0..3
  106.       if FileTest.exist?("Save#{i+1}.rxdata")
  107.         @continue_enabled = true
  108.       end
  109.     end
  110.     if @continue_enabled
  111.       @command_index = 1
  112.     else
  113.       @command_index = 0
  114.       @sprite[3].tone = Tone.new(0, 0, 0, 255)
  115.       @sprite[4].tone = Tone.new(0, 0, 0, 255)
  116.     end
  117.     $game_system.bgm_play($data_system.title_bgm)
  118.     Audio.me_stop
  119.     Audio.bgs_stop
  120.     Graphics.transition
  121.     loop do
  122.       Graphics.update
  123.       #淡出背景圖形
  124.       if @sprite[0].opacity <= 255
  125.         @sprite[0].opacity += 15
  126.       end
  127.       Input.update
  128.       update
  129.       if $scene != self
  130.         break
  131.       end
  132.     end
  133.     Graphics.freeze
  134.     # 釋放圖形
  135.     for i in 0..8
  136.       @sprite[i].bitmap.dispose
  137.       @sprite[i].dispose
  138.     end
  139.   end
  140.   def update
  141.   chaochaocommandchaochao
  142.     if Input.trigger?(Input::C)
  143.     case @command_index
  144.       when 0
  145.         command_new_game
  146.       when 1
  147.         command_continue
  148.       when 2
  149.         command_help
  150.       when 3
  151.         command_shutdown
  152.     end
  153.     end
  154.   end
  155.   def chaochaocommandchaochao
  156.     if Input.trigger?(Input::UP)
  157.       @command_index -= 1
  158.       if @command_index < 0
  159.         @command_index = 3
  160.       end
  161.       $game_system.se_play($data_system.cursor_se)
  162.     end
  163.     if Input.trigger?(Input::DOWN)
  164.       @command_index += 1
  165.       if @command_index > 3
  166.         @command_index = 0
  167.       end
  168.       $game_system.se_play($data_system.cursor_se)
  169.     end
  170.     case @command_index
  171.     when 0
  172.       if @sprite[1].opacity >= 0
  173.         @sprite[1].opacity -= 30
  174.       end
  175.       if @sprite[2].opacity <= 240
  176.         @sprite[2].opacity += 30
  177.       end
  178.       if @sprite[3].opacity <= 210
  179.         @sprite[3].opacity += 30
  180.       end
  181.       if @sprite[4].opacity >= 0
  182.         @sprite[4].opacity -= 30
  183.       end
  184.       if @sprite[5].opacity <= 210
  185.         @sprite[5].opacity += 30
  186.       end
  187.       if @sprite[6].opacity >= 0
  188.         @sprite[6].opacity -= 30
  189.       end
  190.       if @sprite[7].opacity <= 210
  191.         @sprite[7].opacity +=30
  192.       end
  193.       if @sprite[8].opacity >= 0
  194.         @sprite[8].opacity -=30
  195.       end
  196.     when 1
  197.       if @sprite[1].opacity <= 210
  198.         @sprite[1].opacity += 30
  199.       end
  200.       if @sprite[2].opacity >= 0
  201.         @sprite[2].opacity -= 30
  202.       end
  203.       if @sprite[3].opacity >= 0
  204.         @sprite[3].opacity -= 30
  205.       end
  206.       if @sprite[4].opacity <= 240
  207.         @sprite[4].opacity += 30
  208.       end
  209.       if @sprite[5].opacity <= 210
  210.         @sprite[5].opacity += 30
  211.       end
  212.       if @sprite[6].opacity >= 0
  213.         @sprite[6].opacity -= 30
  214.       end
  215.       if @sprite[7].opacity <= 210
  216.         @sprite[7].opacity +=30
  217.       end
  218.       if @sprite[8].opacity >=0
  219.         @sprite[8].opacity -=30
  220.       end
  221.     when 2
  222.       if @sprite[1].opacity <= 210
  223.         @sprite[1].opacity += 30
  224.       end
  225.       if @sprite[2].opacity >= 0
  226.         @sprite[2].opacity -= 30
  227.       end
  228.       if @sprite[3].opacity <= 210
  229.         @sprite[3].opacity += 30
  230.       end
  231.       if @sprite[4].opacity >= 0
  232.         @sprite[4].opacity -= 30
  233.       end
  234.       if @sprite[5].opacity >= 0
  235.         @sprite[5].opacity -= 30
  236.       end
  237.       if @sprite[6].opacity <= 240
  238.         @sprite[6].opacity += 30
  239.       end  
  240.       if @sprite[7].opacity <= 210
  241.         @sprite[7].opacity +=30
  242.       end
  243.       if @sprite[8].opacity >=0
  244.         @sprite[8].opacity -=30
  245.       end      
  246.      when 3   
  247.       if @sprite[1].opacity <= 210
  248.         @sprite[1].opacity += 30
  249.       end
  250.       if @sprite[2].opacity >= 0
  251.         @sprite[2].opacity -= 30
  252.       end
  253.       if @sprite[3].opacity <= 210
  254.         @sprite[3].opacity += 30
  255.       end
  256.       if @sprite[4].opacity >=0
  257.         @sprite[4].opacity -= 30
  258.       end
  259.       if @sprite[5].opacity <= 210
  260.         @sprite[5].opacity += 30
  261.       end
  262.       if @sprite[6].opacity >=0
  263.         @sprite[6].opacity -= 30
  264.       end  
  265.       if @sprite[7].opacity >= 0
  266.         @sprite[7].opacity -=30
  267.       end
  268.       if @sprite[8].opacity <= 240
  269.         @sprite[8].opacity += 30
  270.        end
  271.       end
  272.      end
  273.    end
  274. #--------------------------------------------------------------------------
  275.   # ● 命令 : 新游戏
  276.   #--------------------------------------------------------------------------
  277.   def command_new_game
  278.     # 演奏确定 SE
  279.     $game_system.se_play($data_system.decision_se)
  280.     # 停止 BGM
  281.     Audio.bgm_stop
  282.     # 重置测量游戏时间用的画面计数器
  283.     Graphics.frame_count = 0
  284.     # 生成各种游戏对像
  285.     $game_temp          = Game_Temp.new
  286.     $game_system        = Game_System.new
  287.     $game_switches      = Game_Switches.new
  288.     $game_variables     = Game_Variables.new
  289.     $game_self_switches = Game_SelfSwitches.new
  290.     $game_screen        = Game_Screen.new
  291.     $game_actors        = Game_Actors.new
  292.     $game_party         = Game_Party.new
  293.     $game_troop         = Game_Troop.new
  294.     $game_map           = Game_Map.new
  295.     $game_player        = Game_Player.new
  296.     # 设置初期同伴位置
  297.     $game_party.setup_starting_members
  298.     # 设置初期位置的地图
  299.     $game_map.setup($data_system.start_map_id)
  300.     # 主角向初期位置移动
  301.     $game_player.moveto($data_system.start_x, $data_system.start_y)
  302.     # 刷新主角
  303.     $game_player.refresh
  304.     # 执行地图设置的 BGM 与 BGS 的自动切换
  305.     $game_map.autoplay
  306.     # 刷新地图 (执行并行事件)
  307.     $game_map.update
  308.     # 主角暂时是不能显示出来的……
  309.     $game_player.transparent = true
  310.     # 切换地图画面
  311.     $scene = Scene_Map.new
  312.   end
  313.   #--------------------------------------------------------------------------
  314.   # ● 命令 : 继续
  315.   #--------------------------------------------------------------------------
  316.   def command_continue
  317.     # 继续无效的情况下
  318.     unless @continue_enabled
  319.       # 演奏无效 SE
  320.       $game_system.se_play($data_system.buzzer_se)
  321.       return
  322.     end
  323.     # 演奏确定 SE
  324.     $game_system.se_play($data_system.decision_se)
  325.     # 切换到读档画面
  326.     $scene = Scene_Load.new
  327.   end
  328.   #--------------------------------------------------------------------------
  329.   # ● 命令 : 新手指导
  330.   #--------------------------------------------------------------------------
  331.   def command_help
  332.     $game_system.se_play($data_system.decision_se)
  333.     Audio.bgm_stop
  334.     Graphics.frame_count = 0
  335.     $game_temp          = Game_Temp.new
  336.     $game_system        = Game_System.new
  337.     $game_switches      = Game_Switches.new
  338.     $game_variables     = Game_Variables.new
  339.     $game_self_switches = Game_SelfSwitches.new
  340.     $game_screen        = Game_Screen.new
  341.     $game_actors        = Game_Actors.new
  342.     $game_party         = Game_Party.new
  343.     $game_troop         = Game_Troop.new
  344.     $game_map           = Game_Map.new
  345.     $game_player        = Game_Player.new
  346.     $game_party.setup_starting_members
  347.     $game_map.setup(15)
  348.     $game_player.moveto(Start_X, Start_Y)
  349.     $game_player.refresh
  350.     $game_map.autoplay
  351.     $game_map.update
  352.     $game_player.transparent = true
  353.     $scene = Scene_Map.new
  354.   end
  355.   #--------------------------------------------------------------------------
  356.   # ● 命令 : 退出
  357.   #--------------------------------------------------------------------------
  358.   def command_shutdown
  359.     # 演奏确定 SE
  360.     $game_system.se_play($data_system.decision_se)
  361.     # BGM、BGS、ME 的淡入淡出
  362.     Audio.bgm_fade(800)
  363.     Audio.bgs_fade(800)
  364.     Audio.me_fade(800)
  365.     # 退出
  366.     $scene = nil
  367.   end
  368.   #--------------------------------------------------------------------------
  369.   # ● 战斗测试
  370.   #--------------------------------------------------------------------------
  371.   def battle_test
  372.     # 载入数据库 (战斗测试用)
  373.     $data_actors        = load_data("Data/BT_Actors.rxdata")
  374.     $data_classes       = load_data("Data/BT_Classes.rxdata")
  375.     $data_skills        = load_data("Data/BT_Skills.rxdata")
  376.     $data_items         = load_data("Data/BT_Items.rxdata")
  377.     $data_weapons       = load_data("Data/BT_Weapons.rxdata")
  378.     $data_armors        = load_data("Data/BT_Armors.rxdata")
  379.     $data_enemies       = load_data("Data/BT_Enemies.rxdata")
  380.     $data_troops        = load_data("Data/BT_Troops.rxdata")
  381.     $data_states        = load_data("Data/BT_States.rxdata")
  382.     $data_animations    = load_data("Data/BT_Animations.rxdata")
  383.     $data_tilesets      = load_data("Data/BT_Tilesets.rxdata")
  384.     $data_common_events = load_data("Data/BT_CommonEvents.rxdata")
  385.     $data_system        = load_data("Data/BT_System.rxdata")
  386.     # 重置测量游戏时间用的画面计数器
  387.     Graphics.frame_count = 0
  388.     # 生成各种游戏对像
  389.     $game_temp          = Game_Temp.new
  390.     $game_system        = Game_System.new
  391.     $game_switches      = Game_Switches.new
  392.     $game_variables     = Game_Variables.new
  393.     $game_self_switches = Game_SelfSwitches.new
  394.     $game_screen        = Game_Screen.new
  395.     $game_actors        = Game_Actors.new
  396.     $game_party         = Game_Party.new
  397.     $game_troop         = Game_Troop.new
  398.     $game_map           = Game_Map.new
  399.     $game_player        = Game_Player.new
  400.     # 设置战斗测试用同伴
  401.     $game_party.setup_battle_test_members
  402.     # 设置队伍 ID、可以逃走标志、战斗背景
  403.     $game_temp.battle_troop_id = $data_system.test_troop_id
  404.     $game_temp.battle_can_escape = true
  405.     $game_map.battleback_name = $data_system.battleback_name
  406.     # 演奏战斗开始 BGM
  407.     $game_system.se_play($data_system.battle_start_se)
  408.     # 演奏战斗 BGM
  409.     $game_system.bgm_play($game_system.battle_bgm)
  410.     # 切换到战斗画面
  411.     $scene = Scene_Battle.new
  412.   end
  413. end
  414. #==============================================================================
  415. # 本脚本来自[url]www.66RPG.com[/url],使用和转载请保留此信息
  416. #==============================================================================
复制代码
回复

使用道具 举报

38

主题

129

帖子

1151

积分

⑥精研

无既空,空既色

积分
1151
 楼主| 发表于 2010-2-1 22:52:00 | 显示全部楼层
鼠标脚本
  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. else
  27.    case d
  28.    when 1
  29.      if ($game_player.passable?(x, y, 4) and
  30.        $game_player.passable?(x - 1, y, 2)) or
  31.         ($game_player.passable?(x, y, 2) and
  32.        $game_player.passable?(x, y + 1, 4))
  33.        return true
  34.      else
  35.        return false
  36.      end
  37.    when 3
  38.      if ($game_player.passable?(x, y, 6) and
  39.        $game_player.passable?(x + 1, y, 2)) or
  40.         ($game_player.passable?(x, y, 2) and
  41.        $game_player.passable?(x, y + 1, 6))
  42.        return true
  43.      else
  44.        return false
  45.      end
  46.    when 7
  47.      if ($game_player.passable?(x, y, 4) and
  48.        $game_player.passable?(x - 1, y, 8)) or
  49.         ($game_player.passable?(x, y, 8) and
  50.        $game_player.passable?(x, y - 1, 4))
  51.        return true
  52.      else
  53.        return false
  54.      end
  55.    when 9
  56.      if ($game_player.passable?(x, y, 6) and
  57.        $game_player.passable?(x + 1, y, 8)) or
  58.         ($game_player.passable?(x, y, 8) and
  59.        $game_player.passable?(x, y - 1, 6))
  60.        return true
  61.      else
  62.        return false
  63.      end
  64.    end
  65. end
  66. end  #结束判定通行
  67. #--------------------------------------------------------------------------
  68. def get_g(now_point)  #开始计算G值
  69. d = now_point[2]
  70. return 0 if d == 5
  71. father_point = get_father_point(now_point)
  72. g = father_point[3] + ((d == 1 or d == 3 or d == 7 or d == 9) ? 14 : 10)
  73. return g
  74. end  #结束计算G值
  75. #--------------------------------------------------------------------------
  76. def get_h(now_point)  #开始计算H值
  77. now_x = now_point[0]
  78. now_y = now_point[1]
  79. #print @trg_x,now_x,@trg_y,now_y
  80. h = (@trg_x - now_x).abs + (@trg_y - now_y).abs
  81. return h * 10
  82. end  #结束计算H值
  83. #--------------------------------------------------------------------------
  84. def get_f(now_point)  #开始计算F值
  85. f = now_point[3] + now_point[4]
  86. return f
  87. end  #结束计算F值
  88. #--------------------------------------------------------------------------
  89. def get_point(x, y) #取已知坐标点
  90. if @open_list.size != 0
  91.    @open_list.each do |point|
  92.      if point[0] == x and point[1] == y
  93.        return point
  94.        break
  95.      end
  96.    end
  97. end
  98. if @close_list.size != 0
  99.    @close_list.each do |point|
  100.      if point[0] == x and point[1] == y
  101.        return point
  102.        break
  103.      end
  104.    end
  105. end
  106. end  #结束取已知坐标点
  107. #--------------------------------------------------------------------------
  108. def get_father_point(now_point)  #取已知点的父节点
  109. d = now_point[2]
  110. return now_point if d == 5
  111. x = now_point[0] + ((d == 9 or d == 6 or d == 3) ? 1 : ((d == 7 or d == 4 or d == 1) ? -1 : 0))
  112. y = now_point[1] + ((d == 1 or d == 2 or d == 3) ? 1 : ((d == 7 or d == 8 or d == 9) ? -1 : 0))
  113. return get_point(x, y)
  114. end  #结束取已知点的父节点
  115. #--------------------------------------------------------------------------
  116. def new_point(x, y, d)  #开始建立新节点
  117. #print x,y,d
  118. point = [x, y, d]
  119. point.push get_g(point)
  120. point.push get_h(point)
  121. point.push get_f(point)
  122. return point
  123. end  #结束建立新节点
  124. #--------------------------------------------------------------------------
  125. def get_direction(self_x, self_y, trg_x, trg_y)
  126.   if trg_x > self_x
  127.     if trg_y - self_y > - 0.4 * ( trg_x - self_x ) and
  128.       trg_y - self_y < 0.4 * ( trg_x - self_x )
  129.       return 6
  130.     end
  131.     if trg_y - self_y > 0.4 * ( trg_x - self_x ) and
  132.       trg_y - self_y < 2.4 * ( trg_x - self_x )
  133.       return 3
  134.     end
  135.     if trg_y - self_y < - 0.4 * ( trg_x - self_x ) and
  136.       trg_y - self_y > - 2.4 * ( trg_x - self_x )
  137.       return 9
  138.     end
  139.     if trg_y - self_y > 2.4 * ( trg_x - self_x )
  140.       return 2
  141.     end
  142.     if trg_y - self_y < - 2.4 * ( trg_x - self_x )
  143.       return 8
  144.     end
  145.   end
  146.   if trg_x < self_x
  147.     if trg_y - self_y > - 0.4 * ( self_x - trg_x ) and
  148.       trg_y - self_y < 0.4 * ( self_x - trg_x )
  149.       return 4
  150.     end
  151.     if trg_y - self_y > 0.4 * ( self_x - trg_x ) and
  152.       trg_y - self_y < 2.4 * ( self_x - trg_x )
  153.       return 1
  154.     end
  155.     if trg_y - self_y < - 0.4 * ( self_x - trg_x ) and
  156.       trg_y - self_y > - 2.4 * ( self_x - trg_x )
  157.       return 7
  158.     end
  159.     if trg_y - self_y > 2.4 * ( self_x - trg_x )
  160.       return 2
  161.     end
  162.     if trg_y - self_y < - 2.4 * ( self_x - trg_x )
  163.       return 8
  164.     end
  165.   end
  166. end
  167. #--------------------------------------------------------------------------
  168. def get_d_x_y(x, y, d)
  169.   d_x = x + ((d == 9 or d == 6 or d == 3) ? 1 : ((d == 7 or d == 4 or d == 1) ? -1 : 0))
  170.   d_y = y + ((d == 1 or d == 2 or d == 3) ? 1 : ((d == 7 or d == 8 or d == 9) ? -1 : 0))
  171.   return d_x, d_y
  172. end
  173. #--------------------------------------------------------------------------
  174. def find_short_path_other(self_x, self_y, trg_x, trg_y,
  175.                           real_self_x, real_self_y, real_trg_x, real_trg_y)
  176.   @self_x = self_x
  177.   @self_y = self_y
  178.   @now_x = self_x
  179.   @now_y = self_y
  180.   @trg_x = trg_x
  181.   @trg_y = trg_y
  182.   @path = []
  183.   direction = get_direction(real_self_x, real_self_y, real_trg_x, real_trg_y)
  184.   @now_trg_x, @now_trg_y = get_d_x_y(@self_x, @self_y, direction)
  185.   while fp_passable?(@now_x, @now_y, direction)
  186.     @path.push direction
  187.     @now_x = @now_trg_x
  188.     @now_y = @now_trg_y
  189.     @now_trg_x, @now_trg_y = get_d_x_y(@now_x, @now_y, direction)
  190.   end
  191.   return @path
  192. end
  193. #--------------------------------------------------------------------------
  194. def find_short_path(self_x, self_y, trg_x, trg_y,
  195.                     real_self_x, real_self_y, real_trg_x, real_trg_y)  #开始搜索路径
  196.   
  197. return find_short_path_other(self_x, self_y, trg_x, trg_y,
  198.                               real_self_x, real_self_y, real_trg_x, real_trg_y) if not
  199.                   (fp_passable?(trg_x, trg_y + 1, 8) or
  200.                    fp_passable?(trg_x + 1, trg_y, 4) or
  201.                    fp_passable?(trg_x - 1, trg_y, 6) or
  202.                    fp_passable?(trg_x, trg_y - 1, 2)) and @goal_type != 1
  203.                   
  204.                   
  205.   #根据屏幕限定搜索面积..加速
  206. @unable_xa = $game_map.display_x / 128 - 1
  207. @unable_ya = $game_map.display_y / 128 - 1
  208. @unable_xb = $game_map.display_x / 128 + 20
  209. @unable_yb = $game_map.display_y / 128 + 20
  210. @self_x = self_x
  211. @self_y = self_y
  212. @now_x = self_x
  213. @now_y = self_y
  214. @trg_x = trg_x
  215. @trg_y = trg_y
  216. @open_list = []
  217. @close_list = []
  218. #准备搜索
  219. #print @self_x,@self_y
  220. @now_point = new_point(@self_x, @self_y, 5) #令起始点为当前点
  221. @open_list.push @now_point #将当前点加入关闭列表
  222. #开始搜索
  223. begin
  224. loop do
  225.    check_trg = check_around_point(@now_point)
  226.    if check_trg == true
  227.      @path = get_path
  228.      break
  229.    end
  230.    @now_point = get_lowest_f_point
  231.    if @now_point == [] or @now_point == nil
  232.      @path = []
  233.      break
  234.    end
  235. end
  236. rescue Hangup
  237.   retry
  238. end
  239. return @path
  240. end  #结束搜索路径
  241. #--------------------------------------------------------------------------
  242. def find_player_short_path(trg_x, trg_y,
  243.                            real_trg_x, real_trg_y)  #寻找角色的最短路径
  244. self_x = $game_player.x
  245. self_y = $game_player.y
  246. real_self_x = $game_player.screen_x
  247. real_self_y = $game_player.screen_y
  248. @goal_type, event = $game_map.check_event_custom_exist(real_trg_x, real_trg_y)
  249. if @goal_type == 1
  250.    trg_x = event.x
  251.    trg_y = event.y
  252. end
  253. return find_short_path(self_x, self_y, trg_x, trg_y,
  254.                         real_self_x, real_self_y, real_trg_x, real_trg_y)
  255. end  #结束角色的寻找路径
  256. #--------------------------------------------------------------------------
  257. def get_path  #取得最终的路径
  258. path = []
  259. now_point = @open_list[@open_list.size - 1]
  260. path.push(10 - now_point[2])
  261. last_point = now_point
  262. loop do
  263.    now_point = get_father_point(now_point)
  264.    break if now_point[2] == 5
  265.    path.push(10 - now_point[2])
  266. end
  267. return path.reverse
  268. end  #结束取得最终的路径
  269. #--------------------------------------------------------------------------
  270. def get_lowest_f_point  #开始取得最低F值的点
  271. if @open_list == []
  272.    return []
  273. end
  274. last_lowest_f_point = @open_list[0]
  275. @open_list.each do |point|
  276.    last_lowest_f_point = point if point[5] < last_lowest_f_point[5]
  277. end
  278. return last_lowest_f_point
  279. end  #结束取得最低F值点
  280. #--------------------------------------------------------------------------
  281. def check_around_point(point)  #开始检查已知点的八方节点
  282. for d in [1, 2, 3, 4, 6, 7, 8, 9]
  283.    x = point[0] + ((d == 9 or d == 6 or d == 3) ? 1 : ((d == 7 or d == 4 or d == 1) ? -1 : 0))
  284.    y = point[1] + ((d == 1 or d == 2 or d == 3) ? 1 : ((d == 7 or d == 8 or d == 9) ? -1 : 0))
  285.    if in_close_list?(x, y) #在关闭列表中
  286.      next
  287.    elsif in_open_list?(x, y) #在开启列表中
  288.      get_new_g_point = new_point(x, y, 10 - d)
  289.      get_last_g_point = get_point(x, y)
  290.      if get_new_g_point[3] >= get_last_g_point[3]
  291.        next
  292.      else
  293.        #如果改变父节点是新G值更小则确定改变
  294.        @open_list[@open_list.index(get_last_g_point)] = get_new_g_point
  295.      end
  296.    else
  297.      if fp_passable?(point[0], point[1], d, x, y)
  298.        # 如果不在开启列表中、且不在关闭列表中、且通行则添加它到新八周节点
  299.        @open_list.push new_point(x, y, 10 - d)
  300.        #如果将目标点添加到了开启列表中就返回true
  301.        return true if x == @trg_x and y == @trg_y
  302.        return true if @goal_type == 1 and [1, 0, -1].include?(x - @trg_x) and [1, 0, -1].include?(y - @trg_y)
  303.      end
  304.    end
  305. end
  306. #此刻没有找到目标点并将当前点加入关闭列表并在开启列表中删除
  307. @close_list.push point
  308. @open_list.delete(point)
  309. #此刻没找到目标点并返回false
  310. return false
  311. end  #结束计算已知点的八方节点
  312. #--------------------------------------------------------------------------
  313. def in_open_list?(x, y)  #开始检查谋点是否在开启列表中
  314. @open_list.each do |point|
  315.    return true if point[0] == x and point[1] == y
  316. end
  317. return false
  318. end  #结束检查谋点是否在开启列表中
  319. #--------------------------------------------------------------------------
  320. def in_close_list?(x, y)  #开始检查谋点是否在关闭列表中
  321. @close_list.each do |point|
  322.    return true if point[0] == x and point[1] == y
  323. end
  324. return false
  325. end  #结束检查谋点是否在关闭列表中
  326. #--------------------------------------------------------------------------
  327. end
复制代码
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|幻想森林

GMT+8, 2024-5-22 05:14 , Processed in 0.018720 second(s), 20 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

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