Project1

标题: 怎么做只能斜向的移动 [打印本页]

作者: 落月小天魔    时间: 2014-5-25 17:27
标题: 怎么做只能斜向的移动
本帖最后由 落月小天魔 于 2014-5-25 17:45 编辑

如题,RMVA的默认移动是上下左右,而我想做一个
    ↖ ↗
    ↙ ↘的移动,现在找到了八方向移动的脚本,
https://rpg.blue/forum.php?mod=viewthread&tid=242869&highlight=%E5%85%AB%E6%96%B9%E5%90%91

就是在这种地图上的斜向移动,只能斜向移动,不能水平垂直移动,要怎么修改这个脚本?

作者: taroxd    时间: 2014-5-25 17:32
本帖最后由 taroxd 于 2014-5-25 17:33 编辑

删除脚本第33行或优化版第19行:when 2,4,6,8;  move_straight(Input.dir4)试试
作者: taroxd    时间: 2014-5-25 17:43
Sion优化版
  1. class Game_Player
  2.   def move_by_input
  3.     return if !movable? || $game_map.interpreter.running?
  4.     case Input.dir4
  5.     when 2 then move_diagonal(4, 2)
  6.     when 6 then move_diagonal(6, 2)
  7.     when 4 then move_diagonal(4, 8)
  8.     when 8 then move_diagonal(6, 8)
  9.     end
  10.   end
  11. end
复制代码

作者: Sion    时间: 2014-5-25 18:14
只能走斜线的话,就类似国际象棋棋盘上的象了,只能走白色或者黑色的格子。
并且只能触发位于自己无法抵达位置的事件。
实际朝向与行走图朝向不一致,也是一个问题。
作者: moy    时间: 2014-5-25 18:28
Sion 发表于 2014-5-25 18:14
只能走斜线的话,就类似国际象棋棋盘上的象了,只能走白色或者黑色的格子。
并且只能触发位于自己无法抵达 ...

我觉得行走图倒不用担心。楼主看起来就是准备做类似仙剑1那样的游戏,肯定找好了素材了。。我觉得搞不好得在check_event_trigger_there的关联方法上动手。。
  1. def check_event_trigger_there(triggers)
  2.     x2 = $game_map.round_x_with_direction(@x, @direction)
  3.     y2 = $game_map.round_y_with_direction(@y, @direction)
  4.     start_map_event(x2, y2, triggers, true)
  5.     return if $game_map.any_event_starting?
  6.     return unless $game_map.counter?(x2, y2)
  7.     x3 = $game_map.round_x_with_direction(x2, @direction)
  8.     y3 = $game_map.round_y_with_direction(y2, @direction)
  9.     start_map_event(x3, y3, triggers, true)
  10. end
复制代码
但是那两个round看得我晕晕乎乎的……2468绕死我啦!
  1.   #--------------------------------------------------------------------------
  2.   # ● 计算特定方向推移一个图块的 X 坐标(没有循环修正)
  3.   #--------------------------------------------------------------------------
  4.   def round_x_with_direction(x, d)
  5.     round_x(x + (d == 6 ? 1 : d == 4 ? -1 : 0))
  6.   end
  7.   #--------------------------------------------------------------------------
  8.   # ● 计算特定方向推移一个图块的 Y 坐标(没有循环修正)
  9.   #--------------------------------------------------------------------------
  10.   def round_y_with_direction(y, d)
  11.     round_y(y + (d == 2 ? 1 : d == 8 ? -1 : 0))
  12.   end
复制代码
@taroxd 善后交给你了← ←
作者: taroxd    时间: 2014-5-25 18:35
本帖最后由 taroxd 于 2014-5-25 18:49 编辑

添加脚本:
RUBY 代码复制
  1. class Game_Map
  2.   DIR8_4 = [nil,[4,2],[5,2],[6,2],[4,5],[5,5],[6,5],[4,8],[5,8],[6,8]]
  3.   def round_xy_with_direction(x, y, d)
  4.     x = round_x_with_direction(x, DIR8_4[d][0])
  5.     y = round_y_with_direction(y, DIR8_4[d][1])
  6.     return x, y
  7.   end
  8. end
  9.  
  10. class Game_Player
  11.   def check_event_trigger_there(triggers)
  12.     x, y = $game_map.round_xy_with_direction(@x, @y, @direction)
  13.     start_map_event(x, y, triggers, true)
  14.     return if $game_map.any_event_starting?
  15.     return unless $game_map.counter?(x, y)
  16.     x, y = $game_map.round_xy_with_direction(x, y, @direction)
  17.     start_map_event(x, y, triggers, true)
  18.   end
  19. end





欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1