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

Project1

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

[已经过期] 伪·像素移动的问题...

 关闭 [复制链接]

Lv1.梦旅人

虱子

梦石
0
星屑
121
在线时间
1782 小时
注册时间
2010-6-19
帖子
3597
跳转到指定楼层
1
发表于 2011-2-27 11:58:46 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
  1. class Game_Character
  2.   def x
  3.     return @x.round
  4.   end
  5.   def y
  6.     return @y.round
  7.   end
  8.   #def passable?(x,y,d)
  9.     #return true
  10.   #end
  11.   def screen_x
  12.     shizi = (@real_x - $game_map.display_x + 3) / 4 + 16
  13.     return shizi.floor
  14.   end
  15.   def screen_y
  16.     y = (@real_y - $game_map.display_y + 3) / 4 + 32
  17.     if @jump_count >= @jump_peak
  18.       n = @jump_count - @jump_peak
  19.     else
  20.       n = @jump_peak - @jump_count
  21.     end
  22.     shizi = y - (@jump_peak * @jump_peak - n * n) / 2
  23.     return shizi.floor
  24.   end
  25.   def move_down(turn_enabled = true)
  26.     if turn_enabled
  27.       turn_down
  28.     end
  29.     for i in 1..@move_speed
  30.     if passable?(@x, @y, 2)
  31.       turn_down
  32.         @y += (1/32.0000000)
  33.         increase_steps
  34.     else
  35.       check_event_trigger_touch(@x, @y+1)
  36.     end
  37.     end
  38.   end
  39.   def move_left(turn_enabled = true)
  40.     if turn_enabled
  41.       turn_left
  42.     end
  43.     for i in 1..@move_speed
  44.     if passable?(@x, @y, 4)
  45.       turn_left
  46.       @x -= (1/32.0000000)
  47.       increase_steps
  48.     else
  49.       check_event_trigger_touch(@x-1, @y)
  50.     end
  51.     end
  52.   end
  53.   def move_right(turn_enabled = true)
  54.     if turn_enabled
  55.       turn_right
  56.     end
  57.     for i in 1..@move_speed
  58.     if passable?(@x, @y, 6)
  59.       turn_right
  60.       @x += (1/32.0000000)
  61.       increase_steps
  62.     else
  63.       check_event_trigger_touch(@x+1, @y)
  64.     end
  65.     end
  66.   end
  67.   def move_up(turn_enabled = true)
  68.     if turn_enabled
  69.       turn_up
  70.     end
  71.     for i in 1..@move_speed
  72.     if passable?(@x, @y, 8)
  73.       turn_up
  74.       @y -= (1/32.0000000)
  75.       increase_steps
  76.     else
  77.       check_event_trigger_touch(@x, @y-1)
  78.     end
  79.     end
  80.   end
  81. end
复制代码

这是我自己写的一段脚本,但是测试时发现主角/事件不能走到x为0的位置...这个原因是什么?

点评

写法本身就有问题 随便放个障碍物判断可通行的位置就不对  发表于 2011-2-27 18:16

http://rpg.blue/thread-175056-1-2.html
PVZ型塔防物一个
http://rpg.blue/thread-155199-1-2.html
RMXP技术讨论区手动认可帖,得到答案请认可

Lv2.观梦者

虚構歪曲

梦石
0
星屑
334
在线时间
1196 小时
注册时间
2010-12-18
帖子
3928

贵宾

2
发表于 2011-2-27 12:10:23 | 只看该作者
  1. # ▼▲▼ No78. Xムーブ ▼▲▼
  2. #
  3. # update 2007/12/18
  4. #
  5. #==============================================================================
  6. # --- プレイヤー移動速度設定 ---
  7. #==============================================================================
  8. module XMoveSmoother
  9.   #--------------------------------------------------------------------------
  10.   # オブジェクト初期化
  11.   #--------------------------------------------------------------------------
  12.   def initialize
  13.     super
  14.     xmove_reset
  15.   end
  16.   #--------------------------------------------------------------------------
  17.   # ずれリセット
  18.   #--------------------------------------------------------------------------
  19.   def xmove_reset
  20.     @xf = 0
  21.     @yf = 0
  22.   end
  23.   #--------------------------------------------------------------------------
  24.   # 接触イベントの判定 と 歩数カウント
  25.   #--------------------------------------------------------------------------
  26.   def check_event_touch_here_x
  27.     if @xf == 0
  28.       increase_steps
  29.       return check_event_trigger_here([1,2])
  30.     end
  31.     return false
  32.   end
  33.   def check_event_touch_here_y
  34.     if @yf == 0
  35.       increase_steps
  36.       return check_event_trigger_here([1,2])
  37.     end
  38.     return false
  39.   end
  40.   #--------------------------------------------------------------------------
  41.   # 通行可能?[拡張版]
  42.   #--------------------------------------------------------------------------
  43.   def passablex?(x, y, d)
  44.     # ずれ補正のみ による移動可
  45.     case d
  46.     when 2
  47.       return true if @yf < 0
  48.     when 4
  49.       return true if @xf > 0
  50.     when 6
  51.       return true if @xf < 0
  52.     when 8
  53.       return true if @yf > 0
  54.     end
  55.     # 通常の通行可能判定
  56.     result = passable?(x, y, d)
  57.     # ぶれによる追加判定
  58.     unless (@xf == 0 and @yf == 0)
  59.       case d
  60.       when 2, 8
  61.         nx = @xf > 0 ? 1 : (@xf < 0 ? -1 : 0)
  62.         ny = d == 2 ? 1 : -1
  63.         nd = @xf > 0 ? 6 : (@xf < 0 ? 4 : 0)
  64.         result &= passable?(x + nx, y,  d)
  65.         result &= passable?(x, y + ny, nd)
  66.       when 4, 6
  67.         nx = d == 6 ? 1 : -1
  68.         ny = @yf > 0 ? 1 : (@yf < 0 ? -1 : 0)
  69.         nd = @yf > 0 ? 2 : (@yf < 0 ? 8 : 0)
  70.         result &= passable?(x + nx, y, nd)
  71.         result &= passable?(x, y + ny,  d)
  72.       end
  73.     end
  74.     # 結果
  75.     return result
  76.   end
  77.   #--------------------------------------------------------------------------
  78.   # 下に移動
  79.   #--------------------------------------------------------------------------
  80.   def move_down(turn_enabled = true)
  81.     # 移動指定されているなら本来どおり or 移動速度4でない場合
  82.     return super if @move_route_forcing or @move_speed != 4
  83.     # 下を向く
  84.     if turn_enabled
  85.       turn_down
  86.     end
  87.     # 通行可能な場合
  88.     if passablex?(@x, @y, 2)
  89.       # ぶれを更新
  90.       @yf += 1
  91.       if @yf >= 3
  92.         @yf = -2
  93.         @y += 1
  94.       end
  95.       # 接触判定
  96.       check_event_touch_here_y
  97.     # 通行不可能な場合
  98.     else
  99.       # 接触イベントの起動判定
  100.       if check_event_trigger_touch(@x, @y+1)
  101.         turn_down
  102.         xmove_reset
  103.         return
  104.       end
  105.       # ぬるり
  106.       if turn_enabled and @yf == 0 and passable?(@x, @y, 2)
  107.         if @xf >= 1 and (not passable?(@x+1, @y, 2) or not passable?(@x, @y+1, 6))
  108.           @xf -= 1
  109.           check_event_touch_here_x
  110.         elsif @xf <= -1 and (not passable?(@x-1, @y, 2) or not passable?(@x, @y+1, 4))
  111.           @xf += 1
  112.           check_event_touch_here_x
  113.         end
  114.       end
  115.     end
  116.   end
  117.   #--------------------------------------------------------------------------
  118.   # 左に移動
  119.   #--------------------------------------------------------------------------
  120.   def move_left(turn_enabled = true)
  121.     # 移動指定されているなら本来どおり or 移動速度4でない場合
  122.     return super if @move_route_forcing or @move_speed != 4
  123.     # 左を向く
  124.     if turn_enabled
  125.       turn_left
  126.     end
  127.     # 通行可能な場合
  128.     if passablex?(@x, @y, 4)
  129.       # ぶれを更新
  130.       @xf -= 1
  131.       if @xf <= -3
  132.         @xf = 2
  133.         @x -= 1
  134.       end
  135.       # 接触判定
  136.       check_event_touch_here_x
  137.     # 通行不可能な場合
  138.     else
  139.       # 接触イベントの起動判定
  140.       if check_event_trigger_touch(@x-1, @y)
  141.         turn_left
  142.         xmove_reset
  143.         return
  144.       end
  145.       # ぬるり
  146.       if @xf == 0 and turn_enabled and passable?(@x, @y, 4)
  147.         if @yf >= 1 and (not passable?(@x, @y+1, 4) or not passable?(@x-1, @y, 2))
  148.           @yf -= 1
  149.           check_event_touch_here_y
  150.         elsif @yf <= -1 and (not passable?(@x, @y-1, 4) or not passable?(@x-1, @y, 8))
  151.           @yf += 1
  152.           check_event_touch_here_y
  153.         end
  154.       end
  155.     end
  156.   end
  157.   #--------------------------------------------------------------------------
  158.   # 右に移動
  159.   #--------------------------------------------------------------------------
  160.   def move_right(turn_enabled = true)
  161.     # 移動指定されているなら本来どおり or 移動速度4でない場合
  162.     return super if @move_route_forcing or @move_speed != 4
  163.     # 右を向く
  164.     if turn_enabled
  165.       turn_right
  166.     end
  167.     # 通行可能な場合
  168.     if passablex?(@x, @y, 6)
  169.       # ぶれを更新
  170.       @xf += 1
  171.       if @xf >= 3
  172.         @xf = -2
  173.         @x += 1
  174.       end
  175.       # 接触判定
  176.       check_event_touch_here_x
  177.     # 通行不可能な場合
  178.     else
  179.       # 接触イベントの起動判定
  180.       if check_event_trigger_touch(@x+1, @y)
  181.         turn_right
  182.         xmove_reset
  183.         return
  184.       end
  185.       # ぬるり
  186.       if turn_enabled and @xf == 0 and passable?(@x, @y, 6)
  187.         if @yf >= 1 and (not passable?(@x, @y+1, 6) or not passable?(@x+1, @y, 2))
  188.           @yf -= 1
  189.           check_event_touch_here_y
  190.         elsif @yf <= -1 and (not passable?(@x, @y-1, 6) or not passable?(@x+1, @y, 8))
  191.           @yf += 1
  192.           check_event_touch_here_y
  193.         end
  194.       end
  195.     end
  196.   end
  197.   #--------------------------------------------------------------------------
  198.   # 上に移動
  199.   #--------------------------------------------------------------------------
  200.   def move_up(turn_enabled = true)
  201.     # 移動指定されているなら本来どおり or 移動速度4でない場合
  202.     return super if @move_route_forcing or @move_speed != 4
  203.     # 上を向く
  204.     if turn_enabled
  205.       turn_up
  206.     end
  207.     # 通行可能な場合
  208.     if passablex?(@x, @y, 8)
  209.       # ぶれを更新
  210.       @yf -= 1
  211.       if @yf <= -3
  212.         @yf = 2
  213.         @y -= 1
  214.       end
  215.       # 接触判定
  216.       check_event_touch_here_y
  217.     # 通行不可能な場合
  218.     else
  219.       # 接触イベントの起動判定
  220.       if check_event_trigger_touch(@x, @y-1)
  221.         turn_up
  222.         xmove_reset
  223.         return
  224.       end
  225.       # ぬるり
  226.       if turn_enabled and @yf == 0 and passable?(@x, @y, 8)
  227.         if @xf >= 1 and (not passable?(@x+1, @y, 8) or not passable?(@x, @y-1, 6))
  228.           @xf -= 1
  229.           check_event_touch_here_x
  230.         elsif @xf <= -1 and (not passable?(@x-1, @y, 8) or not passable?(@x, @y-1, 4))
  231.           @xf += 1
  232.           check_event_touch_here_x
  233.         end
  234.       end
  235.     end
  236.   end
  237.   #--------------------------------------------------------------------------
  238.   # 左下に移動
  239.   #--------------------------------------------------------------------------
  240.   def move_lower_left
  241.     # 移動指定されているなら本来どおり or 移動速度4でない場合
  242.     return super if @move_route_forcing or @move_speed != 4
  243.     # 左を向く
  244.     turn_left
  245.     move_down(false)
  246.     move_left(false)
  247.   end
  248.   #--------------------------------------------------------------------------
  249.   # 右下に移動
  250.   #--------------------------------------------------------------------------
  251.   def move_lower_right
  252.     # 移動指定されているなら本来どおり or 移動速度4でない場合
  253.     return super if @move_route_forcing or @move_speed != 4
  254.     # 下を向く
  255.     turn_down
  256.     move_down(false)
  257.     move_right(false)
  258.   end
  259.   #--------------------------------------------------------------------------
  260.   # 左上に移動
  261.   #--------------------------------------------------------------------------
  262.   def move_upper_left
  263.     # 移動指定されているなら本来どおり or 移動速度4でない場合
  264.     return super if @move_route_forcing or @move_speed != 4
  265.     # 上を向く
  266.     turn_up
  267.     move_up(false)
  268.     move_left(false)
  269.   end
  270.   #--------------------------------------------------------------------------
  271.   # 右上に移動
  272.   #--------------------------------------------------------------------------
  273.   def move_upper_right
  274.     # 移動指定されているなら本来どおり or 移動速度4でない場合
  275.     return super if @move_route_forcing or @move_speed != 4
  276.     # 右を向く
  277.     turn_right
  278.     move_up(false)
  279.     move_right(false)
  280.   end
  281.   #--------------------------------------------------------------------------
  282.   # 座標の瞬時更新
  283.   #--------------------------------------------------------------------------
  284.   def refresh_position
  285.     @real_x = @x * 128 + (@xf * 25.6).to_i
  286.     @real_y = @y * 128 + (@yf * 25.6).to_i
  287.   end
  288.   #--------------------------------------------------------------------------
  289.   # 移動中判定 [オーバーライド]
  290.   #--------------------------------------------------------------------------
  291.   def moving?
  292.     # イベント実行中の場合
  293.     return super if $game_system.map_interpreter.running?
  294.     return super if @move_route_forcing
  295.     @xf = 0 if @xf == nil
  296.     @yf = 0 if @yf == nil
  297.     # 論理座標と実座標が違っていれば移動中
  298.     return (@real_x != @x * 128 + (@xf * 25.6).to_i or
  299.             @real_y != @y * 128 + (@yf * 25.6).to_i )
  300.   end
  301.   #--------------------------------------------------------------------------
  302.   # ○ フレーム更新 (移動) [オーバーライド]
  303.   #--------------------------------------------------------------------------
  304.   def update_move
  305.     # 移動指定されているなら本来どおり or 移動速度4でない場合
  306.     if $game_system.map_interpreter.running? or
  307.        @move_route_forcing or @move_speed != 4
  308.       xmove_reset
  309.       super
  310.     else
  311.       super
  312.       # 表示位置を更新
  313.       refresh_position
  314.     end
  315.   end
  316.   #--------------------------------------------------------------------------
  317.   # 歩数増加
  318.   #--------------------------------------------------------------------------
  319.   def increase_steps
  320.     super
  321.     # イベント実行中の場合
  322.     return if $game_system.map_interpreter.running?
  323.     # デバッグモードが ON かつ CTRL キーが押されている場合を除き
  324.     unless $DEBUG and Input.press?(Input::CTRL)
  325.       # エンカウント カウントダウン
  326.       if @encounter_count > 0
  327.         @encounter_count -= 1
  328.         if $game_map.bush?(self.x, self.y)
  329.           @encounter_extra += 80
  330.         end
  331.       end
  332.     end
  333.   end
  334.   #--------------------------------------------------------------------------
  335.   # 移動ルートの強制
  336.   #--------------------------------------------------------------------------
  337.   def force_move_route(move_route)
  338.     xmove_reset
  339.     super
  340.   end
  341. end
  342. class Game_Player < Game_Character
  343.   include XMoveSmoother
  344. end

复制代码
回复

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
1281 小时
注册时间
2006-8-27
帖子
590
3
发表于 2011-2-27 18:00:05 | 只看该作者
往左或往上 坐标达到 1.0 以下时

判断下一步(-1) 坐标为负数 不可通行
回复

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
55
在线时间
323 小时
注册时间
2010-8-21
帖子
666
4
发表于 2011-3-11 16:56:32 | 只看该作者
这种问题认真分析还是很容易的,
假设现在主角坐标为[1,2],在你的脚本里面就为[1.0,2.0],再假设现在往左走,
判断[1.0.to_i-1,2.0.to_i]是否可通行(我用的是.to_i,),也就是[0,2]坐标,发现可通行,就移动到大概
[0.97,2.0],再次判断:[0.97.to_i-1,2.0.to_i],也就是[-1,2],在范围外,返回false,通行不能。
所以,不应该用to_i或者floor,应用ceil,当然,这仅仅是解决了这个小bug,还有更大的问题——

假设主角坐标[1.5,3.0],地图[1.0,2.0]不能通行,而[2.0,2.0]可以通行,现在主角向上移动,是动,还是不动?
目前,得到了:若主角卡在两个坐标之间,那两个坐标只要有一个不可通行,则不可通行,不过
又有问题了——

假设地图上[1.0,2.0]和[3.0,2.0]不可通行,而[2.0,2.0]可通行,要想主角从中间走过去,
以上面的“结论”,主角的x坐标必须为2.0,不然不能过,不过...你也知道....刚刚为2.0是较为困难的,很容易
1.9,2.1之类的.....又有大问题....

到这,只有建议:若主角卡在两个坐标之间,那两个坐标只要有一个可通行,“自动转弯”,校正其
x或y坐标到  n.0
>>猛戳>>MetalSagaR游戏主页<<这里<<
欢迎提供您的意见
回复

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2025-7-23 20:12

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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