Advertisement
neutale

Enemy Battle Effects [VX]

Jul 30th, 2019
777
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 8.12 KB | None | 0 0
  1. #==============================================================================
  2. # ■ Enemy Battle Effects
  3. #   @version 0.32 10/03/19
  4. #   @author sabakan
  5. #   @license: MIT License
  6. #------------------------------------------------------------------------------
  7. # A script that changes enemy battle effects.
  8. # You can change the following.
  9. #
  10. # ■ When the enemy is damaged
  11. # Default: blink
  12. # ↓
  13. # This script: random shake
  14. #
  15. # ■ When an enemy attacks
  16. # Default: white flash
  17. # ↓
  18. # This script: move down (+ white flash)
  19. #
  20. # ■ When an enemy appears (0 turn only)
  21. # Default: increasingly opaque
  22. # ↓
  23. # This script :: move up and down + + down
  24. #  
  25. #==============================================================================
  26. module Saba
  27.   module BattleEffect
  28.    
  29.     # Set to true if you want the effect to appear when enemy appears.
  30.     APPEAR_ENABLED = true
  31.     # Speed at the time of appearance.
  32.     APPEAR_SPEED = 1.9
  33.    
  34.     # Set to true if you want the sound to play when the enemy appears.
  35.     APPEAR_SE_ENABLED = true
  36.     # An integer from 0 to 16 The larger the sound, the faster it sounds.
  37.     APPEAR_SE_TIMING = 5
  38.     # Stting for the sound effect.
  39.     APPEAR_SE = "Audio/SE/Battle2"
  40.     APPEAR_SE_VOLUME = 100
  41.     APPEAR_SE_PITCH = 95
  42.  
  43.     # Set to true to enable shake when damage is done to the enemy.
  44.     SHAKE_ENABLED = true
  45.     # Time of the shake.
  46.     SHAKE_DURATION = 8
  47.     # Intensity of the shake.
  48.     SHAKE_POWER = 8
  49.     # Speed of the shake.
  50.     SHAKE_SPEED = 10
  51.     # Set to true if you also shake the picture at the same time.
  52.     SHAKE_PICTURE = false
  53.    
  54.     # Set to true to enable movement when the enemy attacks.
  55.     MOVE_ENABLED = true
  56.     # Set to true if you also want to enable white flash when the enemy attacks.
  57.     WHITE_FLASH_ENABLED = true
  58.     # If you press the button to fast forward, it will be halved automatically.
  59.     MOVE_DURATION = 80
  60.     # Distance of movement.
  61.     MOVE_DISTANCE = 20
  62.    
  63.   end
  64. end
  65.  
  66. class Game_Temp
  67.   attr_accessor :appear_se_play
  68. end
  69.  
  70. class Spriteset_Battle
  71.   #--------------------------------------------------------------------------
  72.   # ● Create enemy characters sprite
  73.   #--------------------------------------------------------------------------
  74.   alias saba_battle_effect_create_enemies create_enemies
  75.   def create_enemies
  76.     saba_battle_effect_create_enemies
  77.     for sprite in @enemy_sprites
  78.       sprite.picture_viewport = @viewport2
  79.     end
  80.   end
  81. end
  82.  
  83.  
  84. class Game_Battler
  85.   attr_accessor :shake
  86.   attr_accessor :move
  87.  
  88.   def blink=(value)
  89.     @blink = value
  90.     if Saba::BattleEffect::SHAKE_ENABLED
  91.       @shake = value if value
  92.     end
  93.   end
  94.  
  95.   def white_flash=(value)
  96.     @white_flash = value
  97.     if Saba::BattleEffect::MOVE_ENABLED && (! escape_action?)
  98.       @move = value if value
  99.     end
  100.   end
  101.   def escape_action?
  102.     return (action.kind == 0 and action.basic == 2)
  103.   end
  104. end
  105.  
  106. class Sprite_Battler
  107.   SHAKE  = 10                      # shake
  108.   MOVE  = 11                      # move
  109.  
  110.   attr_writer :picture_viewport
  111.  
  112.   alias saba_battle_effect_initialize initialize
  113.   def initialize(viewport, battler = nil)
  114.     saba_battle_effect_initialize(viewport, battler)
  115.     @shake = 0
  116.     @shake_power = Saba::BattleEffect::SHAKE_POWER
  117.     @shake_speed = Saba::BattleEffect::SHAKE_SPEED
  118.     @shake_direction = 1
  119.  
  120.     $game_temp.appear_se_play = false
  121.   end
  122.   alias saba_battle_effect_update update
  123.   def update
  124.     duration = @effect_duration
  125.     saba_battle_effect_update
  126.     if @battler != nil && duration > 0 && @effect_duration == 0
  127.       @use_sprite = @battler.use_sprite?
  128.       if @use_sprite && @picture_viewport && Saba::BattleEffect::SHAKE_PICTURE
  129.         @picture_viewport.ox = 0
  130.         @picture_viewport.oy = 0
  131.       end
  132.     end
  133.   end
  134.   #--------------------------------------------------------------------------
  135.   # ● New effect settings
  136.   #--------------------------------------------------------------------------
  137.   alias saba_battle_effect_setup_new_effect setup_new_effect
  138.   def setup_new_effect
  139.     white_flash = @battler.white_flash
  140.     saba_battle_effect_setup_new_effect
  141.     if @battler.shake
  142.       @effect_type = SHAKE
  143.       @effect_duration = Saba::BattleEffect::SHAKE_DURATION
  144.       @battler.shake = false
  145.     end
  146.     if @battler.move && white_flash
  147.       @effect_type = MOVE
  148.       @effect_duration = Saba::BattleEffect::MOVE_DURATION
  149.       @battler.move = false
  150.     end
  151.   end
  152.  
  153.   #--------------------------------------------------------------------------
  154.   # ● Effect updates
  155.   #--------------------------------------------------------------------------
  156.   alias saba_battle_effect_update_effect update_effect
  157.   def update_effect
  158.     if @effect_duration > 0
  159.       case @effect_type
  160.       when SHAKE
  161.         update_shake
  162.         @effect_duration -= 1
  163.         return
  164.       when MOVE
  165.         update_move
  166.         @effect_duration -= 1
  167.         @effect_duration -= 1 if $scene.show_fast?
  168.         return
  169.       end
  170.     end
  171.     saba_battle_effect_update_effect
  172.   end
  173.  
  174.   #--------------------------------------------------------------------------
  175.   # ● Movement effect update
  176.   #--------------------------------------------------------------------------
  177.   def update_move
  178.     duration = Saba::BattleEffect::MOVE_DURATION
  179.     if Saba::BattleEffect::WHITE_FLASH_ENABLED
  180.       temp = @effect_duration
  181.       @effect_duration = 16 - (duration - @effect_duration)
  182.       update_whiten
  183.       @effect_duration = temp
  184.     end
  185.     @distance = 0
  186.     if @effect_duration <= 1
  187.       @distance = 0
  188.     else
  189.       distance = Saba::BattleEffect::MOVE_DISTANCE
  190.       if @effect_duration > duration / 2
  191.         @distance = distance * (duration - @effect_duration) * 2 / duration
  192.       else
  193.         @distance = distance * @effect_duration * 2 / duration
  194.       end
  195.     end
  196.     if @use_sprite && (! @battler.actor?)
  197.       self.y = @battler.screen_y + @distance.to_i
  198.     end
  199.   end
  200.  
  201.   #--------------------------------------------------------------------------
  202.   # ● Shake effect updates
  203.   #--------------------------------------------------------------------------
  204.   def update_shake
  205.     self.blend_type = 0
  206.     self.color.set(0, 0, 0, 0)
  207.     self.opacity = 255
  208.     delta = (@shake_power * @shake_speed * @shake_direction) / 10.0
  209.     if @effect_duration <= 1 and @shake * (@shake + delta) < 0
  210.       @shake = 0
  211.     else
  212.       @shake += delta
  213.     end
  214.     if @shake > @shake_power * 2
  215.       @shake_direction = -1
  216.     end
  217.     if @shake < - @shake_power * 2
  218.       @shake_direction = 1
  219.     end
  220.     if @use_sprite && (! @battler.actor?)
  221.       x_value = rand(@shake) * random_direction
  222.       self.x = @battler.screen_x + x_value
  223.       y_value = rand(@shake) * random_direction
  224.       self.y = @battler.screen_y + y_value
  225.       self.z = @battler.screen_z
  226.       if @picture_viewport && Saba::BattleEffect::SHAKE_PICTURE
  227.         @picture_viewport.ox = x_value
  228.         @picture_viewport.oy = y_value
  229.       end
  230.     end
  231.   end
  232.  
  233.   def random_direction
  234.     if rand(2) == 0
  235.       return 1
  236.     else
  237.       return -1
  238.     end
  239.   end
  240.  
  241.   #--------------------------------------------------------------------------
  242.   # ● Update appearance effects
  243.   #--------------------------------------------------------------------------
  244.   alias saba_battle_effect_update_appear update_appear
  245.   def update_appear
  246.     timing = Saba::BattleEffect::APPEAR_SE_TIMING
  247.     if @effect_duration == timing && $game_troop.turn_count == 0
  248.       if Saba::BattleEffect::APPEAR_SE_ENABLED && $game_temp.appear_se_play != true
  249.         se = Saba::BattleEffect::APPEAR_SE
  250.         volume = Saba::BattleEffect::APPEAR_SE_VOLUME
  251.         pitch = Saba::BattleEffect::APPEAR_SE_PITCH
  252.         Audio.se_play(se, volume, pitch)
  253.         $game_temp.appear_se_play = true
  254.       end
  255.     end
  256.     saba_battle_effect_update_appear
  257.     return unless Saba::BattleEffect::APPEAR_ENABLED
  258.     if @use_sprite && (! @battler.actor?) && $game_troop.turn_count == 0
  259.       speed = Saba::BattleEffect::APPEAR_SPEED
  260.       self.y = @battler.screen_y - (@effect_duration * Saba::BattleEffect::APPEAR_SPEED).to_i
  261.     end
  262.   end
  263. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement