指令碼列表裡的Game_Character定義了不同方向的移動。

除了方向不同的移動之外,裡面還定義了各種不同的移動方式。不過現在我只需要不同方向就可以了。


  #--------------------------------------------------------------------------
  # * Move Down-往下
  #     turn_ok : Allows change of direction on the spot
  #--------------------------------------------------------------------------
  def move_down(turn_ok = true)
    if passable?(@x, @y+1)                  # Passable
      turn_down
      @y = $game_map.round_y(@y+1)
      @real_y = (@y-1)*256
      increase_steps
      @move_failed = false
    else                                    # Impassable
      turn_down if turn_ok
      check_event_trigger_touch(@x, @y+1)   # Touch event is triggered?
      @move_failed = true
    end
  end
  #--------------------------------------------------------------------------
  # * Move Left-往左
  #     turn_ok : Allows change of direction on the spot
  #--------------------------------------------------------------------------
  def move_left(turn_ok = true)
    if passable?(@x-1, @y)                  # Passable
      turn_left
      @x = $game_map.round_x(@x-1)
      @real_x = (@x+1)*256
      increase_steps
      @move_failed = false
    else                                    # Impassable
      turn_left if turn_ok
      check_event_trigger_touch(@x-1, @y)   # Touch event is triggered?
      @move_failed = true
    end
  end
  #--------------------------------------------------------------------------
  # * Move Right-往右
  #     turn_ok : Allows change of direction on the spot
  #--------------------------------------------------------------------------
  def move_right(turn_ok = true)
    if passable?(@x+1, @y)                  # Passable
      turn_right
      @x = $game_map.round_x(@x+1)
      @real_x = (@x-1)*256
      increase_steps
      @move_failed = false
    else                                    # Impassable
      turn_right if turn_ok
      check_event_trigger_touch(@x+1, @y)   # Touch event is triggered?
      @move_failed = true
    end
  end
  #--------------------------------------------------------------------------
  # * Move up-往上
  #     turn_ok : Allows change of direction on the spot
  #--------------------------------------------------------------------------
  def move_up(turn_ok = true)
    if passable?(@x, @y-1)                  # Passable
      turn_up
      @y = $game_map.round_y(@y-1)
      @real_y = (@y+1)*256
      increase_steps
      @move_failed = false
    else                                    # Impassable
      turn_up if turn_ok
      check_event_trigger_touch(@x, @y-1)   # Touch event is triggered?
      @move_failed = true
    end
  end
  #--------------------------------------------------------------------------
  # * Move Lower Left-左下
  #--------------------------------------------------------------------------
  def move_lower_left
    unless @direction_fix
      @direction = (@direction == 6 ? 4 : @direction == 8 ? 2 : @direction)
    end
    if (passable?(@x, @y+1) and passable?(@x-1, @y+1)) or
       (passable?(@x-1, @y) and passable?(@x-1, @y+1))
      @x -= 1
      @y += 1
      increase_steps
      @move_failed = false
    else
      @move_failed = true
    end
  end
  #--------------------------------------------------------------------------
  # * Move Lower Right-右下
  #--------------------------------------------------------------------------
  def move_lower_right
    unless @direction_fix
      @direction = (@direction == 4 ? 6 : @direction == 8 ? 2 : @direction)
    end
    if (passable?(@x, @y+1) and passable?(@x+1, @y+1)) or
       (passable?(@x+1, @y) and passable?(@x+1, @y+1))
      @x += 1
      @y += 1
      increase_steps
      @move_failed = false
    else
      @move_failed = true
    end
  end
  #--------------------------------------------------------------------------
  # * Move Upper Left-左上
  #--------------------------------------------------------------------------
  def move_upper_left
    unless @direction_fix
      @direction = (@direction == 6 ? 4 : @direction == 2 ? 8 : @direction)
    end
    if (passable?(@x, @y-1) and passable?(@x-1, @y-1)) or
       (passable?(@x-1, @y) and passable?(@x-1, @y-1))
      @x -= 1
      @y -= 1
      increase_steps
      @move_failed = false
    else
      @move_failed = true
    end
  end
  #--------------------------------------------------------------------------
  # * Move Upper Right-右上
  #--------------------------------------------------------------------------
  def move_upper_right
    unless @direction_fix
      @direction = (@direction == 4 ? 6 : @direction == 2 ? 8 : @direction)
    end
    if (passable?(@x, @y-1) and passable?(@x+1, @y-1)) or
       (passable?(@x+1, @y) and passable?(@x+1, @y-1))
      @x += 1
      @y -= 1
      increase_steps
      @move_failed = false
    else
      @move_failed = true
    end
  end


好拉我承認這段是貼來拉長文章長度

 

 

 

拿其中兩段來講解一下部分的指令,不要重複貼阿


  #--------------------------------------------------------------------------
  # * Move up-往上
  #     turn_ok : Allows change of direction on the spot
  #--------------------------------------------------------------------------
  def move_up(turn_ok = true)
    if passable?(@x, @y-1)                  # 判斷往上一格的地方是否可以通過
      turn_up                                      # 角色面對上方
      @y = $game_map.round_y(@y-1)
      @real_y = (@y+1)*256
      increase_steps
      @move_failed = false
    else                                    # Impassable
      turn_up if turn_ok
      check_event_trigger_touch(@x, @y-1)   # Touch event is triggered?
      @move_failed = true
    end
  end
  #--------------------------------------------------------------------------
  # * Move Lower Left-左下
  #--------------------------------------------------------------------------
  def move_lower_left
    unless @direction_fix
      @direction = (@direction == 6 ? 4 : @direction == 8 ? 2 : @direction)# 角色方向的修正,把面向右邊/上方更改成左邊/下方。
    end
    if (passable?(@x, @y+1) and passable?(@x-1, @y+1)) or
       (passable?(@x-1, @y) and passable?(@x-1, @y+1))   # 判斷往左下的地方是否可以通過,同時判斷左邊或下面任一是否可以通過,這樣可以避免穿牆.....
      @x -= 1
      @y += 1
      increase_steps
      @move_failed = false
    else
      @move_failed = true
    end
  end


 

無意義無責任解說完畢,接下來我需要的是讓鍵盤移動也可以觸發斜方向的移動。

好了那這個要去哪裡設定呢~(?!)

 

 

 

 

 

Game_Player裡面有一段這樣的東西


  #--------------------------------------------------------------------------
  # * Processing of Movement via input from the Directional Buttons
  #--------------------------------------------------------------------------
  def move_by_input
    return unless movable?
    return if $game_map.interpreter.running?
    case Input.dir4
    when 2;  move_down
    when 4;  move_left
    when 6;  move_right
    when 8;  move_up
    end
  end


我很想直接改成這樣啦....


  #--------------------------------------------------------------------------
  # * Processing of Movement via input from the Directional Buttons
  #--------------------------------------------------------------------------
  def move_by_input
    return unless movable?
    return if $game_map.interpreter.running?
    case Input.dir9    #看起來本來就是按照數字鍵去設定的,因為5=不移動所以實際上有九個方向?

    when 1;  move_lower_left
    when 2;  move_down
    when 3;  move_lower_right
    when 4;  move_left
    when 6;  move_right
    when 7;  move_upper_left
    when 8;  move_up    
    when 9;  move_upper_right


    end
  end


一看就知道是錯的呢,dir9是甚麼鬼,方向變數應該不是我隨便改就可以用的阿XDDDDD

 

果然跳出了dir9的碩誤訊息,那就改成dir8拉~其實我覺得這樣應該也是錯的,因為我沒有定義dir8。 


  #--------------------------------------------------------------------------
  # * Processing of Movement via input from the Directional Buttons
  #--------------------------------------------------------------------------
  def move_by_input
    return unless movable?
    return if $game_map.interpreter.running?
    case Input.dir8    #因為dir9說沒定義所以改成8來玩玩

    when 1;  move_lower_left
    when 2;  move_down
    when 3;  move_lower_right
    when 4;  move_left
    when 6;  move_right
    when 7;  move_upper_left
    when 8;  move_up   
    when 9;  move_upper_right


    end
  end


 

....................................結果這樣就可以用了,END(?!?!)

 

 

 

 

 

 

 

 

.........................................結果其實VX有定義8方向的走法,只是沒有斜像貼圖就鎖起來嗎?

讓我找一下dir8在哪裡偷定義好了。

 

 

找不到呢...連上網GOOGLE也沒看見,我就當作是他內建吧OTZ。

創作者介紹
IVY

思緒集散地

IVY 發表在 痞客邦 PIXNET 留言(0) 人氣()