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

Project1

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

[已经过期] 关于八方向脚本的问题

[复制链接]

Lv1.梦旅人

梦石
0
星屑
127
在线时间
10 小时
注册时间
2018-1-31
帖子
13
跳转到指定楼层
1
发表于 2018-3-3 21:40:48 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
  1. #==============================================================================
  2. # 本脚本来自www.66RPG.com,使用和转载请保留此信息
  3. #==============================================================================
  4. #==============================================================================
  5. #
  6. # XP版八方向移动及遇到障碍自动转向脚本整合 by 7408,使用和转载请保留此信息
  7. # 效果:实现手感加强的八方向移动,遇到障碍自动绕开
  8. # 使用:将此脚本插入到Main前即可,面对事件不进行自动转向,
  9. #      对于个别需要自动转向的事件,在该事件的第一页
  10. #      第一行写一句注释"not_npc"(不含引号),
  11. #      如不需要自动转向功能请删掉354行到593行的内容(就是保留最后一个end)
  12. #
  13. #==============================================================================
  14. class Game_Player < Game_Character
  15.   #--------------------------------------------------------------------------
  16.   # ● 画面更新
  17.   #--------------------------------------------------------------------------
  18.   def update
  19.     # 本地变量记录移动信息
  20.     last_moving = moving?
  21.     # 移动中、事件执行中、强制移动路线中、
  22.     # 信息窗口一个也不显示的时候
  23.     unless moving? or $game_system.map_interpreter.running? or
  24.            @move_route_forcing or $game_temp.message_window_showing
  25.       # 如果方向键被按下、主角就朝那个方向移动
  26.       case Input.dir8
  27.       when 1
  28.         move_lower_left
  29.       when 2
  30.         move_down
  31.       when 3
  32.         move_lower_right
  33.       when 4
  34.         move_left
  35.       when 6
  36.         move_right
  37.       when 7
  38.         move_upper_left
  39.       when 8
  40.         move_up
  41.       when 9
  42.         move_upper_right
  43.       end

  44.     end
  45.     # 本地变量记忆坐标
  46.     last_real_x = @real_x
  47.     last_real_y = @real_y
  48.     super
  49.     # 角色向下移动、画面上的位置在中央下方的情况下
  50.     if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y
  51.       # 画面向下卷动
  52.       $game_map.scroll_down(@real_y - last_real_y)
  53.     end
  54.     # 角色向左移动、画面上的位置在中央左方的情况下
  55.     if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X
  56.       # 画面向左卷动
  57.       $game_map.scroll_left(last_real_x - @real_x)
  58.     end
  59.     # 角色向右移动、画面上的位置在中央右方的情况下
  60.     if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X
  61.       # 画面向右卷动
  62.       $game_map.scroll_right(@real_x - last_real_x)
  63.     end
  64.     # 角色向上移动、画面上的位置在中央上方的情况下
  65.     if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y
  66.       # 画面向上卷动
  67.       $game_map.scroll_up(last_real_y - @real_y)
  68.     end
  69.     # 不在移动中的情况下
  70.     unless moving?
  71.       # 上次主角移动中的情况
  72.       if last_moving
  73.         # 与同位置的事件接触就判定为事件启动
  74.         result = check_event_trigger_here([1,2])
  75.         # 没有可以启动的事件的情况下
  76.         if result == false
  77.           # 调试模式为 ON 并且按下 CTRL 键的情况下除外
  78.           unless $DEBUG and Input.press?(Input::CTRL)
  79.             # 遇敌计数下降
  80.             if @encounter_count > 0
  81.               @encounter_count -= 1
  82.             end
  83.           end
  84.         end
  85.       end
  86.       # 按下 C 键的情况下
  87.       if Input.trigger?(Input::C)
  88.         # 判定为同位置以及正面的事件启动
  89.         check_event_trigger_here([0])
  90.         check_event_trigger_there([0,1,2])
  91.       end
  92.     end
  93.   end
  94. end
  95. class Game_Character
  96.   #--------------------------------------------------------------------------
  97.   # ● 向左下移动
  98.   #--------------------------------------------------------------------------
  99.   def move_lower_left
  100.     # 没有固定面向的场合
  101.     unless @direction_fix
  102.       # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
  103.       @direction = (@direction == 6 ? 4 : @direction == 8 ? 2 : @direction)
  104.     end
  105.     # 下→左、左→下 的通道可以通行的情况下
  106.     if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 4)) and
  107.        (passable?(@x, @y, 4) and passable?(@x - 1, @y, 2))
  108.       # 更新坐标
  109.       @x -= 1
  110.       @y += 1
  111.       # 增加步数
  112.       increase_steps
  113.     # 下→左能够通行的情况下
  114.     elsif (passable?(@x, @y, 2) and passable?(@x, @y + 1, 4))
  115.       # 向下移动后向左移动
  116.       move_down
  117.       move_left
  118.     # 左→下能够通行的情况下
  119.     elsif (passable?(@x, @y, 4) and passable?(@x - 1, @y, 2))
  120.       # 向左移动后向下移动
  121.       move_left
  122.       move_down
  123.     # 如果移动的对象是角色且非强制移动
  124.     elsif self.is_a?(Game_Player) and not @move_route_forcing
  125.       # 面向左时
  126.       if @direction = 4
  127.         # 左方可以通行时
  128.         if passable?(@x, @y, 4)
  129.           # 向左移动
  130.           move_left
  131.         # 不能通行时
  132.         else
  133.           # 左面接触事件启动
  134.           result = check_event_trigger_touch(@x-1, @y)
  135.           # 没有事件的情况下
  136.           unless result
  137.             # 向下移动
  138.             move_down
  139.           end
  140.         end
  141.       # 不面向左时
  142.       else
  143.         # 下方可以通行时
  144.         if passable?(@x, @y, 2)
  145.           # 向下移动
  146.           move_down
  147.         # 不能通行时
  148.         else
  149.           # 下面接触事件启动
  150.           result = check_event_trigger_touch(@x, @y+1)
  151.           # 没有事件的情况下
  152.           unless result
  153.             # 向左移动
  154.             move_left
  155.           end
  156.         end
  157.       end
  158.     end
  159.   end
  160.   #--------------------------------------------------------------------------
  161.   # ● 向右下移动
  162.   #--------------------------------------------------------------------------
  163.   def move_lower_right
  164.     # 没有固定面向的场合
  165.     unless @direction_fix
  166.       # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
  167.       @direction = (@direction == 4 ? 6 : @direction == 8 ? 2 : @direction)
  168.     end
  169.     # 下→右、右→下 的通道可以通行的情况下
  170.     if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 6)) or
  171.        (passable?(@x, @y, 6) and passable?(@x + 1, @y, 2))
  172.       # 更新坐标
  173.       @x += 1
  174.       @y += 1
  175.       # 增加步数
  176.       increase_steps
  177.     # 下→右能够通行的情况下
  178.     elsif (passable?(@x, @y, 2) and passable?(@x, @y + 1, 6))
  179.       # 向下移动后向右移动
  180.       move_down
  181.       move_right
  182.     # 右→下能够通行的情况下
  183.     elsif (passable?(@x, @y, 6) and passable?(@x + 1, @y, 2))
  184.       # 向右移动后向下移动
  185.       move_right
  186.       move_down
  187.     # 如果移动的对象是角色且非强制移动
  188.     elsif self.is_a?(Game_Player) and not @move_route_forcing
  189.       # 面向右时
  190.       if @direction = 6
  191.         # 右方可以通行时
  192.         if passable?(@x, @y, 6)
  193.           # 向右移动
  194.           move_right
  195.         # 不能通行时
  196.         else
  197.           # 右面接触事件启动
  198.           result = check_event_trigger_touch(@x+1, @y)
  199.           # 没有事件的情况下
  200.           unless result
  201.             # 向下移动
  202.             move_down
  203.           end
  204.         end
  205.       # 不面向右时
  206.       else
  207.         # 下方可以通行时
  208.         if passable?(@x, @y, 2)
  209.           # 向下移动
  210.           move_down
  211.         # 不能通行时
  212.         else
  213.           # 下面接触事件启动
  214.           result = check_event_trigger_touch(@x, @y+1)
  215.           # 没有事件的情况下
  216.           unless result
  217.             # 向右移动
  218.             move_right
  219.           end
  220.         end
  221.       end
  222.     end
  223.   end
  224.   #--------------------------------------------------------------------------
  225.   # ● 向左上移动
  226.   #--------------------------------------------------------------------------
  227.   def move_upper_left
  228.     # 没有固定面向的场合
  229.     unless @direction_fix
  230.       # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
  231.       @direction = (@direction == 6 ? 4 : @direction == 2 ? 8 : @direction)
  232.     end
  233.     # 上→左、左→上 的通道可以通行的情况下
  234.     if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 4)) or
  235.        (passable?(@x, @y, 4) and passable?(@x - 1, @y, 8))
  236.       # 更新坐标
  237.       @x -= 1
  238.       @y -= 1
  239.       # 增加步数
  240.       increase_steps
  241.     # 上→左能够通行的情况下
  242.     elsif (passable?(@x, @y, 8) and passable?(@x, @y - 1, 4))
  243.       # 向上移动后向左移动
  244.       move_up
  245.       move_left
  246.     # 左→上能够通行的情况下
  247.     elsif (passable?(@x, @y, 4) and passable?(@x - 1, @y, 8))
  248.       # 向左移动后向上移动
  249.       move_left
  250.       move_up
  251.     # 如果移动的对象是角色且非强制移动
  252.     elsif self.is_a?(Game_Player) and not @move_route_forcing
  253.       # 面向左时
  254.       if @direction = 4
  255.         # 左方可以通行时
  256.         if passable?(@x, @y, 4)
  257.           # 向左移动
  258.           move_left
  259.         # 不能通行时
  260.         else
  261.           # 左面接触事件启动
  262.           result = check_event_trigger_touch(@x-1, @y)
  263.           # 没有事件的情况下
  264.           unless result
  265.             # 向上移动
  266.             move_up
  267.           end
  268.         end
  269.       # 不面向左时
  270.       else
  271.         # 上方可以通行时
  272.         if passable?(@x, @y, 8)
  273.           # 向上移动
  274.           move_up
  275.         # 不能通行时
  276.         else
  277.           # 上面接触事件启动
  278.           result = check_event_trigger_touch(@x, @y-1)
  279.           # 没有事件的情况下
  280.           unless result
  281.             # 向左移动
  282.             move_left
  283.           end
  284.         end
  285.       end
  286.     end
  287.   end
  288.   #--------------------------------------------------------------------------
  289.   # ● 向右上移动
  290.   #--------------------------------------------------------------------------
  291.   def move_upper_right
  292.     # 没有固定面向的场合
  293.     unless @direction_fix
  294.       # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
  295.       @direction = (@direction == 4 ? 6 : @direction == 2 ? 8 : @direction)
  296.     end
  297.     # 上→右、右→上 的通道可以通行的情况下
  298.     if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 6)) or
  299.        (passable?(@x, @y, 6) and passable?(@x + 1, @y, 8))
  300.       # 更新坐标
  301.       @x += 1
  302.       @y -= 1
  303.       # 增加步数
  304.       increase_steps
  305.     # 上→右能够通行的情况下
  306.     elsif (passable?(@x, @y, 8) and passable?(@x, @y - 1, 6))
  307.       # 向上移动后向右移动
  308.       move_up
  309.       move_right
  310.     # 右→上能够通行的情况下
  311.     elsif (passable?(@x, @y, 6) and passable?(@x + 1, @y, 8))
  312.       # 向右移动后向上移动
  313.       move_right
  314.       move_up
  315.     # 如果移动的对象是角色且非强制移动
  316.     elsif self.is_a?(Game_Player) and not @move_route_forcing
  317.       # 面向右时
  318.       if @direction = 6
  319.         # 右方可以通行时
  320.         if passable?(@x, @y, 6)
  321.           # 向右移动
  322.           move_right
  323.         # 不能通行时
  324.         else
  325.           # 右面接触事件启动
  326.           result = check_event_trigger_touch(@x+1, @y)
  327.           # 没有事件的情况下
  328.           unless result
  329.             # 向上移动
  330.             move_up
  331.           end
  332.         end
  333.       # 不面向右时
  334.       else
  335.         # 上方可以通行时
  336.         if passable?(@x, @y, 8)
  337.           # 向上移动
  338.           move_up
  339.         # 不能通行时
  340.         else
  341.           # 上面接触事件启动
  342.           result = check_event_trigger_touch(@x, @y-1)
  343.           # 没有事件的情况下
  344.           unless result
  345.             # 向右移动
  346.             move_right
  347.           end
  348.         end
  349.       end
  350.     end
  351.   end
  352. end
复制代码

我这个萌新又来求问了,是这样的,我用了这个八方向的脚本(里面原有的自动绕路被我删了),很完美的实现了八方向移动,但是我觉得在斜向移动的同时还是以原来的正向角色图形很别扭。
就说说我的请求吧,假设角色行走图的名字为“QAQ.png”,哪位大佬帮我设定当斜向的同时把角色图形更改为“QAQ_X.png”,正向时再改回来,并且要求不与人物跟随、近大远小脚本冲突,万分感谢哦……
2Al+2Cu====Cl₂↑+2Au

Lv5.捕梦者

梦石
0
星屑
37829
在线时间
5413 小时
注册时间
2006-11-10
帖子
6549
2
发表于 2018-3-6 18:33:00 | 只看该作者
你的这个是"伪"八方向, 斜向移动只是把原本按一下方向移动一次, 变成按一下方向移动两次~

根据脚本原理,你把自动绕路删了的话,某些情况下可是会出现类似象棋中别马脚一样的现象哦,  不要自动绕路的话,建议画地图都用横平竖直的大路,不要在路上设置不可通行的零碎障碍物~~

如果要实现更换行走图, 有两种方法,  1是把它变成"真"八方向, 也就是给4个斜向定义direction= 1,3,7,9. 然后到Sprite_Character里追加4个角色矩形的计算.
用这个方法可以保证"转向自然","无懈可击"~~ 缺点是,你要给所有NPC都准备8方向

2是偷懒法,只给主角用8反向, 思路:加个开关, 用它来判断是正常操作还是斜向操作, 然后移动操作里追加这个开关的打开和关闭.  然后用这个开关来判断, 当Character是主角的时候,开关关闭使用XXX行走图,开关打开使用XXX2行走图.
用这个方法可以一定程度上实现"不会正向斜移动", 然而缺点是, 一些接触式的事件可能会有囧情况~~ 比如斜着进门之类的, 不想出现这些BUG, 设置这些事件同样要考虑到这个开关问题. 考研细心  
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-4-30 21:37

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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