VX 스크립트

####부드러운 화면 스크롤#########
#===============================================================
# ● [VX] ◦ Smooth Scrolling ◦ □
# * Nice scrolling effect like an action game~! *
# *   Ported from XP Version (by Toby Zerner)   *
#--------------------------------------------------------------
# ◦ by Woratana [woratana@hotmail.com]
# ◦ Thaiware RPG Maker Community
# ◦ Released on: 08/02/2009
# ◦ Version: 1.0
#--------------------------------------------------------------
# ◦ Compatibility:
#--------------------------------------------------------------
# □ This script will rewrite 6 method(s):
#     Game_Map.start_scroll
#     Game_Map.scroll_up
#     Game_Map.scroll_down
#     Game_Map.scroll_left
#     Game_Map.scroll_right
#     Game_Map.update_scroll
#
# □ This script will alias 1 method(s):
#     Game_Map.setup_scroll
#
# □ This script would crash with other custom scripts that rewrite same method(s)
#
# □ This script may not work with maps that use loop.
#--------------------------------------------------------------
# ◦ Installation:
#--------------------------------------------------------------
# 1) This script should be placed JUST AFTER ▼ Materials.
#
# □ Like this:
# ▼ Materials
# * Smooth Scrolling
# ...
# ...
# ▼ Main Process
# Main
#
# 2) Setup this script in Setup Part below.
#
#--------------------------------------------------------------
# ◦ How to use:
#--------------------------------------------------------------
# □ Just place this script and try moving player in your game.
#
#=================================================================
class Game_System
 
  #=================================================================
  # ++ Setup Part
  #-----------------------------------------------------------------
  DEFAULT_DECELERATION_START = 4 # (default: 4)
  # How fast before it will start decelerating (Higher = Start Faster)
  # You can change this value in game by call script:
  #   $game_system.decel_start = (value)
 
  DEFAULT_DECELERATION_SPEED = 4 # (default: 4)
  # How fast it will decelerate each frame (Higher = Decelerate Faster)
  # You can change this value in game by call script:
  #   $game_system.decel_speed = (value)
  #-----------------------------------------------------------------
 
  def decel_start
    @decel_start ||= DEFAULT_DECELERATION_START
    return @decel_start
  end
 
  def decel_speed
    @decel_speed ||= DEFAULT_DECELERATION_SPEED
    return @decel_speed
  end
 
  def decel_start=(value)
    @decel_start = value
  end
 
  def decel_speed=(value)
    @decel_speed = value
  end
end
class Game_Map
  #--------------------------------------------------------------------------
  # * Scroll Setup
  #--------------------------------------------------------------------------
  alias wora_smoscr_gammap_setscr setup_scroll
  def setup_scroll(*args)
    wora_smoscr_gammap_setscr(*args)
    # Initialize smooth scrolling variables
    # scroll_remain: the number of pixels * 4 the still need to be scrolled
    @scroll_remain_x = 0
    @scroll_remain_y = 0
    # scroll_take: the number of pixels * 4 that are being scrolled every frame
    #   i.e. scrolling speed
    @scroll_take_x = 0
    @scroll_take_y = 0
    # scroll_decel: variables for calculating decelaration
    @scroll_decel_x = 0
    @scroll_decel_y = 0
  end
  #--------------------------------------------------------------------------
  # * Start Scroll
  #--------------------------------------------------------------------------
  def start_scroll(direction, distance, speed)
    # Set scrolling variables
    distance          = distance.ceil * 256
    @scroll_direction = direction
    @scroll_speed     = speed
    @scroll_rest      = distance
    # Execute scrolling
    case @scroll_direction
    when 2  # Down
      scroll_down(@scroll_rest)
    when 4  # Left
      scroll_left(@scroll_rest)
    when 6  # Right
      scroll_right(@scroll_rest)
    when 8  # Up
      scroll_up(@scroll_rest)
    end
  end
  #--------------------------------------------------------------------------
  # * Scroll Down
  #--------------------------------------------------------------------------
  def scroll_down(distance)
    # Ceil the distance
    distance = distance.ceil
    # If the map is scrolling from an event command, then use that scroll speed
    if scrolling? then @scroll_take_y = 2 ** @scroll_speed
    # If the map is not scrolling
    else
      # Make sure the distance is always divisible by 4
      if distance.ceil % 4 == 0 then @scroll_take_y = distance.ceil
      elsif distance.ceil % 4 <= 2 then @scroll_take_y = distance.ceil - distance.ceil % 4
      else @scroll_take_y = distance.ceil + (4 - (distance.ceil % 4)) end
    end
    # If scrolling coordinates are inside the map's boundaries
    unless @display_y + @scroll_remain_y + distance > (self.height - 13) * 256
      # Add onto the amount left to be scrolled
      @scroll_remain_y += distance
    end
  end
  #--------------------------------------------------------------------------
  # * Scroll Left
  #--------------------------------------------------------------------------
  def scroll_left(distance)
    # Ceil the distance
    distance = distance.ceil
    # If the map is scrolling from an event command, then use that scroll speed
    if scrolling? then @scroll_take_x = 2 ** @scroll_speed
    # If the map is not scrolling
    else
      # Make sure the distance is always divisible by 4
      if distance.ceil % 4 == 0 then @scroll_take_x = distance.ceil
      elsif distance.ceil % 4 <= 2 then @scroll_take_x = distance.ceil - distance.ceil % 4
      else @scroll_take_x = distance.ceil + (4 - (distance.ceil % 4)) end
    end
    # If scrolling coordinates are inside the map's boundaries
    unless @display_x - @scroll_remain_x - distance < 0
      # Add onto the amount left to be scrolled
      @scroll_remain_x -= distance
    end
  end
  #--------------------------------------------------------------------------
  # * Scroll Right
  #--------------------------------------------------------------------------
  def scroll_right(distance)
    # Ceil the distance
    distance = distance.ceil
    # If the map is scrolling from an event command, then use that scroll speed
    if scrolling? then @scroll_take_x = 2 ** @scroll_speed
    # If the map is not scrolling
    else
      # Make sure the distance is always divisible by 4
      if distance.ceil % 4 == 0 then @scroll_take_x = distance.ceil
      elsif distance.ceil % 4 <= 2 then @scroll_take_x = distance.ceil - distance.ceil % 4
      else @scroll_take_x = distance.ceil + (4 - (distance.ceil % 4)) end
    end
    # If scrolling coordinates are inside the map's boundaries
    unless @display_x + @scroll_remain_x + distance > (self.width - 17) * 256
      # Add onto the amount left to be scrolled
      @scroll_remain_x += distance
    end
  end
  #--------------------------------------------------------------------------
  # * Scroll Up
  #--------------------------------------------------------------------------
  def scroll_up(distance)
    # Ceil the distance
    distance = distance.ceil
    # If the map is scrolling from an event command, then use that scroll speed
    if scrolling? then @scroll_take_y = 2 ** @scroll_speed
    # If the map is not scrolling
    else
      # Make sure the distance is always divisible by 4
      if distance.ceil % 4 == 0 then @scroll_take_y = distance.ceil
      elsif distance.ceil % 4 <= 2 then @scroll_take_y = distance.ceil - distance.ceil % 4
      else @scroll_take_y = distance.ceil + (4 - (distance.ceil % 4)) end
    end
    # If scrolling coordinates are inside the map's boundaries
    unless @display_y - @scroll_remain_y - distance < 0
      # Add onto the amount left to be scrolled
      @scroll_remain_y -= distance
    end
  end
  #--------------------------------------------------------------------------
  # * Update Scroll
  #--------------------------------------------------------------------------
  def update_scroll
    # If the map is still scrolling
    if @scroll_rest > 0 then @scroll_rest -= 2 ** @scroll_speed end
   
    # If the x axis needs to be scrolled to the right
    if @scroll_remain_x > 0
      # If the amount to be scrolled is close enough to 0 to decelerate
      if @scroll_remain_x <= @scroll_take_x * $game_system.decel_start
        old_display_x = @display_x
        # Add onto the deceleration variable
        @scroll_decel_x += $game_system.decel_speed
        # Work out how much to scroll
        distance = [@scroll_take_x - @scroll_decel_x, 4].max
        # If the scrolling coordinates are within the map's boundaries
        unless @display_x + distance > (self.width - 17) * 256
          @display_x += distance
          @parallax_x += distance
        end
        # Subtract the amount that was scrolled
        @scroll_remain_x += old_display_x - @display_x
        if @scroll_remain_x < 0 then @scroll_remain_x = 0 end
      # Otherwise, scroll at a normal speed
      else
        # Reset the deceleration variable
        @scroll_decel_x = 0
        # If the scrolling coordinates are out of range
        if @display_x + @scroll_take_x > (self.width - 17) * 256
          @display_x = (self.width - 20) * 256
          @scroll_remain_x = 0
        # Otherwise, scroll normally
        else
          @display_x += @scroll_take_x
          @parallax_x += @scroll_take_x
          @scroll_remain_x -= @scroll_take_x
        end
      end
     
    # If the x axis needs to be scrolled to the left
    elsif @scroll_remain_x < 0
      # If the amount to be scrolled is close enough to 0 to decelerate
      if @scroll_remain_x >= -@scroll_take_x * $game_system.decel_start
        old_display_x = @display_x
        # Add onto the deceleration variable
        @scroll_decel_x += $game_system.decel_speed
        # Work out how much to scroll
        distance = [@scroll_take_x - @scroll_decel_x, 4].max
        # If the scrolling coordinates are within the map's boundaries
        unless @display_x - distance < 0
          @display_x -= distance
          @parallax_x -= distance
        end
        # Subtract the amount that was scrolled
        @scroll_remain_x += old_display_x - @display_x
        if @scroll_remain_x > 0 then @scroll_remain_x = 0 end
      # Otherwise, scroll at a normal speed
      else
        # Reset the deceleration variable
        @scroll_decel_x = 0
        # If the scrolling coordinates are out of range
        if @display_x - @scroll_take_x < 0
          @display_x = 0
          @scroll_remain_x = 0
        # Otherwise, scroll normally
        else
          @display_x -= @scroll_take_x
          @parallax_x -= @scroll_take_x
          @scroll_remain_x += @scroll_take_x
        end
      end
   
    # If no x scrolling needs to be done, reset the deceleration variable
    else @scroll_decel_x = 0 end
   
    # If the y axis needs to be scrolled downwards
    if @scroll_remain_y > 0
      # If the amount to be scrolled is close enough to 0 to decelerate
      if @scroll_remain_y <= @scroll_take_y * $game_system.decel_start
        old_display_y = @display_y
        # Add onto the deceleration variable
        @scroll_decel_y += $game_system.decel_speed
        # Work out how much to scroll
        distance = [@scroll_take_y - @scroll_decel_y, 4].max
        # If the scrolling coordinates are within the map's boundaries
        unless @display_y + distance > (self.height - 13) * 256
          @display_y += distance
          @parallax_y += distance
        end
        # Subtract the amount that was scrolled
        @scroll_remain_y += old_display_y - @display_y
        if @scroll_remain_y < 0 then @scroll_remain_y = 0 end
      # Otherwise, scroll at a normal speed
      else
        # Reset the deceleration variable
        @scroll_speed_accel_y = 0
        # If the scrolling coordinates are out of range
        if @display_y + @scroll_take_y > (self.height - 13) * 256
          @display_y = (self.height - 15) * 256
          @scroll_remain_y = 0
        # Otherwise, scroll normally
        else
          @display_y += @scroll_take_y
          @parallax_y += @scroll_take_y
          @scroll_remain_y -= @scroll_take_y
        end
      end
   
    # If the y axis needs to be scrolled upwards
    elsif @scroll_remain_y < 0
      # If the amount to be scrolled is close enough to 0 to decelerate
      if @scroll_remain_y >= -@scroll_take_y * $game_system.decel_start
        old_display_y = @display_y
        # Add onto the deceleration variable
        @scroll_decel_y += $game_system.decel_speed
        # Work out how much to scroll
        distance = [@scroll_take_y - @scroll_decel_y, 4].max
        # If the scrolling coordinates are within the map's boundaries
        unless @display_y - distance < 0
          @display_y -= distance
          @parallax_y -= distance
        end
        # Subtract the amount that was scrolled
        @scroll_remain_y += old_display_y - @display_y
        if @scroll_remain_y > 0 then @scroll_remain_y = 0 end
      # Otherwise, scroll at a normal speed
      else
        # Reset the deceleration variable
        @scroll_speed_accel_y = 0
        # If the scrolling coordinates are out of range
        if @display_y - @scroll_take_y < 0
          @display_y = 0
          @scroll_remain_y = 0
        # Otherwise, scroll normally
        else
          @display_y -= @scroll_take_y
          @parallax_y -= @scroll_take_y
          @scroll_remain_y += @scroll_take_y
        end
      end
   
    # If no y scrolling needs to be done, reset the deceleration variable
    else
      @scroll_decel_y = 0
    end
  end
end
TAG •

Who's 카르와푸딩의아틀리에

profile

엘카르디아 제작자 (현재 MV로 리메이크중)

유튜브

https://www.youtube.com/channel/UCMwirNTR-pOEzJNB0jL3y_g

트위터

https://twitter.com/karsis98

블로그

https://blog.naver.com/karsis98

Comment '32'

List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
공지 스크립트 자료 게시물 작성시 주의사항 3 습작 2012.12.24 5398
357 타이틀/게임오버 타이틀화면 커스터마이즈 29 file 可わいい 2009.03.16 6141
356 이름입력 한글로 이름 입력하는 스크립트입니다. 55 file 헤르코스 2009.03.18 6662
355 메시지 문자픽쳐 표시 스크립트 7 file 좀비사냥꾼 2009.03.19 4144
354 기타 시야범위 스크립트 18 file 좀비사냥꾼 2009.03.19 4047
353 메뉴 [자작]명성치 사용 시스템(메뉴 출력) 16 Rainsy 2009.03.22 4360
352 상태/속성 어떤 상태일때에만 사용가능한 스킬 14 file 좀비사냥꾼 2009.03.25 3266
351 장비 KGC확장장비창 스크립트 15 file 티라엘 2009.03.27 3622
350 장비 KGC장비종류 추가 스크립트. 36 file 루시페르 2009.03.28 4674
349 기타 캐릭터 소개화면 16 file 좀비사냥꾼 2009.03.29 6044
348 키입력 답을 입력하는 텍스트박스 스크립트!! 21 file 좀비사냥꾼 2009.03.29 4206
347 기타 [자작] 횡스크롤 점프스크립트 18 file 좀비사냥꾼 2009.04.03 4276
346 타이틀/게임오버 [자작] 타이틀 화면 없이 게임을 시작하자! Title Skiper 29 케류 2009.04.05 4423
345 기타 KGC 리버스 데미지! 28 루시페르 2009.04.13 2979
344 이동 및 탈것 A* 알고리즘을 이용한 길찾기 스크립트 3 file 허걱 2009.04.20 3527
343 이동 및 탈것 대각선 이동 스크립트 17 아방스 2009.05.02 3677
342 기타 스크립트강좌 4 아하!잘봤어요. 2009.05.04 2158
341 메뉴 몬스터도감 Tankentai사이드뷰에 작동하도록 수정 13 카르와푸딩의아틀리에 2009.05.22 3775
340 기타 능력치에 따른 스테이트변화 / 능력치한계지정 5 Evangelista 2009.05.26 2479
339 전투 에너미를 아이템으로 변화하는 스킬 8 Evangelista 2009.05.27 2850
338 기타 <중수이상>RPG VX의 대표적 참조값 6 까까까 2009.05.31 3236
Board Pagination Prev 1 ... 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 ... 32 Next
/ 32