RPGXP 스크립트
2014.02.22 05:28

8방향 이동스크립트

조회 수 1723 추천 수 6 댓글 5
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
#==============================================================================
# ■ Game_Player
#------------------------------------------------------------------------------
#  플레이어를 취급하는 클래스입니다. 이벤트의 기동 판정이나, 맵의 스크롤등의
# 기능을 가지고 있습니다. 이 클래스의 인스턴스는 $game_player 로 참조됩니다.
#==============================================================================
 
class Game_Player < Game_Character
  #--------------------------------------------------------------------------
  # ● 정수
  #--------------------------------------------------------------------------
  CENTER_X = (320 - 16) * 4   # 화면 중앙의 X 좌표 * 4
  CENTER_Y = (240 - 16) * 4   # 화면 중앙의 Y 좌표 * 4
  #--------------------------------------------------------------------------
  # ● 통행 가능 판정
  #     x : X 좌표
  #     y : Y 좌표
  #     d : 방향 (0,2,4,6,8)  ※ 0 = 전방향 통행 불가의 경우를 판정 (점프용)
  #--------------------------------------------------------------------------
  def passable? (x, y, d)
    # 새로운 좌표를 요구한다
    new_x = x + (d == 6 ?  1 : d == 4 ?  -1 : 0)
    new_y = y + (d == 2 ?  1 : d == 8 ?  -1 : 0)
    # 좌표가 맵외의 경우
    unless $game_map.valid? (new_x, new_y)
      # 통행 불가
      return false
    end
    # 디버그 모드가 ON 또한 CTRL 키가 밀리고 있는 경우
    if $DEBUG and Input.press? (Input::CTRL)
      # 통행가능
      return true
    end
    super
  end
  #--------------------------------------------------------------------------
  # ● 화면 중앙에 오도록(듯이) 맵의 표시 위치를 설정
  #--------------------------------------------------------------------------
  def center(x, y)
    max_x = ($game_map.width - 20) * 128
    max_y = ($game_map.height - 15) * 128
    $game_map.display_x = [0, [x * 128 - CENTER_X, max_x]. min]. max
    $game_map.display_y = [0, [y * 128 - CENTER_Y, max_y]. min]. max
  end
  #--------------------------------------------------------------------------
  # ● 지정 위치에 이동
  #     x : X 좌표
  #     y : Y 좌표
  #--------------------------------------------------------------------------
  def moveto(x, y)
    super
    # 센터링
    center(x, y)
    # 엔카운트카운트를 작성
    make_encounter_count
  end
  #--------------------------------------------------------------------------
  # ● 보수 증가
  #--------------------------------------------------------------------------
  def increase_steps
    super
    # 이동 루트 강제중이 아닌 경우
    unless @move_route_forcing
      # 보수 증가
      $game_party.increase_steps
      # 보수가 짝수의 경우
      if $game_party.steps % 2 == 0
        # 슬립 데미지 체크
        $game_party.check_map_slip_damage
      end
    end
  end
  #--------------------------------------------------------------------------
  # ● 엔카운트카운트 취득
  #--------------------------------------------------------------------------
  def encounter_count
    return @encounter_count
  end
  #--------------------------------------------------------------------------
  # ● 엔카운트카운트 작성
  #--------------------------------------------------------------------------
  def make_encounter_count
    # 주사위를 2 개 거절하는 이미지
    n = $game_map.encounter_step
    @encounter_count = rand(n) + rand(n) + 1
  end
  #--------------------------------------------------------------------------
  # ● 리프레쉬
  #--------------------------------------------------------------------------
  def refresh
    # 파티 인원수가 0 명의 경우
    if $game_party.actors.size == 0
      # 캐릭터의 파일명과 색상을 클리어
      @character_name = ""
      @character_hue = 0
      # 메소드 종료
      return
    end
    # 선두의 엑터를 취득
    actor = $game_party.actors[0]
    # 캐릭터의 파일명과 색상을 설정
    @character_name = actor.character_name
    @character_hue = actor.character_hue
    # 불투명도와 합성 방법을 초기화
    @opacity = 255
    @blend_type = 0
  end
  #--------------------------------------------------------------------------
  # ● 동위치의 이벤트 기동 판정
  #--------------------------------------------------------------------------
  def check_event_trigger_here(triggers)
    result = false
    # 이벤트 실행중의 경우
    if $game_system.map_interpreter.running?
      return result
    end
    # 전이벤트의 루프
    for event in $game_map.events.values
      # 이벤트의 좌표와 트리거가 일치했을 경우
      if event.x == @x and event.y == @y and triggers.include? (event.trigger)
        # 기동 판정이 동위치의 이벤트라면
        if event.over_trigger?
          event.start
          result = true
        end
      end
    end
    return result
  end
  #--------------------------------------------------------------------------
  # ● 정면의 이벤트 기동 판정
  #--------------------------------------------------------------------------
  def check_event_trigger_there(triggers)
    result = false
    # 이벤트 실행중의 경우
    if $game_system.map_interpreter.running?
      return result
    end
    # 정면의 좌표를 계산
    new_x = @x + (@direction == 6 ?  1 : @direction == 4 ?  -1 : 0)
    new_y = @y + (@direction == 2 ?  1 : @direction == 8 ?  -1 : 0)
    # 전이벤트의 루프
    for event in $game_map.events.values
      # 이벤트의 좌표와 트리거가 일치했을 경우
      if event.x == new_x and event.y == new_y and
         triggers.include? (event.trigger)
        # 기동 판정이 정면의 이벤트라면
        unless event.over_trigger?
          event.start
          result = true
        end
      end
    end
    # 해당하는 이벤트가 발견되지 않았던 경우
    if result == false
      # 정면의 타일이 카운터라면
      if $game_map.counter? (new_x, new_y)
        # 1 타일안쪽의 좌표를 계산
        new_x += (@direction == 6 ?  1 : @direction == 4 ?  -1 : 0)
        new_y += (@direction == 2 ?  1 : @direction == 8 ?  -1 : 0)
        # 전이벤트의 루프
        for event in $game_map.events.values
          # 이벤트의 좌표와 트리거가 일치했을 경우
          if event.x == new_x and event.y == new_y and
             triggers.include? (event.trigger)
            # 기동 판정이 정면의 이벤트라면
            unless event.over_trigger?
              event.start
              result = true
            end
          end
        end
      end
    end
    return result
  end
  #--------------------------------------------------------------------------
  # ● 접촉 이벤트의 기동 판정
  #--------------------------------------------------------------------------
  def check_event_trigger_touch(x, y)
    result = false
    # 이벤트 실행중의 경우
    if $game_system.map_interpreter.running?
      return result
    end
    # 전이벤트의 루프
    for event in $game_map.events.values
      # 이벤트의 좌표와 트리거가 일치했을 경우
      if event.x == x and event.y == y and [1,2]. include? (event.trigger)
        # 기동 판정이 정면의 이벤트라면
        unless event.over_trigger?
          event.start
          result = true
        end
      end
    end
    return result
  end
  #--------------------------------------------------------------------------
  # ● 프레임 갱신
  #--------------------------------------------------------------------------
  def update
    # 로컬 변수에 이동중인가 어떤가를 기억
    last_moving = moving?
    # 이동중, 이벤트 실행중, 이동 루트 강제중,
    # 메세지 윈도우 표시중의 머지않아도 아닌 경우
    unless moving?  or $game_system.map_interpreter.running?  or
           @move_route_forcing or $game_temp.message_window_showing
      # 방향 버튼이 밀리고 있으면, 그 방향에 플레이어를 이동
# ==========================================================================
      # 방향을 보존
      direction = @direction
      case Input.dir8
      when 1  # 좌하
        move_left
        move_down
        # 방향 고정이 아닌 경우
        unless @direction_fix
          # 오른쪽 방향이었던 경우는 왼쪽을 , 오름새였던 경우는 아래를 향하는
          @direction = (direction == 6 ? 4 : direction == 8 ? 2 : direction)
        end
      when 2  # 하
        move_down
      when 3  # 우하
        move_down
        move_right
        # 방향 고정이 아닌 경우
        unless @direction_fix
          # 좌향이었던 경우는 오른쪽을 , 오름새였던 경우는 아래를 향하는
          @direction = (direction == 4 ? 6 : direction == 8 ? 2 : direction)
        end
      when 4  # 좌
        move_left
      when 6  # 우
        move_right
      when 7  # 좌상
        move_up
        move_left
        # 방향 고정이 아닌 경우
        unless @direction_fix
          # 오른쪽 방향이었던 경우는 왼쪽을 , 하향이었던 경우는 위를 향하는
          @direction = (direction == 6 ? 4 : direction == 2 ? 8 : direction)
        end
      when 8  # 상
        move_up
      when 9  # 우상
        move_right
        move_up
        # 방향 고정이 아닌 경우
        unless @direction_fix
          # 좌향이었던 경우는 오른쪽을 , 하향이었던 경우는 위를 향하는
          @direction = (direction == 4 ? 6 : direction == 2 ? 8 : direction)
        end
      end
# ==========================================================================
    end
    # 로컬 변수에 좌표를 기억
    last_real_x = @real_x
    last_real_y = @real_y
    super
    # 캐릭터가 아래로 이동해, 한편 화면상의 위치가 중앙에서(보다) 아래의 경우
    if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y
      # 맵을 아래에 스크롤
      $game_map.scroll_down(@real_y - last_real_y)
    end
    # 캐릭터가 왼쪽으로 이동해, 한편 화면상의 위치가 중앙에서(보다) 왼쪽의 경우
    if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X
      # 맵을 왼쪽으로 스크롤
      $game_map.scroll_left(last_real_x - @real_x)
    end
    # 캐릭터가 오른쪽으로 이동해, 한편 화면상의 위치가 중앙에서(보다) 오른쪽의 경우
    if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X
      # 맵을 오른쪽으로 스크롤
      $game_map.scroll_right(@real_x - last_real_x)
    end
    # 캐릭터가 위로 이동해, 한편 화면상의 위치가 중앙에서(보다) 위의 경우
    if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y
      # 맵을 위에 스크롤
      $game_map.scroll_up(last_real_y - @real_y)
    end
    # 이동중이 아닌 경우
    unless moving?
      # 전회 플레이어가 이동중이었던 경우
      if last_moving
        # 동위치의 이벤트와의 접촉에 의한 이벤트 기동 판정
        result = check_event_trigger_here([1,2])
        # 기동한 이벤트가 없는 경우
        if result == false
          # 디버그 모드가 ON 또한 CTRL 키가 밀리고 있는 경우를 제외해
          unless $DEBUG and Input.press? (Input::CTRL)
            # 엔카운트카운트다운
            if @encounter_count > 0
              @encounter_count -= 1
            end
          end
        end
      end
      # C 버튼이 밀렸을 경우
      if Input.trigger? (Input::C)
        # 동위치 및 정면의 이벤트 기동 판정
        check_event_trigger_here([0])
        check_event_trigger_there([0,1,2])
      end
    end
  end
end
 
?
  • ?
    neopop 2014.03.16 20:07
    이거면 대각선으로 이동 가능하나요?
  • profile
    천둥번들 2014.03.16 20:21
  • ?
    d메탈소울b 2014.04.23 07:41
    어떻게해서 이동하는지 원 ㅋ
  • ?
    세이즈 2014.12.04 22:46
    왼쪽위는 키를 이 말대로 왼쪽과 위쪽으로 가는 거 동시에 누르면 가능 나머지도 이렇게
  • ?
    A-RISE 2015.03.07 23:31
    이거저만오류뜨나요??

  1. 퀘스트 스크립트

  2. 메뉴에 퀘스트 있는거

  3. 문과 상자를 쉽게 만들수 있는 스크립트

  4. 이름조합스크립트

  5. 아이템 조합 스크립트

  6. 모션 스크립트

  7. 메세지에 얼굴, 이름등 다양한 기능 넣기 UMS 스크립트

  8. 타이틀 로고 띄우기 + 로고 SE 가능(예제있음)

  9. Rpg Vx Ace 에서 이벤트 이름 팝업

  10. 3D스크립트!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  11. AraLab_MultiStartingPoint (다중 출발점 스크립트, 캐릭터 선택 스크립트) ver.0.2beta

  12. 8방향 이동스크립트

  13. 달리기스크립트

  14. 스텟찍기스크립트

  15. 말풍선 메세지 스크립트

  16. 횡스크롤 점프 [버튼허용스위치추가]

  17. 얼굴표시/문장을 한글자씩 나타내주는 스크립트 (출처-히페리온)

  18. RPG Maker VX Ace용 로고 스크립트

  19. RPG Maker VX Ace용 640*480 리사이징 스크립트

  20. VX Ace 스크립트 사이트

Board Pagination Prev 1 ... 4 5 6 7 8 9 10 11 12 13 ... 15 Next
/ 15






[개인정보취급방침] | [이용약관] | [제휴문의] | [후원창구] | [인디사이드연혁]

Copyright © 1999 - 2016 INdiSide.com/(주)씨엘쓰리디 All Rights Reserved.
인디사이드 운영자 : 천무(이지선) | kernys(김원배) | 사신지(김병국)