Advertisement
diamondandplatinum3

Battler Breathing Effect

Jun 7th, 2014
627
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 11.41 KB | None | 0 0
  1. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  2. #             Battler Breathing Effect
  3. #             Version: 1.0
  4. #             Author: DiamondandPlatinum3
  5. #             Date: June 7, 2014
  6. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7. #  Description:
  8. #
  9. #    This script adds a breathing effect to battlers.
  10. #    This means that enemies will change size when battling in accordance
  11. #    to their breathing.
  12. #
  13. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  14. #------------------------------------------------------------------------------
  15. #  Instructions:
  16. #
  17. #  ~  Modify Editable Region to your liking.
  18. #
  19. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  20. module DiamondandPlatinum3
  21.   module BattlerBreathe
  22.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  23.     #                                                        -=
  24.     #                 Editable Region        ////            ==
  25.     #                                                        =-
  26.     #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  27.    
  28.     # How long does it take to Breath In/Out? How many Seconds?
  29.     # Note: Inserting a value such as 2.5 quite literally means
  30.     #         two and half seconds
  31.     BreatheTime = 2.0
  32.    
  33.     # How long will the battler stay at a particular size before
  34.     # breathing in/out again
  35.     BreatheHoldTime = 1.0
  36.    
  37.    
  38.     # The Size of the Battler when they have "Breathed Out" Completely.
  39.     # Note: The Battler by default is size 100. So by putting this value
  40.     #       lower than 100, you are allowing the battler to become smaller
  41.     #       when breathing
  42.     BreatheOutSize = 90
  43.    
  44.    
  45.     # The Size of the Battler when they have "Breathed In" Completely
  46.     BreatheInSize = 105
  47.    
  48.     #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  49.     #                                           \/
  50.     #               End of Editable Region      /\
  51.     #                                           \/
  52.     #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  53.   end
  54. end
  55.  
  56.  
  57.  
  58. #==============================================================================
  59. # ** Sprite_Battler
  60. #------------------------------------------------------------------------------
  61. #  This sprite is used to display battlers. It observes an instance of the
  62. # Game_Battler class and automatically changes sprite states.
  63. #==============================================================================
  64.  
  65. class Sprite_Battler < Sprite_Base
  66.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  67.   # *= Alias Listings
  68.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  69.   alias_method(:dp3_enemybattlerbreathe_sprbattler_init_kajsbk,   :initialize)
  70.   alias_method(:dp3_enemybattlerbreathe_sprbattler_update_kajsbk, :update)
  71.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  72.   # * Aliased Method: Object Initialization
  73.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  74.   def initialize(*args)
  75.     dp3_enemybattlerbreathe_sprbattler_init_kajsbk(*args)
  76.    
  77.     @dp3_breathing_stage    = rand(4)
  78.     @dp3_breathe_timer      = DPCore::TimeTracker.new(DiamondandPlatinum3::BattlerBreathe::BreatheTime)
  79.     @dp3_breathe_wait_timer = DPCore::TimeTracker.new(DiamondandPlatinum3::BattlerBreathe::BreatheHoldTime)
  80.     @dp3_min_battler_size   = DiamondandPlatinum3::BattlerBreathe::BreatheOutSize.to_f / 100.0
  81.     @dp3_max_battler_size   = DiamondandPlatinum3::BattlerBreathe::BreatheInSize.to_f / 100.0
  82.    
  83.    
  84.     self.zoom_x = @dp3_min_battler_size
  85.     self.zoom_y = @dp3_min_battler_size
  86.   end
  87.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  88.   # * Aliased Method: Frame Update
  89.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  90.   def update(*args)
  91.     dp3_enemybattlerbreathe_sprbattler_update_kajsbk(*args)
  92.     dp3_update_breathing_effect() if @battler && @use_sprite
  93.   end
  94.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  95.   # * New Method: Update Breathing Effect
  96.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  97.   def dp3_update_breathing_effect
  98.     if @dp3_breathing_stage == 1 # Breathing in
  99.       @dp3_breathe_timer.update()
  100.       if @dp3_breathe_timer.time_up?()
  101.         @dp3_breathe_timer.reset()
  102.         self.zoom_x = @dp3_max_battler_size
  103.         self.zoom_y = @dp3_max_battler_size
  104.         @dp3_breathing_stage = 2
  105.       else
  106.         self.zoom_x = (@dp3_min_battler_size + ((@dp3_max_battler_size - @dp3_min_battler_size) * @dp3_breathe_timer.get_completion_percentage()))
  107.         self.zoom_y = self.zoom_x
  108.       end
  109.      
  110.     elsif @dp3_breathing_stage == 2 # Hold in Breath
  111.       @dp3_breathe_wait_timer.update()
  112.       if @dp3_breathe_wait_timer.time_up?()
  113.         @dp3_breathe_wait_timer.reset()
  114.         @dp3_breathing_stage = 3
  115.       end
  116.      
  117.     elsif @dp3_breathing_stage == 3 # Breathing Out
  118.       @dp3_breathe_timer.update()
  119.       if @dp3_breathe_timer.time_up?()
  120.         @dp3_breathe_timer.reset()
  121.         self.zoom_x = @dp3_min_battler_size
  122.         self.zoom_y = @dp3_min_battler_size
  123.         @dp3_breathing_stage = 4
  124.       else
  125.         self.zoom_x = (@dp3_max_battler_size - ((@dp3_max_battler_size - @dp3_min_battler_size) * @dp3_breathe_timer.get_completion_percentage()))
  126.         self.zoom_y = self.zoom_x
  127.       end
  128.      
  129.     else  # Hold Out Breathe
  130.       @dp3_breathe_wait_timer.update()
  131.       if @dp3_breathe_wait_timer.time_up?()
  132.         @dp3_breathe_wait_timer.reset()
  133.         @dp3_breathing_stage = 1
  134.       end
  135.     end
  136.   end
  137. end
  138.  
  139.  
  140.  
  141. unless ($diamondandplatinum3scripts ||= {})[:TimeTracker]
  142.  
  143. #=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
  144. # **  New Class:   Time Tracker
  145. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  146. # Once initialised, this class keeps track of time in seconds.
  147. # All instances of the TimeTracker class are updated automatically if you
  148. # have chosen to allow themselves to be added to the list (true by default).
  149. #
  150. # Once initialised, simply call the ' time_up? ' method to see if the time
  151. # is up for this TimeTracker.
  152. # Call ' dispose ' once finished.
  153. #~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
  154. ($diamondandplatinum3scripts ||= {})[:TimeTracker] = true
  155. #~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
  156. module DPCore
  157.   class TimeTracker
  158.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  159.     # *+ Public Instance Variables
  160.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  161.     attr_reader :current_frame  # Current Frame the Tracker is on: Use to Reset Tracker.
  162.     attr_reader :seconds        # Seconds until TimeUp: Change to Increase/Decrease the Wait Time.
  163.     attr_reader :scenetype      # Scenetype: If not nil, this TimeTracker will only Update if SceneManager is in that Specified Scene.
  164.    
  165.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  166.     # *- Private Static Variables
  167.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  168.     @@timetracker_list = []     # Static Variable List/Array containing active instances of TimeTrackers
  169.  
  170.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  171.     # * New Method:   Object Initialisation
  172.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  173.     # Time:             How long (in seconds) until this TimeTracker has been successful
  174.     # Scene Class:      Which Scene Can this TimeTracker be updated in : nil by default, which means it can always be updated no matter what scene it is.
  175.     # Add Self To List: Add Self to the Automatic Update List? : false by default. If not true, you need to update the TimeTracker manually
  176.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  177.     def initialize(time, scene_class = nil, add_self_to_list = false)
  178.       @current_time   = 0.0
  179.       @finish_time    = time.to_f
  180.       @scenetype      = scene_class
  181.       @time_up        = false
  182.      
  183.       @@timetracker_list.push(self) if add_self_to_list
  184.     end
  185.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  186.     # * New Method:   Dispose
  187.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  188.     def dispose()
  189.       @@timetracker_list.reject! { |tracker| tracker == self }
  190.     end
  191.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  192.     # * New Method:   Update
  193.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  194.     def update()
  195.       if !@time_up
  196.         @current_time  += (1.0 / Graphics.frame_rate)
  197.         @time_up        = (@current_time > @finish_time)
  198.         @current_time   =  @finish_time if @time_up
  199.       end
  200.     end
  201.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  202.     # * New Method:   Reset
  203.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  204.     def reset()
  205.       @current_time = 0.0
  206.       @time_up      = false
  207.     end
  208.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  209.     # * New Method:   Set Current Time
  210.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  211.     def set_current_time(time)
  212.       @current_time = time
  213.       @time_up      = (@current_time > @finish_time)
  214.       @current_time =  @finish_time if @time_up
  215.     end
  216.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  217.     # * New Method:   Set Finish Time
  218.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  219.     def set_finish_time(time)
  220.       @finish_time  = time
  221.       @time_up      = (@current_time > @finish_time)
  222.       @current_time =  @finish_time if @time_up
  223.     end
  224.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  225.     # * New Method:   Get Current Time (in seconds)
  226.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  227.     def get_current_time()
  228.       return @current_time
  229.     end
  230.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  231.     # * New Method:   Is Time Up?
  232.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  233.     def time_up?()
  234.       return @time_up
  235.     end
  236.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  237.     # * New Method:   Get Total Completion Percentage
  238.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  239.     def get_completion_percentage()
  240.       return (@current_time / @finish_time)
  241.     end
  242.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  243.     # * New Method:   Get TimeTracker List
  244.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  245.     def self.get_timetracker_list()
  246.       return @@timetracker_list
  247.     end
  248.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  249.     # * New Method:   Update TimeTrackers
  250.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  251.     def self.update_timetrackers()
  252.       @@timetracker_list.each do |tracker|
  253.         tracker.update() unless !tracker.scenetype.nil? &&
  254.                                   !SceneManager.scene_is?(tracker.scenetype)
  255.       end
  256.     end
  257.   end
  258. end
  259.  
  260. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement