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

Project1

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

[已经解决] 真·八方向像素行走

[复制链接]

Lv1.梦旅人

梦石
0
星屑
50
在线时间
28 小时
注册时间
2005-10-24
帖子
170
跳转到指定楼层
1
发表于 2013-7-28 23:02:41 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
本帖最后由 阁中人 于 2013-7-28 23:23 编辑

RUBY 代码复制
  1. # 全方向ドット移動 Ver θ
  2. # 配布元・サポートURL
  3. # [url]http://members.jcom.home.ne.jp/cogwheel/[/url]
  4.  
  5. #==============================================================================
  6. # ■ Game_Player
  7. #------------------------------------------------------------------------------
  8. #  プレイヤーを扱うクラスです。イベントの起動判定や、マップのスクロールなどの
  9. # 機能を持っています。このクラスのインスタンスは $game_player で参照されます。
  10. #==============================================================================
  11.  
  12. class Game_Player < Game_Character
  13.   #--------------------------------------------------------------------------
  14.   # ● 定数
  15.   #--------------------------------------------------------------------------
  16.   UP    = 0                   # 上方向の余裕(0 <= UP <= 63)
  17.   SIDE  = 0                   # 左右方向の余裕(0 <= SIDE <= 63)
  18.   SLANT = false               # 移動ルートの斜め移動時、速度修正
  19.   #--------------------------------------------------------------------------
  20.   # ● 公開インスタンス変数
  21.   #--------------------------------------------------------------------------
  22.   attr_reader   :walk                     # プレーヤー移動速度
  23.   attr_reader   :event                    # イベント時移動速度
  24.   attr_accessor :move_speed               # 移動速度
  25.   #--------------------------------------------------------------------------
  26.   # ● オブジェクト初期化
  27.   #--------------------------------------------------------------------------
  28.   def initialize
  29.     super
  30.     # @walk:歩行速度 @dash:ダッシュ時移動速度
  31.     # @event:イベント時移動速度(0の時は、イベント時に速度変更をしない)
  32.     [url=home.php?mod=space&uid=348285]@walk[/url]  = 4
  33.     [url=home.php?mod=space&uid=81012]@Dash[/url]  = 6
  34.     @event = 4
  35.     @dot_m = true
  36.     @revise_x = 0
  37.     @revise_y = 0
  38.     @move == false
  39.     @anime_count = 18 - @walk * 2
  40.   end
  41.   #--------------------------------------------------------------------------
  42.   # ● フレーム更新
  43.   #--------------------------------------------------------------------------
  44.   alias :update_original :update
  45.   def update
  46.     #ダッシュ機能。エンターキーが押されている間、移動速度を変更する。
  47.     unless moving? or $game_system.map_interpreter.running? or
  48.             @move_route_forcing or $game_temp.message_window_showing
  49.       if @walk != @dash
  50.         if Input.press?(Input::C)
  51.           if @move_speed != @dash
  52.             @move_speed = @dash
  53.           end
  54.         else
  55.           if @move_speed != @walk
  56.             @move_speed = @walk
  57.           end
  58.         end
  59.       end
  60.     end
  61.     if @revise_x == nil and @revise_y == nil
  62.       @revise_x = 0
  63.       @revise_y = 0
  64.     end
  65.     unless @dot_m
  66.       update_original
  67.       return
  68.     end
  69.     if @move_route_forcing
  70.       # ローカル変数に移動中かどうかを記憶
  71.       last_moving = moving?
  72.       # ローカル変数に座標を記憶
  73.       last_real_x = @real_x
  74.       last_real_y = @real_y
  75.       # 座標がずれている場合
  76.       if (@revise_x != 0 or @revise_y != 0) and not jumping? and @move == true
  77.         if @revise_x != @real_x - @x * 128 or @revise_y != @real_y - @y * 128
  78.           @revise_x = @real_x - @x * 128
  79.           @revise_y = @real_y - @y * 128
  80.         end
  81.         # 移動距離distance1と目標距離distance2を設定
  82.         distance1 = 2 ** @move_speed
  83.         distance2 = Math.sqrt(@revise_x ** 2 + @revise_y ** 2)
  84.         # 移動距離が目標距離を越えた場合
  85.         if distance1 > distance2
  86.           # 強制的に補正座標を零にする
  87.           @real_x = @real_x - @revise_x
  88.           @real_y = @real_y - @revise_y
  89.           @revise_x = 0
  90.           @revise_y = 0
  91.           step_anime
  92.         # 移動距離が目標距離に達しない場合
  93.         else
  94.           # 移動距離分目標距離に近づく
  95.           @real_x -= (distance1 * @revise_x / distance2).round
  96.           @real_y -= (distance1 * @revise_y / distance2).round
  97.           @revise_x = @real_x - @x * 128
  98.           @revise_y = @real_y - @y * 128
  99.           step_anime
  100.         end
  101.       else
  102.         super
  103.       end
  104.     else
  105.       @move = false
  106.       # 移動中、イベント実行中、移動ルート強制中、
  107.       # メッセージウィンドウ表示中のいずれでもない場合
  108.       unless moving? or $game_system.map_interpreter.running? or
  109.              @move_route_forcing or $game_temp.message_window_showing
  110.         @event_run = false
  111.         # 方向ボタンが押されていれば、その方向へプレイヤーを移動
  112.         case Input.dir8
  113.         when 1
  114.           move_lower_left_p
  115.         when 2
  116.           move_down_p
  117.         when 3
  118.           move_lower_right_p
  119.         when 4
  120.           move_left_p
  121.         when 6
  122.           move_right_p
  123.         when 7
  124.           move_upper_left_p
  125.         when 8
  126.           move_up_p
  127.         when 9
  128.           move_upper_right_p
  129.         end
  130.       end
  131.       # ローカル変数に座標を記憶
  132.       last_real_x = @real_x
  133.       last_real_y = @real_y
  134.       # 移動処理
  135.       @real_x = @x * 128 + @revise_x
  136.       @real_y = @y * 128 + @revise_y
  137.       # ローカル変数に移動中かどうかを記憶
  138.       last_moving = moving?
  139.       # 座標更新
  140.       move_on
  141.       # 現在の座標と以前の座標が異なる場合
  142.       if (last_real_x != @real_x or last_real_y != @real_y)
  143.         @move_distance = 0 if @move_distance == nil
  144.         @move_distance += Math.sqrt((last_real_x - @real_x) ** 2 +
  145.                                       (last_real_y - @real_y) ** 2)
  146.         if @move_distance >= 128
  147.           @move_distance %= 128
  148.           increase_steps
  149.         end
  150.         # アニメーションを更新
  151.         step_anime
  152.       else
  153.         stop_anime
  154.       end
  155.     end
  156.     # キャラクターが下に移動し、かつ画面上の位置が中央より下の場合
  157.     if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y
  158.       # マップを下にスクロール
  159.       $game_map.scroll_down(@real_y - last_real_y)
  160.     end
  161.     # キャラクターが左に移動し、かつ画面上の位置が中央より左の場合
  162.     if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X
  163.       # マップを左にスクロール
  164.       $game_map.scroll_left(last_real_x - @real_x)
  165.     end
  166.     # キャラクターが右に移動し、かつ画面上の位置が中央より右の場合
  167.     if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X
  168.       # マップを右にスクロール
  169.       $game_map.scroll_right(@real_x - last_real_x)
  170.     end
  171.     # キャラクターが上に移動し、かつ画面上の位置が中央より上の場合
  172.     if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y
  173.       # マップを上にスクロール
  174.       $game_map.scroll_up(last_real_y - @real_y)
  175.     end
  176.     # 前回プレイヤーが移動中だった場合
  177.     if last_moving
  178.       # 同位置のイベントとの接触によるイベント起動判定
  179.       result = check_event_trigger_here([1,2])
  180.       if result == true
  181.         if (last_real_x / 128.0).round != @x and
  182.             (last_real_y / 128.0).round != @y
  183.           if @direction == 2 or @direction == 8
  184.             if (last_real_x / 128.0).round > @x
  185.               turn_left
  186.             else
  187.               turn_right
  188.             end
  189.           else
  190.             if (last_real_y / 128.0).round > @y
  191.               turn_up
  192.             else
  193.               turn_down
  194.             end
  195.           end
  196.         elsif (last_real_x / 128.0).round > @x
  197.           turn_left
  198.         elsif (last_real_x / 128.0).round < @x
  199.           turn_right
  200.         elsif (last_real_y / 128.0).round > @y
  201.           turn_up
  202.         elsif (last_real_y / 128.0).round < @y
  203.           turn_down
  204.         end
  205.       end
  206.       # 起動したイベントがない場合
  207.       if result == false
  208.         # デバッグモードが ON かつ CTRL キーが押されている場合を除き
  209.         unless $DEBUG and Input.press?(Input::CTRL)
  210.           # エンカウント カウントダウン
  211.           if @encounter_count > 0
  212.             @encounter_count -= 1
  213.           end
  214.         end
  215.       end
  216.     end
  217.     # C ボタンが押された場合
  218.     if Input.trigger?(Input::C)
  219.       # 同位置および正面のイベント起動判定
  220.       check_event_trigger_here([0])
  221.       check_event_trigger_there([0,1,2])
  222.     end
  223.   end
  224.   #--------------------------------------------------------------------------
  225.   # ● 移動判定
  226.   #--------------------------------------------------------------------------
  227.   def moving?
  228.     unless @dot_m
  229.       result = super
  230.       return result
  231.     end
  232.     # 強制移動の場合オリジナルの判定をさせる
  233.     if @move_route_forcing
  234.       if @move == false
  235.         return false
  236.       end
  237.       super
  238.     # 通常時は現座標が実座標と異なる場合のみ移動中と判定
  239.     else
  240.       return (@x != (@real_x / 128.0).round or @y != (@real_y / 128.0).round)
  241.     end
  242.   end
  243.   #--------------------------------------------------------------------------
  244.   # ● 移動判定
  245.   #--------------------------------------------------------------------------
  246.   def moving_a?
  247.     if @move == false
  248.       if (@move_route.list[@move_route_index].code <= 14 or
  249.           @move_route.list[@move_route_index].code == 25)
  250.         @move = true
  251.       end
  252.       return false
  253.     end
  254.     moving?
  255.   end
  256.   #--------------------------------------------------------------------------
  257.   # ● フレーム更新 (ジャンプ)
  258.   #--------------------------------------------------------------------------
  259.   def update_jump
  260.     # ジャンプカウントを 1 減らす
  261.     @jump_count -= 1
  262.     # 新しい座標を計算
  263.     @real_x = (@real_x * @jump_count + @x * 128) / (@jump_count + 1)
  264.     @real_y = (@real_y * @jump_count + @y * 128) / (@jump_count + 1)
  265.     if @jump_count == 0
  266.       @revise_x = 0
  267.       @revise_y = 0
  268.     end
  269.   end
  270.   #--------------------------------------------------------------------------
  271.   # ● 移動タイプ : カスタム
  272.   #--------------------------------------------------------------------------
  273.   def move_type_custom
  274.     unless @dot_m
  275.       super
  276.       return
  277.     end
  278.     # 停止中でなければ中断
  279.     if jumping? or moving_a?
  280.       return
  281.     end
  282.     # 移動コマンドのリストの最後に到達するまでループ
  283.     while @move_route_index < @move_route.list.size
  284.       # 移動コマンドを取得
  285.       command = @move_route.list[@move_route_index]
  286.       # コマンドコード 0 番 (リストの最後) の場合
  287.       if command.code == 0
  288.         # オプション [動作を繰り返す] が ON の場合
  289.         if @move_route.repeat
  290.           # 移動ルートのインデックスを最初に戻す
  291.           @move_route_index = 0
  292.         end
  293.         # オプション [動作を繰り返す] が OFF の場合
  294.         unless @move_route.repeat
  295.           # 移動ルート強制中の場合
  296.           if @move_route_forcing and not @move_route.repeat
  297.             # 移動ルートの強制を解除
  298.             @move_route_forcing = false
  299.             # オリジナルの移動ルートを復帰
  300.             @move_route = @original_move_route
  301.             @move_route_index = @original_move_route_index
  302.             @original_move_route = nil
  303.           end
  304.           # 停止カウントをクリア
  305.           @stop_count = 0
  306.         end
  307.         return
  308.       end
  309.       # 移動系コマンド (下に移動~ジャンプ) の場合
  310.       if command.code <= 14
  311.         # コマンドコードで分岐
  312.         case command.code
  313.         when 1  # 下に移動
  314.           move_down
  315.         when 2  # 左に移動
  316.           move_left
  317.         when 3  # 右に移動
  318.           move_right
  319.         when 4  # 上に移動
  320.           move_up
  321.         when 5  # 左下に移動
  322.           move_lower_left
  323.         when 6  # 右下に移動
  324.           move_lower_right
  325.         when 7  # 左上に移動
  326.           move_upper_left
  327.         when 8  # 右上に移動
  328.           move_upper_right
  329.         when 9  # ランダムに移動
  330.           move_random
  331.         when 10  # プレイヤーに近づく
  332.           move_toward_player
  333.         when 11  # プレイヤーから遠ざかる
  334.           move_away_from_player
  335.         when 12  # 一歩前進
  336.           move_forward
  337.         when 13  # 一歩後退
  338.           move_backward
  339.         when 14  # ジャンプ
  340.           jump(command.parameters[0], command.parameters[1])
  341.         end
  342.         # オプション [移動できない場合は無視] が OFF で、移動失敗の場合
  343.         if not @move_route.skippable and not moving? and not jumping?
  344.           return
  345.         end
  346.         @move_route_index += 1
  347.         return
  348.       end
  349.       # ウェイトの場合
  350.       if command.code == 15
  351.         # ウェイトカウントを設定
  352.         @wait_count = command.parameters[0] * 2 - 1
  353.         @move_route_index += 1
  354.         return
  355.       end
  356.       # 向き変更系のコマンドの場合
  357.       if command.code >= 16 and command.code <= 26
  358.         # コマンドコードで分岐
  359.         case command.code
  360.         when 16  # 下を向く
  361.           turn_down
  362.         when 17  # 左を向く
  363.           turn_left
  364.         when 18  # 右を向く
  365.           turn_right
  366.         when 19  # 上を向く
  367.           turn_up
  368.         when 20  # 右に 90 度回転
  369.           turn_right_90
  370.         when 21  # 左に 90 度回転
  371.           turn_left_90
  372.         when 22  # 180 度回転
  373.           turn_180
  374.         when 23  # 右か左に 90 度回転
  375.           turn_right_or_left_90
  376.         when 24  # ランダムに方向転換
  377.           turn_random
  378.         when 25  # プレイヤーの方を向く
  379.           turn_toward_player
  380.         when 26  # プレイヤーの逆を向く
  381.           turn_away_from_player
  382.         end
  383.         @move_route_index += 1
  384.         return
  385.       end
  386.       # その他のコマンドの場合
  387.       if command.code >= 27
  388.         # コマンドコードで分岐
  389.         case command.code
  390.         when 27  # スイッチ ON
  391.           $game_switches[command.parameters[0]] = true
  392.           $game_map.need_refresh = true
  393.         when 28  # スイッチ OFF
  394.           $game_switches[command.parameters[0]] = false
  395.           $game_map.need_refresh = true
  396.         when 29  # 移動速度の変更
  397.           @move_speed = command.parameters[0]
  398.         when 30  # 移動頻度の変更
  399.           @move_frequency = command.parameters[0]
  400.         when 31  # 移動時アニメ ON
  401.           @walk_anime = true
  402.         when 32  # 移動時アニメ OFF
  403.           @walk_anime = false
  404.         when 33  # 停止時アニメ ON
  405.           @step_anime = true
  406.         when 34  # 停止時アニメ OFF
  407.           @step_anime = false
  408.         when 35  # 向き固定 ON
  409.           @direction_fix = true
  410.         when 36  # 向き固定 OFF
  411.           @direction_fix = false
  412.         when 37  # すり抜け ON
  413.           @through = true
  414.         when 38  # すり抜け OFF
  415.           @through = false
  416.         when 39  # 最前面に表示 ON
  417.           @always_on_top = true
  418.         when 40  # 最前面に表示 OFF
  419.           @always_on_top = false
  420.         when 41  # グラフィック変更
  421.           @tile_id = 0
  422.           @character_name = command.parameters[0]
  423.           @character_hue = command.parameters[1]
  424.           if @original_direction != command.parameters[2]
  425.             @direction = command.parameters[2]
  426.             @original_direction = @direction
  427.             @prelock_direction = 0
  428.           end
  429.           if @original_pattern != command.parameters[3]
  430.             @pattern = command.parameters[3]
  431.             @original_pattern = @pattern
  432.           end
  433.         when 42  # 不透明度の変更
  434.           [url=home.php?mod=space&uid=316553]@opacity[/url] = command.parameters[0]
  435.         when 43  # 合成方法の変更
  436.           @blend_type = command.parameters[0]
  437.         when 44  # SE の演奏
  438.           $game_system.se_play(command.parameters[0])
  439.         when 45  # スクリプト
  440.           result = eval(command.parameters[0])
  441.         end
  442.         @move_route_index += 1
  443.         return
  444.       end
  445.     end
  446.   end
  447.   #--------------------------------------------------------------------------
  448.   # ● 下に移動
  449.   #--------------------------------------------------------------------------
  450.   def move_down_p
  451.     # 下を向く
  452.     turn_down
  453.     # 移動距離を算出
  454.     distance = 2 ** @move_speed
  455.     down1(((@x * 128 + @revise_x) / 128.0).round,
  456.           ((@y * 128 + @revise_y) / 128.0).round, distance, true)
  457.   end
  458.   #--------------------------------------------------------------------------
  459.   # ● 下に移動可能かどうかの判定1
  460.   #--------------------------------------------------------------------------
  461.   def down1(x, y, distance, down = false)
  462.     result = down2(x, y, distance)
  463.     if result == false
  464.       @event_run = check_event_trigger_touch(x, y+1)
  465.       return result
  466.     end
  467.     if @revise_x < -SIDE
  468.       result = down2(x, y + 1, distance, 4)
  469.       result &= down2(x - 1, y, distance)
  470.       if result == false
  471.         if down
  472.           move_lower_right_p
  473.           if @revise_x > SIDE
  474.             @revise_x = SIDE
  475.           end
  476.         end
  477.         return result
  478.       end
  479.     elsif @revise_x > SIDE
  480.       result = down2(x, y + 1, distance, 6)
  481.       result &= down2(x + 1, y, distance)
  482.       if result == false
  483.         if down
  484.           move_lower_left_p
  485.           if @revise_x < -SIDE
  486.             @revise_x = -SIDE
  487.           end
  488.         end
  489.         return result
  490.       end
  491.     end
  492.     # 下に移動可能ならば距離分移動
  493.     @revise_y += distance
  494.     return result
  495.   end
  496.   #--------------------------------------------------------------------------
  497.   # ● 下に移動可能かどうかの判定2
  498.   #--------------------------------------------------------------------------
  499.   def down2(x, y, distance, d = 2)
  500.     if @revise_y + distance > 0
  501.       unless passable?(x, y, d)
  502.         if @revise_y < 0
  503.           @revise_y = 0
  504.         end
  505.         return false
  506.       end
  507.     end
  508.     return true
  509.   end
  510.   #--------------------------------------------------------------------------
  511.   # ● 左に移動
  512.   #--------------------------------------------------------------------------
  513.   def move_left_p
  514.     # 左を向く
  515.     turn_left
  516.     distance = 2 ** @move_speed
  517.     left1(((@x * 128 + @revise_x) / 128.0).round,
  518.           ((@y * 128 + @revise_y) / 128.0).round, distance, true)
  519.   end
  520.   #--------------------------------------------------------------------------
  521.   # ● 左に移動可能かどうかの判定1
  522.   #--------------------------------------------------------------------------
  523.   def left1(x, y, distance, left = false)
  524.     result = left2(x, y, distance)
  525.     if result == false
  526.       @event_run = check_event_trigger_touch(x-1, y)
  527.       return result
  528.     end
  529.     if @revise_y < -UP
  530.       result = left2(x - 1, y, distance, 8)
  531.       result &= left2(x, y - 1, distance)
  532.       if result == false
  533.         if left
  534.           move_lower_left_p
  535.           if @revise_y > 0
  536.             @revise_y = 0
  537.           end
  538.         end
  539.         return result
  540.       end
  541.     elsif @revise_y > 0
  542.       result = left2(x - 1, y, distance, 2)
  543.       result &= left2(x, y + 1, distance)
  544.       if result == false
  545.         if left
  546.           move_upper_left_p
  547.           if @revise_y < -UP
  548.             @revise_y = -UP
  549.           end
  550.         end
  551.         return result
  552.       end
  553.     end
  554.     @revise_x -= distance
  555.     return result
  556.   end
  557.   #--------------------------------------------------------------------------
  558.   # ● 左に移動可能かどうかの判定2
  559.   #--------------------------------------------------------------------------
  560.   def left2(x, y, distance, d = 4)
  561.     if @revise_x - distance < -SIDE
  562.       unless passable?(x, y, d)
  563.         if @revise_x > -SIDE
  564.           @revise_x = -SIDE
  565.         end
  566.         return false
  567.       end
  568.     end
  569.     return true
  570.   end
  571.   #--------------------------------------------------------------------------
  572.   # ● 右に移動
  573.   #--------------------------------------------------------------------------
  574.   def move_right_p
  575.       # 右を向く
  576.       turn_right
  577.     distance = 2 ** @move_speed
  578.     right1(((@x * 128 + @revise_x) / 128.0).round,
  579.             ((@y * 128 + @revise_y) / 128.0).round, distance, true)
  580.   end
  581.   #--------------------------------------------------------------------------
  582.   # ● 右に移動可能かどうかの判定1
  583.   #--------------------------------------------------------------------------
  584.   def right1(x, y, distance, right = false)
  585.     result = right2(x, y, distance)
  586.     if result == false
  587.       @event_run = check_event_trigger_touch(x+1, y)
  588.       return result
  589.     end
  590.     if @revise_y < -UP
  591.       result = right2(x + 1, y, distance, 8)
  592.       result &= right2(x, y - 1, distance)
  593.       if result == false
  594.         if right
  595.           move_lower_right_p
  596.           if @revise_y > 0
  597.             @revise_y = 0
  598.           end
  599.         end
  600.         return result
  601.       end
  602.     elsif @revise_y > 0
  603.       result = right2(x + 1, y, distance, 2)
  604.       result &= right2(x, y + 1, distance)
  605.       if result == false
  606.         if right
  607.           move_upper_right_p
  608.           if @revise_y < -UP
  609.             @revise_y = -UP
  610.           end
  611.         end
  612.         return result
  613.       end
  614.     end
  615.     @revise_x += distance
  616.     return result
  617.   end
  618.   #--------------------------------------------------------------------------
  619.   # ● 右に移動可能かどうかの判定2
  620.   #--------------------------------------------------------------------------
  621.   def right2(x, y, distance, d = 6)
  622.     if @revise_x + distance > SIDE
  623.       unless passable?(x, y, d)
  624.         if @revise_x < SIDE
  625.           @revise_x = SIDE
  626.         end
  627.         return false
  628.       end
  629.     end
  630.     return true
  631.   end
  632.   #--------------------------------------------------------------------------
  633.   # ● 上に移動
  634.   #--------------------------------------------------------------------------
  635.   def move_up_p
  636.     # 上を向く
  637.     turn_up
  638.     # 下に移動
  639.     distance = 2 ** @move_speed
  640.     up1(((@x * 128 + @revise_x) / 128.0).round,
  641.         ((@y * 128 + @revise_y) / 128.0).round, distance, true)
  642.   end
  643.   #--------------------------------------------------------------------------
  644.   # ● 上に移動可能かどうかの判定1
  645.   #--------------------------------------------------------------------------
  646.   def up1(x, y, distance, up = false)
  647.     result = up2(x, y, distance)
  648.     if result == false
  649.       @event_run = check_event_trigger_touch(x, y-1)
  650.       return result
  651.     end
  652.     if @revise_x < -SIDE
  653.       result = up2(x, y - 1, distance, 4)
  654.       result &= up2(x - 1, y, distance)
  655.       if result == false
  656.         if up
  657.           move_upper_right_p
  658.           if @revise_x > SIDE
  659.             @revise_x = SIDE
  660.           end
  661.         end
  662.         return result
  663.       end
  664.     elsif @revise_x > SIDE
  665.       result = up2(x, y - 1, distance, 6)
  666.       result &= up2(x + 1, y, distance)
  667.       if result == false
  668.         if up
  669.           move_upper_left_p
  670.           if @revise_x < -SIDE
  671.             @revise_x = -SIDE
  672.           end
  673.         end
  674.         return result
  675.       end
  676.     end
  677.     @revise_y -= distance
  678.     return result
  679.   end
  680.   #--------------------------------------------------------------------------
  681.   # ● 上に移動可能かどうかの判定2
  682.   #--------------------------------------------------------------------------
  683.   def up2(x, y, distance, d = 8)
  684.     if @revise_y - distance < -UP
  685.       unless passable?(x, y, d)
  686.         if @revise_y > -UP
  687.           @revise_y = -UP
  688.         end
  689.         return false
  690.       end
  691.     end
  692.     return true
  693.   end
  694.   #--------------------------------------------------------------------------
  695.   # ● 左下に移動
  696.   #--------------------------------------------------------------------------
  697.   def move_lower_left_p
  698.     # 向き固定でない場合
  699.     unless @direction_fix
  700.       # 右向きだった場合は左を、上向きだった場合は下を向く
  701.       @direction = (@direction == 6 ? 4 : @direction == 8 ? 2 : @direction)
  702.     end
  703.     # 左下に移動
  704.     distance = (2 ** @move_speed) / Math.sqrt(2)
  705.     if @direction == 2
  706.       turn_left unless down1(((@x * 128 + @revise_x) / 128.0).round,
  707.                               ((@y * 128 + @revise_y) / 128.0).round, distance)
  708.       turn_down if @event_run
  709.       unless @event_run
  710.         if last_move?(@real_x, @real_y, 2, distance)
  711.           result = check_event_trigger_here([1,2], false)
  712.           if result == true
  713.             return
  714.           end
  715.         end
  716.         move_on
  717.         if @revise_y > 0 and -UP > @revise_y - distance
  718.           @revise_y = 0
  719.         end
  720.         turn_down unless left1(((@x * 128 + @revise_x) / 128.0).round,
  721.                               ((@y * 128 + @revise_y) / 128.0).round, distance)
  722.         turn_left if @event_run
  723.       end
  724.     else
  725.       turn_down unless left1(((@x * 128 + @revise_x) / 128.0).round,
  726.                               ((@y * 128 + @revise_y) / 128.0).round, distance)
  727.       turn_left if @event_run
  728.       unless @event_run
  729.         if last_move?(@real_x, @real_y, 4, distance)
  730.           result = check_event_trigger_here([1,2], false)
  731.           if result == true
  732.             return
  733.           end
  734.         end
  735.         move_on
  736.         if  @revise_x + distance> SIDE and -SIDE > @revise_x
  737.           @revise_x = -SIDE
  738.         end
  739.         turn_left unless down1(((@x * 128 + @revise_x) / 128.0).round,
  740.                               ((@y * 128 + @revise_y) / 128.0).round, distance)
  741.         turn_down if @event_run
  742.       end
  743.     end
  744.     @direction=1
  745.   end
  746.   #--------------------------------------------------------------------------
  747.   # ● 右下に移動
  748.   #--------------------------------------------------------------------------
  749.   def move_lower_right_p
  750.     # 向き固定でない場合
  751.     unless @direction_fix
  752.       # 左向きだった場合は右を、上向きだった場合は下を向く
  753.       @direction = (@direction == 4 ? 6 : @direction == 8 ? 2 : @direction)
  754.     end
  755.     # 右下に移動
  756.     distance = (2 ** @move_speed) / Math.sqrt(2)
  757.     if @direction == 2
  758.       turn_right unless down1(((@x * 128 + @revise_x) / 128.0).round,
  759.                               ((@y * 128 + @revise_y) / 128.0).round, distance)
  760.       turn_down if @event_run
  761.       unless @event_run
  762.         if last_move?(@real_x, @real_y, 2, distance)
  763.           result = check_event_trigger_here([1,2], false)
  764.           if result == true
  765.             return
  766.           end
  767.         end
  768.         move_on
  769.         if @revise_y > 0 and -UP > @revise_y - distance
  770.           @revise_y = 0
  771.         end
  772.         turn_down unless right1(((@x * 128 + @revise_x) / 128.0).round,
  773.                               ((@y * 128 + @revise_y) / 128.0).round, distance)
  774.         turn_right if @event_run
  775.       end
  776.     else
  777.       turn_down unless right1(((@x * 128 + @revise_x) / 128.0).round,
  778.                               ((@y * 128 + @revise_y) / 128.0).round, distance)
  779.       turn_right if @event_run
  780.       unless @event_run
  781.         if last_move?(@real_x, @real_y, 6, distance)
  782.           result = check_event_trigger_here([1,2], false)
  783.           if result == true
  784.             return
  785.           end
  786.         end
  787.         move_on
  788.         if @revise_x > SIDE and -SIDE > @revise_x - distance
  789.           @revise_x = SIDE
  790.         end
  791.         turn_right unless down1(((@x * 128 + @revise_x) / 128.0).round,
  792.                               ((@y * 128 + @revise_y) / 128.0).round, distance)
  793.         turn_down if @event_run
  794.       end
  795.       @direction=3
  796.     end
  797.   end
  798.   #--------------------------------------------------------------------------
  799.   # ● 左上に移動
  800.   #--------------------------------------------------------------------------
  801.   def move_upper_left_p
  802.     # 向き固定でない場合
  803.     unless @direction_fix
  804.       # 右向きだった場合は左を、下向きだった場合は上を向く
  805.       @direction = (@direction == 6 ? 4 : @direction == 2 ? 8 : @direction)
  806.     end
  807.     # 左上に移動
  808.     distance = (2 ** @move_speed) / Math.sqrt(2)
  809.     if @direction == 8
  810.       turn_left unless up1(((@x * 128 + @revise_x) / 128.0).round,
  811.                             ((@y * 128 + @revise_y) / 128.0).round, distance)
  812.       turn_up if @event_run
  813.       unless @event_run
  814.         if last_move?(@real_x, @real_y, 8, distance)
  815.           result = check_event_trigger_here([1,2], false)
  816.           if result == true
  817.             return
  818.           end
  819.         end
  820.         move_on
  821.         if @revise_y + distance > 0 and -UP > @revise_y
  822.           @revise_y = -UP
  823.         end
  824.         turn_up unless left1(((@x * 128 + @revise_x) / 128.0).round,
  825.                               ((@y * 128 + @revise_y) / 128.0).round, distance)
  826.         turn_left if @event_run
  827.       end
  828.     else
  829.       turn_up unless left1(((@x * 128 + @revise_x) / 128.0).round,
  830.                             ((@y * 128 + @revise_y) / 128.0).round, distance)
  831.       turn_left if @event_run
  832.       unless @event_run
  833.         if last_move?(@real_x, @real_y, 4, distance)
  834.           result = check_event_trigger_here([1,2], false)
  835.           if result == true
  836.             return
  837.           end
  838.         end
  839.         move_on
  840.         if @revise_x > SIDE and -SIDE > @revise_x - distance
  841.           @revise_x = SIDE
  842.         end
  843.         turn_left unless up1(((@x * 128 + @revise_x) / 128.0).round,
  844.                               ((@y * 128 + @revise_y) / 128.0).round, distance)
  845.         turn_up if @event_run
  846.       end
  847.     end
  848.     @direction=7
  849.   end
  850.   #--------------------------------------------------------------------------
  851.   # ● 右上に移動
  852.   #--------------------------------------------------------------------------
  853.   def move_upper_right_p
  854.     # 向き固定でない場合
  855.     unless @direction_fix
  856.       # 左向きだった場合は右を、下向きだった場合は上を向く
  857.       @direction = (@direction == 4 ? 6 : @direction == 2 ? 8 : @direction)
  858.     end
  859.     # 右上に移動
  860.     distance = (2 ** @move_speed) / Math.sqrt(2)
  861.     if @direction == 8
  862.       turn_right unless up1(((@x * 128 + @revise_x) / 128.0).round,
  863.                             ((@y * 128 + @revise_y) / 128.0).round, distance)
  864.       turn_up if @event_run
  865.       unless @event_run
  866.         if last_move?(@real_x, @real_y, 8, distance)
  867.           result = check_event_trigger_here([1,2], false)
  868.           if result == true
  869.             return
  870.           end
  871.         end
  872.         move_on
  873.         if @revise_y + distance > 0 and -UP > @revise_y
  874.           @revise_y = -UP
  875.         end
  876.         turn_up unless right1(((@x * 128 + @revise_x) / 128.0).round,
  877.                               ((@y * 128 + @revise_y) / 128.0).round, distance)
  878.         turn_right if @event_run
  879.       end
  880.     else
  881.       turn_up unless right1(((@x * 128 + @revise_x) / 128.0).round,
  882.                             ((@y * 128 + @revise_y) / 128.0).round, distance)
  883.       turn_right if @event_run
  884.       unless @event_run
  885.         if last_move?(@real_x, @real_y, 6, distance)
  886.           result = check_event_trigger_here([1,2], false)
  887.           if result == true
  888.             return
  889.           end
  890.         end
  891.         move_on
  892.         if @revise_x > SIDE and -SIDE > @revise_x - distance
  893.           @revise_x = SIDE
  894.         end
  895.         turn_right unless up1(((@x * 128 + @revise_x) / 128.0).round,
  896.                               ((@y * 128 + @revise_y) / 128.0).round, distance)
  897.         turn_up if @event_run
  898.       end
  899.     end
  900.     @direction=9
  901.   end
  902.   #--------------------------------------------------------------------------
  903.   # ● 同位置のイベント起動判定
  904.   #--------------------------------------------------------------------------
  905.   def check_event_trigger_here(triggers, run = true)
  906.     result = false
  907.     # イベント実行中の場合
  908.     if $game_system.map_interpreter.running?
  909.       return result
  910.     end
  911.     # 全イベントのループ
  912.     for event in $game_map.events.values
  913.       # イベントの座標とトリガーが一致した場合
  914.       if event.x == ((@x * 128 + @revise_x) / 128.0).round and
  915.           event.y == ((@y * 128 + @revise_y) / 128.0).round and
  916.           triggers.include?(event.trigger)
  917.         # ジャンプ中以外で、起動判定が同位置のイベントなら
  918.         if not event.jumping? and event.over_trigger?
  919.           if event.list.size > 1
  920.             if run == true
  921.               event.start
  922.             end
  923.             result = true
  924.           end
  925.         end
  926.       end
  927.     end
  928.     return result
  929.   end
  930.   #--------------------------------------------------------------------------
  931.   # ● 座標修正
  932.   #--------------------------------------------------------------------------
  933.   def move_on
  934.     if @y < (@y + @revise_y / 128.0).round
  935.       @y += 1
  936.       @revise_y -= 128
  937.     end
  938.     if @x > (@x + @revise_x / 128.0).round
  939.       @x -= 1
  940.       @revise_x += 128
  941.     end
  942.     if @x < (@x + @revise_x / 128.0).round
  943.       @x += 1
  944.       @revise_x -= 128
  945.     end
  946.     if @y > (@y + @revise_y / 128.0).round
  947.       @y -= 1
  948.       @revise_y += 128
  949.     end
  950.   end
  951.   #--------------------------------------------------------------------------
  952.   # ● 移動時のアニメーション
  953.   #--------------------------------------------------------------------------
  954.   def step_anime
  955.     # 移動時アニメが ON の場合
  956.     if @walk_anime
  957.       # アニメカウントを 1.5 増やす
  958.       @anime_count += 1.5
  959.     # 移動時アニメが OFF で、停止時アニメが ON の場合
  960.     elsif @step_anime
  961.       # アニメカウントを 1 増やす
  962.       @anime_count += 1
  963.     end
  964.     anime_update
  965.   end
  966.   #--------------------------------------------------------------------------
  967.   # ● 停止時のアニメーション
  968.   #--------------------------------------------------------------------------
  969.   def stop_anime
  970.     # 停止時アニメが ON の場合
  971.     if @step_anime
  972.       # アニメカウントを 1 増やす
  973.       @anime_count += 1
  974.     # 停止時アニメが OFF だが、現在のパターンがオリジナルと異なる場合
  975.     elsif @pattern != @original_pattern
  976.       # アニメカウントを 1.5 増やす
  977.       @anime_count += 1.5
  978.     else
  979.       # アニメカウント更新直前に変更
  980.       @anime_count = 18 - @move_speed * 2
  981.     end
  982.     # イベント実行待機中またはロック状態ではない場合
  983.     # ※ロックは、実行中のイベントが立ち止まる処理
  984.     unless @starting or lock?
  985.       # 停止カウントを 1 増やす
  986.       @stop_count += 1
  987.     end
  988.     anime_update
  989.   end
  990.   #--------------------------------------------------------------------------
  991.   # ● アニメーションアップデート
  992.   #--------------------------------------------------------------------------
  993.   def anime_update
  994.     # アニメカウントが最大値を超えた場合
  995.     # ※最大値は、基本値 18 から移動速度 * 1 を引いた値
  996.     if @anime_count > 18 - @move_speed * 2
  997.       # 停止時アニメが OFF かつ 停止中の場合
  998.       if not @step_anime and @stop_count > 0
  999.         # パターンをオリジナルに戻す
  1000.         @pattern = @original_pattern
  1001.       # 停止時アニメが ON または 移動中の場合
  1002.       else
  1003.         # パターンを更新
  1004.         @pattern = (@pattern + 1) % 4
  1005.       end
  1006.       # アニメカウントをクリア
  1007.       @anime_count = 0
  1008.     end
  1009.   end
  1010.   #--------------------------------------------------------------------------
  1011.   # ● 指定位置に移動
  1012.   #--------------------------------------------------------------------------
  1013.   # オリジナルのイベントを改名
  1014.   alias :moveto_original :moveto
  1015.   def moveto(x, y)
  1016.     # 補正座標を初期化
  1017.     @revise_x = 0
  1018.     @revise_y = 0
  1019.     # オリジナルのイベントを呼び出し
  1020.     moveto_original(x, y)
  1021.   end
  1022.   #--------------------------------------------------------------------------
  1023.   # ● 移動したかどうかの判定
  1024.   #--------------------------------------------------------------------------
  1025.   def last_move?(x, y, direction, distance)
  1026.     if direction == 2 or direction == 6
  1027.       distance *= -1
  1028.     end
  1029.     if (direction == 2 or direction == 8) and
  1030.         (y / 128.0).round != ((y - distance) / 128.0).round
  1031.       return true
  1032.     end
  1033.     if (direction == 4 or direction == 6) and
  1034.         (x / 128.0).round != ((x - distance) / 128.0).round
  1035.       return true
  1036.     end
  1037.     return false
  1038.   end
  1039. end
  1040.  
  1041. #==============================================================================
  1042. # ■ Game_Character (分割定義 1)
  1043. #------------------------------------------------------------------------------
  1044. #  キャラクターを扱うクラスです。このクラスは Game_Player クラスと Game_Event
  1045. # クラスのスーパークラスとして使用されます。
  1046. #==============================================================================
  1047.  
  1048. class Game_Character
  1049.   #--------------------------------------------------------------------------
  1050.   # ● 画面 X 座標の取得
  1051.   #--------------------------------------------------------------------------
  1052.   def screen_x
  1053.     # 実座標とマップの表示位置から画面座標を求める
  1054.     return ((@real_x - $game_map.display_x) / 4).ceil + 16
  1055.   end
  1056.   #--------------------------------------------------------------------------
  1057.   # ● 画面 Y 座標の取得
  1058.   #--------------------------------------------------------------------------
  1059.   def screen_y
  1060.     # 実座標とマップの表示位置から画面座標を求める
  1061.     y = ((@real_y - $game_map.display_y) / 4).ceil + 32
  1062.     # ジャンプカウントに応じて Y 座標を小さくする
  1063.     if @jump_count >= @jump_peak
  1064.       n = @jump_count - @jump_peak
  1065.     else
  1066.       n = @jump_peak - @jump_count
  1067.     end
  1068.     return y - (@jump_peak * @jump_peak - n * n) / 2
  1069.   end
  1070.   #--------------------------------------------------------------------------
  1071.   # ● フレーム更新 (移動)
  1072.   #--------------------------------------------------------------------------
  1073.   def update_move
  1074.     # 移動速度からマップ座標系での移動距離に変換
  1075.     distance = 2 ** @move_speed
  1076.     if @x * 128 != @real_x and @y * 128 != @real_y and Game_Player::SLANT
  1077.       distance /= Math.sqrt(2)
  1078.     end
  1079.     # 論理座標が実座標より下の場合
  1080.     if @y * 128 > @real_y
  1081.       # 下に移動
  1082.       @real_y = [@real_y + distance, @y * 128].min
  1083.     end
  1084.     # 論理座標が実座標より左の場合
  1085.     if @x * 128 < @real_x
  1086.       # 左に移動
  1087.       @real_x = [@real_x - distance, @x * 128].max
  1088.     end
  1089.     # 論理座標が実座標より右の場合
  1090.     if @x * 128 > @real_x
  1091.       # 右に移動
  1092.       @real_x = [@real_x + distance, @x * 128].min
  1093.     end
  1094.     # 論理座標が実座標より上の場合
  1095.     if @y * 128 < @real_y
  1096.       # 上に移動
  1097.       @real_y = [@real_y - distance, @y * 128].max
  1098.     end
  1099.     # 移動時アニメが ON の場合
  1100.     if @walk_anime
  1101.       # アニメカウントを 1.5 増やす
  1102.       @anime_count += 1.5
  1103.     # 移動時アニメが OFF で、停止時アニメが ON の場合
  1104.     elsif @step_anime
  1105.       # アニメカウントを 1 増やす
  1106.       @anime_count += 1
  1107.     end
  1108.   end
  1109. end
  1110.  
  1111. #==============================================================================
  1112. # ■ Game_Event
  1113. #------------------------------------------------------------------------------
  1114. #  イベントを扱うクラスです。条件判定によるイベントページ切り替えや、並列処理
  1115. # イベント実行などの機能を持っており、Game_Map クラスの内部で使用されます。
  1116. #==============================================================================
  1117.  
  1118. class Game_Event < Game_Character
  1119.   #--------------------------------------------------------------------------
  1120.   # ● イベント起動
  1121.   #--------------------------------------------------------------------------
  1122.   def start
  1123.     # 実行内容が空でない場合
  1124.     if @list.size > 1
  1125.       unless @starting
  1126.         # $game_player.event が0でない場合
  1127.         if $game_player.event != 0
  1128.           # 移動速度を $game_player.event にする
  1129.           $game_player.move_speed = $game_player.event
  1130.         elsif self.trigger == 0
  1131.           $game_player.move_speed = $game_player.walk
  1132.         end
  1133.       end
  1134.       @starting = true
  1135.     end
  1136.   end
  1137. end
  1138.  
  1139. #==============================================================================
  1140. # ■ Sprite_Character
  1141. #------------------------------------------------------------------------------
  1142.  
  1143. class Sprite_Character < RPG::Sprite
  1144.   def update
  1145.     super
  1146.     # 元件 ID、文件名、色相与现在的情况存在差异的情况下
  1147.     if @tile_id != @character.tile_id or
  1148.        @character_name != @character.character_name or
  1149.        @character_hue != @character.character_hue
  1150.       # 记忆元件 ID 与文件名、色相
  1151.       @tile_id = @character.tile_id
  1152.       @character_name = @character.character_name
  1153.       @character_hue = @character.character_hue
  1154.       # 元件 ID 为有效值的情况下
  1155.       if @tile_id >= 384
  1156.         self.bitmap = RPG::Cache.tile($game_map.tileset_name,
  1157.           @tile_id, @character.character_hue)
  1158.         self.src_rect.set(0, 0, 32, 32)
  1159.         self.ox = 16
  1160.         self.oy = 32
  1161.       # 元件 ID 为无效值的情况下
  1162.       else
  1163.         self.bitmap = RPG::Cache.character(@character.character_name,
  1164.           @character.character_hue)
  1165.         @cw = bitmap.width / 4
  1166.         @ch = bitmap.height / 8
  1167.         self.ox = @cw / 2
  1168.         self.oy = @ch
  1169.       end
  1170.     end
  1171.     # 设置可视状态
  1172.     self.visible = (not @character.transparent)
  1173.     # 图形是角色的情况下
  1174.     if @tile_id == 0
  1175.       # 设置传送目标的矩形
  1176.       sx = @character.pattern * @cw
  1177.         case @character.direction
  1178.         when 2
  1179.           sy = 0 * @ch
  1180.         when 4
  1181.           sy = 1 * @ch
  1182.         when 6
  1183.           sy = 2 * @ch
  1184.         when 8
  1185.           sy = 3 * @ch
  1186.         when 1
  1187.           sy = 4 * @ch
  1188.         when 3
  1189.           sy = 5 * @ch
  1190.         when 7
  1191.           sy = 6 * @ch
  1192.         when 9
  1193.           sy = 7 * @ch
  1194.         end
  1195.       self.src_rect.set(sx, sy, @cw, @ch)
  1196.     end
  1197.     # 设置脚本的坐标
  1198.     self.x = @character.screen_x
  1199.     self.y = @character.screen_y
  1200.     self.z = @character.screen_z(@ch)
  1201.     # 设置不透明度、合成方式、茂密
  1202.     self.opacity = @character.opacity
  1203.     self.blend_type = @character.blend_type
  1204.     self.bush_depth = @character.bush_depth
  1205.     # 动画
  1206.     if @character.animation_id != 0
  1207.       animation = $data_animations[@character.animation_id]
  1208.       animation(animation, true)
  1209.       @character.animation_id = 0
  1210.     end
  1211.   end
  1212. end

霓虹玩家做的八方行走不太喜欢考虑行走图的问题吗。嘛反正自己搞定了。
以上代码框内是成品。可用真八方的行走图。可正常相应。不拘束于32*32的格子,完美配合三远景。
闪人~

评分

参与人数 1星屑 +13 收起 理由
紫英晓狼1130 + 13 很好

查看全部评分

Lv3.寻梦者

梦石
0
星屑
3846
在线时间
1966 小时
注册时间
2013-1-3
帖子
9536
2
发表于 2013-7-29 16:29:09 | 只看该作者
LZ的这个脚本应该发到原创技术区呀~
应该是不错
《宿愿·寻剑篇》正式版已经发布!快去看看!点击进入论坛发布贴
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
28 小时
注册时间
2005-10-24
帖子
170
3
 楼主| 发表于 2013-7-29 16:33:54 | 只看该作者
紫英晓狼1130 发表于 2013-7-29 16:29
LZ的这个脚本应该发到原创技术区呀~
应该是不错

完全不是原创,这是从几个日站上的脚本中挑选出来的。只是日本人很奇妙的虽然做出了8方向行走却不考虑8方向行走图……
所以说,最多发到地球村或者水世界吧。
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
120
在线时间
188 小时
注册时间
2014-1-18
帖子
254
4
发表于 2014-1-19 08:29:14 | 只看该作者
哇,谢谢LZ,我正好打算下个安到ARPG上呢

点评

好吧,刚刚那句话没看到...  发表于 2014-1-19 09:41

评分

参与人数 1星屑 -20 收起 理由
myownroc -20 挖坟

查看全部评分

回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
147 小时
注册时间
2013-12-2
帖子
132
5
发表于 2014-1-20 08:34:59 | 只看该作者
32行出错了
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-10-1 06:12

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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