#==============================================================================
# ** HP_Bar
#------------------------------------------------------------------------------
# This sprite will show the user how much HP an enemy has.
#==============================================================================
class Enemy_HPBar < Sprite_Base
#--------------------------------------------------------------------------
# * Constant Variables
#--------------------------------------------------------------------------
# The bar uses a gradient. Default is (red to green)/(left to right)
# respectively.
HP_COLOR_LEFT =
Color.new(255, 0, 0) # The left color of the HP Bar. *Default : Red*
HP_COLOR_RIGHT =
Color.new(0, 255, 0) # The right color of the HP Bar. *Default : Green*
HP_BAR_LENGTH = 64 # The length of the bar. 1 pixel border is not
# taken into account.
HP_BAR_HEIGHT = 6 # The height ob the bar. 1 pixel border is not
# taken into account.
HP_BAR_OPACITY = 170 # The opacity of the bar.
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(viewport, sprite_battler)
super(viewport)
# Save the battler.
@sprite_battler = sprite_battler
self.opacity = HP_BAR_OPACITY
# Create the bitmap.
self.bitmap = Bitmap.new(HP_BAR_LENGTH + 2, HP_BAR_HEIGHT + 2)
# Create the outline it will never change.
self.bitmap.fill_rect(0, 0, HP_BAR_LENGTH + 2, 1, Color.new(0, 0, 0))
self.bitmap.fill_rect(0, HP_BAR_HEIGHT + 1, HP_BAR_LENGTH + 2, 1, Color.new(0, 0, 0))
self.bitmap.fill_rect(0, 1, 1, HP_BAR_HEIGHT, Color.new(0, 0, 0))
self.bitmap.fill_rect(HP_BAR_LENGTH + 1, 1, 1, HP_BAR_HEIGHT, Color.new(0, 0, 0))
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
super()
# Turn it off if the battler is either dead or hidden.
self.visible = @sprite_battler.visible
# Return if this object can not be seen.
return unless self.visible
# Put the bar dead center over the sprite.
self.x = @sprite_battler.x +
(@sprite_battler.bitmap.width / 2) - HP_BAR_LENGTH
# Move it up away from the sprite just a little.
self.y = @sprite_battler.y - 10
self.z = @sprite_battler.z + 1
if @hp != @sprite_battler.battler.hp
# Clear out the portion we want to draw to.
self.bitmap.clear_rect(1, 1, HP_BAR_LENGTH, HP_BAR_HEIGHT)
# Save the current hp.
@hp = @sprite_battler.battler.hp
# Determine how many pixels wide the health bar should be.
pixel_width = HP_BAR_LENGTH * (@hp / @sprite_battler.battler.maxhp.to_f)
# Draw the health bar.
self.bitmap.gradient_fill_rect(Rect.new(1, 1, pixel_width, HP_BAR_HEIGHT),
HP_COLOR_LEFT, HP_COLOR_RIGHT)
end
end
#--------------------------------------------------------------------------
# * Dispose
#--------------------------------------------------------------------------
def dispose
super()
self.bitmap.dispose unless self.bitmap.disposed?
end
end
#==============================================================================
# ** Spriteset_Battle
#------------------------------------------------------------------------------
# This class brings together battle screen sprites. It's used within the
# Scene_Battle class.
#==============================================================================
class Spriteset_Battle
#--------------------------------------------------------------------------
# * Alias Methods
#--------------------------------------------------------------------------
alias_method :djfl_hpbars_spriteset_battle_create_enemies, :create_enemies
alias_method :djfl_hpbars_spriteset_battle_dispose_enemies, :dispose_enemies
alias_method :djfl_hpbars_spriteset_battle_update_enemies, :update_enemies
#--------------------------------------------------------------------------
# * Create Enemy Sprite
#--------------------------------------------------------------------------
def create_enemies
djfl_hpbars_spriteset_battle_create_enemies
@enemy_hpbars = []
@enemy_sprites.each { |enemy|
@enemy_hpbars << Enemy_HPBar.new(@viewport1, enemy)
}
end
#--------------------------------------------------------------------------
# * Dispose of Enemy Sprite
#--------------------------------------------------------------------------
def dispose_enemies
djfl_hpbars_spriteset_battle_dispose_enemies
@enemy_hpbars.each { |enemy_hp| enemy_hp.dispose }
end
#--------------------------------------------------------------------------
# * Update Enemy Sprite
#--------------------------------------------------------------------------
def update_enemies
djfl_hpbars_spriteset_battle_update_enemies
@enemy_hpbars.each { |enemy_hp| enemy_hp.update }
end
end