Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 17.45 KB | None | 0 0
  1. #    ______________________
  2. #  <  EB Backgtounds       │
  3. #   │ By tuckie            │
  4. #   │                      │
  5. #   │ 4/22/17              │
  6. #   │ Version: eh% done    │
  7. #   │______________________│
  8.  
  9. #        ____________
  10. # (-o-)< hungry! !!  │
  11. #       │____________│
  12.  
  13. #   __________________________________________
  14. # <                                           │
  15. #  │ This script changes battle backgrounds   │
  16. #  │ to emulate the cool effects of the       │
  17. #  │ backgrounds in famous SNES title         │
  18. #  │ Earthbound. have fun lol :))))           │
  19. #  │__________________________________________│
  20.  
  21. module Tuckie_eb_bb_config
  22.  
  23.   # Hey what's up dudes, it ur boy Tuckie 👌
  24.   # Back at it again with scripting 🔥🔥🔥
  25.  
  26.   BACKGROUND_DEETS = {
  27.  
  28.     "Default" => {
  29.       #== Basic Info ==#
  30.         "amplitude"   => 30,
  31.         "frequency"   => 2,
  32.         "time_scale"  => 0.05,
  33.         "compression" => 1,
  34.       #== Type ==#
  35.         #== 0 = sinewave, 1 = criss-cross, 2 = vertical stretch ==#
  36.         "type"        => 0,
  37.       #== vertical stretch settings, only used with "type" => 2, ==#
  38.         "v_scale"     => 0.5,
  39.         "v_zoom"      => 2,
  40.       #== "Pixel Precise" - sets the x of each strip to allign to 2x2 grid ==#
  41.         "pixel"       => true,
  42.       #== Y scrolling, images do loop. ==#
  43.         "scrl_y_spd"  => 0,
  44.       #== Image Cycling (for palette swap effect) ==#
  45.         "img_cycle"   => false,
  46.         #== Will look in Graphics/Battlebacks[1/2], whichever it is ==#
  47.         "img_array"   => ["bb02", "bb1"],
  48.         #== Background cycle updates every X frames ==#
  49.         "img_speed"   => 32,
  50.         #== Image changes all at once, or layer by layer ==#
  51.         "img_sync"    => false,
  52.       #== Change basic element info to animate as a sinewave ==#
  53.         "anim_basic"  => true,
  54.         #== Changing frequency/time/amp over time looks cool ==#
  55.           #== Amp. = 0, Freq. = 1, Time = 2, scrl_y_spd = 3, ==#
  56.         "anim_target" => 0,
  57.         #== Type of animation: sinewave = 0, linear = 1 ==#
  58.         "anim_type"   => 0,
  59.         #== The value the animation reaches to, positive and negative ==#
  60.         "anim_str"    => 20,
  61.         #== The speed the animation plays through ==#
  62.         "anim_spd"    => 0.01,
  63.         #== Animate all at once, or layer by layer ==#
  64.         "anim_sync"   => true,
  65.         #== anim_str will always remain positive ==#
  66.           #==  anim_str 16 -> 0...16 NOT -16...16  ==#
  67.         "anim_pos"    => false,
  68.     },
  69.  
  70.     #== Type your filename WITHOUT .png ==#
  71.     #== Probably best to copy the default and modify it ==#
  72.   "bb05" => {
  73.       #== Basic Info ==#
  74.         "amplitude"   => 30,
  75.         "frequency"   => 2,
  76.         "time_scale"  => 0.05,
  77.         "compression" => 1,
  78.       #== Type ==#
  79.         #== 0 = sinewave, 1 = criss-cross, 2 = vertical stretch ==#
  80.         "type"        => 0,
  81.       #== vertical stretch settings, only used with "type" => 2, ==#
  82.         "v_scale"     => 0.5,
  83.         "v_zoom"      => 2,
  84.       #== "Pixel Precise" - sets the x of each strip to allign to 2x2 grid ==#
  85.         "pixel"       => true,
  86.       #== Y scrolling, images do loop. ==#
  87.         "scrl_y_spd"  => 2,
  88.       #== Image Cycling (for palette swap effect) ==#
  89.         "img_cycle"   => false,
  90.         #== Will look in Graphics/Battlebacks[1/2], whichever it is ==#
  91.         "img_array"   => ["bb02", "bb03"],
  92.         #== Background cycle updates every X frames ==#
  93.         "img_speed"   => 16,
  94.         #== Image changes all at once, or layer by layer ==#
  95.         "img_sync"    => true,
  96.       #== Change basic element info to animate as a sinewave ==#
  97.         "anim_basic"  => true,
  98.         #== Changing frequency/time/amp over time looks cool ==#
  99.           #== Amp. = 0, Freq. = 1, Time = 2, scrl_y_spd = 3, ==#
  100.         "anim_target" => 0,
  101.         #== Type of animation: sinewave = 0, linear = 1 ==#
  102.         "anim_type"   => 0,
  103.         #== The value the animation reaches to, positive and negative ==#
  104.         "anim_str"    => 20,
  105.         #== The speed the animation plays through ==#
  106.         "anim_spd"    => 0.01,
  107.         #== Animate all at once, or layer by layer ==#
  108.         "anim_sync"   => true,
  109.         #== anim_str will always remain positive ==#
  110.           #==  anim_str 16 -> 0...16 NOT -16...16  ==#
  111.         "anim_pos"    => false,
  112.     },
  113.   }
  114.  
  115. end
  116.  
  117. #==============================================================================
  118. # ** Earthbound_Back
  119. #------------------------------------------------------------------------------
  120. #  This class is a modification of the Sprite class with built-in functionality
  121. #  to animate along a sinewave, for those trippy battlebacks that are so in
  122. #  these days 🎮🎮🎮🎮
  123. #==============================================================================
  124. class Earthbound_Back < Sprite
  125. #--------------------------------------------------------------------------
  126. # * Attribute Accessor setup
  127. #--------------------------------------------------------------------------
  128.   attr_accessor :time
  129.   attr_accessor :count
  130.   attr_accessor :offset
  131.   attr_accessor :timer
  132.   attr_accessor :orig_y
  133.   attr_accessor :bb_num
  134.   attr_accessor :config
  135. #--------------------------------------------------------------------------
  136. # * Initialize
  137. #--------------------------------------------------------------------------
  138.   def initialize(*args)
  139.     @val = 0 #variable to hold end value
  140.     @sync_time = 0
  141.     @anim_forward = true
  142.     @timer = 1
  143.     super(*args)
  144.   end
  145. #--------------------------------------------------------------------------
  146. # * Update
  147. #--------------------------------------------------------------------------
  148.   def update()
  149.     @offset =  @config["amplitude"] *
  150.       Math.sin(@config["frequency"] * @orig_y + @time * @config["time_scale"])
  151.     tuckie_eb_update()
  152.     @time += 1
  153.     @sync_time += 1
  154.   end
  155. #--------------------------------------------------------------------------
  156. # * Update method breakdowns
  157. #--------------------------------------------------------------------------
  158.   def tuckie_eb_update()
  159.     @config["img_sync"]  ? eb_cycle_s() : eb_cycle()
  160.     @config["anim_sync"] ? eb_anim_s()  : eb_anim()
  161.     eb_placement()
  162.     eb_scroll_y()
  163.     eb_wave()
  164.     eb_placement()
  165.   end
  166. #--------------------------------------------------------------------------
  167. # * Basic Wave updating
  168. #--------------------------------------------------------------------------
  169.   def eb_wave()
  170.     case @config["type"]
  171.       when 0
  172.         self.ox = @offset
  173.       when 1
  174.         self.ox = @count.even? ? @offset - 1: -@offset
  175.       when 2
  176.         newoff = @offset * @config["v_scale"]
  177.         self.y = @orig_y * @config["compression"] + newoff
  178.         self.y -= 1 if self.y.even?
  179.         self.y -= 1 if self.y < 2
  180.         self.zoom_y = @config["v_zoom"]
  181.     end
  182.   end
  183. #--------------------------------------------------------------------------
  184. # * Vertical Scrolling
  185. #--------------------------------------------------------------------------
  186.   def eb_scroll_y
  187.     self.y += @config["scrl_y_spd"]
  188.   end
  189. #--------------------------------------------------------------------------
  190. # * Image cycling
  191. #--------------------------------------------------------------------------
  192.   def eb_cycle
  193.     return if !@config["img_cycle"]
  194.     @cycle_frame = 0 if !defined? @cycle_frame
  195.     @crrent_y = 0 if !defined? @crrent_y
  196.     if @sync_time % @config["img_speed"] == 0
  197.       @cycle_frame += 1
  198.       @cycle_frame = 0 if @cycle_frame > -1 + @config["img_array"].length
  199.       @crrent_y += 1
  200.       @crrent_y = (@crrent_y + Graphics.height) % Graphics.height
  201.     end    
  202.     imgarray = @config["img_array"]
  203.     if @crrent_y == @orig_y
  204.       case bb_num
  205.         when 1
  206.           self.bitmap = Cache.battleback1(imgarray[@cycle_frame])
  207.         when 2
  208.           self.bitmap = Cache.battleback2(imgarray[@cycle_frame])
  209.       end
  210.     end
  211.   end
  212. #--------------------------------------------------------------------------
  213. # * Synced image cycling
  214. #--------------------------------------------------------------------------
  215.   def eb_cycle_s
  216.     return if !@config["img_cycle"]
  217.     @cycle_frame = 0 if !defined? @cycle_frame
  218.     if @sync_time % @config["img_speed"] == 0
  219.       @cycle_frame += 1
  220.       @cycle_frame = 0 if @cycle_frame > -1 + @config["img_array"].length
  221.     end
  222.     imgarray = @config["img_array"]
  223.     case bb_num
  224.       when 1
  225.         self.bitmap = Cache.battleback1(imgarray[@cycle_frame])
  226.       when 2
  227.        
  228.         self.bitmap = Cache.battleback2(imgarray[@cycle_frame])
  229.     end
  230.   end
  231. #--------------------------------------------------------------------------
  232. # * Animation of elements
  233. #--------------------------------------------------------------------------
  234.   def eb_anim
  235.     return if !@config["anim_basic"]
  236.     case @config["anim_type"]
  237.       when 0
  238.         @val = @config["anim_str"] * Math.sin(@config["anim_spd"] * @time)
  239.         if @config["anim_pos"]
  240.           half = @val * 0.5
  241.           @val = @config["anim_str"] * 0.5 * Math.sin(@config["anim_spd"] * @sync_time)
  242.           @val += half
  243.         end
  244.       when 1
  245.         @anim_forward ? @val += @config["anim_spd"] : @val -= @config["anim_spd"]
  246.         @anim_forward = true  if @val <= -@config["anim_str"]
  247.         @anim_forward = false if @val >=  @config["anim_str"]
  248.     end
  249.     case @config["anim_target"]
  250.       when 0
  251.         @config["amplitude"]  = @val
  252.       when 1
  253.         @config["frequency"]  = @val
  254.       when 2
  255.         @config["time_scale"] = @val
  256.       when 3
  257.         @config["scrl_y_spd"] = @val
  258.     end
  259.   end
  260. #--------------------------------------------------------------------------
  261. # * animation of elements SYNCED
  262. #--------------------------------------------------------------------------
  263.   def eb_anim_s
  264.     return if !@config["anim_basic"]
  265.     case @config["anim_type"]
  266.       when 0
  267.         @val = @config["anim_str"] * Math.sin(@config["anim_spd"] * @sync_time)
  268.         if @config["anim_pos"]
  269.           half = @val * 0.5
  270.           @val = @config["anim_str"] * 0.5 * Math.sin(@config["anim_spd"] * @sync_time)
  271.           @val += half
  272.         end
  273.       when 1
  274.         @anim_forward ? @val += @config["anim_spd"] : @val -= @config["anim_spd"]
  275.         @anim_forward = true  if @val <= -@config["anim_str"]
  276.         @anim_forward = false if @val >=  @config["anim_str"]
  277.         @val.abs if @config["anim_pos"]
  278.     end
  279.     case @config["anim_target"]
  280.       when 0
  281.         @config["amplitude"]  = @val
  282.       when 1
  283.         @config["frequency"]  = @val
  284.       when 2
  285.         @config["time_scale"] = @val
  286.       when 3
  287.         @config["scrl_y_spd"] = @val
  288.     end
  289.   end
  290. #--------------------------------------------------------------------------
  291. # * Corrects screen looping, and "pixel perfect x values"
  292. #--------------------------------------------------------------------------
  293.   def eb_placement
  294.     self.y = (self.y + Graphics.height) % Graphics.height
  295.     if @config["pixel"]
  296.       self.ox -= 1 if !self.ox.even?
  297.     end
  298.   end
  299. end
  300. #==============================================================================
  301. # ** Spriteset_Battle
  302. #------------------------------------------------------------------------------
  303. #  This class brings together battle screen sprites. It's used within the
  304. # Scene_Battle class.
  305. #==============================================================================
  306. class Spriteset_Battle
  307.  
  308.   #--------------------------------------------------------------------------
  309.   # * Move Sprite to Screen Center | new
  310.   #--------------------------------------------------------------------------
  311.   def center_sprite_x(sprite)
  312.     diff = sprite.bitmap.width - Graphics.width
  313.     sprite.x = 0 - diff * 0.5
  314.   end
  315.   #--------------------------------------------------------------------------
  316.   # * Pull Settings for battleback 1 | new method
  317.   #--------------------------------------------------------------------------
  318.   def get_bb1_settings()
  319.     if Tuckie_eb_bb_config::BACKGROUND_DEETS.has_key? battleback1_name
  320.       default = Tuckie_eb_bb_config::BACKGROUND_DEETS["Default"]
  321.       options = Tuckie_eb_bb_config::BACKGROUND_DEETS[battleback1_name]
  322.       options = default.merge(options)
  323.       return options
  324.     else
  325.       print("Default")
  326.       return Tuckie_eb_bb_config::BACKGROUND_DEETS["Default"]
  327.     end
  328.   end
  329.   #--------------------------------------------------------------------------
  330.   # * Pull Settings for battleback 1 | new method
  331.   #--------------------------------------------------------------------------
  332.   def get_bb2_settings()
  333.     if Tuckie_eb_bb_config::BACKGROUND_DEETS.has_key? battleback2_name
  334.       default = Tuckie_eb_bb_config::BACKGROUND_DEETS["Default"]
  335.       options = Tuckie_eb_bb_config::BACKGROUND_DEETS[battleback2_name]
  336.       options = default.merge(options)
  337.             return options
  338.     else
  339.       return Tuckie_eb_bb_config::BACKGROUND_DEETS["Default"]
  340.     end
  341.   end
  342.   #--------------------------------------------------------------------------
  343.   # * Create Battle Background (Floor) Sprite | overwrite
  344.   #--------------------------------------------------------------------------
  345.   def create_battleback1
  346.     count = 0
  347.     @back1_sprite = []
  348.     setup = get_bb1_settings
  349.     while count * 2 <= battleback1_bitmap.height - 2 do
  350.       strip = Earthbound_Back.new(@viewport1)
  351.       #set strip boys
  352.       strip.config = setup
  353.       strip.bb_num = 1
  354.       strip.time = count
  355.       #get strip image
  356.       strip.bitmap = battleback1_bitmap
  357.       rc = Rect.new(0, count * 2, battleback1_bitmap.width, 2)
  358.       strip.src_rect = rc
  359.       center_sprite_x(strip)
  360.       strip.z = 2
  361.       strip.orig_y = count * 2
  362.       strip.y = count * 2
  363.       strip.count = count
  364.       @back1_sprite.push(strip)
  365.       count += 1
  366.     end
  367.   end
  368.   #--------------------------------------------------------------------------
  369.   # * Create Battle Background (Wall) Sprite
  370.   #--------------------------------------------------------------------------
  371.   def create_battleback2
  372.     count = 0
  373.     setup = get_bb2_settings
  374.     @back2_sprite = []
  375.     while count * 2 <= battleback2_bitmap.height - 2 do
  376.       strip = Earthbound_Back.new(@viewport1)
  377.       #set strip boys
  378.       strip.config = setup
  379.       strip.bb_num = 2
  380.       strip.time = count
  381.       strip.orig_y = count * 2
  382.       #get strip image
  383.       strip.bitmap = battleback2_bitmap
  384.       rc = Rect.new(0, count * 2, battleback2_bitmap.width, 2)
  385.       strip.src_rect = rc
  386.       center_sprite_x(strip)
  387.       strip.z = 4
  388.       strip.count = count
  389.       strip.y = count * 2
  390.       @back2_sprite.push(strip)
  391.       count += 1
  392.     end
  393.   end
  394.   #--------------------------------------------------------------------------
  395.   # * Get Battle Background (Floor) Bitmap
  396.   #--------------------------------------------------------------------------
  397.   def battleback1_bitmap
  398.     if battleback1_name
  399.       Cache.battleback1(battleback1_name)
  400.     else
  401.       create_blurry_background_bitmap
  402.     end
  403.   end
  404.   #--------------------------------------------------------------------------
  405.   # * Get Battle Background (Wall) Bitmap
  406.   #--------------------------------------------------------------------------
  407.   def battleback2_bitmap
  408.     if battleback2_name
  409.       Cache.battleback2(battleback2_name)
  410.     else
  411.       Bitmap.new(1, 1)
  412.     end
  413.   end
  414.   #--------------------------------------------------------------------------
  415.   # * Get Filename of Battle Background (Floor)
  416.   #--------------------------------------------------------------------------
  417.   def battleback1_name
  418.     if $BTEST
  419.       $data_system.battleback1_name
  420.     elsif $game_map.battleback1_name
  421.       $game_map.battleback1_name
  422.     elsif $game_map.overworld?
  423.       overworld_battleback1_name
  424.     end
  425.   end
  426.   #--------------------------------------------------------------------------
  427.   # * Get Filename of Battle Background (Wall)
  428.   #--------------------------------------------------------------------------
  429.   def battleback2_name
  430.     if $BTEST
  431.       $data_system.battleback2_name
  432.     elsif $game_map.battleback2_name
  433.       $game_map.battleback2_name
  434.     elsif $game_map.overworld?
  435.       overworld_battleback2_name
  436.     end
  437.   end
  438.   #--------------------------------------------------------------------------
  439.   # * Free Battle Background (Floor) Sprite
  440.   #--------------------------------------------------------------------------
  441.   def dispose_battleback1
  442.     unless @back1_sprite.empty?
  443.       @back1_sprite.each { |bb| bb.dispose() }
  444.       @back1_sprite = []
  445.     end
  446.   end
  447.   #--------------------------------------------------------------------------
  448.   # * Free Battle Background (Wall) Sprite
  449.   #--------------------------------------------------------------------------
  450.   def dispose_battleback2
  451.     unless @back2_sprite.empty?
  452.       @back2_sprite.each { |bb| bb.dispose() }
  453.       @back2_sprite = []
  454.     end
  455.   end
  456.   #--------------------------------------------------------------------------
  457.   # * Update Battle Background (Floor) Sprite
  458.   #--------------------------------------------------------------------------
  459.   def update_battleback1
  460.     unless @back1_sprite.empty?
  461.       @back1_sprite.each { |bb| bb.update() }
  462.     end
  463.   end
  464.   #--------------------------------------------------------------------------
  465.   # * Update Battle Background (Wall) Sprite
  466.   #--------------------------------------------------------------------------
  467.   def update_battleback2
  468.     unless @back2_sprite.empty?
  469.       @back2_sprite.each { |bb| bb.update() }
  470.     end
  471.   end
  472. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement