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

Project1

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

如何判断两个以上事件的同时移动(续)

 关闭 [复制链接]

Lv3.寻梦者 (暗夜天使)

精灵族の天使

梦石
0
星屑
1707
在线时间
3039 小时
注册时间
2007-3-16
帖子
33731

开拓者贵宾

跳转到指定楼层
1
发表于 2008-6-20 00:05:27 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
我利用一个按键来操作多个事件,但是出现了问题。
问题就是
如果直接设置所有事件的移动路线的话,遇到障碍物会死机。
如果把移动路线加上判定
$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]版务信息:版主帮忙结贴~

Lv1.梦旅人

梦石
0
星屑
60
在线时间
41 小时
注册时间
2008-3-5
帖子
2072
2
发表于 2008-6-20 00:14:14 | 只看该作者
不移动的事件的事件坐标 A=[[1,1],[3,1]]
移动的事件移动后坐标 B=[[1,2],[2,2],[2,1]]
没有重复,都能移动
与A中重复,不能移动
与B中重复,优先的能移动,其他不能移动.......

抛砖引玉中...
你它囧一字母君谁记得……
当时那把剑离我的喉咙只有0.01工分。可是一柱香之后,这个女主人会深深的爱上我,虽然本人平生说了无数的谎话,可是这句最有效:“你应该这么做,我也应该死。
曾经有一取ID的机会放在我面前,我没有珍惜,等我失去的时候我才后悔莫及,人世间最痛苦的事莫过于此。你的剑在我的咽喉上割下去吧!不用再犹豫了!如果上天能够给我一个再来一次的机会,我绝对会取个汉字君。如果非要给这ID加点修饰的话,我希望是……红色加粗……

回复 支持 反对

使用道具 举报

Lv3.寻梦者 (暗夜天使)

精灵族の天使

梦石
0
星屑
1707
在线时间
3039 小时
注册时间
2007-3-16
帖子
33731

开拓者贵宾

3
 楼主| 发表于 2008-6-20 00:19:18 | 只看该作者
数组啊?能做个范例工程么?
只要使用上下左右能同时操纵4个并在一起的事件,而且能识别障碍物就可以。
回复 支持 反对

使用道具 举报

头像被屏蔽

Lv1.梦旅人 (禁止发言)

梦石
0
星屑
50
在线时间
0 小时
注册时间
2008-3-6
帖子
148
4
发表于 2008-6-20 00:25:42 | 只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
签名被屏蔽
回复 支持 反对

使用道具 举报

Lv3.寻梦者 (暗夜天使)

精灵族の天使

梦石
0
星屑
1707
在线时间
3039 小时
注册时间
2007-3-16
帖子
33731

开拓者贵宾

5
 楼主| 发表于 2008-6-20 00:39:49 | 只看该作者
那么好吧……

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

逆序的话,下面的无法移动
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
60
在线时间
41 小时
注册时间
2008-3-5
帖子
2072
6
发表于 2008-6-20 01:00:41 | 只看该作者
随机朝向的

  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
复制代码
你它囧一字母君谁记得……
当时那把剑离我的喉咙只有0.01工分。可是一柱香之后,这个女主人会深深的爱上我,虽然本人平生说了无数的谎话,可是这句最有效:“你应该这么做,我也应该死。
曾经有一取ID的机会放在我面前,我没有珍惜,等我失去的时候我才后悔莫及,人世间最痛苦的事莫过于此。你的剑在我的咽喉上割下去吧!不用再犹豫了!如果上天能够给我一个再来一次的机会,我绝对会取个汉字君。如果非要给这ID加点修饰的话,我希望是……红色加粗……

回复 支持 反对

使用道具 举报

Lv3.寻梦者 (暗夜天使)

精灵族の天使

梦石
0
星屑
1707
在线时间
3039 小时
注册时间
2007-3-16
帖子
33731

开拓者贵宾

7
 楼主| 发表于 2008-6-20 01:08:20 | 只看该作者
我回来了~你可以做个范例工程给我。
你那个太复杂了。
把那个表达式直接换成turn_random就可以了。
回复 支持 反对

使用道具 举报

头像被屏蔽

Lv1.梦旅人 (禁止发言)

梦石
0
星屑
50
在线时间
0 小时
注册时间
2008-3-6
帖子
148
8
发表于 2008-6-20 01:28:14 | 只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
签名被屏蔽
回复 支持 反对

使用道具 举报

头像被屏蔽

Lv1.梦旅人 (禁止发言)

梦石
0
星屑
50
在线时间
0 小时
注册时间
2008-3-6
帖子
148
9
发表于 2008-6-20 01:30:16 | 只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
签名被屏蔽
回复 支持 反对

使用道具 举报

Lv3.寻梦者 (暗夜天使)

精灵族の天使

梦石
0
星屑
1707
在线时间
3039 小时
注册时间
2007-3-16
帖子
33731

开拓者贵宾

10
 楼主| 发表于 2008-6-20 01:43:28 | 只看该作者
你的那个问题很明显,也出现了截图里一样的问题。
我的游戏中设定无法移动的时候是不能随机移动的。要不游戏就无法进行下去了。
我要的目标是:两个人一起向上走。
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2025-8-6 14:55

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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