The RPG Maker Resource Kit

RMRK RPG Maker Creation => VX => VX Scripts Database => Topic started by: modern algebra on August 03, 2008, 12:56:15 AM

Title: Parallax Horizon
Post by: modern algebra on August 03, 2008, 12:56:15 AM
Parallax Horizon
Version: 1.0
Author: modern algebra
Date: August 2, 2008

Version History



Description


This script allows you to set a speed for a parallax to scroll extra when the player is moving. It will scroll in the opposite direction, to give the illusion of a horizon to which the player is moving.

Features


Screenshots

Not applicable

Instructions

See inside the script for instructions

Script


Code: [Select]
#==============================================================================
#  Parallax Horizon
#  Version 1.0
#  Author: modern algebra (rmrk.net)
#  Date: August 2, 2008
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#  Description:
#    This script allows you to set a speed for a parallax to scroll extra
#  when the player is moving. It will scroll in the opposite direction, to
#  give the illusion of a horizon.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#  Instructions:
#    To make it so that the parallax will scroll, you must check the box in the
#  map settings for it to scroll, even if you do not want it to scroll
#  regularly. You can avoid it scrolling regularly by leaving the scroll value
#  at 0. For instructions on setting up the maps, see the CONFIGURABLE REGION
#  at line 49. You can also use this code:
#
#    $game_map.p_scroll_mod =
#
#    to set the speed manually in game. It will reset once you leave the map.
#==============================================================================
# ** Game_Map
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#  Summary of Changes:
#    new public instance variable - p_scroll_mod
#    aliased method - update_parallax
#==============================================================================

class Game_Map
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Public Instance Variables
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  attr_accessor :p_scroll_mod
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Update Parallax
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias modalg_arclg_req_parallax_moving_response_53b6 update_parallax
  def update_parallax
    # IF player is moving and parallax stats not updated yet
    if $game_player.moving? && @old_parallax_sx == nil
      # Set variables to save the default values of parallax stats
      @old_parallax_sx = @parallax_sx
      @old_parallax_sy = @parallax_sy
      # Initialize scroll modifier
      if @p_scroll_mod == nil
        @p_scroll_mod = case map_id
        #\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
        #  CONFIGURABLE REGION
        #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        #  To configure this script, set up the lines below like this:
        #  
        #    when map_id then scroll_speed
        #
        #  So if you set:
        #    when 1 then 10
        #
        #  That means that the parallax on Map with ID 1 will scroll at
        #  speed 10 in the opposite direction when the player is moving.
        #||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
        when 1 then 10
        #||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
        #  END CONFIGURABLE REGION
        #//////////////////////////////////////////////////////////////////
        else
          0
        end
      end
      # Modify the scrolling
      if @p_scroll_mod != 0
        # Adjust for dashing
        mod = $game_player.dash? ? @p_scroll_mod*2 : @p_scroll_mod
        # Adjust scroll in the direction the player is moving
        @parallax_sx -= mod if $game_player.x * 256 < $game_player.real_x
        @parallax_sx += mod if $game_player.x * 256 > $game_player.real_x
        @parallax_sy -= mod if $game_player.y * 256 < $game_player.real_y
        @parallax_sy += mod if $game_player.y * 256 > $game_player.real_y
      end
    # Restore Parallax Scroll to default if not moving
    elsif @old_parallax_sx != nil
      @parallax_sx = @old_parallax_sx
      @parallax_sy = @old_parallax_sy
      @old_parallax_sx = nil
      @old_parallax_sy = nil
    end
    # Run Original Method
    modalg_arclg_req_parallax_moving_response_53b6
  end
end

Credit



Thanks


Support


Please post here at rmrk.net for the swiftest response

Demo


Not really necessary.


Creative Commons License
This script by modern algebra is licensed under a Creative Commons Attribution-Non-Commercial-Share Alike 2.5 Canada License.