Project1

标题: 如何判断两个以上事件的同时移动(续) [打印本页]

作者: 精灵使者    时间: 2008-6-20 00:05
标题: 如何判断两个以上事件的同时移动(续)
我利用一个按键来操作多个事件,但是出现了问题。
问题就是
如果直接设置所有事件的移动路线的话,遇到障碍物会死机。
如果把移动路线加上判定
$game_player.passable?($game_map.events[a].x,$game_map.events[a].y,方向)
+多重事件判断
的话会解决这个问题,但是出现了另外一种情况。
问题发生在两个事件或者多个事件挨在一起的时候
问题发生在前面的判断的事件如果有其他未移动的事件在上面的时候,就会判断错误而无法移动。
例如首先判断1号,然后判断2号。
如果事件是2号和1号同方向排列的话,1号因为判定2号在前方而无法移动。
1号和2号同方向排列的话,2个可以同时移动。
如何实现两全其美(即可以自由移动而又识别障碍物呢?)
请高人解答。 [LINE]1,#dddddd[/LINE]版务信息:版主帮忙结贴~
作者: hitlerson    时间: 2008-6-20 00:14
不移动的事件的事件坐标 A=[[1,1],[3,1]]
移动的事件移动后坐标 B=[[1,2],[2,2],[2,1]]
没有重复,都能移动
与A中重复,不能移动
与B中重复,优先的能移动,其他不能移动.......

抛砖引玉中...
作者: 精灵使者    时间: 2008-6-20 00:19
数组啊?能做个范例工程么?
只要使用上下左右能同时操纵4个并在一起的事件,而且能识别障碍物就可以。
作者: 此ID只用一次    时间: 2008-6-20 00:25
提示: 作者被禁止或删除 内容自动屏蔽
作者: 精灵使者    时间: 2008-6-20 00:39
那么好吧……

如果顺序的话可以实现同时移动

逆序的话,下面的无法移动

作者: hitlerson    时间: 2008-6-20 01:00
随机朝向的

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

作者: 精灵使者    时间: 2008-6-20 01:08
我回来了~你可以做个范例工程给我。
你那个太复杂了。
把那个表达式直接换成turn_random就可以了。
作者: 此ID只用一次    时间: 2008-6-20 01:28
提示: 作者被禁止或删除 内容自动屏蔽
作者: 此ID只用一次    时间: 2008-6-20 01:30
提示: 作者被禁止或删除 内容自动屏蔽
作者: 精灵使者    时间: 2008-6-20 01:43
你的那个问题很明显,也出现了截图里一样的问题。
我的游戏中设定无法移动的时候是不能随机移动的。要不游戏就无法进行下去了。
我要的目标是:两个人一起向上走。
作者: 此ID只用一次    时间: 2008-6-20 02:01
提示: 作者被禁止或删除 内容自动屏蔽
作者: 精灵使者    时间: 2008-6-20 04:45
允许穿透?恩恩……稍后我下载看看。
作者: 身之察察    时间: 2008-6-20 05:36
研究出来一个,请精灵达人过目

http://rpg.blue/upload_program/files/Project18_94342020.rar
[LINE]1,#dddddd[/LINE]版主对此帖的认可:『解决问题发奖』,积分『+500』。
作者: TERENCE    时间: 2008-6-20 06:25
屏蔽

作者: TERENCE    时间: 2008-6-20 06:51
多定义新的passable?叫new_passable?
貼在main前即可

  1. class Game_Character
  2.   #--------------------------------------------------------------------------
  3.   # ● 新通行判定方法
  4.   #     x : X 坐标
  5.   #     y : Y 坐标
  6.   #     d : 方向 (0,2,4,6,8)  ※ 0 = 全方向不能通行的情况判定 (跳跃用)
  7.   #--------------------------------------------------------------------------
  8.   def new_passable?(x, y, d)
  9.     # 求得新的坐标
  10.     new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
  11.     new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
  12.     # 坐标在地图以外的情况
  13.     unless $game_map.valid?(new_x, new_y)
  14.       # 不能通行
  15.       return false
  16.     end
  17.     # 穿透是 ON 的情况下
  18.     if @through
  19.       # 可以通行
  20.       return true
  21.     end
  22.     # 移动者的元件无法来到指定方向的情况下
  23.     unless $game_map.passable?(x, y, d, self)
  24.       # 通行不可
  25.       return false
  26.     end
  27.     # 从指定方向不能进入到移动处的元件的情况下
  28.     unless $game_map.passable?(new_x, new_y, 10 - d)
  29.       # 不能通行
  30.       return false
  31.     end
  32.     # 循环全部事件
  33.     for event in $game_map.events.values
  34.       # 事件坐标于移动目标坐标一致的情况下
  35.       if event.x == new_x and event.y == new_y
  36.         # 穿透为 ON
  37.         unless event.through
  38.           # 自己就是事件的情况下
  39.           if self != $game_player
  40.             # 不能通行
  41.             return false
  42.           end
  43.           # 自己是主角、对方的图形是角色的情况下
  44.           if event.character_name != ""
  45.             # 不能通行
  46.             return true
  47.           end
  48.         end
  49.       end
  50.     end
  51.     # 主角的坐标与移动目标坐标一致的情况下
  52.     if $game_player.x == new_x and $game_player.y == new_y
  53.       # 穿透为 ON
  54.       unless $game_player.through
  55.         # 自己的图形是角色的情况下
  56.         if @character_name != ""
  57.           # 不能通行
  58.           return false
  59.         end
  60.       end
  61.     end
  62.     # 可以通行
  63.     return true
  64.   end
  65. end
复制代码

调用方式:
$game_player.new_passable?($game_map.events[a].x,$game_map.events[a].y,方向)
范例:
http://rpg.blue/upload_program/files/Project2_94344311.rar
作者: hitlerson    时间: 2008-6-20 07:48
  1. class Game_Character
  2.   attr_accessor :move                     # 已经行动
  3. end

  4. NAME = "019-Thief04"  #设置哪些角色你能控制,现在设置的是图为019-Thief04的

  5. #==============================================================================
  6. # ■ Scene_Map
  7. #------------------------------------------------------------------------------
  8. #  处理地图画面的类。
  9. #==============================================================================

  10. class Scene_Map
  11.   #--------------------------------------------------------------------------
  12.   # ● 主处理
  13.   #--------------------------------------------------------------------------
  14.   def main
  15.     # 生成活动块
  16.     @spriteset = Spriteset_Map.new
  17.     # 生成信息窗口
  18.     @message_window = Window_Message.new
  19.     # 执行过渡
  20.     Graphics.transition
  21.     # 主循环
  22.     loop do
  23.       # 刷新游戏画面
  24.       Graphics.update
  25.       # 刷新输入信息
  26.       Input.update
  27.       # 刷新画面
  28.       update
  29.       # 如果画面切换的话就中断循环
  30.       if $scene != self
  31.         break
  32.       end
  33.     end
  34.     # 准备过渡
  35.     Graphics.freeze
  36.     # 释放活动块
  37.     @spriteset.dispose
  38.     # 释放信息窗口
  39.     @message_window.dispose
  40.     # 标题画面切换中的情况下
  41.     if $scene.is_a?(Scene_Title)
  42.       # 淡入淡出画面
  43.       Graphics.transition
  44.       Graphics.freeze
  45.     end
  46.   end
  47.   #--------------------------------------------------------------------------
  48.   # ● 刷新画面
  49.   #--------------------------------------------------------------------------
  50.   def update
  51.     # 循环
  52.     loop do
  53.       # 按照地图、实例、主角的顺序刷新
  54.       # (本更新顺序不会在的满足事件的执行条件下成为给予角色瞬间移动
  55.       #  的机会的重要因素)
  56.       $game_map.update
  57.       $game_system.map_interpreter.update
  58.       $game_player.update
  59.       # 系统 (计时器)、画面刷新
  60.       $game_system.update
  61.       $game_screen.update
  62.       # 如果主角在场所移动中就中断循环
  63.       unless $game_temp.player_transferring
  64.         break
  65.       end
  66.       # 执行场所移动
  67.       transfer_player
  68.       # 处理过渡中的情况下、中断循环
  69.       if $game_temp.transition_processing
  70.         break
  71.       end
  72.     end
  73.     # 刷新活动块
  74.     @spriteset.update
  75.     # 刷新信息窗口
  76.     @message_window.update
  77.     # 游戏结束的情况下
  78.     if $game_temp.gameover
  79.       # 切换的游戏结束画面
  80.       $scene = Scene_Gameover.new
  81.       return
  82.     end
  83.     # 返回标题画面的情况下
  84.     if $game_temp.to_title
  85.       # 切换到标题画面
  86.       $scene = Scene_Title.new
  87.       return
  88.     end
  89.     # 处理过渡中的情况下
  90.     if $game_temp.transition_processing
  91.       # 清除过渡处理中标志
  92.       $game_temp.transition_processing = false
  93.       # 执行过渡
  94.       if $game_temp.transition_name == ""
  95.         Graphics.transition(20)
  96.       else
  97.         Graphics.transition(40, "Graphics/Transitions/" +
  98.           $game_temp.transition_name)
  99.       end
  100.     end
  101.     # 显示信息窗口中的情况下
  102.     if $game_temp.message_window_showing
  103.       return
  104.     end
  105.     # 遇敌计数为 0 且、且遇敌列表不为空的情况下
  106.     if $game_player.encounter_count == 0 and $game_map.encounter_list != []
  107.       # 不是在事件执行中或者禁止遇敌中
  108.       unless $game_system.map_interpreter.running? or
  109.              $game_system.encounter_disabled
  110.         # 确定队伍
  111.         n = rand($game_map.encounter_list.size)
  112.         troop_id = $game_map.encounter_list[n]
  113.         # 队伍有效的话
  114.         if $data_troops[troop_id] != nil
  115.           # 设置调用战斗标志
  116.           $game_temp.battle_calling = true
  117.           $game_temp.battle_troop_id = troop_id
  118.           $game_temp.battle_can_escape = true
  119.           $game_temp.battle_can_lose = false
  120.           $game_temp.battle_proc = nil
  121.         end
  122.       end
  123.     end
  124.     ########################################################################
  125.     if Input.press?(Input::LEFT)
  126.       turn(4)
  127.     end
  128.     if Input.press?(Input::RIGHT)
  129.       turn(6)
  130.     end
  131.     if Input.press?(Input::UP)
  132.       turn(8)
  133.     end
  134.     if Input.press?(Input::DOWN)
  135.       turn(2)
  136.     end
  137.     ########################################################################
  138.     # 按下 B 键的情况下
  139.     if Input.trigger?(Input::B)
  140.       # 不是在事件执行中或菜单禁止中
  141.       unless $game_system.map_interpreter.running? or
  142.              $game_system.menu_disabled
  143.         # 设置菜单调用标志以及 SE 演奏
  144.         $game_temp.menu_calling = true
  145.         $game_temp.menu_beep = true
  146.       end
  147.     end
  148.     # 调试模式为 ON 并且按下 F9 键的情况下
  149.     if $DEBUG and Input.press?(Input::F9)
  150.       # 设置调用调试标志
  151.       $game_temp.debug_calling = true
  152.     end
  153.     # 不在主角移动中的情况下
  154.     unless $game_player.moving?
  155.       # 执行各种画面的调用
  156.       if $game_temp.battle_calling
  157.         call_battle
  158.       elsif $game_temp.shop_calling
  159.         call_shop
  160.       elsif $game_temp.name_calling
  161.         call_name
  162.       elsif $game_temp.menu_calling
  163.         call_menu
  164.       elsif $game_temp.save_calling
  165.         call_save
  166.       elsif $game_temp.debug_calling
  167.         call_debug
  168.       end
  169.     end
  170.   end
  171.   ########################################################################
  172.   def turn(type)
  173.     unless $game_system.map_interpreter.running? or moving? or
  174.            @move_route_forcing or $game_temp.message_window_showing
  175.       case type
  176.       when 2  #下
  177.         x0 = 0 ; y0 = 1
  178.       when 4
  179.         x0 = -1 ; y0 = 0
  180.       when 6
  181.         x0 = 1 ; y0 = 0
  182.       when 8
  183.         x0 = 0 ; y0 = -1
  184.       end
  185.       e = {} ; b = []
  186.       for event in $game_map.events.values
  187.         event.move = false
  188.         if event.character_name == "019-Thief04"
  189.           e[event.id] = ([event.x,event.y])
  190.         else
  191.           event.move = true
  192.           b.push([event.x,event.y])
  193.         end
  194.       end
  195.       for id in e.keys
  196.         event = $game_map.events[id]
  197.         if !passable?(event.x+x0,event.y+y0,type)
  198.           event.move = true
  199.           event.turn_random
  200.           e.delete(id)
  201.         end
  202.       end
  203.       while e.size > 0
  204.         for id in e.keys
  205.           event = $game_map.events[id]
  206.           next if event == nil
  207.           if b.include?([event.x+x0,event.y+y0])
  208.             event.move = true
  209.             e.delete(id)
  210.           else
  211.             for ev in $game_map.events.values
  212.               if ev.x == event.x+x0 and ev.y == event.y+y0
  213.                 have = true
  214.                 if ev.move == true
  215.                   event.move = true
  216.                   event.turn_random
  217.                   event = nil
  218.                   e.delete(id)
  219.                   break
  220.                 else
  221.                   event = nil
  222.                   break
  223.                 end
  224.               end
  225.             end
  226.             if event
  227.               #event.x += x0 ; event.y += y0
  228.               case type
  229.               when 2
  230.                 event.move_down
  231.               when 4
  232.                 event.move_left
  233.               when 6
  234.                 event.move_right
  235.               when 8
  236.                 event.move_up
  237.               end
  238.               event.move = true
  239.               e.delete(id)
  240.             end
  241.           end
  242.         end
  243.       end
  244.     end
  245.       
  246.       
  247.   end
  248.         
  249.   def passable?(x,y,d)
  250.     unless $game_map.valid?(x, y)
  251.       return false
  252.     end
  253.     if @through
  254.       return true
  255.     end
  256.     unless $game_map.passable?(x, y, d)
  257.       return false
  258.     end
  259.     return true
  260.   end
  261.   
  262.   def moving?
  263.     for event in $game_map.events.values
  264.       if event.moving?
  265.         return true
  266.       end
  267.     end
  268.     return false
  269.   end
  270.   ########################################################################
  271.   #--------------------------------------------------------------------------
  272.   # ● 调用战斗
  273.   #--------------------------------------------------------------------------
  274.   def call_battle
  275.     # 清除战斗调用标志
  276.     $game_temp.battle_calling = false
  277.     # 清除菜单调用标志
  278.     $game_temp.menu_calling = false
  279.     $game_temp.menu_beep = false
  280.     # 生成遇敌计数
  281.     $game_player.make_encounter_count
  282.     # 记忆地图 BGM 、停止 BGM
  283.     $game_temp.map_bgm = $game_system.playing_bgm
  284.     $game_system.bgm_stop
  285.     # 演奏战斗开始 SE
  286.     $game_system.se_play($data_system.battle_start_se)
  287.     # 演奏战斗 BGM
  288.     $game_system.bgm_play($game_system.battle_bgm)
  289.     # 矫正主角姿势
  290.     $game_player.straighten
  291.     # 切换到战斗画面
  292.     $scene = Scene_Battle.new
  293.   end
  294.   #--------------------------------------------------------------------------
  295.   # ● 调用商店
  296.   #--------------------------------------------------------------------------
  297.   def call_shop
  298.     # 清除商店调用标志
  299.     $game_temp.shop_calling = false
  300.     # 矫正主角姿势
  301.     $game_player.straighten
  302.     # 切换到商店画面
  303.     $scene = Scene_Shop.new
  304.   end
  305.   #--------------------------------------------------------------------------
  306.   # ● 调用名称输入
  307.   #--------------------------------------------------------------------------
  308.   def call_name
  309.     # 清除商店调用名称输入标志
  310.     $game_temp.name_calling = false
  311.     # 矫正主角姿势
  312.     $game_player.straighten
  313.     # 切换到名称输入画面
  314.     $scene = Scene_Name.new
  315.   end
  316.   #--------------------------------------------------------------------------
  317.   # ● 调用菜单
  318.   #--------------------------------------------------------------------------
  319.   def call_menu
  320.     # 清除商店调用菜单标志
  321.     $game_temp.menu_calling = false
  322.     # 已经设置了菜单 SE 演奏标志的情况下
  323.     if $game_temp.menu_beep
  324.       # 演奏确定 SE
  325.       $game_system.se_play($data_system.decision_se)
  326.       # 清除菜单演奏 SE 标志
  327.       $game_temp.menu_beep = false
  328.     end
  329.     # 矫正主角姿势
  330.     $game_player.straighten
  331.     # 切换到菜单画面
  332.     $scene = Scene_Menu.new
  333.   end
  334.   #--------------------------------------------------------------------------
  335.   # ● 调用存档
  336.   #--------------------------------------------------------------------------
  337.   def call_save
  338.     # 矫正主角姿势
  339.     $game_player.straighten
  340.     # 切换到存档画面
  341.     $scene = Scene_Save.new
  342.   end
  343.   #--------------------------------------------------------------------------
  344.   # ● 调用调试
  345.   #--------------------------------------------------------------------------
  346.   def call_debug
  347.     # 清除商店调用调试标志
  348.     $game_temp.debug_calling = false
  349.     # 演奏确定 SE
  350.     $game_system.se_play($data_system.decision_se)
  351.     # 矫正主角姿势
  352.     $game_player.straighten
  353.     # 切换到调试画面
  354.     $scene = Scene_Debug.new
  355.   end
  356.   #--------------------------------------------------------------------------
  357.   # ● 主角的场所移动
  358.   #--------------------------------------------------------------------------
  359.   def transfer_player
  360.     # 清除主角场所移动调试标志
  361.     $game_temp.player_transferring = false
  362.     # 移动目标与现在的地图有差异的情况下
  363.     if $game_map.map_id != $game_temp.player_new_map_id
  364.       # 设置新地图
  365.       $game_map.setup($game_temp.player_new_map_id)
  366.     end
  367.     # 设置主角位置
  368.     $game_player.moveto($game_temp.player_new_x, $game_temp.player_new_y)
  369.     # 设置主角朝向
  370.     case $game_temp.player_new_direction
  371.     when 2  # 下
  372.       $game_player.turn_down
  373.     when 4  # 左
  374.       $game_player.turn_left
  375.     when 6  # 右
  376.       $game_player.turn_right
  377.     when 8  # 上
  378.       $game_player.turn_up
  379.     end
  380.     # 矫正主角姿势
  381.     $game_player.straighten
  382.     # 刷新地图 (执行并行事件)
  383.     $game_map.update
  384.     # 在生成活动块
  385.     @spriteset.dispose
  386.     @spriteset = Spriteset_Map.new
  387.     # 处理过渡中的情况下
  388.     if $game_temp.transition_processing
  389.       # 清除过渡处理中标志
  390.       $game_temp.transition_processing = false
  391.       # 执行过渡
  392.       Graphics.transition(20)
  393.     end
  394.     # 执行地图设置的 BGM、BGS 的自动切换
  395.     $game_map.autoplay
  396.     # 设置画面
  397.     Graphics.frame_reset
  398.     # 刷新输入信息
  399.     Input.update
  400.   end
  401. end
复制代码


忘记转脸了~~~补上  顺便说句:  给character加了个新属性,scene_map中间加#的一大段就是 [LINE]1,#dddddd[/LINE]系统信息:本贴由本区版主认可为正确答案,66RPG感谢您的热情解答~
作者: 此ID只用一次    时间: 2008-6-20 18:13
提示: 作者被禁止或删除 内容自动屏蔽
作者: 精灵使者    时间: 2008-6-20 18:34
以下引用此ID只用一次于2008-6-20 10:13:37的发言:

其实何必这么麻烦,要达到精灵的效果根本不必大动干戈.
你原来的东西不必改,只需要将 设置移动路线的向上移动用脚本来调用Game_Character里的向上移动,因为它可以自行判断出前方是否可以移动,而且不卡.
如:
条件分歧 $game_player.passable?($game_map.events[x].x, $game_map.events[x].y, 8)
事件第3页-脚本:$game_map.events[x].move_up
除此之外的场合
$game_map.events[x].turn_random
分歧结束.

你可以试试看.解决了你之前所不能移动的问题`

这样么。
刚才做了测试,会有连续运行的迹象。
没有上面几位做的那么好。
作者: 精灵使者    时间: 2008-6-20 18:54
以下引用TERENCE于2008-6-19 22:51:03的发言:

多定义新的passable?叫new_passable?
貼在main前即可
  1. class Game_Character
  2.   #--------------------------------------------------------------------------
  3.   # ● 新通行判定方法
  4.   #     x : X 坐标
  5.   #     y : Y 坐标
  6.   #     d : 方向 (0,2,4,6,8)  ※ 0 = 全方向不能通行的情况判定 (跳跃用)
  7.   #--------------------------------------------------------------------------
  8.   def new_passable?(x, y, d)
  9.     # 求得新的坐标
  10.     new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
  11.     new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
  12.     # 坐标在地图以外的情况
  13.     unless $game_map.valid?(new_x, new_y)
  14.       # 不能通行
  15.       return false
  16.     end
  17.     # 穿透是 ON 的情况下
  18.     if @through
  19.       # 可以通行
  20.       return true
  21.     end
  22.     # 移动者的元件无法来到指定方向的情况下
  23.     unless $game_map.passable?(x, y, d, self)
  24.       # 通行不可
  25.       return false
  26.     end
  27.     # 从指定方向不能进入到移动处的元件的情况下
  28.     unless $game_map.passable?(new_x, new_y, 10 - d)
  29.       # 不能通行
  30.       return false
  31.     end
  32.     # 循环全部事件
  33.     for event in $game_map.events.values
  34.       # 事件坐标于移动目标坐标一致的情况下
  35.       if event.x == new_x and event.y == new_y
  36.         # 穿透为 ON
  37.         unless event.through
  38.           # 自己就是事件的情况下
  39.           if self != $game_player
  40.             # 不能通行
  41.             return false
  42.           end
  43.           # 自己是主角、对方的图形是角色的情况下
  44.           if event.character_name != ""
  45.             # 不能通行
  46.             return true
  47.           end
  48.         end
  49.       end
  50.     end
  51.     # 主角的坐标与移动目标坐标一致的情况下
  52.     if $game_player.x == new_x and $game_player.y == new_y
  53.       # 穿透为 ON
  54.       unless $game_player.through
  55.         # 自己的图形是角色的情况下
  56.         if @character_name != ""
  57.           # 不能通行
  58.           return false
  59.         end
  60.       end
  61.     end
  62.     # 可以通行
  63.     return true
  64.   end
  65. end
复制代码


调用方式:
$game_player.new_passable?($game_map.events[a].x,$game_map.events[a].y,方向)
范例:
http://rpg.blue/upload_program/files/Project2_94344311.rar

龙皇的设计思路和我的很接近,经测试没有多余的现象。恩恩。
hiterson的设计思路已接近了游戏的基本要求,但是运行似乎没有龙皇的效果好。
如果能两者综合起来就太好了。
察察的那个判断有问题,有障碍的时候仅仅挡住了一个人,而不是所有人都不可行动。
作者: 身之察察    时间: 2008-6-20 21:05
以下引用精灵使者于2008-6-20 10:54:09的发言:


察察的那个判断有问题,有障碍的时候仅仅挡住了一个人,而不是所有人都不可行动。


原来我理解错题了,默默地离开。。
作者: 此ID只用一次    时间: 2008-6-20 21:07
提示: 作者被禁止或删除 内容自动屏蔽
作者: 精灵使者    时间: 2008-6-21 06:18
精灵:已经突破了关键系统,问题解决了。所以特此发奖……
hiterson获得全额奖金,帮我做完了整个系统。
龙皇获得4vip
此id只用一次获得3vip
身之察察获得积分500
感谢大家的帮忙,关键系统突破!正在继续努力中。




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