查看: 2185|回复: 4

[已经解决] 各位来看看这个追逐要求,是不是无解了?

[复制链接]
梦石
0
星屑
50
在线时间
338 小时
注册时间
2014-7-15
回帖
491
发表于 2014-11-20 19:03:12 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 hys111111 于 2014-12-6 22:19 编辑

我已经是绞尽脑汁了:
HHA{AN$%~0GI8G2O3%O(V)5.png
重点如下:
1.猫在往下面和右边逃的时候,遇到无法通行的边缘时,能流畅选择通行的方向转向避开玩家追赶
2.猫在往左边和上面逃的时候,能跳跃上酒桶和草坪的边框内
我现在只能做到这个程度,只能做到神似,但是完全不能做到那些要求:
  1. class Game_Character
  2. def toward_player_add2(x = 1,y = 1)
  3. # 求得与主角坐标的差
  4. sx = (@x - $game_player.x).abs
  5. sy = (@y - $game_player.y).abs
  6. if sx <= x and sy <= y
  7. if passable?(@x, @y, 2)
  8. if sx <= 1 and sy <= 1
  9. move_random
  10. else
  11.   move_away_from_player
  12.   end
  13. @move_speed = @last_speed  + 2
  14. move_away_from_player
  15.     # 不能通行的情况下
  16. else
  17.       # 接触事件的启动判定
  18.       jump(0, -2)
  19.     end
  20. else
  21. move_random
  22. @move_speed = @last_speed
  23. end
  24. end
  25. end
复制代码
我感觉无解了....
无法解决卡住的问题,无法解决在面对无法通行时多种要求的移动方式。
梦石
0
星屑
50
在线时间
338 小时
注册时间
2014-7-15
回帖
491
 楼主| 发表于 2014-11-20 19:13:50 | 显示全部楼层
感觉只有通过识别事件坐标来完成,比如具体到四个段的时候,事件如何移动,感觉只用远离主角来做,很难达到理想效果,各位怎么看?
回复

使用道具 举报

梦石
0
星屑
50
在线时间
338 小时
注册时间
2014-7-15
回帖
491
 楼主| 发表于 2014-11-20 19:14:24 | 显示全部楼层
@yang1zhi  

评分

参与人数 1星屑 -10 收起 理由
︶ㄣ牛排ぶ -10 有人举报你连帖,经核实无误

查看全部评分

回复

使用道具 举报

梦石
0
星屑
12161
在线时间
4435 小时
注册时间
2014-4-11
回帖
5616

开拓者

发表于 2014-11-20 22:05:56 | 显示全部楼层
你觉得这个走路方式怎么样。跳上箱子我还不知道怎么写。


[pre lang="ruby" line="1"]#==============================================================================
# ■ Game_Character (接近专定义)
#------------------------------------------------------------------------------
#  处理角色的类。本类作为 Game_Player 类与 Game_Event
# 类的超级类使用。
#==============================================================================
# 使用方法:
# 在设置事件移动那里改为自定义,路线为:toward_player_add(x范围,y范围)
#==============================================================================
class Game_Character
def toward_player_add(x = 1,y = 1)
# 求得与主角坐标的差
sx = (@x - $game_player.x).abs
sy = (@y - $game_player.y).abs
if sx <= x and sy <= y
  unless passable?(@x, @y, 2)
    if passable?(@x, @y, 4)
      move_left
    end
    if passable?(@x, @y, 6)
      move_right
    end
    if passable?(@x, @y, 8)
      move_up
    end
  end
  unless passable?(@x, @y, 4)
      if passable?(@x, @y, 2)
      move_down
    end
    if passable?(@x, @y, 6)
      move_right
    end
    if passable?(@x, @y, 8)
      move_up
    end
  end
      unless passable?(@x, @y, 6)
    if passable?(@x, @y, 2)
      move_down
    end

    if passable?(@x, @y, 4)
      move_left
    end
    if passable?(@x, @y, 8)
      move_up
    end
  end
      unless passable?(@x, @y, 8)
    if passable?(@x, @y, 2)
      move_down
    end

    if passable?(@x, @y, 4)
      move_left
    end
    if passable?(@x, @y, 6)
      move_right
    end
    end
move_away_from_player

else
move_random
end
end
end[/pre]

评分

参与人数 1星屑 +100 梦石 +1 收起 理由
hys111111 + 100 + 1 认可答案

查看全部评分

回复

使用道具 举报

薄凉看客

梦石
0
星屑
50
在线时间
1269 小时
注册时间
2010-6-20
回帖
1223
发表于 2014-11-20 23:20:40 | 显示全部楼层
本帖最后由 恐惧剑刃 于 2014-11-20 23:28 编辑

不知道有没有什么BUG
喵喵.zip (229.65 KB, 下载次数: 27)

[pre lang="ruby" line="1"]=begin

事件注释(必须在最上边):
[Move_Away_From_Player]
Away_Distance          :   [警戒距离]
Speed_Plus             :   [逃跑速度的增加值]
Jump_Distance          :   [检索的最大跳跃距离]
Terrain_Tags           :   [可跳跃墙壁的地形标志]
Jump_Se                :   [跳跃时播放的SE文件名称]

=end


#==============================================================================
# 开始刷新
#==============================================================================
class Game_Character
  alias upd_move_away_from_player update
  def update
    upd_move_away_from_player
    if @away_distance and
      # 与频率联系
      @stop_count > (40 - @move_frequency * 2) * (6 - @move_frequency)
      an_move_away_from_player
    end
  end
end
class Game_Event < Game_Character
  #============================================================================
  # 初始化
  #============================================================================
  def init_move_away_from_player(*args)
    args[0].sub(/\[(.+)\]/, "ha ha !")
    return !args[1] ? $1 : $1.to_i
  end
  alias ref_move_away_from_player refresh
  def refresh
    ref_move_away_from_player
    away_page = @event.pages[@event.pages.index(@page)]
    list = away_page.list
    if list[0].parameters[0] == "[Move_Away_From_Player]"
      # 初始化
      @away_distance = init_move_away_from_player(list[1].parameters[0], true)#视野
      @speed_plus = init_move_away_from_player(list[2].parameters[0], true)#速度附加值
      @jump_distance = init_move_away_from_player(list[3].parameters[0], true)#跳跃检查距离
      @terrain_tags = init_move_away_from_player(list[4].parameters[0], true)#可跳跃的地形标志
      @jump_se = RPG::AudioFile.new
      @jump_se.name = init_move_away_from_player(list[5].parameters[0])#跳跃SE
      # 备份数据
      @old_move_speed = away_page.move_speed
      @old_move_frequency = away_page.move_frequency
      @old_through = away_page.through
      @old_always_on_top = away_page.always_on_top
      return
    end
    # 清理数据
    @away_distance = @speed_plus = @check_distance = @terrain_tags = @jump_se = nil
  end
  #============================================================================
  # 执行刷新
  #============================================================================
  def an_move_away_from_player
    sx = @x - $game_player.x
    sy = @y - $game_player.y
    if sx.abs > @away_distance or sy.abs > @away_distance
      # 恢复速度,频率
      @move_speed = @old_move_speed
      @move_frequency = @old_move_frequency
      move_rand
    else
      # 墙角(???)
      #if (@x == $game_map.width - 1 and @y == $game_map.height - 1) or
      #  (@x == 0 and @y == $game_map.height - 1) or
      #  (@x == $game_map.width - 1 and @y == 0) or
      #  (@x == 0 and @y == 0)
      #  return
      #end
      # 快速逃离
      @move_speed = [@old_move_speed + @speed_plus, 6].min
      @move_frequency = 6
      # 在墙上远离角色
      if $game_map.terrain_tag(@x, @y) == @terrain_tags
        move_away_from_player
        return
      end
      # 跳上墙
      ax = [*(@x - @jump_distance)..(@x + @jump_distance)]
      ay = [*(@y - @jump_distance)..(@y + @jump_distance)]
      for ix in 0...ax.size
        for iy in 0...ay.size
          x = ax[ix]
          y = ay[iy]
          if not $game_map.valid?(x, y)
            next
          end
          if $game_map.terrain_tag(x, y) == @terrain_tags
            # 穿透,置顶
            @through = @always_on_top = true
            $game_system.se_play(@jump_se)
            jump(x - @x, y - @y)
            return
          end
        end
      end
      # 远离角色
      move_away_from_player
    end
  end
  #============================================================================
  # 随机移动
  #============================================================================
  def move_rand
    n = rand(4)
    # 跳下来
    if $game_map.terrain_tag(x, y) == @terrain_tags
      case n
      when 0
        arc = [@x, @y + 1]
        arj = [0, 1]
      when 1
        arc = [@x - 1, @y]
        arj = [-1, 0]
      when 2
        arc = [@x + 1, @y]
        arj = [1, 0]
      when 3
        arc = [@x, @y - 1]
        arj = [0, -1]
      end
      if $game_map.valid?(*arc) and
        $game_map.terrain_tag(*arc) != @terrain_tags
        $game_system.se_play(@jump_se)
        jump(*arj)
        # 恢复穿透,置顶设置
        @through = @old_through
        @always_on_top = @old_always_on_top
        return
      end
    end
    # 随机移动
    case n
    when 0
      move_down(false)
    when 1
      move_left(false)
    when 2
      move_right(false)
    when 3
      move_up(false)
    end
  end
end[/pre]

点评

应该不是地图边缘,现在呢?刚修改了下  发表于 2014-11-20 23:40
有个地方可以堵死猫,不知道是不是你故意留下的。还有就是代码挺复杂的,还有这种方法要试试在封闭空间会不会出现卡顿,因为是跳跃检测不出来  发表于 2014-11-20 23:30

评分

参与人数 1星屑 +100 梦石 +1 收起 理由
hys111111 + 100 + 1 认可答案

查看全部评分

回复

使用道具 举报

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

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部