#==============================================================================
# ** Sprite_HPbar
#------------------------------------------------------------------------------
# This sprite is used to display the battler.It observes the Game_Character
# class and automatically changes sprite conditions.
#==============================================================================
class Sprite_Hpbar < Sprite
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :battler # battler
#--------------------------------------------------------------------------
# * Object Initialization
# viewport : viewport
# battler : battler (Game_Battler)
#--------------------------------------------------------------------------
def initialize(viewport, battler = nil)
super(viewport)
@battler = battler
# Set sprite coordinates
self.x = @battler.screen_x - 40
self.y = 64
self.z = @battler.screen_z
self.bitmap = Bitmap.new(80, 24)
gray1 = Color.new(50, 50, 50)
gray2 = Color.new(64, 64, 64)
gray3 = Color.new(80, 80, 80)
gray4 = Color.new(100, 100, 100)
self.bitmap.fill_rect(2,0,76,24,gray1)
self.bitmap.fill_rect(0,2,80,20,gray1)
self.bitmap.fill_rect(2,2,76,20,gray2)
self.bitmap.fill_rect(4,4,72,16,gray3)
self.bitmap.fill_rect(8,8,64,8,gray4)
self.bitmap.fill_rect(8,10,64,4,gray1)
self.bitmap.fill_rect(10,8,60,8,gray1)
@old_hp = @battler.hp
refresh
end
#--------------------------------------------------------------------------
# * Dispose
#--------------------------------------------------------------------------
def dispose
if self.bitmap != nil
self.bitmap.dispose
end
super
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
green1 = Color.new(128, 200, 48)
green2 = Color.new(56, 136, 0)
yellow1 = Color.new(248, 224, 56)
yellow2 = Color.new(200, 168, 8)
red1 = Color.new(248, 104, 72)
red2 = Color.new(192, 56, 56)
gray = Color.new(136, 136, 144)
self.bitmap.fill_rect(10, 10, 60, 4, gray)
# check battlers HP
width = @battler.hp * 60 / @battler.maxhp
# Draw the HP Bar
if width > 40
self.bitmap.fill_rect(10, 10, width, 2, green1)
self.bitmap.fill_rect(10, 12, width, 2, green2)
return
end
if width > 20
self.bitmap.fill_rect(10, 10, width, 2, yellow1)
self.bitmap.fill_rect(10, 12, width, 2, yellow2)
return
end
self.bitmap.fill_rect(10, 10, width, 2, red1)
self.bitmap.fill_rect(10, 12, width, 2, red2)
return
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
super
# If battler is nil
if @battler == nil
self.bitmap = nil
return
end
if @old_hp != @battler.hp
refresh
end
@old_hp = @battler_hp
end
end
#==============================================================================
# ** Spriteset_Battle
#------------------------------------------------------------------------------
# This class brings together battle screen sprites. It's used within
# the Scene_Battle class.
#==============================================================================
class Spriteset_Battle
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_reader :viewport1 # enemy viewport
attr_reader :viewport2 # actor viewport
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
# Make viewports
@viewport1 = Viewport.new(0, 0, 640, 320)
@viewport2 = Viewport.new(0, 0, 640, 480)
@viewport3 = Viewport.new(0, 0, 640, 480)
@viewport4 = Viewport.new(0, 0, 640, 480)
@viewport2.z = 101
@viewport3.z = 200
@viewport4.z = 5000
# Make battleback sprite
@battleback_sprite = Sprite.new(@viewport1)
# Make enemy sprites
@enemy_sprites = []
for enemy in $game_troop.enemies.reverse
@enemy_sprites.push(Sprite_Battler.new(@viewport1, enemy))
end
# Make actor sprites
@actor_sprites = []
@actor_sprites.push(Sprite_Battler.new(@viewport2))
@actor_sprites.push(Sprite_Battler.new(@viewport2))
@actor_sprites.push(Sprite_Battler.new(@viewport2))
@actor_sprites.push(Sprite_Battler.new(@viewport2))
# Make HP bar sprites
@hpbar_sprites = []
for actor in $game_party.actors
@hpbar_sprites.push(Sprite_Hpbar.new(@viewport1, actor))
end
# Make weather
@weather = RPG::Weather.new(@viewport1)
# Make picture sprites
@picture_sprites = []
for i in 51..100
@picture_sprites.push(Sprite_Picture.new(@viewport3,
$game_screen.pictures[i]))
end
# Make timer sprite
@timer_sprite = Sprite_Timer.new
# Frame update
update
end
#--------------------------------------------------------------------------
# * Dispose
#--------------------------------------------------------------------------
def dispose
# If battleback bit map exists, dispose of it
if @battleback_sprite.bitmap != nil
@battleback_sprite.bitmap.dispose
end
# Dispose of battleback sprite
@battleback_sprite.dispose
# Dispose of enemy sprites and actor sprites
for sprite in @enemy_sprites + @actor_sprites
sprite.dispose
end
# Dispose of weather
@weather.dispose
# Dispose of picture sprites
for sprite in @picture_sprites
sprite.dispose
end
# Dispose of timer sprite
@timer_sprite.dispose
# Dispose of viewports
@viewport1.dispose
@viewport2.dispose
@viewport3.dispose
@viewport4.dispose
end
#--------------------------------------------------------------------------
# * Determine if Effects are Displayed
#--------------------------------------------------------------------------
def effect?
# Return true if even 1 effect is being displayed
for sprite in @enemy_sprites + @actor_sprites
return true if sprite.effect?
end
return false
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Update actor sprite contents (corresponds with actor switching)
@actor_sprites[0].battler = $game_party.actors[0]
@actor_sprites[1].battler = $game_party.actors[1]
@actor_sprites[2].battler = $game_party.actors[2]
@actor_sprites[3].battler = $game_party.actors[3]
# Update the hpbar sprites
i = 0
for actor in $game_party.actors
@hpbar_sprites[i].battler = actor
@hpbar_sprites[i].update
i += 1
end
# If battleback file name is different from current one
if @battleback_name != $game_temp.battleback_name
@battleback_name = $game_temp.battleback_name
if @battleback_sprite.bitmap != nil
@battleback_sprite.bitmap.dispose
end
@battleback_sprite.bitmap = RPG::Cache.battleback(@battleback_name)
@battleback_sprite.src_rect.set(0, 0, 640, 320)
end
# Update battler sprites
for sprite in @enemy_sprites + @actor_sprites
sprite.update
end
# Update weather graphic
@weather.type = $game_screen.weather_type
@weather.max = $game_screen.weather_max
@weather.update
# Update picture sprites
for sprite in @picture_sprites
sprite.update
end
# Update timer sprite
@timer_sprite.update
# Set screen color tone and shake position
@viewport1.tone = $game_screen.tone
@viewport1.ox = $game_screen.shake
# Set screen flash color
@viewport4.color = $game_screen.flash_color
# Update viewports
@viewport1.update
@viewport2.update
@viewport4.update
end
end