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. 1인용메뉴

    Date2010.07.18 CategoryRPGVX Ace 스크립트 ByA.M.S Views2609 Votes0
    Read More
  2. 1인용메뉴

    Date2010.07.18 CategoryRPGVX 스크립트 ByA.M.S Views2560 Votes0
    Read More
  3. 2D 마인크래프트 프로젝트

    Date2013.09.26 CategoryRPGXP 스크립트 By Views3048 Votes2
    Read More
  4. 3D 그래픽 파티클 스크립트

    Date2013.09.29 CategoryRPGVX 스크립트 By청담 Views1272 Votes0
    Read More
  5. 3D스크립트!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    Date2014.01.18 CategoryRPGXP 스크립트 By공박사 Views2805 Votes2
    Read More
  6. 8방향 이동스크립트

    Date2014.02.22 CategoryRPGXP 스크립트 By천둥번들 Views1723 Votes6
    Read More
  7. 8방향이동

    Date2010.10.14 CategoryRPGXP 스크립트 ByA.M.S Views2151 Votes0
    Read More
  8. 8방향이동

    Date2010.10.14 CategoryRPGXP 스크립트 ByA.M.S Views2330 Votes0
    Read More
  9. 9마리 이상의 몬스터 설정 | More Enemies

    Date2018.08.31 CategoryRPGMV 플러그인 By러닝은빛 Views763 Votes0
    Read More
  10. Ace로 만든 습작 랜덤 위치로 지형변환.

    Date2014.10.04 CategoryRPGVX Ace 스크립트 ByJunkMan Views512 Votes0
    Read More
  11. Action Sequence Pack 2 (전투모드 액션 플러그인)

    Date2016.01.05 CategoryRPGMV 플러그인 Byplam Views1821 Votes0
    Read More
  12. Advanced Game Time (게임에 시간개념을 적용해주는 플러그인)

    Date2016.01.06 CategoryRPGMV 플러그인 Byplam Views1398 Votes0
    Read More
  13. AraLab_MultiStartingPoint (다중 출발점 스크립트, 캐릭터 선택 스크립트) ver.0.2beta

    Date2014.01.21 CategoryRPGXP 스크립트 By 운 Views1973 Votes1
    Read More
  14. Bind Pictures To Map (이미지 결합 플러그인)

    Date2015.10.30 CategoryRPGMV 플러그인 By이녕 Views1049 Votes0
    Read More
  15. Crafting System (아이템 조합 시스템)

    Date2016.01.06 CategoryRPGMV 플러그인 Byplam Views1709 Votes0
    Read More
  16. CSS 캔버스 필터

    Date2016.10.06 CategoryRPGMV 플러그인 By러닝은빛 Views912 Votes0
    Read More
  17. Custom Icon Sheets (커스텀 아이콘 적용 스크립트)

    Date2016.01.10 CategoryRPGVX Ace 스크립트 Byplam Views470 Votes0
    Read More
  18. c[n] 명령어 줄때의 색상 결정.

    Date2008.02.14 CategoryRPGXP 스크립트 By창조도시 Views1015 Votes1
    Read More
  19. c[n] 명령어 줄때의 색상 결정.

    Date2008.02.14 CategoryRPGXP 스크립트 By창조도시 Views1438 Votes1
    Read More
  20. Damage Popup by Dargor (데미지 수치 팝업하는 스크립트)

    Date2016.01.10 CategoryRPGVX Ace 스크립트 Byplam Views612 Votes0
    Read More
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 15 Next
/ 15






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

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