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

Project1

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

[已经过期] 寻路遇到障碍直接绕过继续行走

[复制链接]

Lv3.寻梦者

梦石
0
星屑
1556
在线时间
626 小时
注册时间
2010-8-5
帖子
451
跳转到指定楼层
1
发表于 2014-9-7 00:05:15 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
简单的说,平常控制角色走路,角色碰到一个阻挡就会停下

如何让角色碰到阻挡后,还贴着周边的阻挡依然行走。。。。


我是八方向
RUBY 代码复制
  1. #==============================================================================
  2. # ■ Game_Player
  3. #------------------------------------------------------------------------------
  4. #  处理主角的类。事件启动的判定、以及地图的滚动等功能。
  5. # 本类的实例请参考 $game_player。
  6. #==============================================================================
  7.  
  8. class Game_Player < Game_Character
  9.   if @self_alias == nil
  10.     alias self_update update
  11.     @self_alias = true
  12.   end
  13.   #--------------------------------------------------------------------------
  14.   # ● 完整鼠标系统
  15.   #--------------------------------------------------------------------------
  16.   def update
  17.     # 搜索路径
  18.     seek_path
  19.     # 当持续按下鼠标左键时
  20.     if Mouse.press?(0x01)
  21.       return if !System.whether_move
  22.       @count = 20 if @count.nil?
  23.       @count -= 1
  24.       if @count <= 0
  25.         @self_state = 2
  26.         @count = nil
  27.       end
  28.       follow(true) if @self_state != 2 and @count < 18
  29.     elsif Mouse.trigger?(0x02)
  30.       @self_state = 0
  31.       follow(false)
  32.     else
  33.       @count = 20
  34.     end
  35.     # 移动
  36.     if @self_state == 1
  37.       player_move
  38.     elsif @paths != nil and @self_state == 2
  39.       follow(true)
  40.     end
  41.     # 别名
  42.     self_update
  43.   end
  44.   #--------------------------------------------------------------------------
  45.   # ● 搜索路径
  46.   #--------------------------------------------------------------------------
  47.   def seek_path
  48.     # 获取鼠标在画面的坐标
  49.     x, y = Mouse.get_mouse_pos
  50.     # 当按下鼠标左键时
  51.     if Mouse.trigger?(0x01)
  52.       # 禁止移动的情况下返回
  53.       return if !System.whether_move
  54.       # 排除各种无效的情况
  55.       unless $game_system.map_interpreter.running? or
  56.         @move_route_forcing or $game_temp.message_window_showing
  57.         # 获取目标点
  58.         trg_x = (x + $game_map.display_x / 4) / 32
  59.         trg_y = (y + $game_map.display_y / 4) / 32
  60.         # 目标点不可以通行的情况下返回
  61.         return unless target_passable?(trg_x,trg_y)
  62.         # 初始化未开启事件
  63.         @event = nil
  64.         # 判断是否可以打开事件
  65.         event_start = check_event_custom_start(x, y)
  66.         # 若不能开启事件
  67.         if !event_start
  68.           # 初始化
  69.           @paths = []
  70.           @steps = 0
  71.           @self_state = 1
  72.           # 若存在未开启事件
  73.           if @event != nil
  74.             trg_x,trg_y = @event.x,@event.y
  75.           end
  76.           # 若目标不为自身则开始寻路
  77.           if trg_x != self.x or trg_y != self.y
  78.             # 添加点击动画
  79.             add_animation if @event.nil?
  80.             # 获得路径
  81.             @paths = Find_Path.new.find_player_short_path(trg_x, trg_y, x, y)
  82.           end
  83.         else
  84.           # 角色面向事件
  85.           self.turn_toward_player(@event) if !@event.nil? and !self.moving?
  86.           @steps = @paths = nil
  87.         end
  88.       end
  89.     end
  90.   end
  91.   #--------------------------------------------------------------------------
  92.   # ● 可以通行判定
  93.   #     x : X 坐标
  94.   #     y : Y 坐标
  95.   #--------------------------------------------------------------------------
  96.   def target_passable?(x, y)
  97.     # 获取地图通行表
  98.     passages = $data_tilesets[$game_map.tileset_id].passages
  99.     # 从层按从上到下的顺序调查循环
  100.     for i in [2, 1, 0]
  101.       # 取得元件 ID
  102.       tile_id = $game_map.data[x, y, i]
  103.       # 取得元件 ID 失败
  104.       if tile_id == nil
  105.         # 不能通行
  106.         return false
  107.       # 如果全方向的障碍物的接触被设置的情况下
  108.       elsif passages[tile_id] & 0x0f == 0x0f
  109.         # 不能通行
  110.         return false
  111.       # 这以外的优先度为 0 的情况下
  112.       elsif $game_map.priorities[tile_id] == 0
  113.         # 可以通行
  114.         return true
  115.       end
  116.     end
  117.     # 可以通行
  118.     return true
  119.   end
  120.   #--------------------------------------------------------------------------
  121.   # ● 判断是否可以打开事件
  122.   #--------------------------------------------------------------------------
  123.   def check_event_custom_start(x, y)
  124.     # 循环检查所有事件
  125.     for event in $game_map.events.values
  126.       bitmap = RPG::Cache.character(event.character_name,event.character_hue)
  127.       cw = bitmap.width / 9#event.animation_frame
  128.       ch = bitmap.height / 8#event.direction_frame
  129.       _x = event.screen_x
  130.       _y = event.screen_y
  131.       d = event.direction
  132.       case event.direction_frame
  133.       when 4
  134.         sy = d > 8 ? 2 : d > 7 ? 3 : d > 6 ? 3 : d > 5 ? 2 : d > 3 ? 1 : d > 2 ? 0 : d > 1 ? 0 : d > 0 ? 1 : 5
  135.       when 8
  136.         sy = d > 8 ? 7 : d > 7 ? 3 : d > 6 ? 6 : d > 5 ? 2 : d > 3 ? 1 : d > 2 ? 5 : d > 1 ? 0 : d > 0 ? 4 : 5
  137.       end
  138.       if x >= _x - cw / 2 and x <= _x + cw / 2 and y >= _y - ch and y <= _y and
  139.         bitmap.get_pixel(x - _x + cw / 2 + event.pattern * cw, y - _y + ch + sy * ch).alpha > 0
  140.         for i in 0...event.list.size
  141.           if ["Item", "Npc"].include?(event.list[i].parameters[0])
  142.             way_x = self.x - event.x
  143.             way_y = self.y - event.y
  144.             if way_x.abs + way_y.abs <= 8 and !self.moving?
  145.               # 矫正主角姿势
  146.               self.straighten
  147.               # 角色面向事件
  148.  
  149.               # 开启事件
  150.               event.start
  151.               return true
  152.               self.pattern
  153.             else
  154.               @event = event
  155.               return self.moving? ? true : false
  156.             end
  157.           end
  158.         end
  159.       end
  160.     end
  161.     return false
  162.   end
  163.   #--------------------------------------------------------------------------
  164.   # ● 添加鼠标点击动画
  165.   #--------------------------------------------------------------------------
  166.   def add_animation
  167.     x, y = Mouse.get_mouse_pos
  168.     animation = Sprite.new
  169.     animation.visible = false
  170.     animation.bitmap = Bitmap.new("UI/鼠标效果序列图")
  171.     map_x = x - 10 + $game_map.display_x / 4
  172.     map_y = y - 5 + $game_map.display_y / 4
  173.     animation.src_rect.set(0, 0, 24, 13)
  174.     $鼠标效果.push([animation,0,map_x,map_y])
  175.   end
  176.   #--------------------------------------------------------------------------
  177.   # ● 开始移动
  178.   #--------------------------------------------------------------------------
  179.   def player_move
  180.     # 排除无效情况
  181.     unless moving? or $game_system.map_interpreter.running? or
  182.       @move_route_forcing or $game_temp.message_window_showing
  183.       # 若没有完成路径
  184.       if @steps != nil and @paths != nil and @steps <= @paths.size
  185.         # 判断路径
  186.         case @paths[@steps]
  187.         when 6
  188.           move_right
  189.           @steps += 1
  190.         when 4
  191.           move_left
  192.           @steps += 1
  193.         when 2
  194.           move_down
  195.           @steps += 1
  196.         when 8
  197.           move_up
  198.           @steps += 1
  199.         when 1
  200.           move_lower_left
  201.           @steps += 1
  202.         when 3
  203.           move_lower_right
  204.           @steps += 1
  205.         when 7
  206.           move_upper_left
  207.           @steps += 1
  208.         when 9
  209.           move_upper_right
  210.           @steps += 1
  211.         end
  212.         # 若存在未开启事件
  213.         if @event != nil
  214.           way_x = self.x - @event.x
  215.           way_y = self.y - @event.y
  216.           if way_x.abs + way_y.abs <= 8
  217.             # 角色面向事件
  218.             self.turn_toward_player(@event)
  219.             # 矫正主角姿势
  220.             self.straighten
  221.             # 开启事件
  222.             @event.start
  223.             # 终止路径
  224.             @paths = nil
  225.             return
  226.           end
  227.         end
  228.       end
  229.     end
  230.   end
  231.   #--------------------------------------------------------------------------
  232.   # ● 跟随/转向
  233.   #--------------------------------------------------------------------------
  234.   def follow(move = true)
  235.     # 禁止移动的情况下返回
  236.     return if !System.whether_move
  237.     # 选择主角的情况下
  238.     if $select_player
  239.       for i in $鼠标效果
  240.         Picture.dispose(i[0])
  241.       end
  242.       return
  243.     end
  244.     # 鼠标在移动或者转向的情况下
  245.     x, y = Mouse.get_mouse_pos
  246.     # 鼠标在移动中的情况下
  247.     if @mouse_x != x or @mouse_y != y or @display_x != $game_map.display_x or @display_y != $game_map.display_y
  248.       # 添加点击动画
  249.       add_animation if move
  250.       # 获取角色位置
  251.       self_x = self.screen_x
  252.       self_y = self.screen_y
  253.       # 排除无效情况
  254.       unless moving? or $game_system.map_interpreter.running? or
  255.         @move_route_forcing or $game_temp.message_window_showing
  256.         if x > self_x
  257.           if y - self_y > - 0.4 * (x - self_x) and y - self_y < 0.4 * (x - self_x)
  258.             move_right if move
  259.             @direction = 6
  260.           end
  261.           if y - self_y > 0.4 * (x - self_x) and y - self_y < 2.4 * (x - self_x)
  262.             move_lower_right if move
  263.             @direction = 3
  264.           end
  265.           if y - self_y < - 0.4 * (x - self_x) and y - self_y > - 2.4 * (x - self_x)
  266.             move_upper_right if move
  267.             @direction = 9
  268.           end
  269.           if y - self_y > 2.4 * (x - self_x)
  270.             move_down if move
  271.             @direction = 2
  272.           end
  273.           if y - self_y < - 2.4 * (x - self_x)
  274.             move_up if move
  275.             @direction = 8
  276.           end
  277.         end
  278.         if x < self_x
  279.           if y - self_y > - 0.4 * (self_x - x) and y - self_y < 0.4 * (self_x - x)
  280.             move_left if move
  281.             @direction = 4
  282.           end
  283.           if y - self_y > 0.4 * (self_x - x) and y - self_y < 2.4 * (self_x - x)
  284.             move_lower_left if move
  285.             @direction = 1
  286.           end
  287.           if y - self_y < - 0.4 * (self_x - x) and y - self_y > - 2.4 * (self_x - x)
  288.             move_upper_left if move
  289.             @direction = 7
  290.           end
  291.           if y - self_y > 2.4 * (self_x - x)
  292.             move_down if move
  293.             @direction = 2
  294.           end
  295.           if y - self_y < - 2.4 * (self_x - x)
  296.             move_up if move
  297.             @direction = 8
  298.           end
  299.         end
  300.       end
  301.       # 记忆变量
  302.       @mouse_x,@mouse_y = Mouse.get_mouse_pos
  303.       @display_x = $game_map.display_x
  304.       @display_y = $game_map.display_y
  305.     end
  306.   end
  307. end
@芯☆淡茹水  

点评

另外我想说你给的脚本不全,建议上工程。  发表于 2014-9-7 00:19

Lv3.寻梦者

梦石
0
星屑
2744
在线时间
2630 小时
注册时间
2013-1-16
帖子
5657

贵宾

2
发表于 2014-9-7 00:09:25 | 只看该作者
我签名档有个寻路,不过只是四方向。抽个空帮你整合一下吧。
(Created by @喵kano)


施工现场:hotege.github.io
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
49
在线时间
200 小时
注册时间
2014-7-17
帖子
410
3
发表于 2014-9-7 21:45:29 | 只看该作者
http://6rweb.sinaapp.com/articles/3249
心目中的神whbm的神作,看你脚本水平如何能否整合了,A星算法。

知其然,而不欲知其所以然,耻也!
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
1556
在线时间
626 小时
注册时间
2010-8-5
帖子
451
4
 楼主| 发表于 2014-9-9 22:29:44 | 只看该作者
myownroc 发表于 2014-9-7 00:09
我签名档有个寻路,不过只是四方向。抽个空帮你整合一下吧。

整合完了木,版主大哥{:2_277:}

点评

你给的脚本不全  发表于 2014-9-9 23:25
回复 支持 反对

使用道具 举报

Lv3.寻梦者

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

点评

这只是寻路……我想看看你在用哪个八方的脚本  发表于 2014-9-10 13:03
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
1556
在线时间
626 小时
注册时间
2010-8-5
帖子
451
6
 楼主| 发表于 2014-9-10 13:14:16 | 只看该作者
第一个
  1. #==============================================================================
  2. # ■ Game_Character (分割定义 3)
  3. #------------------------------------------------------------------------------
  4. #  处理角色的类。本类作为 Game_Player 类与 Game_Event
  5. # 类的超级类使用。
  6. #==============================================================================

  7. class Game_Character
  8.   #--------------------------------------------------------------------------
  9.   # ● 向下移动
  10.   #     turn_enabled : 本场地位置更改许可标志
  11.   #--------------------------------------------------------------------------
  12.   def move_down(turn_enabled = true)
  13.     # 面向下
  14.     if turn_enabled
  15.       turn_down
  16.     end
  17.     # 可以通行的场合
  18.     if passable?(@x, @y, 2)
  19.       # 面向下
  20.       turn_down
  21.       # 更新坐标
  22.       @y += 1
  23.       # 增加步数
  24.       increase_steps
  25.     # 不能通行的情况下
  26.     else
  27.       # 接触事件的启动判定
  28.       check_event_trigger_touch(@x, @y+1)
  29.     end
  30.   end
  31.   #--------------------------------------------------------------------------
  32.   # ● 向左移动
  33.   #     turn_enabled : 本场地位置更改许可标志
  34.   #--------------------------------------------------------------------------
  35.   def move_left(turn_enabled = true)
  36.     # 面向左
  37.     if turn_enabled
  38.       turn_left
  39.     end
  40.     # 可以通行的情况下
  41.     if passable?(@x, @y, 4)
  42.       # 面向左
  43.       turn_left
  44.       # 更新坐标
  45.       @x -= 1
  46.       # 增加步数
  47.       increase_steps
  48.     # 不能通行的情况下
  49.     else
  50.       # 接触事件的启动判定
  51.       check_event_trigger_touch(@x-1, @y)
  52.     end
  53.   end
  54.   #--------------------------------------------------------------------------
  55.   # ● 向右移动
  56.   #     turn_enabled : 本场地位置更改许可标志
  57.   #--------------------------------------------------------------------------
  58.   def move_right(turn_enabled = true)
  59.     # 面向右
  60.     if turn_enabled
  61.       turn_right
  62.     end
  63.     # 可以通行的场合
  64.     if passable?(@x, @y, 6)
  65.       # 面向右
  66.       turn_right
  67.       # 更新坐标
  68.       @x += 1
  69.       # 增加部数
  70.       increase_steps
  71.     # 不能通行的情况下
  72.     else
  73.       # 接触事件的启动判定
  74.       check_event_trigger_touch(@x+1, @y)
  75.     end
  76.   end
  77.   #--------------------------------------------------------------------------
  78.   # ● 向上移动
  79.   #     turn_enabled : 本场地位置更改许可标志
  80.   #--------------------------------------------------------------------------
  81.   def move_up(turn_enabled = true)
  82.     # 面向上
  83.     if turn_enabled
  84.       turn_up
  85.     end
  86.     # 可以通行的情况下
  87.     if passable?(@x, @y, 8)
  88.       # 面向上
  89.       turn_up
  90.       # 更新坐标
  91.       @y -= 1
  92.       # 歩数増加
  93.       increase_steps
  94.     # 不能通行的情况下
  95.     else
  96.       # 接触事件的启动判定
  97.       check_event_trigger_touch(@x, @y-1)
  98.     end
  99.   end
  100.   #--------------------------------------------------------------------------
  101.   # ● 向左下移动
  102.   #--------------------------------------------------------------------------
  103.   def move_lower_left
  104.     # 没有固定面向的场合
  105.     unless @direction_fix
  106.       # 面向左下
  107.       @direction = 1
  108.     end
  109.     # 下→左、左→下 的通道可以通行的情况下
  110.     if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 4)) or
  111.        (passable?(@x, @y, 4) and passable?(@x - 1, @y, 2))
  112.       # 更新坐标
  113.       @x -= 1
  114.       @y += 1
  115.       # 增加步数
  116.       increase_steps
  117.     end
  118.   end
  119.   #--------------------------------------------------------------------------
  120.   # ● 向右下移动
  121.   #--------------------------------------------------------------------------
  122.   def move_lower_right
  123.     # 没有固定面向的场合
  124.     unless @direction_fix
  125.       # 面向右下
  126.       @direction = 3
  127.     end
  128.     # 下→右、右→下 的通道可以通行的情况下
  129.     if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 6)) or
  130.        (passable?(@x, @y, 6) and passable?(@x + 1, @y, 2))
  131.       # 更新坐标
  132.       @x += 1
  133.       @y += 1
  134.       # 增加步数
  135.       increase_steps
  136.     end
  137.   end
  138.   #--------------------------------------------------------------------------
  139.   # ● 向左上移动
  140.   #--------------------------------------------------------------------------
  141.   def move_upper_left
  142.     # 没有固定面向的场合
  143.     unless @direction_fix
  144.       # 面向左上
  145.       @direction = 7
  146.     end
  147.     # 上→左、左→上 的通道可以通行的情况下
  148.     if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 4)) or
  149.        (passable?(@x, @y, 4) and passable?(@x - 1, @y, 8))
  150.       # 更新坐标
  151.       @x -= 1
  152.       @y -= 1
  153.       # 增加步数
  154.       increase_steps
  155.     end
  156.   end
  157.   #--------------------------------------------------------------------------
  158.   # ● 向右上移动
  159.   #--------------------------------------------------------------------------
  160.   def move_upper_right
  161.     # 没有固定面向的场合
  162.     unless @direction_fix
  163.       # 面向右上
  164.       @direction = 9
  165.     end
  166.     # 上→右、右→上 的通道可以通行的情况下
  167.     if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 6)) or
  168.        (passable?(@x, @y, 6) and passable?(@x + 1, @y, 8))
  169.       # 更新坐标
  170.       @x += 1
  171.       @y -= 1
  172.       # 增加步数
  173.       increase_steps
  174.     end
  175.   end
  176.   #--------------------------------------------------------------------------
  177.   # ● 随机移动
  178.   #--------------------------------------------------------------------------
  179.   def move_random
  180.     # 行走图方向为4
  181.     if self.direction_frame == 4
  182.       # 随机移动(四方向)
  183.       case rand(4)
  184.       when 0  # 向左下移动
  185.         move_lower_left
  186.       when 1  # 向左上移动
  187.         move_upper_left
  188.       when 2  # 向右下移动
  189.         move_lower_right
  190.       when 3  # 向右上移动
  191.         move_upper_right
  192.       end
  193.     else
  194.       # 随机移动(八方向)
  195.       case rand(8)
  196.       when 0  # 向下移动
  197.         move_down(false)
  198.       when 1  # 向左移动
  199.         move_left(false)
  200.       when 2  # 向右移动
  201.         move_right(false)
  202.       when 3  # 向上移动
  203.         move_up(false)
  204.       when 4  # 向左下移动
  205.         move_lower_left
  206.       when 5  # 向左上移动
  207.         move_upper_left
  208.       when 6  # 向右下移动
  209.         move_lower_right
  210.       when 7  # 向右上移动
  211.         move_upper_right
  212.       end
  213.     end
  214.   end
  215.   #--------------------------------------------------------------------------
  216.   # ● 接近主角
  217.   #--------------------------------------------------------------------------
  218.   def move_toward_player
  219.     # 求得与主角的坐标差
  220.     sx = @x - $game_player.x
  221.     sy = @y - $game_player.y
  222.     # 坐标相等情况下
  223.     if sx == 0 and sy == 0
  224.       return
  225.     end
  226.     # 求得差的绝对值
  227.     abs_sx = sx.abs
  228.     abs_sy = sy.abs
  229.     # 横距离与纵距离相等的情况下
  230.     if abs_sx == abs_sy
  231.       # 随机将边数增加 1
  232.       rand(2) == 0 ? abs_sx += 1 : abs_sy += 1
  233.     end
  234.     # 横侧距离长的情况下
  235.     if abs_sx > abs_sy
  236.       # 左右方向优先。向主角移动
  237.       sx > 0 ? move_left : move_right
  238.       if not moving? and sy != 0
  239.         sy > 0 ? move_up : move_down
  240.       end
  241.     # 竖侧距离长的情况下
  242.     else
  243.       # 上下方向优先。向主角移动
  244.       sy > 0 ? move_up : move_down
  245.       if not moving? and sx != 0
  246.         sx > 0 ? move_left : move_right
  247.       end
  248.     end
  249.   end
  250.   #--------------------------------------------------------------------------
  251.   # ● 远离主角
  252.   #--------------------------------------------------------------------------
  253.   def move_away_from_player
  254.     # 求得与主角的坐标差
  255.     sx = @x - $game_player.x
  256.     sy = @y - $game_player.y
  257.     # 坐标相等情况下
  258.     if sx == 0 and sy == 0
  259.       return
  260.     end
  261.     # 求得差的绝对值
  262.     abs_sx = sx.abs
  263.     abs_sy = sy.abs
  264.     # 横距离与纵距离相等的情况下
  265.     if abs_sx == abs_sy
  266.       # 随机将边数增加 1
  267.       rand(2) == 0 ? abs_sx += 1 : abs_sy += 1
  268.     end
  269.     # 横侧距离长的情况下
  270.     if abs_sx > abs_sy
  271.       # 左右方向优先。远离主角移动
  272.       sx > 0 ? move_right : move_left
  273.       if not moving? and sy != 0
  274.         sy > 0 ? move_down : move_up
  275.       end
  276.     # 竖侧距离长的情况下
  277.     else
  278.       # 上下方向优先。远离主角移动
  279.       sy > 0 ? move_down : move_up
  280.       if not moving? and sx != 0
  281.         sx > 0 ? move_right : move_left
  282.       end
  283.     end
  284.   end
  285.   #--------------------------------------------------------------------------
  286.   # ● 前进一步
  287.   #--------------------------------------------------------------------------
  288.   def move_forward
  289.     case @direction
  290.     when 2  # 下
  291.       move_down(false)
  292.     when 4  # 左
  293.       move_left(false)
  294.     when 6  # 右
  295.       move_right(false)
  296.     when 8  # 上
  297.       move_up(false)
  298.     when 1  # 左下
  299.       turn_lower_left
  300.     when 3  # 右下
  301.       turn_lower_right
  302.     when 7  # 左上
  303.       turn_upper_left
  304.     when 9  # 右上
  305.       turn_upper_right
  306.     end
  307.   end
  308.   #--------------------------------------------------------------------------
  309.   # ● 后退一步
  310.   #--------------------------------------------------------------------------
  311.   def move_backward
  312.     # 记忆朝向固定信息
  313.     last_direction_fix = @direction_fix
  314.     # 强制固定朝向
  315.     @direction_fix = true
  316.     # 朝向分支
  317.     case @direction
  318.     when 2  # 下
  319.       move_up(false)
  320.     when 4  # 左
  321.       move_right(false)
  322.     when 6  # 右
  323.       move_left(false)
  324.     when 8  # 上
  325.       move_down(false)
  326.     when 1  # 左下
  327.       turn_upper_right
  328.     when 3  # 右下
  329.       turn_upper_left
  330.     when 7  # 左上
  331.       turn_lower_right
  332.     when 9  # 右上
  333.       turn_lower_left
  334.     end
  335.     # 还原朝向固定信息
  336.     @direction_fix = last_direction_fix
  337.   end
  338.   #--------------------------------------------------------------------------
  339.   # ● 跳跃
  340.   #     x_plus : X 坐标增加值
  341.   #     y_plus : Y 坐标增加值
  342.   #--------------------------------------------------------------------------
  343.   def jump(x_plus, y_plus)
  344.     # 增加值不是 (0,0) 的情况下
  345.     if x_plus != 0 or y_plus != 0
  346.       # 横侧距离长的情况下
  347.       if x_plus.abs > y_plus.abs
  348.         # 变更左右方向
  349.         x_plus < 0 ? turn_left : turn_right
  350.       # 竖侧距离长的情况下
  351.       else
  352.         # 变更上下方向
  353.         y_plus < 0 ? turn_up : turn_down
  354.       end
  355.     end
  356.     # 计算新的坐标
  357.     new_x = @x + x_plus
  358.     new_y = @y + y_plus
  359.     # 增加值为 (0,0) 的情况下、跳跃目标可以通行的场合
  360.     if (x_plus == 0 and y_plus == 0) or passable?(new_x, new_y, 0)
  361.       # 矫正姿势
  362.       straighten
  363.       # 更新坐标
  364.       @x = new_x
  365.       @y = new_y
  366.       # 距计算距离
  367.       distance = Math.sqrt(x_plus * x_plus + y_plus * y_plus).round
  368.       # 设置跳跃记数
  369.       @jump_peak = 10 + distance - @move_speed
  370.       @jump_count = @jump_peak * 2
  371.       # 清除停止记数信息
  372.       @stop_count = 0
  373.     end
  374.   end
  375.   #--------------------------------------------------------------------------
  376.   # ● 面向向下
  377.   #--------------------------------------------------------------------------
  378.   def turn_down
  379.     unless @direction_fix
  380.       @direction = 2
  381.       @stop_count = 0
  382.     end
  383.   end
  384.   #--------------------------------------------------------------------------
  385.   # ● 面向向左
  386.   #--------------------------------------------------------------------------
  387.   def turn_left
  388.     unless @direction_fix
  389.       @direction = 4
  390.       @stop_count = 0
  391.     end
  392.   end
  393.   #--------------------------------------------------------------------------
  394.   # ● 面向向右
  395.   #--------------------------------------------------------------------------
  396.   def turn_right
  397.     unless @direction_fix
  398.       @direction = 6
  399.       @stop_count = 0
  400.     end
  401.   end
  402.   #--------------------------------------------------------------------------
  403.   # ● 面向向上
  404.   #--------------------------------------------------------------------------
  405.   def turn_up
  406.     unless @direction_fix
  407.       @direction = 8
  408.       @stop_count = 0
  409.     end
  410.   end
  411.   #--------------------------------------------------------------------------
  412.   # ● 面向左下
  413.   #--------------------------------------------------------------------------
  414.   def turn_lower_left
  415.     unless @direction_fix
  416.       @direction = 1
  417.       @stop_count = 0
  418.     end
  419.   end
  420.   #--------------------------------------------------------------------------
  421.   # ● 面向右下
  422.   #--------------------------------------------------------------------------
  423.   def turn_lower_right
  424.     unless @direction_fix
  425.       @direction = 3
  426.       @stop_count = 0
  427.     end
  428.   end
  429.   #--------------------------------------------------------------------------
  430.   # ● 面向左上
  431.   #--------------------------------------------------------------------------
  432.   def turn_upper_left
  433.     unless @direction_fix
  434.       @direction = 7
  435.       @stop_count = 0
  436.     end
  437.   end
  438.   #--------------------------------------------------------------------------
  439.   # ● 面向右上
  440.   #--------------------------------------------------------------------------
  441.   def turn_upper_right
  442.     unless @direction_fix
  443.       @direction = 9
  444.       @stop_count = 0
  445.     end
  446.   end
  447.   #--------------------------------------------------------------------------
  448.   # ● 向右旋转 90 度
  449.   #--------------------------------------------------------------------------
  450.   def turn_right_90
  451.     case @direction
  452.     when 2
  453.       turn_left
  454.     when 4
  455.       turn_up
  456.     when 6
  457.       turn_down
  458.     when 8
  459.       turn_right
  460.     end
  461.   end
  462.   #--------------------------------------------------------------------------
  463.   # ● 向左旋转 90 度
  464.   #--------------------------------------------------------------------------
  465.   def turn_left_90
  466.     case @direction
  467.     when 2
  468.       turn_right
  469.     when 4
  470.       turn_down
  471.     when 6
  472.       turn_up
  473.     when 8
  474.       turn_left
  475.     end
  476.   end
  477.   #--------------------------------------------------------------------------
  478.   # ● 旋转 180 度
  479.   #--------------------------------------------------------------------------
  480.   def turn_180
  481.     case @direction
  482.     when 2
  483.       turn_up
  484.     when 4
  485.       turn_right
  486.     when 6
  487.       turn_left
  488.     when 8
  489.       turn_down
  490.     end
  491.   end
  492.   #--------------------------------------------------------------------------
  493.   # ● 从右向左旋转 90 度
  494.   #--------------------------------------------------------------------------
  495.   def turn_right_or_left_90
  496.     if rand(2) == 0
  497.       turn_right_90
  498.     else
  499.       turn_left_90
  500.     end
  501.   end
  502.   #--------------------------------------------------------------------------
  503.   # ● 随机变换方向
  504.   #--------------------------------------------------------------------------
  505.   def turn_random
  506.     # 行走图方向为4
  507.     if self.direction_frame == 4
  508.       case rand(4)
  509.       when 0
  510.         turn_lower_left
  511.       when 1
  512.         turn_lower_right
  513.       when 2
  514.         turn_upper_left
  515.       when 3
  516.         turn_upper_right
  517.       end
  518.     else
  519.       case rand(8)
  520.       when 0
  521.         turn_up
  522.       when 1
  523.         turn_right
  524.       when 2
  525.         turn_left
  526.       when 3
  527.         turn_down
  528.       when 4
  529.         turn_lower_left
  530.       when 5
  531.         turn_lower_right
  532.       when 6
  533.         turn_upper_left
  534.       when 7
  535.         turn_upper_right
  536.       end
  537.     end
  538.   end
  539.   #--------------------------------------------------------------------------
  540.   # ● 接近主角的方向
  541.   #--------------------------------------------------------------------------
  542.   def turn_toward_player
  543.     # 求得与主角的坐标差
  544.     sx = @x - $game_player.x
  545.     sy = @y - $game_player.y
  546.     # 坐标相等的场合下
  547.     if sx == 0 and sy == 0
  548.       return
  549.     end
  550.     # 横侧距离长的情况下
  551.     if sx.abs > sy.abs
  552.       # 将左右方向变更为朝向主角的方向
  553.       sx > 0 ? turn_left : turn_right
  554.     # 竖侧距离长的情况下
  555.     else
  556.       # 将上下方向变更为朝向主角的方向
  557.       sy > 0 ? turn_up : turn_down
  558.     end
  559.   end
  560.   #--------------------------------------------------------------------------
  561.   # ● 背向主角的方向
  562.   #--------------------------------------------------------------------------
  563.   def turn_away_from_player
  564.     # 求得与主角的坐标差
  565.     sx = @x - $game_player.x
  566.     sy = @y - $game_player.y
  567.     # 坐标相等的场合下
  568.     if sx == 0 and sy == 0
  569.       return
  570.     end
  571.     # 横侧距离长的情况下
  572.     if sx.abs > sy.abs
  573.       # 将左右方向变更为背离主角的方向
  574.       sx > 0 ? turn_right : turn_left
  575.     # 竖侧距离长的情况下
  576.     else
  577.       # 将上下方向变更为背离主角的方向
  578.       sy > 0 ? turn_down : turn_up
  579.     end
  580.   end
  581. end
复制代码
第二个
  1. #==============================================================================
  2. # ■ Game_Character (分割定义 3)
  3. #------------------------------------------------------------------------------
  4. #  处理角色的类。本类作为 Game_Player 类与 Game_Event
  5. # 类的超级类使用。
  6. #==============================================================================

  7. class Game_Character
  8.   #--------------------------------------------------------------------------
  9.   # ● 向下移动
  10.   #     turn_enabled : 本场地位置更改许可标志
  11.   #--------------------------------------------------------------------------
  12.   def move_down(turn_enabled = true)
  13.     # 面向下
  14.     if turn_enabled
  15.       turn_down
  16.     end
  17.     # 可以通行的场合
  18.     if passable?(@x, @y, 2)
  19.       # 面向下
  20.       turn_down
  21.       # 更新坐标
  22.       @y += 1
  23.       # 增加步数
  24.       increase_steps
  25.     # 不能通行的情况下
  26.     else
  27.       # 接触事件的启动判定
  28.       check_event_trigger_touch(@x, @y+1)
  29.     end
  30.   end
  31.   #--------------------------------------------------------------------------
  32.   # ● 向左移动
  33.   #     turn_enabled : 本场地位置更改许可标志
  34.   #--------------------------------------------------------------------------
  35.   def move_left(turn_enabled = true)
  36.     # 面向左
  37.     if turn_enabled
  38.       turn_left
  39.     end
  40.     # 可以通行的情况下
  41.     if passable?(@x, @y, 4)
  42.       # 面向左
  43.       turn_left
  44.       # 更新坐标
  45.       @x -= 1
  46.       # 增加步数
  47.       increase_steps
  48.     # 不能通行的情况下
  49.     else
  50.       # 接触事件的启动判定
  51.       check_event_trigger_touch(@x-1, @y)
  52.     end
  53.   end
  54.   #--------------------------------------------------------------------------
  55.   # ● 向右移动
  56.   #     turn_enabled : 本场地位置更改许可标志
  57.   #--------------------------------------------------------------------------
  58.   def move_right(turn_enabled = true)
  59.     # 面向右
  60.     if turn_enabled
  61.       turn_right
  62.     end
  63.     # 可以通行的场合
  64.     if passable?(@x, @y, 6)
  65.       # 面向右
  66.       turn_right
  67.       # 更新坐标
  68.       @x += 1
  69.       # 增加部数
  70.       increase_steps
  71.     # 不能通行的情况下
  72.     else
  73.       # 接触事件的启动判定
  74.       check_event_trigger_touch(@x+1, @y)
  75.     end
  76.   end
  77.   #--------------------------------------------------------------------------
  78.   # ● 向上移动
  79.   #     turn_enabled : 本场地位置更改许可标志
  80.   #--------------------------------------------------------------------------
  81.   def move_up(turn_enabled = true)
  82.     # 面向上
  83.     if turn_enabled
  84.       turn_up
  85.     end
  86.     # 可以通行的情况下
  87.     if passable?(@x, @y, 8)
  88.       # 面向上
  89.       turn_up
  90.       # 更新坐标
  91.       @y -= 1
  92.       # 歩数増加
  93.       increase_steps
  94.     # 不能通行的情况下
  95.     else
  96.       # 接触事件的启动判定
  97.       check_event_trigger_touch(@x, @y-1)
  98.     end
  99.   end
  100.   #--------------------------------------------------------------------------
  101.   # ● 向左下移动
  102.   #--------------------------------------------------------------------------
  103.   def move_lower_left
  104.     # 没有固定面向的场合
  105.     unless @direction_fix
  106.       # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
  107.       @direction = 1
  108.     end
  109.     # 下→左、左→下 的通道可以通行的情况下
  110.     if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 4)) or
  111.        (passable?(@x, @y, 4) and passable?(@x - 1, @y, 2))
  112.       # 更新坐标
  113.       @x -= 1
  114.       @y += 1
  115.       # 增加步数
  116.       increase_steps
  117.     end
  118.   end
  119.   #--------------------------------------------------------------------------
  120.   # ● 向右下移动
  121.   #--------------------------------------------------------------------------
  122.   def move_lower_right
  123.     # 没有固定面向的场合
  124.     unless @direction_fix
  125.       # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
  126.       @direction = 3
  127.     end
  128.     # 下→右、右→下 的通道可以通行的情况下
  129.     if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 6)) or
  130.        (passable?(@x, @y, 6) and passable?(@x + 1, @y, 2))
  131.       # 更新坐标
  132.       @x += 1
  133.       @y += 1
  134.       # 增加步数
  135.       increase_steps
  136.     end
  137.   end
  138.   #--------------------------------------------------------------------------
  139.   # ● 向左上移动
  140.   #--------------------------------------------------------------------------
  141.   def move_upper_left
  142.     # 没有固定面向的场合
  143.     unless @direction_fix
  144.       # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
  145.       @direction = 7
  146.     end
  147.     # 上→左、左→上 的通道可以通行的情况下
  148.     if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 4)) or
  149.        (passable?(@x, @y, 4) and passable?(@x - 1, @y, 8))
  150.       # 更新坐标
  151.       @x -= 1
  152.       @y -= 1
  153.       # 增加步数
  154.       increase_steps
  155.     end
  156.   end
  157.   #--------------------------------------------------------------------------
  158.   # ● 向右上移动
  159.   #--------------------------------------------------------------------------
  160.   def move_upper_right
  161.     # 没有固定面向的场合
  162.     unless @direction_fix
  163.       # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
  164.       @direction = 9
  165.     end
  166.     # 上→右、右→上 的通道可以通行的情况下
  167.     if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 6)) or
  168.        (passable?(@x, @y, 6) and passable?(@x + 1, @y, 8))
  169.       # 更新坐标
  170.       @x += 1
  171.       @y -= 1
  172.       # 增加步数
  173.       increase_steps
  174.     end
  175.   end
  176.   #--------------------------------------------------------------------------
  177.   # ● 随机移动(八方向)
  178.   #--------------------------------------------------------------------------
  179.   def move_random
  180.     # 行走图方向为4
  181.     if self.direction_frame == 4
  182.       # 随机移动(四方向)
  183.       case rand(4)
  184.       when 0  # 向左下移动
  185.         move_lower_left
  186.       when 1  # 向左上移动
  187.         move_upper_left
  188.       when 2  # 向右下移动
  189.         move_lower_right
  190.       when 3  # 向右上移动
  191.         move_upper_right
  192.       end
  193.     else
  194.       # 随机移动(八方向)
  195.       case rand(8)
  196.       when 0  # 向下移动
  197.         move_down(false)
  198.       when 1  # 向左移动
  199.         move_left(false)
  200.       when 2  # 向右移动
  201.         move_right(false)
  202.       when 3  # 向上移动
  203.         move_up(false)
  204.       when 4  # 向左下移动
  205.         move_lower_left
  206.       when 5  # 向左上移动
  207.         move_upper_left
  208.       when 6  # 向右下移动
  209.         move_lower_right
  210.       when 7  # 向右上移动
  211.         move_upper_right
  212.       end
  213.     end
  214.   end
  215.   #--------------------------------------------------------------------------
  216.   # ● 接近主角
  217.   #--------------------------------------------------------------------------
  218.   def move_toward_player
  219.     # 求得与主角的坐标差
  220.     sx = @x - $game_player.x
  221.     sy = @y - $game_player.y
  222.     # 坐标相等情况下
  223.     if sx.abs == 0 and sy.abs == 1
  224.       return
  225.     end
  226.     if sx.abs == 1 and sy.abs == 0
  227.       return
  228.     end
  229.     if sx.abs == 1 and sy.abs == 1
  230.       return
  231.     end
  232.     # 行走图方向为4
  233.     if self.direction_frame == 4
  234.       # 以角色为中心,事件在第四象限
  235.       if sx > 0 and sy > 0
  236.         # 向左上移动
  237.         move_upper_left
  238.       # 以角色为中心,事件在第一象限
  239.       elsif sx > 0 and sy < 0
  240.         # 向左下移动
  241.         move_lower_left
  242.       # 以角色为中心,事件在第三象限
  243.       elsif sx < 0 and sy > 0
  244.         # 向右上移动
  245.         move_upper_right
  246.       # 以角色为中心,事件在第二象限
  247.       elsif sx < 0 and sy < 0
  248.         # 向右下移动
  249.         move_lower_right
  250.       end
  251.     else
  252.       # 以角色为中心,事件在第四象限
  253.       if sx > 0 and sy > 0
  254.         # 向左上移动
  255.         move_upper_left
  256.       # 以角色为中心,事件在第一象限
  257.       elsif sx > 0 and sy < 0
  258.         # 向左下移动
  259.         move_lower_left
  260.       # 以角色为中心,事件在第三象限
  261.       elsif sx < 0 and sy > 0
  262.         # 向右上移动
  263.         move_upper_right
  264.       # 以角色为中心,事件在第二象限
  265.       elsif sx < 0 and sy < 0
  266.         # 向右下移动
  267.         move_lower_right
  268.       # 以角色为中心,Y 轴相等 X 轴大于 0
  269.       elsif  sx > 0 and sy == 0
  270.         # 向左移动
  271.         move_left(false)
  272.       # 以角色为中心,Y 轴相等 X 轴小于 0
  273.       elsif  sx < 0 and sy == 0
  274.         # 向右移动
  275.         move_right(false)
  276.       # 以角色为中心,X 轴相等 Y 轴大于 0
  277.       elsif  sx == 0 and sy > 0
  278.         # 向上移动
  279.         move_up(false)
  280.       # 以角色为中心,X 轴相等 Y 轴小于 0
  281.       elsif  sx == 0 and sy < 0
  282.         # 向下移动
  283.         move_down(false)
  284.       end
  285.     end
  286.   end
  287.   #--------------------------------------------------------------------------
  288.   # ● 远离主角
  289.   #--------------------------------------------------------------------------
  290.   def move_away_from_player
  291.     # 求得与主角的坐标差
  292.     sx = @x - $game_player.x
  293.     sy = @y - $game_player.y
  294.     # 坐标相等情况下
  295.     if sx == 0 and sy == 0
  296.       return
  297.     end
  298.     # 行走图方向为4
  299.     if self.direction_frame == 4
  300.       # 以角色为中心,事件在第四象限
  301.       if sx > 0 and sy > 0
  302.         # 向右下移动
  303.         move_lower_right
  304.       # 以角色为中心,事件在第一象限
  305.       elsif sx > 0 and sy < 0
  306.         # 向右上移动
  307.         move_upper_right
  308.       # 以角色为中心,事件在第三象限
  309.       elsif sx < 0 and sy > 0
  310.         # 向左下移动
  311.         move_lower_left
  312.       # 以角色为中心,事件在第二象限
  313.       elsif sx < 0 and sy < 0
  314.         # 向左上移动
  315.         move_upper_left
  316.       end
  317.     else
  318.       # 以角色为中心,事件在第四象限
  319.       if sx > 0 and sy > 0
  320.         # 向右下移动
  321.         move_lower_right
  322.       # 以角色为中心,事件在第一象限
  323.       elsif sx > 0 and sy < 0
  324.         # 向右上移动
  325.         move_upper_right
  326.       # 以角色为中心,事件在第三象限
  327.       elsif sx < 0 and sy > 0
  328.         # 向左下移动
  329.         move_lower_left
  330.       # 以角色为中心,事件在第二象限
  331.       elsif sx < 0 and sy < 0
  332.         # 向左上移动
  333.         move_upper_left
  334.       # 以角色为中心,Y 轴相等 X 轴大于 0
  335.       elsif  sx > 0 and sy == 0
  336.         # 向右移动
  337.         move_right(false)
  338.       # 以角色为中心,Y 轴相等 X 轴小于 0
  339.       elsif  sx < 0 and sy == 0
  340.         # 向左移动
  341.         move_left(false)
  342.       # 以角色为中心,X 轴相等 Y 轴大于 0
  343.       elsif  sx == 0 and sy > 0
  344.         # 向下移动
  345.         move_down(false)
  346.       # 以角色为中心,X 轴相等 Y 轴小于 0
  347.       elsif  sx == 0 and sy < 0
  348.         # 向上移动
  349.         move_up(false)
  350.       end
  351.     end
  352.   end
  353.   #--------------------------------------------------------------------------
  354.   # ● 前进一步
  355.   #--------------------------------------------------------------------------
  356.   def move_forward
  357.     case @direction
  358.     when 2  # 下
  359.       move_down(false)
  360.     when 4  # 左
  361.       move_left(false)
  362.     when 6  # 右
  363.       move_right(false)
  364.     when 8  # 上
  365.       move_up(false)
  366.     when 1  # 左下
  367.       turn_lower_left
  368.     when 3  # 右下
  369.       turn_lower_right
  370.     when 7  # 左上
  371.       turn_upper_left
  372.     when 9  # 右上
  373.       turn_upper_right
  374.     end
  375.   end
  376.   #--------------------------------------------------------------------------
  377.   # ● 后退一步
  378.   #--------------------------------------------------------------------------
  379.   def move_backward
  380.     # 记忆朝向固定信息
  381.     last_direction_fix = @direction_fix
  382.     # 强制固定朝向
  383.     @direction_fix = true
  384.     # 朝向分支
  385.     case @direction
  386.     when 2  # 下
  387.       move_up(false)
  388.     when 4  # 左
  389.       move_right(false)
  390.     when 6  # 右
  391.       move_left(false)
  392.     when 8  # 上
  393.       move_down(false)
  394.     when 1  # 左下
  395.       turn_upper_right
  396.     when 3  # 右下
  397.       turn_upper_left
  398.     when 7  # 左上
  399.       turn_lower_right
  400.     when 9  # 右上
  401.       turn_lower_left
  402.     end
  403.     # 还原朝向固定信息
  404.     @direction_fix = last_direction_fix
  405.   end
  406.   #--------------------------------------------------------------------------
  407.   # ● 跳跃
  408.   #     x_plus : X 坐标增加值
  409.   #     y_plus : Y 坐标增加值
  410.   #--------------------------------------------------------------------------
  411.   def jump(x_plus, y_plus)
  412.     # 增加值不是 (0,0) 的情况下
  413.     if x_plus != 0 or y_plus != 0
  414.       # 横侧距离长的情况下
  415.       if x_plus.abs > y_plus.abs
  416.         # 变更左右方向
  417.         x_plus < 0 ? turn_left : turn_right
  418.       # 竖侧距离长的情况下
  419.       else
  420.         # 变更上下方向
  421.         y_plus < 0 ? turn_up : turn_down
  422.       end
  423.     end
  424.     # 计算新的坐标
  425.     new_x = @x + x_plus
  426.     new_y = @y + y_plus
  427.     # 增加值为 (0,0) 的情况下、跳跃目标可以通行的场合
  428.     if (x_plus == 0 and y_plus == 0) or passable?(new_x, new_y, 0)
  429.       # 矫正姿势
  430.       straighten
  431.       # 更新坐标
  432.       @x = new_x
  433.       @y = new_y
  434.       # 距计算距离
  435.       distance = Math.sqrt(x_plus * x_plus + y_plus * y_plus).round
  436.       # 设置跳跃记数
  437.       @jump_peak = 10 + distance - @move_speed
  438.       @jump_count = @jump_peak * 2
  439.       # 清除停止记数信息
  440.       @stop_count = 0
  441.     end
  442.   end
  443.   #--------------------------------------------------------------------------
  444.   # ● 面向向下
  445.   #--------------------------------------------------------------------------
  446.   def turn_down
  447.     unless @direction_fix
  448.       @direction = 2
  449.       @stop_count = 0
  450.     end
  451.   end
  452.   #--------------------------------------------------------------------------
  453.   # ● 面向向左
  454.   #--------------------------------------------------------------------------
  455.   def turn_left
  456.     unless @direction_fix
  457.       @direction = 4
  458.       @stop_count = 0
  459.     end
  460.   end
  461.   #--------------------------------------------------------------------------
  462.   # ● 面向向右
  463.   #--------------------------------------------------------------------------
  464.   def turn_right
  465.     unless @direction_fix
  466.       @direction = 6
  467.       @stop_count = 0
  468.     end
  469.   end
  470.   #--------------------------------------------------------------------------
  471.   # ● 面向向上
  472.   #--------------------------------------------------------------------------
  473.   def turn_up
  474.     unless @direction_fix
  475.       @direction = 8
  476.       @stop_count = 0
  477.     end
  478.   end
  479.   #--------------------------------------------------------------------------
  480.   # ● 面向左下
  481.   #--------------------------------------------------------------------------
  482.   def turn_lower_left
  483.     unless @direction_fix
  484.       @direction = 1
  485.       @stop_count = 0
  486.     end
  487.   end
  488.   #--------------------------------------------------------------------------
  489.   # ● 面向右下
  490.   #--------------------------------------------------------------------------
  491.   def turn_lower_right
  492.     unless @direction_fix
  493.       @direction = 3
  494.       @stop_count = 0
  495.     end
  496.   end
  497.   #--------------------------------------------------------------------------
  498.   # ● 面向左上
  499.   #--------------------------------------------------------------------------
  500.   def turn_upper_left
  501.     unless @direction_fix
  502.       @direction = 7
  503.       @stop_count = 0
  504.     end
  505.   end
  506.   #--------------------------------------------------------------------------
  507.   # ● 面向右上
  508.   #--------------------------------------------------------------------------
  509.   def turn_upper_right
  510.     unless @direction_fix
  511.       @direction = 9
  512.       @stop_count = 0
  513.     end
  514.   end
  515.   #--------------------------------------------------------------------------
  516.   # ● 向右旋转 90 度
  517.   #--------------------------------------------------------------------------
  518.   def turn_right_90
  519.     case @direction
  520.     when 2
  521.       turn_left
  522.     when 4
  523.       turn_up
  524.     when 6
  525.       turn_down
  526.     when 8
  527.       turn_right
  528.     end
  529.   end
  530.   #--------------------------------------------------------------------------
  531.   # ● 向左旋转 90 度
  532.   #--------------------------------------------------------------------------
  533.   def turn_left_90
  534.     case @direction
  535.     when 2
  536.       turn_right
  537.     when 4
  538.       turn_down
  539.     when 6
  540.       turn_up
  541.     when 8
  542.       turn_left
  543.     end
  544.   end
  545.   #--------------------------------------------------------------------------
  546.   # ● 旋转 180 度
  547.   #--------------------------------------------------------------------------
  548.   def turn_180
  549.     case @direction
  550.     when 2
  551.       turn_up
  552.     when 4
  553.       turn_right
  554.     when 6
  555.       turn_left
  556.     when 8
  557.       turn_down
  558.     end
  559.   end
  560.   #--------------------------------------------------------------------------
  561.   # ● 向右旋转 90 度
  562.   #--------------------------------------------------------------------------
  563.   def turn_right_90
  564.     case @direction
  565.     when 2
  566.       turn_left
  567.     when 4
  568.       turn_up
  569.     when 6
  570.       turn_down
  571.     when 8
  572.       turn_right
  573.     when 1
  574.       turn_upper_left
  575.     when 3
  576.       turn_lower_left
  577.     when 7
  578.       turn_upper_right
  579.     when 9
  580.       turn_lower_right
  581.     end
  582.   end
  583.   #--------------------------------------------------------------------------
  584.   # ● 向左旋转 90 度
  585.   #--------------------------------------------------------------------------
  586.   def turn_left_90
  587.     case @direction
  588.     when 2
  589.       turn_right
  590.     when 4
  591.       turn_down
  592.     when 6
  593.       turn_up
  594.     when 8
  595.       turn_left
  596.     when 1
  597.       turn_lower_right
  598.     when 3
  599.       turn_upper_right
  600.     when 7
  601.       turn_lower_left
  602.     when 9
  603.       turn_upper_left
  604.     end
  605.   end
  606.   #--------------------------------------------------------------------------
  607.   # ● 旋转 180 度
  608.   #--------------------------------------------------------------------------
  609.   def turn_180
  610.     case @direction
  611.     when 2
  612.       turn_up
  613.     when 4
  614.       turn_right
  615.     when 6
  616.       turn_left
  617.     when 8
  618.       turn_down
  619.     when 1
  620.       turn_upper_right
  621.     when 3
  622.       turn_upper_left
  623.     when 7
  624.       turn_lower_right
  625.     when 9
  626.       turn_lower_left
  627.     end
  628.   end
  629.   #--------------------------------------------------------------------------
  630.   # ● 从右向左旋转 90 度
  631.   #--------------------------------------------------------------------------
  632.   def turn_right_or_left_90
  633.     if rand(2) == 0
  634.       turn_right_90
  635.     else
  636.       turn_left_90
  637.     end
  638.   end
  639.   #--------------------------------------------------------------------------
  640.   # ● 随机变换方向
  641.   #--------------------------------------------------------------------------
  642.   def turn_random
  643.     # 行走图方向为4
  644.     if self.direction_frame == 4
  645.       case rand(4)
  646.       when 0
  647.         turn_lower_left
  648.       when 1
  649.         turn_lower_right
  650.       when 2
  651.         turn_upper_left
  652.       when 3
  653.         turn_upper_right
  654.       end
  655.     else
  656.       case rand(8)
  657.       when 0
  658.         turn_up
  659.       when 1
  660.         turn_right
  661.       when 2
  662.         turn_left
  663.       when 3
  664.         turn_down
  665.       when 4
  666.         turn_lower_left
  667.       when 5
  668.         turn_lower_right
  669.       when 6
  670.         turn_upper_left
  671.       when 7
  672.         turn_upper_right
  673.       end
  674.     end
  675.   end
  676.   #--------------------------------------------------------------------------
  677.   # ● 面向主角的方向
  678.   #--------------------------------------------------------------------------
  679.   def turn_toward_player(event=nil)
  680.     # 事件的情况下
  681.     if event.nil?
  682.       # 求得与主角的坐标差
  683.       sx = @x - $game_player.x
  684.       sy = @y - $game_player.y
  685.     else
  686.       # 求得与事件的坐标差
  687.       sx = @x - event.x
  688.       sy = @y - event.y
  689.     end
  690.     # 坐标相等的场合下
  691.     if sx == 0 and sy == 0
  692.       return
  693.     end
  694.     # 行走图方向为4
  695.     if self.direction_frame == 4
  696.       # 以角色为中心,事件在第四象限
  697.       if sx > 0 and sy > 0
  698.         # 面向左上
  699.         turn_upper_left
  700.       # 以角色为中心,事件在第一象限
  701.       elsif sx > 0 and sy < 0
  702.         # 面向左下
  703.         turn_lower_left
  704.       # 以角色为中心,事件在第三象限
  705.       elsif sx < 0 and sy > 0
  706.         # 面向右上
  707.         turn_upper_right
  708.       # 以角色为中心,事件在第二象限
  709.       elsif sx < 0 and sy < 0
  710.         # 面向右下
  711.         turn_lower_right
  712.       end
  713.     else
  714.       # 以角色为中心,事件在第四象限
  715.       if sx > 0 and sy > 0
  716.         if sx.abs > sy.abs + 4
  717.           # 面向左
  718.           turn_left
  719.           return
  720.         end
  721.         if sx.abs + 4 < sy.abs
  722.           # 面向上
  723.           turn_up
  724.           return
  725.         end
  726.         # 面向左上
  727.         turn_upper_left
  728.       # 以角色为中心,事件在第一象限
  729.       elsif sx > 0 and sy < 0
  730.         if sx.abs > sy.abs + 4
  731.           # 面向左
  732.           turn_left
  733.           return
  734.         end
  735.         if sx.abs + 4 < sy.abs
  736.           # 面向下
  737.           turn_down
  738.           return
  739.         end
  740.         # 面向左下
  741.         turn_lower_left
  742.       # 以角色为中心,事件在第三象限
  743.       elsif sx < 0 and sy > 0
  744.         if sx.abs > sy.abs + 4
  745.           # 面向右
  746.           turn_right
  747.           return
  748.         end
  749.         if sx.abs + 4 < sy.abs
  750.           # 面向上
  751.           turn_up
  752.           return
  753.         end
  754.         # 面向右上
  755.         turn_upper_right
  756.       # 以角色为中心,事件在第二象限
  757.       elsif sx < 0 and sy < 0
  758.         if sx.abs > sy.abs + 4
  759.           # 面向右
  760.           turn_right
  761.           return
  762.         end
  763.         if sx.abs + 4 < sy.abs
  764.           # 面向下
  765.           turn_down
  766.           return
  767.         end
  768.         # 面向右下
  769.         turn_lower_right
  770.       # 以角色为中心,Y 轴相等 X 轴大于 0
  771.       elsif  sx > 0 and sy == 0
  772.         # 面向左
  773.         turn_left
  774.       # 以角色为中心,Y 轴相等 X 轴小于 0
  775.       elsif  sx < 0 and sy == 0
  776.         # 面向右
  777.         turn_right
  778.       # 以角色为中心,X 轴相等 Y 轴大于 0
  779.       elsif  sx == 0 and sy > 0
  780.         # 面向上
  781.         turn_up
  782.       # 以角色为中心,X 轴相等 Y 轴小于 0
  783.       elsif  sx == 0 and sy < 0
  784.         # 面向下
  785.         turn_down
  786.       end
  787.     end
  788.   end
  789.   #--------------------------------------------------------------------------
  790.   # ● 背向主角的方向
  791.   #--------------------------------------------------------------------------
  792.   def turn_away_from_player
  793.     # 求得与主角的坐标差
  794.     sx = @x - $game_player.x
  795.     sy = @y - $game_player.y
  796.     # 坐标相等的场合下
  797.     if sx == 0 and sy == 0
  798.       return
  799.     end
  800.     # 行走图方向为4
  801.     if self.direction_frame == 4
  802.       # 以角色为中心,事件在第四象限
  803.       if sx > 0 and sy > 0
  804.         # 面向右下
  805.         turn_lower_right
  806.       # 以角色为中心,事件在第一象限
  807.       elsif sx > 0 and sy < 0
  808.         # 面向右上
  809.         turn_upper_right
  810.       # 以角色为中心,事件在第三象限
  811.       elsif sx < 0 and sy > 0
  812.         # 面向左下
  813.         turn_lower_left
  814.       # 以角色为中心,事件在第二象限
  815.       elsif sx < 0 and sy < 0
  816.         # 面向左上
  817.         turn_upper_left
  818.       end
  819.     else
  820.       # 以角色为中心,事件在第四象限
  821.       if sx > 0 and sy > 0
  822.         # 面向右下
  823.         turn_lower_right
  824.       # 以角色为中心,事件在第一象限
  825.       elsif sx > 0 and sy < 0
  826.         # 面向右上
  827.         turn_upper_right
  828.       # 以角色为中心,事件在第三象限
  829.       elsif sx < 0 and sy > 0
  830.         # 面向左下
  831.         turn_lower_left
  832.       # 以角色为中心,事件在第二象限
  833.       elsif sx < 0 and sy < 0
  834.         # 面向左上
  835.         turn_upper_left
  836.       # 以角色为中心,Y 轴相等 X 轴大于 0
  837.       elsif  sx > 0 and sy == 0
  838.         # 面向右
  839.         turn_right
  840.       # 以角色为中心,Y 轴相等 X 轴小于 0
  841.       elsif  sx < 0 and sy == 0
  842.         # 面向左
  843.         turn_left
  844.       # 以角色为中心,X 轴相等 Y 轴大于 0
  845.       elsif  sx == 0 and sy > 0
  846.         # 面向下
  847.         turn_down
  848.       # 以角色为中心,X 轴相等 Y 轴小于 0
  849.       elsif  sx == 0 and sy < 0
  850.         # 面向上
  851.         turn_up
  852.       end
  853.     end
  854.   end
  855. end
复制代码
@myownroc
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
1556
在线时间
626 小时
注册时间
2010-8-5
帖子
451
7
 楼主| 发表于 2014-9-17 21:23:36 | 只看该作者
@myownroc来吧,。,

点评

没@到,准备看看  发表于 2014-9-17 21:25
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
1556
在线时间
626 小时
注册时间
2010-8-5
帖子
451
8
 楼主| 发表于 2014-9-17 21:27:41 | 只看该作者
@myownroc 点评回复不了
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
2744
在线时间
2630 小时
注册时间
2013-1-16
帖子
5657

贵宾

9
发表于 2014-9-17 21:50:28 | 只看该作者
你还是上工程吧=_=
(Created by @喵kano)


施工现场:hotege.github.io
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
1556
在线时间
626 小时
注册时间
2010-8-5
帖子
451
10
 楼主| 发表于 2014-9-17 21:53:55 | 只看该作者
myownroc 发表于 2014-9-17 21:50
你还是上工程吧=_=

工程太大,需要哪方面脚本,大哥尽管说,我贴上来
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-9-21 15:54

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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