Advertisement
diamondandplatinum3

Battle Parallax Background ~ RGSS3

Sep 6th, 2012
609
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 11.82 KB | None | 0 0
  1. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  2. #             Battle Parallax Background
  3. #             Version: 1.0
  4. #             Author: DiamondandPlatinum3
  5. #             Date: September 6, 2012
  6. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7. #  Description:
  8. #
  9. #    This script allows you to use a parallax as a background for your
  10. #    Battles. It also allows you to scroll the parallax like any regular
  11. #    map parallax.
  12. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  13. #------------------------------------------------------------------------------
  14. #  Instructions:
  15. #  
  16. #     -  There are two methods of changing the battle parallax options.
  17. #    
  18. #     ~  One of which is to use a script call with the following line of code
  19. #
  20. #         setbattleparallax( filename, scrollx, scrolly )
  21. #
  22. #        Where 'filename' is where you enter the name of the parallax, this must be
  23. #        done in quotation marks ( ' ' ).
  24. #        'scrollx' is the amount the parallax will scroll to the left or right.
  25. #        'scrolly' is the amount the parallax will scroll up or down.
  26. #
  27. #
  28. #     -  If you do not want to change a specific value, simply pass in nil as the
  29. #        parameter
  30. #
  31. #
  32. #
  33. #
  34. #     ~  The other method is to use notetags for the map, exactly like the following:
  35. #    
  36. #         ~BP_NAME: "Filename"
  37. #         ~BP_SCRX: Number
  38. #         ~BP_SCRY: Number
  39. #
  40. #        This has the same effect as calling the function, in that you can change
  41. #        the name of the battle parallax and it's scrolling variables.
  42. #
  43. #
  44. #
  45. #     -  You can find screenshots to visually explain both methods
  46. #        Here: http://img4host.net/upload/07161653504a01d5e21c4.png
  47. #        Here: http://img4host.net/upload/061210075048767f2a69d.png
  48. #
  49. #        
  50. #     -  The advantage of using the map note is that you can set the parallax to
  51. #        a specific map like when you specify the battle backgrounds in the map
  52. #        settings. The function method is really for use when you want to change
  53. #        the parallax for a specific bossfight.
  54. #
  55. #     -  You can also use negative numbers to reverse the directions of the
  56. #        parallax scroll. You'll need to play around with it to achieve the
  57. #        desired effect
  58. #
  59. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  60. #
  61. #
  62. #                  THERE IS NO EDITABLE REGION TO THIS SCRIPT
  63. #
  64. #==============================================================================
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76. #==============================================================================
  77. # ** Spriteset_Battle
  78. #------------------------------------------------------------------------------
  79. #  This class brings together battle screen sprites. It's used within the
  80. # Scene_Battle class.
  81. #==============================================================================
  82.  
  83. class Spriteset_Battle
  84.   #--------------------------------------------------------------------------
  85.   # * Overwritten Functions
  86.   #--------------------------------------------------------------------------
  87.   #     create_battleback1
  88.   #     create_battleback2
  89.   #     update_battleback1
  90.   #     update_battleback2
  91.   #     dispose_battleback1
  92.   #     dispose_battleback2
  93.   #
  94.   #--------------------------------------------------------------------------
  95.   # * Alias Listings
  96.   #--------------------------------------------------------------------------
  97.   alias dp3_batlparallax_sprsetbatl_init_1h2g       initialize
  98.   alias dp3_batlparallax_sprsetbatl_dispose_1h2g    dispose
  99.   alias dp3_batlparallax_sprsetbatl_update_1h2g     update
  100.   #--------------------------------------------------------------------------
  101.   # * Object Initialization
  102.   #--------------------------------------------------------------------------
  103.   def initialize
  104.     # Call Original Method
  105.     dp3_batlparallax_sprsetbatl_init_1h2g
  106.    
  107.     create_parallax
  108.   end
  109.   #--------------------------------------------------------------------------
  110.   # * Frame Update
  111.   #--------------------------------------------------------------------------
  112.   def update
  113.     update_parallax
  114.    
  115.     # Call Original Method
  116.     dp3_batlparallax_sprsetbatl_update_1h2g
  117.   end
  118.   #--------------------------------------------------------------------------
  119.   # * Free
  120.   #--------------------------------------------------------------------------
  121.   def dispose
  122.     dispose_parallax
  123.    
  124.     # Call Original Method
  125.     dp3_batlparallax_sprsetbatl_dispose_1h2g
  126.   end
  127.  
  128.  
  129.  
  130.   #--------------------------------------------------------------------------
  131.   # * Create Battle Background (Floor) Sprite
  132.   #--------------------------------------------------------------------------
  133.   def create_battleback1
  134.     @back1_sprite = nil
  135.   end
  136.   #--------------------------------------------------------------------------
  137.   # * Create Battle Background (Wall) Sprite
  138.   #--------------------------------------------------------------------------
  139.   def create_battleback2
  140.     @back2_sprite = nil
  141.   end
  142.   #--------------------------------------------------------------------------
  143.   # * Create Parallax
  144.   #--------------------------------------------------------------------------
  145.   def create_parallax
  146.     @backparallax = Plane.new(@viewport1)
  147.     @backparallax.bitmap = Cache.parallax($game_system.battleparallaxgraphicname)
  148.     @backparallax.z = 0
  149.   end
  150.  
  151.  
  152.  
  153.  
  154.  
  155.   #--------------------------------------------------------------------------
  156.   # * Update Battle Background (Floor) Sprite
  157.   #--------------------------------------------------------------------------
  158.   def update_battleback1
  159.     @back1_sprite.update if @back1_sprite
  160.   end
  161.   #--------------------------------------------------------------------------
  162.   # * Update Battle Background (Wall) Sprite
  163.   #--------------------------------------------------------------------------
  164.   def update_battleback2
  165.     @back2_sprite.update if @back2_sprite
  166.   end
  167.   #--------------------------------------------------------------------------
  168.   # * Update Parallax
  169.   #--------------------------------------------------------------------------
  170.   def update_parallax
  171.     if @backparallax
  172.       @backparallax.ox += $game_system.battleparallaxgraphicscrollx
  173.       @backparallax.oy += $game_system.battleparallaxgraphicscrolly
  174.     end
  175.   end
  176.  
  177.  
  178.  
  179.  
  180.   #--------------------------------------------------------------------------
  181.   # * Free Battle Background (Floor) Sprite
  182.   #--------------------------------------------------------------------------
  183.   def dispose_battleback1
  184.     if @back1_sprite
  185.       @back1_sprite.bitmap.dispose
  186.       @back1_sprite.dispose
  187.     end
  188.   end
  189.   #--------------------------------------------------------------------------
  190.   # * Free Battle Background (Wall) Sprite
  191.   #--------------------------------------------------------------------------
  192.   def dispose_battleback2
  193.     if @back2_sprite
  194.       @back2_sprite.bitmap.dispose
  195.       @back2_sprite.dispose
  196.     end
  197.   end
  198.   #--------------------------------------------------------------------------
  199.   # * Free Battle Parallax
  200.   #--------------------------------------------------------------------------
  201.   def dispose_parallax
  202.     if @backparallax
  203.       @backparallax.bitmap.dispose
  204.       @backparallax.dispose
  205.     end
  206.   end
  207.  
  208. end # of Class
  209.  
  210.  
  211.  
  212.  
  213. #==============================================================================
  214. # ** Game_System
  215. #------------------------------------------------------------------------------
  216. #  This class handles system data. It saves the disable state of saving and
  217. # menus. Instances of this class are referenced by $game_system.
  218. #==============================================================================
  219.  
  220. class Game_System
  221.   #--------------------------------------------------------------------------
  222.   # * New Public Instance Variables
  223.   #--------------------------------------------------------------------------
  224.   attr_accessor :battleparallaxgraphicname
  225.   attr_accessor :battleparallaxgraphicscrollx
  226.   attr_accessor :battleparallaxgraphicscrolly
  227.   #--------------------------------------------------------------------------
  228.   # * Alias Listings
  229.   #--------------------------------------------------------------------------
  230.   alias dp3_batlparallax_gamesys_init_1h2g     initialize
  231.   #--------------------------------------------------------------------------
  232.   # * Object Initialization
  233.   #--------------------------------------------------------------------------
  234.   def initialize
  235.    
  236.     # Call Original Method
  237.     dp3_batlparallax_gamesys_init_1h2g
  238.    
  239.     # Setup Parallax (safety precautions in case the user doesn't do it themselves)
  240.     @battleparallaxgraphicname    = "BlueSky"
  241.     @battleparallaxgraphicscrollx = 0
  242.     @battleparallaxgraphicscrolly = 0
  243.   end
  244.  
  245. end # of Class
  246.  
  247.  
  248.  
  249.  
  250.  
  251. #==============================================================================
  252. # ** Game_Interpreter
  253. #------------------------------------------------------------------------------
  254. #  An interpreter for executing event commands. This class is used within the
  255. # Game_Map, Game_Troop, and Game_Event classes.
  256. #==============================================================================
  257.  
  258. class Game_Interpreter  
  259.   #--------------------------------------------------------------------------
  260.   # * Set Battle Parallax
  261.   #--------------------------------------------------------------------------
  262.   def setbattleparallax( filename, scrollx, scrolly )
  263.     $game_system.battleparallaxgraphicname    = filename if filename.is_a?(String)
  264.     $game_system.battleparallaxgraphicscrollx = scrollx  if scrollx.is_a?(Integer)
  265.     $game_system.battleparallaxgraphicscrolly = scrolly  if scrolly.is_a?(Integer)
  266.   end
  267.  
  268. end # of Class    
  269.  
  270.  
  271.  
  272.  
  273.  
  274. #==============================================================================
  275. # ** Game_Map
  276. #------------------------------------------------------------------------------
  277. #  This class handles maps. It includes scrolling and passage determination
  278. #  functions. The instance of this class is referenced by $game_map.
  279. #==============================================================================
  280.  
  281. class Game_Map
  282.   #--------------------------------------------------------------------------
  283.   # * Alias Listings
  284.   #--------------------------------------------------------------------------
  285.   alias dp3_battleparallaxmapnote_setup_1h2g     setup  
  286.   #--------------------------------------------------------------------------
  287.   # * Setup
  288.   #      map_id : map ID  
  289.   #--------------------------------------------------------------------------
  290.   def setup(*args)
  291.     # Call Original Method
  292.     dp3_battleparallaxmapnote_setup_1h2g(*args)
  293.    
  294.     # Check Map Note
  295.     checkbattleparallax_mapnote
  296.   end  
  297.   #--------------------------------------------------------------------------
  298.   # * Check Map Note for Battle Parallax Info
  299.   #--------------------------------------------------------------------------
  300.   def checkbattleparallax_mapnote
  301.    
  302.     # Set instance variables to current values
  303.     prlxname = $game_system.battleparallaxgraphicname
  304.     scrollx  = $game_system.battleparallaxgraphicscrollx
  305.     scrolly  = $game_system.battleparallaxgraphicscrolly
  306.    
  307.     # Check Map Notetags
  308.    
  309.     # Code by Modern Algebra -----------------------------
  310.     @map.note[/~BP_NAME:\s*\"(.+?)\"/im]
  311.    prlxname = $1.gsub(/[\n\r]+/, "") if $1 # if not nil
  312.    #-----------------------------------------------------
  313.    @map.note[/~BP_SCRX: ([-0-9]+)/]
  314.    scrollx = $1.to_i if $1
  315.    @map.note[/~BP_SCRY: ([-0-9]+)/]
  316.    scrolly = $1.to_i if $1
  317.        
  318.    $game_system.battleparallaxgraphicname    = prlxname
  319.    $game_system.battleparallaxgraphicscrollx = scrollx
  320.    $game_system.battleparallaxgraphicscrolly = scrolly
  321.  end
  322.  
  323. end # of Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement