Advertisement
Raizen

Akea Animated Battle Gauge

Mar 4th, 2017
498
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 12.75 KB | None | 0 0
  1. #=======================================================
  2. #        Akea Animated Battle Gauge
  3. # Author: Raizen
  4. # Community: http://www.centrorpg.com/
  5. # Compatibility: RMVXAce
  6. #
  7. #=======================================================
  8. # Instructions: Put this script above main, and configure the following
  9. # You can configure different gauges for each enemy using this on the
  10. # enemy notetag:
  11. # <akea_hud n>
  12.  
  13. # Example <akea_hud 2> for gauge 2
  14.  
  15. # Where n is the id of one of the gauges configured below,
  16. # if you do not configure this on notetag, it will automatically consider
  17. # the gauge with id 0.
  18.  
  19. # =========================Don't Modify==============================
  20. $imported ||= Hash.new
  21. $imported[:akea_animated_enemy_gauge] = true
  22. module Akea_AEG
  23.  
  24.  
  25. Enemy_Gauge = Hash.new
  26.  
  27. # =========================Não modificar==============================
  28.  
  29.  
  30.  
  31. # Here you can configure as many gauges as you want,
  32. # there are no limits.
  33.  
  34. #==============================================================
  35. # -- Enemy_Gauge[0] - Normal Gauge with 3 bars
  36. #==============================================================
  37. Enemy_Gauge[0] = {
  38. :Gauge_Image => 'Enemy_Hud', # Image on Graphics/Akea for The Hud
  39. :Bar_Image => ['Enemy_Bar', 'Enemy_Bar2', 'Enemy_Bar3'], # Image on Graphics/Akea for The Bars
  40. :center => 'enemy_bottom', #enemy_bottom, enemy_top or global
  41. :position => [-50, 0], #position correction
  42. :bar_position => [13, 8], #bar position correction
  43. :z => 30, # z of the bars, in case you need it above or below other images
  44. :opening_animation_time => 30, # opening animation time
  45. :animation_time => 10, # time of animation when the gauge is affected
  46. :sound => 'Attack3' # Sound when the bar is filling up
  47. }
  48. #==============================================================
  49. # -- Enemy_Gauge[1] - No Gauge, use this to not have any gauge for
  50. # this enemy
  51. #==============================================================
  52. Enemy_Gauge[1] = {
  53. :Gauge_Image => '', # Image on Graphics/Akea for The Hud
  54. :Bar_Image => [''], # Image on Graphics/Akea for The Bars
  55. :center => 'enemy_top', #enemy_bottom, enemy_top or global
  56. :position => [0, 0], #position correction
  57. :bar_position => [20, 20], #bar position correction
  58. :z => 30, # z of the bars, in case you need it above or below other images
  59. :opening_animation_time => 0, # opening animation time
  60. :animation_time => 0, # time of animation when the gauge is affected
  61. :sound => '' # Sound when the bar is filling up
  62. }
  63. #==============================================================
  64. # -- Enemy_Gauge[2] - Boss Gauge with 4 bars
  65. #==============================================================
  66. Enemy_Gauge[2] = {
  67. :Gauge_Image => 'Boss_Hud', # Image on Graphics/Akea for The Hud
  68. :Bar_Image => ['Boss_Bar', 'Boss_Bar2', 'Boss_Bar3', 'Boss_Bar4'], # Image on Graphics/Akea for The Bars
  69. :center => 'global', #enemy_bottom, enemy_top or global
  70. :position => [165, 60], #position correction
  71. :bar_position => [13, 14], #bar position correction
  72. :z => 30, # z of the bars, in case you need it above or below other images
  73. :opening_animation_time => 100, # opening animation time
  74. :animation_time => 30, # time of animation when the gauge is affected
  75. :sound => 'Thunder12' # Sound when the bar is filling up
  76. }
  77. end
  78.  
  79. #==============================================================================
  80. # ** Spriteset_Battle
  81. #------------------------------------------------------------------------------
  82. #  Esta classe reune os sprites da tela de batalha. Esta classe é usada
  83. # internamente pela classe Scene_Battle.
  84. #==============================================================================
  85.  
  86. class Spriteset_Battle
  87. attr_reader :enemy_sprites
  88. end
  89.  
  90. #==============================================================================
  91. # ** Scene_Battle
  92. #------------------------------------------------------------------------------
  93. #  Esta classe executa o processamento da tela de batalha.
  94. #==============================================================================
  95.  
  96. class Scene_Battle < Scene_Base
  97. alias :akea_aeg_start :start
  98. alias :akea_aeg_terminate :terminate
  99. alias :akea_aeg_update_basic :update_basic
  100. alias :akea_aeg_refresh_status :refresh_status
  101.   #--------------------------------------------------------------------------
  102.   # * Renovação das informações da janela de atributos
  103.   #--------------------------------------------------------------------------
  104.   def refresh_status
  105.     @currentAegTimeUpdate = @maxAegTimeUpdate
  106.     akea_aeg_refresh_status
  107.   end
  108.   #--------------------------------------------------------------------------
  109.   # * Inicialização do processo
  110.   #--------------------------------------------------------------------------
  111.   def start
  112.     akea_aeg_start
  113.     create_aeg_variables
  114.     create_aeg_gauges
  115.   end
  116.   #--------------------------------------------------------------------------
  117.   # * Atualização da tela (básico)
  118.   #--------------------------------------------------------------------------
  119.   def update_basic
  120.     update_aeg_gauge_update unless @maxAegTime == 0
  121.     update_aeg_modify unless @currentAegTimeUpdate == 0  
  122.     akea_aeg_update_basic
  123.   end
  124.   #--------------------------------------------------------------------------
  125.   # * Updates the gauges
  126.   #--------------------------------------------------------------------------
  127.   def update_aeg_gauge_update
  128.     RPG::SE.new(@gauge_Aeg_Sound).play
  129.     for n in 0...$game_troop.members.size
  130.     (@currentAegTimeUpdate).times {|i| akea_aeg_update_basic if i < (@currentAegTimeUpdate);
  131.                                       update_aeg_gauges_collapse(n, 255 - 255 * (i + 1) / @currentAegTimeUpdate);
  132.                                       }    
  133.     end
  134.     (@maxAegTime).times {|i| akea_aeg_update_basic if i < (@maxAegTime);
  135.                                       update_aeg_gauges_opening((10000 * (i + 1))/@maxAegTime);
  136.                                       }
  137.     for n in 0...$game_troop.members.size
  138.       @akeaAegBar[n].each {|g| g.zoom_x = 1}
  139.       $game_troop.members[n].nil? ? @akeaAegConfig[n][3] = 0 : @akeaAegConfig[n][3] = $game_troop.members[n].hp * 10000 / $game_troop.members[n].mhp
  140.     end
  141.     @maxAegTime = 0;
  142.   end
  143.   #--------------------------------------------------------------------------
  144.   # * Updates the gauges if the HP is modifies
  145.   #--------------------------------------------------------------------------
  146.   def update_aeg_modify
  147.     @currentAegTimeUpdate -= 1
  148.     update_aeg_gauges_opening(10000 - (10000 * @currentAegTimeUpdate / @maxAegTimeUpdate))
  149.     for n in 0...$game_troop.members.size
  150.       if $game_troop.members[n].dead?
  151.         next if @akeaAegGauge[n].opacity == 0
  152.         update_aeg_gauges_collapse(n, (255 * (@maxAegTimeUpdate - @currentAegTimeUpdate))/@currentAegTimeUpdate)
  153.  
  154.         @akeaAegBar[n].each {|g| g.zoom_x = 0}
  155.         @akeaAegConfig[n][3] = 0
  156.       else
  157.         @akeaAegConfig[n][3] = $game_troop.members[n].hp * 10000 / $game_troop.members[n].mhp if @currentAegTimeUpdate == 0
  158.       end
  159.     end
  160.      
  161.    end
  162.   #--------------------------------------------------------------------------
  163.   # * Updates collapse Animation
  164.   #--------------------------------------------------------------------------
  165.   def update_aeg_gauges_collapse(n, op)
  166.     @akeaAegBar[n].each{|g| g.opacity = 255 - op}
  167.     @akeaAegGauge[n].opacity = 255 - op
  168.   end
  169.   #--------------------------------------------------------------------------
  170.   # * Updates the gauge bars
  171.   #--------------------------------------------------------------------------
  172.   def update_aeg_gauges_opening(currentHP)
  173.     for n in 0...$game_troop.members.size
  174.       beginHP = @akeaAegConfig[n][3]
  175.       endHP = $game_troop.members[n].hp * 10000 / $game_troop.members[n].mhp
  176.       range = (endHP - beginHP) * currentHP / 10000
  177.       currentHP_temp = (beginHP + range)/10
  178.       gauge = @akeaAegConfig[n][2] * currentHP_temp / 1000
  179.       gauge -=1 if gauge > 0 && currentHP_temp == 1000
  180.       @akeaAegBar[n][gauge].zoom_x = currentHP_temp * @akeaAegConfig[n][2] / 1000.0 - gauge
  181.       @akeaAegBar[n][gauge - 1].zoom_x = 1 if gauge > 0
  182.       @akeaAegBar[n][gauge + 1].zoom_x = 0 if @akeaAegBar[n].size > (gauge + 1)
  183.     end
  184.   end
  185.   #--------------------------------------------------------------------------
  186.   # * Creates Gauge Variables
  187.   #--------------------------------------------------------------------------
  188.   def create_aeg_variables
  189.     @maxAegTime = 0
  190.     @maxAegTimeUpdate = 0
  191.     @currentAegTimeUpdate = 0
  192.     @currentAegTime = 0
  193.   end
  194.   #--------------------------------------------------------------------------
  195.   # * Creates Gauge Graphics
  196.   #--------------------------------------------------------------------------
  197.   def create_aeg_gauges
  198.     @akeaAegGauge = Array.new
  199.     @akeaAegBar = Array.new
  200.     @akeaAegConfig = Array.new
  201.     for n in 0...$game_troop.members.size
  202.       $game_troop.members[n].enemy.note =~ /<akea_hud (\d+)>/i ? i = $1.to_i : i = 0
  203.       @akeaAegGauge[n] = Sprite.new
  204.       @akeaAegBar[n] = Array.new
  205.       @akeaAegGauge[n].bitmap = Cache.akea(Akea_AEG::Enemy_Gauge[i][:Gauge_Image])
  206.       @akeaAegGauge[n].x = akea_aeg_gauge_position(0, n, Akea_AEG::Enemy_Gauge[i][:center], Akea_AEG::Enemy_Gauge[i][:position][0])
  207.       @akeaAegGauge[n].y = akea_aeg_gauge_position(1, n, Akea_AEG::Enemy_Gauge[i][:center], Akea_AEG::Enemy_Gauge[i][:position][1])
  208.       for b in 0...Akea_AEG::Enemy_Gauge[i][:Bar_Image].size
  209.         @akeaAegBar[n][b] = Sprite.new
  210.         @akeaAegBar[n][b].bitmap = Cache.akea(Akea_AEG::Enemy_Gauge[i][:Bar_Image][b])
  211.         @akeaAegBar[n][b].x = akea_aeg_gauge_position(0, n, Akea_AEG::Enemy_Gauge[i][:center], Akea_AEG::Enemy_Gauge[i][:position][0])
  212.         @akeaAegBar[n][b].y = akea_aeg_gauge_position(1, n, Akea_AEG::Enemy_Gauge[i][:center], Akea_AEG::Enemy_Gauge[i][:position][1])
  213.         @akeaAegBar[n][b].x += Akea_AEG::Enemy_Gauge[i][:bar_position][0]
  214.         @akeaAegBar[n][b].y += Akea_AEG::Enemy_Gauge[i][:bar_position][1]
  215.         @akeaAegBar[n][b].zoom_x = 0
  216.         @akeaAegBar[n][b].opacity = 0
  217.       end
  218.       @akeaAegGauge[n].opacity = 0
  219.       @maxAegTime = Akea_AEG::Enemy_Gauge[i][:opening_animation_time] if @maxAegTime < Akea_AEG::Enemy_Gauge[i][:opening_animation_time]
  220.       @currentAegTime = @maxAegTime
  221.       @maxAegTimeUpdate = Akea_AEG::Enemy_Gauge[i][:animation_time] if @maxAegTimeUpdate < Akea_AEG::Enemy_Gauge[i][:animation_time]
  222.       @currentAegTimeUpdate = @maxAegTimeUpdate
  223.       @akeaAegConfig[n] = [Akea_AEG::Enemy_Gauge[i][:animation_time], Akea_AEG::Enemy_Gauge[i][:opening_animation_time], @akeaAegBar[n].size, 0]
  224.     end
  225.     @gauge_Aeg_Sound = Akea_AEG::Enemy_Gauge[i][:sound]
  226.   end
  227.   #--------------------------------------------------------------------------
  228.   # * Adjusts Gauge Position
  229.   #--------------------------------------------------------------------------
  230.   def akea_aeg_gauge_position(axis, n, center, position)
  231.     if axis == 0
  232.       case center
  233.         when 'enemy_bottom'
  234.           pos = $game_troop.members[n].screen_x + position
  235.         when 'enemy_top'
  236.           pos = $game_troop.members[n].screen_x + position
  237.         when 'global'
  238.           pos = position
  239.       end
  240.     else
  241.       case center
  242.         when 'enemy_bottom'
  243.           pos = $game_troop.members[n].screen_y + position
  244.         when 'enemy_top'
  245.           pos = $game_troop.members[n].screen_y + position - @spriteset.enemy_sprites[n].height
  246.         when 'global'
  247.           pos = position
  248.       end
  249.     end
  250.   end
  251.   #--------------------------------------------------------------------------
  252.   # * Finalização do processo
  253.   #--------------------------------------------------------------------------
  254.   def terminate
  255.     @akeaAegGauge.each{|battler|battler.bitmap.dispose; battler.dispose}
  256.     for n in 0...@akeaAegBar.size
  257.       @akeaAegBar[n].each{|battler|battler.bitmap.dispose; battler.dispose}
  258.     end
  259.     akea_aeg_terminate
  260.   end
  261. end
  262.  
  263.  
  264.  
  265. #==============================================================================
  266. # ** Cache
  267. #------------------------------------------------------------------------------
  268. #  Este modulo carrega cada gráfico, cria um objeto de Bitmap e retém ele.
  269. # Para acelerar o carregamento e preservar memória, este módulo matém o
  270. # objeto de Bitmap em uma Hash interna, permitindo que retorne objetos
  271. # pré-existentes quando mesmo Bitmap é requerido novamente.
  272. #==============================================================================
  273.  
  274. module Cache
  275.   #--------------------------------------------------------------------------
  276.   # * Carregamento dos gráficos de animação
  277.   #     filename : nome do arquivo
  278.   #     hue      : informações da alteração de tonalidade
  279.   #--------------------------------------------------------------------------
  280.   def self.akea(filename)
  281.     load_bitmap("Graphics/akea/", filename)
  282.   end
  283. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement