dsiver144

DSI Class Image As Battler

Jul 4th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 9.93 KB | None | 0 0
  1. #==============================================================================
  2. # DSI Class Image As Battler (Can't find a fancy name, lol)
  3. # -- Last Updated: 2017.06.09
  4. # -- Author: dsiver144
  5. # -- Level: Normal
  6. # -- Requires: n/a
  7. #==============================================================================
  8. $imported = {} if $imported.nil?
  9. $imported["DSI-ClassImageAsBattler"] = true
  10. #==============================================================================
  11. # + Updates
  12. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  13. # 2017.06.08 - Finish first version.
  14. #==============================================================================
  15. # + Instructions
  16. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  17. # To install this script, open up your script editor and copy/paste this script
  18. # to an open slot below ?? Materials/?f?? but above ?? Main. Remember to save.
  19. #==============================================================================
  20. module DSIVER144
  21.   module CARD_AS_BATTLER
  22.     NON_CLASS_BATTLER_IMAGE = "bt_mgirl_pudding_a" # In Graphics/Battlers Folder
  23.     BATTLER_POSITION = [445,265] # [ X , Y ]
  24.     ZOOM_SCALE = 1.0 # 1.0 = Full size
  25.   end # CARD_AS_BATTLER
  26. end # DSIVER144
  27.  
  28. class Spriteset_Battle
  29.   #--------------------------------------------------------------------------
  30.   # * Create Actor Sprite
  31.   #    By default, the actor image is not displayed, but for convenience
  32.   #    a dummy sprite is created for treating enemies and allies the same.
  33.   #--------------------------------------------------------------------------
  34.   def create_actors
  35.     @actor_sprites = Array.new(4) { Sprite_CardBattler.new(@viewport1) }
  36.   end
  37. end # Spriteset_Battle
  38.  
  39. class Sprite_CardBattler < Sprite_Base
  40.   include DSIVER144::CARD_AS_BATTLER
  41.   #--------------------------------------------------------------------------
  42.   # * Public Instance Variables
  43.   #--------------------------------------------------------------------------
  44.   attr_accessor :battler
  45.   #--------------------------------------------------------------------------
  46.   # * new method: initialize
  47.   #--------------------------------------------------------------------------
  48.   def initialize(viewport, battler = nil)
  49.     super(viewport)
  50.     @battler = battler
  51.     @battler_visible = false
  52.     @effect_type = nil
  53.     @effect_duration = 0
  54.     self.zoom_x = self.zoom_y = ZOOM_SCALE
  55.   end
  56.   #--------------------------------------------------------------------------
  57.   # * new method: update
  58.   #--------------------------------------------------------------------------
  59.   def update
  60.     super
  61.     if @battler
  62.       update_bitmap
  63.       update_origin
  64.       update_position
  65.       setup_new_effect
  66.       setup_new_animation
  67.       update_effect
  68.     else
  69.       self.bitmap = nil
  70.       @effect_type = nil
  71.     end
  72.   end
  73.   #--------------------------------------------------------------------------
  74.   # * new method: update_bitmap
  75.   #--------------------------------------------------------------------------
  76.   def update_bitmap
  77.     id = $game_system.current_class ? $game_system.current_class : 0
  78.     if id == 0
  79.       new_bitmap = Cache.battler(NON_CLASS_BATTLER_IMAGE,0)
  80.     else
  81.       new_bitmap = Cache.picture(DSIVER144::CLASS_CHOOSING::CLASSES[id][:picture])
  82.     end
  83.     if bitmap != new_bitmap
  84.       self.bitmap = new_bitmap
  85.       init_visibility
  86.     end
  87.   end
  88.   #--------------------------------------------------------------------------
  89.   # * new method: dispose
  90.   #--------------------------------------------------------------------------
  91.   def dispose
  92.     bitmap.dispose if bitmap
  93.     super
  94.   end
  95.   #--------------------------------------------------------------------------
  96.   # * new method: init_visibility
  97.   #--------------------------------------------------------------------------
  98.   def init_visibility
  99.     @battler_visible = @battler.alive?
  100.     self.opacity = 0 unless @battler_visible
  101.   end
  102.   #--------------------------------------------------------------------------
  103.   # * new method: update_origin
  104.   #--------------------------------------------------------------------------
  105.   def update_origin
  106.     if bitmap
  107.       self.ox = bitmap.width / 2
  108.       self.oy = bitmap.height
  109.     end
  110.   end
  111.   #--------------------------------------------------------------------------
  112.   # * new method: update_position
  113.   #--------------------------------------------------------------------------
  114.   def update_position
  115.     self.x = BATTLER_POSITION[0]
  116.     self.y = BATTLER_POSITION[1]
  117.     self.z = 100
  118.   end
  119.   #--------------------------------------------------------------------------
  120.   # * new method: setup_new_effect
  121.   #--------------------------------------------------------------------------
  122.   def setup_new_effect
  123.     if !@battler_visible && @battler.alive?
  124.       start_effect(:appear)
  125.     elsif @battler_visible && @battler.hidden?
  126.       start_effect(:disappear)
  127.     end
  128.     if @battler_visible && @battler.sprite_effect_type
  129.       start_effect(@battler.sprite_effect_type)
  130.       @battler.sprite_effect_type = nil
  131.     end
  132.   end
  133.   #--------------------------------------------------------------------------
  134.   # * new method: start_effect
  135.   #--------------------------------------------------------------------------
  136.   def start_effect(effect_type)
  137.     @effect_type = effect_type
  138.     case @effect_type
  139.     when :appear
  140.       @effect_duration = 16
  141.       @battler_visible = true
  142.     when :disappear
  143.       @effect_duration = 32
  144.       @battler_visible = false
  145.     when :whiten
  146.       @effect_duration = 16
  147.       @battler_visible = true
  148.     when :blink
  149.       @effect_duration = 20
  150.       @battler_visible = true
  151.     when :collapse
  152.       @effect_duration = 48
  153.       @battler_visible = false
  154.     when :boss_collapse
  155.       @effect_duration = bitmap.height
  156.       @battler_visible = false
  157.     when :instant_collapse
  158.       @effect_duration = 16
  159.       @battler_visible = false
  160.     end
  161.     revert_to_normal
  162.   end
  163.   #--------------------------------------------------------------------------
  164.   # * new method: revert_to_normal
  165.   #--------------------------------------------------------------------------
  166.   def revert_to_normal
  167.     self.blend_type = 0
  168.     self.color.set(0, 0, 0, 0)
  169.     self.opacity = 255
  170.     self.ox = bitmap.width / 2 if bitmap
  171.     self.src_rect.y = 0
  172.   end
  173.   #--------------------------------------------------------------------------
  174.   # * new method: setup_new_animation
  175.   #--------------------------------------------------------------------------
  176.   def setup_new_animation
  177.     if @battler.animation_id > 0
  178.       animation = $data_animations[@battler.animation_id]
  179.       mirror = @battler.animation_mirror
  180.       start_animation(animation, mirror)
  181.       @battler.animation_id = 0
  182.     end
  183.   end
  184.   #--------------------------------------------------------------------------
  185.   # * new method: effect?
  186.   #--------------------------------------------------------------------------
  187.   def effect?
  188.     @effect_type != nil
  189.   end
  190.   #--------------------------------------------------------------------------
  191.   # * new method: update_effect
  192.   #--------------------------------------------------------------------------
  193.   def update_effect
  194.     if @effect_duration > 0
  195.       @effect_duration -= 1
  196.       case @effect_type
  197.       when :whiten
  198.         update_whiten
  199.       when :blink
  200.         update_blink
  201.       when :appear
  202.         update_appear
  203.       when :disappear
  204.         update_disappear
  205.       when :collapse
  206.         update_collapse
  207.       when :boss_collapse
  208.         update_boss_collapse
  209.       when :instant_collapse
  210.         update_instant_collapse
  211.       end
  212.       @effect_type = nil if @effect_duration == 0
  213.     end
  214.   end
  215.   #--------------------------------------------------------------------------
  216.   # * new method: update_whiten
  217.   #--------------------------------------------------------------------------
  218.   def update_whiten
  219.     self.color.set(255, 255, 255, 0)
  220.     self.color.alpha = 128 - (16 - @effect_duration) * 10
  221.   end
  222.   #--------------------------------------------------------------------------
  223.   # * new method: update_blink
  224.   #--------------------------------------------------------------------------
  225.   def update_blink
  226.     self.opacity = (@effect_duration % 10 < 5) ? 255 : 0
  227.   end
  228.   #--------------------------------------------------------------------------
  229.   # * new method: update_appear
  230.   #--------------------------------------------------------------------------
  231.   def update_appear
  232.     self.opacity = (16 - @effect_duration) * 16
  233.   end
  234.   #--------------------------------------------------------------------------
  235.   # * new method: update_disappear
  236.   #--------------------------------------------------------------------------
  237.   def update_disappear
  238.     self.opacity = 256 - (32 - @effect_duration) * 10
  239.   end
  240.   #--------------------------------------------------------------------------
  241.   # * new method: update_collapse
  242.   #--------------------------------------------------------------------------
  243.   def update_collapse
  244.     self.blend_type = 1
  245.     self.color.set(255, 128, 128, 128)
  246.     self.opacity = 256 - (48 - @effect_duration) * 6
  247.   end
  248.   #--------------------------------------------------------------------------
  249.   # * new method: update_boss_collapse
  250.   #--------------------------------------------------------------------------
  251.   def update_boss_collapse
  252.     alpha = @effect_duration * 120 / bitmap.height
  253.     self.ox = bitmap.width / 2 + @effect_duration % 2 * 4 - 2
  254.     self.blend_type = 1
  255.     self.color.set(255, 255, 255, 255 - alpha)
  256.     self.opacity = alpha
  257.     self.src_rect.y -= 1
  258.     Sound.play_boss_collapse2 if @effect_duration % 20 == 19
  259.   end
  260.   #--------------------------------------------------------------------------
  261.   # * new method: update_instant_collapse
  262.   #--------------------------------------------------------------------------
  263.   def update_instant_collapse
  264.     self.opacity = 0
  265.   end
  266. end # Sprite_CardBattler
Advertisement
Add Comment
Please, Sign In to add comment