Advertisement
Guest User

Untitled

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