Avangs

  • 게임 정보
    • 게임 소개
    • 게임 리뷰
    • 게임 실황
    • 게임 공략
    • 모바일 테스트
  • 게임 작품new
    • 완성작 게임
    • 체험판 게임
    • 한글판 게임new
    • 온라인 게임
    • 추천작 제작자 저장소
  • 투표선정 작품
    • 아방스 추천작
    • 완성 기대작
    • 투표 신청
    • 투표소
    • 투표 결과
  • 강좌
    • 아방스 칼럼
    • 비주얼노벨 강좌
    • 알만툴 강좌
      • MZ 강좌
      • MV 강좌
      • VX Ace 강좌
      • VX 강좌
      • XP 강좌
      • 2003 강좌
      • 2000 강좌
    • 게임메이커 강좌
    • 울프툴 강좌
    • 3D 게임제작 강좌
    • 2D 게임제작 강좌
    • 그래픽 제작 강좌
    • 기타 강좌
  • 질문과 답변
    • 자주 묻는 질문
    • 질문과 답변
    • 제작의뢰
  • 커뮤니티
    • 구인·구직·외주
    • 테스트 요청
    • 자유게시판
    • 게임계 소식
    • 유머&정보
    • 사이트링크
    • 이벤트&대회
  • 창작
    • 게임 기획
    • 맵배치
    • 글쓰기
    • 그리기
    • 음악
  • 자료실
    • 게임제작툴
    • 예제 및 샘플
    • 그래픽 소재
      • 오리지널 소재
      • 이차창작 소재
      • 수정·개조 소재
      • 외부 소재
    • 사운드 소재
    • 확장·플러그인·스크립트
      • MZ 플러그인
      • MV 플러그인
      • Ace 스크립트
      • VX 스크립트
      • XP 스크립트
      • 2k3 플러그인
      • VN 플러그인·확장
    • 외부 소재사이트
    • 기타 자료
      • 한글화툴
      • 무료 폰트
      • 유틸리티
    • 디자인 참고자료
  • 고객센터
    • 공지사항
    • 건의 및 신고
    • 핫 이슈
로그인 회원가입
Avangs
  • 게임 정보
    • 게임 소개
    • 게임 리뷰
    • 게임 실황
    • 게임 공략
    • 모바일 테스트
  • 게임 작품new
    • 완성작 게임
    • 체험판 게임
    • 한글판 게임new
    • 온라인 게임
    • 추천작 제작자 저장소
  • 투표선정 작품
    • 아방스 추천작
    • 완성 기대작
    • 투표 신청
    • 투표소
    • 투표 결과
  • 강좌
    • 아방스 칼럼
    • 비주얼노벨 강좌
    • 알만툴 강좌
      • MZ 강좌
      • MV 강좌
      • VX Ace 강좌
      • VX 강좌
      • XP 강좌
      • 2003 강좌
      • 2000 강좌
    • 게임메이커 강좌
    • 울프툴 강좌
    • 3D 게임제작 강좌
    • 2D 게임제작 강좌
    • 그래픽 제작 강좌
    • 기타 강좌
  • 질문과 답변
    • 자주 묻는 질문
    • 질문과 답변
    • 제작의뢰
  • 커뮤니티
    • 구인·구직·외주
    • 테스트 요청
    • 자유게시판
    • 게임계 소식
    • 유머&정보
    • 사이트링크
    • 이벤트&대회
  • 창작
    • 게임 기획
    • 맵배치
    • 글쓰기
    • 그리기
    • 음악
  • 자료실
    • 게임제작툴
    • 예제 및 샘플
    • 그래픽 소재
      • 오리지널 소재
      • 이차창작 소재
      • 수정·개조 소재
      • 외부 소재
    • 사운드 소재
    • 확장·플러그인·스크립트
      • MZ 플러그인
      • MV 플러그인
      • Ace 스크립트
      • VX 스크립트
      • XP 스크립트
      • 2k3 플러그인
      • VN 플러그인·확장
    • 외부 소재사이트
    • 기타 자료
      • 한글화툴
      • 무료 폰트
      • 유틸리티
    • 디자인 참고자료
  • 고객센터
    • 공지사항
    • 건의 및 신고
    • 핫 이슈
로그인 회원가입

NOTICE

공지사항
더보기
  • 서버 안정성 및 보안 강화 조치 04.20

Recently Added Games

최근 등록 게임
  • 어드벤쳐 고철에 파묻힌 데모나 (屑鉄まとうデモナ) newfile 08.19
  • 어드벤쳐 비올레 저택의 시온 : 꽃눈의 저택|RPG Maker MZ 단편 심리공포 어드벤처 file 08.17
  • 기타 (똥 주의)그저 똥을 누러 가는 게임 Re:Boot updatefile 08.16
  • 롤플레잉 SACCHARINE SYNC (DEMO) 배포 file 08.12
  • 기타 (완성작) 야구장에 가자4 file 2 07.07
이동 및 탈것
2009.02.22 18:12

자동으로 장애물을 피해가는 스크립트

백호
조회 수 2019 추천 수 0 댓글 13
크게 작게 위로 아래로 댓글로 가기 인쇄 첨부
크게 작게 위로 아래로 댓글로 가기 인쇄 첨부


#==============================================================================
# ** Game_Player
#------------------------------------------------------------------------------
#  장애물을 자동으로 피해가는 스크립트 - 준돌
#
#
#  방향키를 지속적으로 누르고 있을경우 앞에 장애물을
#  옆으로 틀어서 피해지나갑니다.
#==============================================================================

class Game_Player < Game_Character
  #--------------------------------------------------------------------------
  # * Invariables
  #--------------------------------------------------------------------------
  CENTER_X = (320 - 16) * 4  # Center screen x-coordinate * 4
  CENTER_Y = (240 - 16) * 4  # Center screen y-coordinate * 4
  #--------------------------------------------------------------------------
  # * Passable Determinants
  #    x : x-coordinate
  #    y : y-coordinate
  #    d : direction (0,2,4,6,8)
  #        * 0 = Determines if all directions are impassable (for jumping)
  #--------------------------------------------------------------------------
  def passable?(x, y, d)
    # Get new coordinates
    new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
    new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
    # If coordinates are outside of map
    unless $game_map.valid?(new_x, new_y)
      # Impassable
      return false
    end
    # If debug mode is ON and ctrl key was pressed
    if $DEBUG and Input.press?(Input::CTRL)
      # Passable
      return true
    end
    super
  end
  #--------------------------------------------------------------------------
  # * Set Map Display Position to Center of Screen
  #--------------------------------------------------------------------------
  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
  #--------------------------------------------------------------------------
  # * Move to Designated Position
  #    x : x-coordinate
  #    y : y-coordinate
  #--------------------------------------------------------------------------
  def moveto(x, y)
    super
    # Centering
    center(x, y)
    # Make encounter count
    make_encounter_count
  end
  #--------------------------------------------------------------------------
  # * Increaase Steps
  #--------------------------------------------------------------------------
  def increase_steps
    super
    # If move route is not forcing
    unless @move_route_forcing
      # Increase steps
      $game_party.increase_steps
      # Number of steps are an even number
      if $game_party.steps % 2 == 0
        # Slip damage check
        $game_party.check_map_slip_damage
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Get Encounter Count
  #--------------------------------------------------------------------------
  def encounter_count
    return @encounter_count
  end
  #--------------------------------------------------------------------------
  # * Make Encounter Count
  #--------------------------------------------------------------------------
  def make_encounter_count
    # Image of two dice rolling
    if $game_map.map_id != 0
      n = $game_map.encounter_step
      @encounter_count = rand(n) + rand(n) + 1
    end
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    # If party members = 0
    if $game_party.actors.size == 0
      # Clear character file name and hue
      @character_name = ""
      @character_hue = 0
      # End method
      return
    end
    # Get lead actor
    actor = $game_party.actors[0]
    # Set character file name and hue
    @character_name = actor.character_name
    @character_hue = actor.character_hue
    # Initialize opacity level and blending method
    @opacity = 255
    @blend_type = 0
  end
  #--------------------------------------------------------------------------
  # * Same Position Starting Determinant
  #--------------------------------------------------------------------------
  def check_event_trigger_here(triggers)
    result = false
    # If event is running
    if $game_system.map_interpreter.running?
      return result
    end
    # All event loops
    for event in $game_map.events.values
      # If event coordinates and triggers are consistent
      if event.x == @x and event.y == @y and triggers.include?(event.trigger)
        # If starting determinant is same position event (other than jumping)
        if not event.jumping? and event.over_trigger?
          event.start
          result = true
        end
      end
    end
    return result
  end
  #--------------------------------------------------------------------------
  # * Front Envent Starting Determinant
  #--------------------------------------------------------------------------
  def check_event_trigger_there(triggers)
    result = false
    # If event is running
    if $game_system.map_interpreter.running?
      return result
    end
    # Calculate front event coordinates
    new_x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
    new_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
    # All event loops
    for event in $game_map.events.values
      # If event coordinates and triggers are consistent
      if event.x == new_x and event.y == new_y and
        triggers.include?(event.trigger)
        # If starting determinant is front event (other than jumping)
        if not event.jumping? and not event.over_trigger?
          event.start
          result = true
        end
      end
    end
    # If fitting event is not found
    if result == false
      # If front tile is a counter
      if $game_map.counter?(new_x, new_y)
        # Calculate 1 tile inside coordinates
        new_x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
        new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
        # All event loops
        for event in $game_map.events.values
          # If event coordinates and triggers are consistent
          if event.x == new_x and event.y == new_y and
            triggers.include?(event.trigger)
            # If starting determinant is front event (other than jumping)
            if not event.jumping? and not event.over_trigger?
              event.start
              result = true
            end
          end
        end
      end
    end
    return result
  end
  #--------------------------------------------------------------------------
  # * Touch Event Starting Determinant
  #--------------------------------------------------------------------------
  def check_event_trigger_touch(x, y)
    result = false
    # If event is running
    if $game_system.map_interpreter.running?
      return result
    end
    # All event loops
    for event in $game_map.events.values
      # If event coordinates and triggers are consistent
      if event.x == x and event.y == y and [1,2].include?(event.trigger)
        # If starting determinant is front event (other than jumping)
        if not event.jumping? and not event.over_trigger?
          event.start
          result = true
        end
      end
    end
    return result
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def turn_ai_side
    case @direction
    when 2
      if not passable?(@x, @y, 4)
      turn_left_90
      elsif not passable?(@x, @y, 6)
      turn_right_90
      else
        rand(2) == 0 ? turn_right_90 : turn_left_90
      end
    when 4
      if not passable?(@x, @y, 2)
      turn_right_90
      elsif not passable?(@x, @y, 8)
      turn_left_90
      else
        rand(2) == 0 ? turn_right_90 : turn_left_90
      end
    when 6
      if not passable?(@x, @y, 2)
      turn_left_90
      elsif not passable?(@x, @y, 8)
      turn_right_90
      else
        rand(2) == 0 ? turn_right_90 : turn_left_90
      end
    when 8
      if not passable?(@x, @y, 4)
      turn_right_90
      elsif not passable?(@x, @y, 6)
      turn_left_90
      else
        rand(2) == 0 ? turn_right_90 : turn_left_90
      end
    end
  end
  def update
    # Remember whether or not moving in local variables
    last_moving = moving?
    # If moving, event running, move route forcing, and message window
    # display are all not occurring
    unless moving? or $game_system.map_interpreter.running? or
          @move_route_forcing or $game_temp.message_window_showing
      # Move player in the direction the directional button is being pressed
      case Input.dir4
      when 2
        move_down
      when 4
        move_left
      when 6
        move_right
      when 8
        move_up
      end
    end
    # Remember coordinates in local variables
    last_real_x = @real_x
    last_real_y = @real_y
    super
    # If character moves down and is positioned lower than the center
    # of the screen
    if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y
      # Scroll map down
      $game_map.scroll_down(@real_y - last_real_y)
    end
    # If character moves left and is positioned more let on-screen than
    # center
    if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X
      # Scroll map left
      $game_map.scroll_left(last_real_x - @real_x)
    end
    # If character moves right and is positioned more right on-screen than
    # center
    if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X
      # Scroll map right
      $game_map.scroll_right(@real_x - last_real_x)
    end
    # If character moves up and is positioned higher than the center
    # of the screen
    if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y
      # Scroll map up
      $game_map.scroll_up(last_real_y - @real_y)
    end
    # If not moving
    unless moving?
      tc_event = false
      d = @direction
      new_x = @x + (d == 6 ? 1 : d == 4 ? -1 : 0)
      new_y = @y + (d == 2 ? 1 : d == 8 ? -1 : 0)
      for event in $game_map.events.values
        tc_event = true if (event.x == new_x and event.y == new_y and [1,2].include?(event.trigger))
      end
      if tc_event == false
        case Input.dir4
        when 2
          if not passable?(@x, @y, d)
            turn_ai_side
            move_forward if Input.press? (Input::DOWN)
          end
        when 4
          if not passable?(@x, @y, d)
            turn_ai_side
            move_forward if Input.press? (Input::LEFT)
          end
        when 6
          if not passable?(@x, @y, d)
            turn_ai_side
            move_forward if Input.press? (Input::RIGHT)
          end
        when 8
          if not passable?(@x, @y, d)
            turn_ai_side
            move_forward if Input.press? (Input::UP)
          end
        end
      end
      # If player was moving last time
      if last_moving
        # Event determinant is via touch of same position event
        result = check_event_trigger_here([1,2])
        # If event which started does not exist
        if result == false
          # Disregard if debug mode is ON and ctrl key was pressed
          unless $DEBUG and Input.press?(Input::CTRL)
            # Encounter countdown
            if @encounter_count > 0
              @encounter_count -= 1
            end
          end
        end
      end
      # If C button was pressed
      if Input.trigger?(Input::C)
        # Same position and front event determinant
        check_event_trigger_here([0])
        check_event_trigger_there([0,1,2])
      end
    end
  end
end

#--------------------------------------------------------------





오랜만에 스크립트를 올리네요 ^^;
예제를 올릴려고 했는데... 제가 1.02a버전으로 옮겨서
스크립트만 올렸습니다
적용하시려면 스크립트란에서 Game_Player 섹션을
이스크립트로 갈아치우시거나
main위에 찔러넣으시면 됩니다.


이스크립트는
그림과 같이 방향키를 꾸욱 누르고있으면
장해물을 오른쪽이나 왼쪽으로 돌아서 피해갑니다
하지만 앞과 오른쪽이 동시에 막혀있으면
자동으로 왼쪽으로 틀어서 쓸대없는 방향전환은 하지 않습니다

그리고 이벤트실행을 해야하는데
스크립트와 충돌하여 이벤트를 피해가는일이 벌어지지 않도록
처리해두었습니다...


그럼 많이 이용해주세요 ^^

열제~

Who's 백호

?

이상혁입니다.

http://elab.kr

0 추천 0 비추천
Atachment
첨부 '1'
  • data_rgss1_s1.jpg,
Facebook Twitter Google Pinterest KakaoStory Band
위로 아래로 댓글로 가기 인쇄 첨부
에디터 선택하기
✔ 텍스트 모드 ✔ 에디터 모드
?
댓글 쓰기 권한이 없습니다. 로그인 하시겠습니까?
Comment '13'
  • ?
    용호작무 2009.09.18 08:22

    우와! 이거 진짜 유용하겠네요!

    감사합니다!
    댓글
  • ?
    라크리모사 2010.01.17 04:21

    우오!!잘쓰겠습니다!!

    댓글
  • ?
    이안 2010.01.17 12:34

    흠 ...............

    댓글
  • ?
    케나이슬라이드 2010.01.18 22:38

    도트단위 이동 스크립트랑 같이 쓰면

    그 스크립트에서 좁은길 들어가기 힘든거 보완이 될지도?..

    댓글
  • ?
    개념있는초등학생 2010.01.19 21:59

    오류입니다. 도트이동이랑합치면 8방향이4방향으로 되고 벽을 통과하고 그 안에서 끼이는 현상이 발생합니다.

    안보이시면 다운하시기 바랍니다.

    다운링크 : 다운로드

    수정 삭제 댓글
  • ?
    개념있는초등학생 2010.01.20 11:56

    제가 실력이 좀 안되서 제가 잘못합친줄 알았는데 님 컴퓨터에서도 그렇습니까?그럼 다행이군요..

    수정 삭제 댓글
  • ?
    케나이 2010.01.20 00:01

    아 그렇네요...

    댓글
  • ?
    포뇨 2010.03.30 23:14

    우옹...완전멋짐ㅋ

    잘쓸게요

    댓글
  • ?
    홈버스트집사 2010.07.22 12:00

    ㄳㄳㄳㄳㄳㄳㄳ

    댓글
  • ?
    지존!! 2010.07.24 14:13

    짱좋아

    댓글
  • ?
    GM인온라인 2014.05.07 16:48
    잘쓰겠습니다 ^^^
    댓글
  • ?
    GM인온라인 2014.05.09 23:05
    제가 기본적인 예제를 통해 적용시키고 해보았는데, npc랑 대화할려고 근처가면 바로 빗겨 나가는 단점이 살 짝 있네요.. 참고하시길
    댓글
  • ?
    비형 2015.06.27 12:20
    너무 좋은 스크립트인데요.. 8방향이랑 호환이 안되서 너 아쉬워요..ㅜㅜ
    댓글

Category
  • 그래픽(16)
  • 맵/타일(15)
  • 메뉴(88)
  • 메시지(26)
  • 미니맵(9)
  • 버그픽스(0)
  • 변수/스위치(10)
  • 상점(14)
  • 상태/속성(8)
  • 스킬(49)
  • 아이템(34)
  • 액터(4)
  • 원경(0)
  • 영상(7)
  • 오디오(8)
  • 온라인(23)
  • 이동 및 탈것(62)
  • 이름입력(10)
  • 장비(34)
  • 저장(34)
  • 전투(174)
  • 제작도구(1)
  • 직업(2)
  • 퀘스트(3)
  • 키입력(18)
  • 타이틀/게임오버(24)
  • 파티(11)
  • HUD(34)
  • 기타(254)
List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
공지 스크립트 자료 게시물 작성시 주의사항 습작 2012.12.24 10171
1021 제작도구 [XP/VX/VXA] Doodad's Editor by newold Alkaid 2020.07.12 600
1020 메시지 Taylor's Simple Message System 2000 Alkaid 2020.07.05 436
1019 이름입력 한글조합입력기(영어가능) file 조규진1 2019.11.10 743
1018 맵/타일 맵연결 스크립트 (데모첨부) file 게임애호가 2018.06.15 909
1017 전투 전투중에 장비들 교체하기 file 레이스89 2017.08.19 940
1016 온라인 인터넷 웹 상에서의 시간을 취득하는 스크립트 1 이우 2016.05.24 1099
1015 장비 착용한 장비에 따라 모습이 달라지는 스크립트 예제 5 file 게임애호가 2015.02.14 2258
1014 기타 [All RGSS] File-Ex file Cheapmunk 2014.12.29 1108
1013 기타 [All RGSS] FileTest (Unicode) file Cheapmunk 2014.12.29 749
1012 기타 [RGSS XP] 게임 해상도 조절 스크립트 (*2) 11 file Cheapmunk 2014.10.03 2867
1011 그래픽 Drago - Custom Resolution II 1 Alkaid 2014.09.10 1267
1010 기타 레벨업스크립트(xp) 2 게임을만들자! 2014.08.05 1950
1009 메뉴 MOG - Scroll Bar for XP file 습작 2014.07.06 1731
1008 기타 [All RGSS] 윈도우 메세지박스 스크립트 (Completed ver) 5 file Cheapmunk 2014.06.22 2396
1007 기타 [All RGSS] 게임 다중 실행 방지 스크립트 1 file Cheapmunk 2014.05.24 1567
1006 기타 RM2kXP file 습작 2014.03.17 1712
1005 기타 [All RGSS] 윈도우 커서 숨기기/보이기 1 file Cheapmunk 2014.03.02 2161
1004 기타 Drago - Custom Resolution by LiTTleDRAgo Alkaid 2014.02.13 1316
1003 그래픽 [XP/VX/VXA] Drago - Transition Pack Alkaid 2014.02.13 1386
1002 기타 [XP/VX/VXA] Map Screenshot by LiTTleDRAgo 1 Alkaid 2014.02.13 1045
쓰기
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ... 52 Next
/ 52
AVANGS

게임 제작, 창작, 자료, 강좌를 연결하는 커뮤니티

  • 개인정보 취급방침

Copyright © 2026 Avangs