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

Project1

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

[已经过期] 急急~~RMXP八方向行走遇到障碍物实现(下->左)行走问题

[复制链接]

Lv1.梦旅人

梦石
0
星屑
50
在线时间
8 小时
注册时间
2014-3-7
帖子
10
跳转到指定楼层
1
发表于 2014-5-17 17:19:45 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
RMXP八方向行走的功能已经学会,不过在遇到障碍物时会卡住,显得很笨拙。比如人物左边有障碍物(即左->下不能通行),但是沿着(下->左)的路径是可以通行的,请问如何实现这一功能?

我根据网上几位大神的答案尝试写了一下脚本但只是实现了下->左,实现不了左->下,这是为什么?

原来左下行走脚本:

  #--------------------------------------------------------------------------
  # ● 向左下移动
  #--------------------------------------------------------------------------
  def move_lower_left(turn_enabled = true,x=-1,y=1)
    turn_1
    # 没有固定面向的场合
    unless @direction_fix
      # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
      @direction = 1
    end
    # 下→左、左→下 的通道可以通行的情况下
    for i in 0 ... @move_speed
    if passable?(x,y,1)
      # 更新坐标
      @real_x += x
      @real_y += y
      # 增加步数
      increase_steps
    end
    end
  end


网上实现此功能的办法:


# 下→左、左→下 的通道可以通行的情况下
   if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 4)) and
      (passable?(@x, @y, 4) and passable?(@x - 1, @y, 2))
这样虽说是可以了,但是,也不能说一条走不通就不让动啊,所以还需要分别判定两个方向的路径:
   # 下→左、左→下 的通道可以通行的情况下
   if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 4)) and
      (passable?(@x, @y, 4) and passable?(@x - 1, @y, 2))
     # 更新坐标
     @x -= 1
     @y += 1
     # 增加步数
     increase_steps
   # 下→左能够通行的情况下
   elsif (passable?(@x, @y, 2) and passable?(@x, @y + 1, 4))
     # 向下移动后向左移动
     move_down
     move_left
   # 左→下能够通行的情况下
   elsif (passable?(@x, @y, 4) and passable?(@x - 1, @y, 2))
     # 向左移动后向下移动
     move_left
     move_down
   end




我自己综合了一下之后:


  def move_lower_left(turn_enabled = true,x=-1,y=1)
    turn_1
    # 没有固定面向的场合
    unless @direction_fix
      # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
      @direction = 1
    end
    for i in 0 ... @move_speed
    if passable?(x,y,1)
      # 更新坐标
       @real_x += x
       @real_y += y
       # 增加步数
       increase_steps
     # 左→下能够通行的情况下
     elsif (passable?(@x, @y, 4) and passable?(@x - 1, @y, 2))
       # 向左移动后向下移动
       @real_x += x
       @real_y += y
       increase_steps
     # 下→左能够通行的情况下
     elsif (passable?(@x, @y, 2) and passable?(@x, @y + 1, 4))
       # 向下移动后向左移动
       @real_y += y        
       @real_x += x
       increase_steps
     end
    end
  end


现在问题是左边遇到障碍物时,可以实现下->左,但是下边遇到障碍物时,却不能实现左->下,请问这是为什么?怎么修改才能解决?

Lv3.寻梦者

梦石
0
星屑
3570
在线时间
3064 小时
注册时间
2011-11-17
帖子
980
2
发表于 2014-5-17 23:20:07 | 只看该作者
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
180
在线时间
509 小时
注册时间
2010-10-1
帖子
97
3
发表于 2014-5-18 17:01:10 | 只看该作者
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-9-30 21:19

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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