Â
#==============================================================================
# ** Energy Bar Addon
#------------------------------------------------------------------------------
# Â Adds an Energy bar to the map
#
#  Use  $game_system.energy_bar = 0  to turn it off, 1 to turn it back on
#
# Â @max_energy defaults to 200
#
# Â To increase or decrease energy:
# Â $game_party.increase_energy(n)
# Â $game_party.decrease_energy(n)
#
# Â Default position is
# Â Â self.x = 520
# Â Â self.y = 0
#
# Â 29Jan09 - Brewmeister
#==============================================================================
Â
#==============================================================================
# ** Game_System
#------------------------------------------------------------------------------
# Â This class handles data surrounding the system. Backround music, etc.
# Â is managed here as well. Refer to "$game_system" for the instance of
# Â this class.
#==============================================================================
Â
class Game_System
 attr_accessor :energy_bar  # 1 if energy bar is on
 alias energy_bar_init initialize
 def initialize
  @energy_bar = 1
  energy_bar_init
 end
end
Â
#==============================================================================
# ** Game_Party
#------------------------------------------------------------------------------
# Â This class handles the party. It includes information on amount of gold
# Â and items. Refer to "$game_party" for the instance of this class.
#==============================================================================
Â
class Game_Party
 #--------------------------------------------------------------------------
 # * Public Instance Variables
 #--------------------------------------------------------------------------
 attr_reader  :energy          # party energy level
 attr_reader  :max_energy
 #--------------------------------------------------------------------------
 # * Object Initialization
 #--------------------------------------------------------------------------
 alias topdod_init initialize
 def initialize
  @energy = @max_energy = 200
  topdod_init
 end
 def increase_energy(amount)
  @energy = [@energy + amount, @max_energy].min
 end
 def decrease_energy(amount)
  @energy = [@energy - amount, 0].max
 end
end
Â
#==============================================================================
# ** Sprite_Energy_Bar
#------------------------------------------------------------------------------
# Â This sprite is used to display the energy bar.
#==============================================================================
Â
class Sprite_Energy_Bar < Sprite
 #--------------------------------------------------------------------------
 # * Object Initialization
 #--------------------------------------------------------------------------
 def initialize
  super
  self.bitmap = Bitmap.new(120, 24)
  self.bitmap.font.name = "Arial"
  self.bitmap.font.size = 22
  self.x = 520
  self.y = 0
  self.z = 500
  @energy = 0
  @max_energy = $game_party.max_energy
  update
 end
 #--------------------------------------------------------------------------
 # * Dispose
 #--------------------------------------------------------------------------
 def dispose
  if self.bitmap != nil
   self.bitmap.dispose
  end
  super
 end
 #--------------------------------------------------------------------------
 # * Frame Update
 #--------------------------------------------------------------------------
 def update
  super
  # Set energy bar to visible if working
  self.visible = $game_system.energy_bar == 1
  # If energy bar needs to be redrawn
  if self.visible
   if @energy != $game_party.energy
    @energy = $game_party.energy
    # Clear window contents
    self.bitmap.clear
    # Draw energy bar
    self.bitmap.font.color.set(255, 255, 255)
    self.bitmap.draw_text(self.bitmap.rect, "E")
    full = @energy * 100 / @max_energy
    black = Color.new(0,0,0)
    green = Color.new(0,255,0)
    self.bitmap.fill_rect(18, 8, 102, 8, black)
    self.bitmap.fill_rect(19, 9, full, 6, green)
   end
  end
 end
end
Â
#==============================================================================
# ** Spriteset_Map
#------------------------------------------------------------------------------
# Â This class brings together map screen sprites, tilemaps, etc.
# Â It's used within the Scene_Map class.
#==============================================================================
Â
class Spriteset_Map
 alias topdod_init initialize
 alias topdod_dispose dispose
 alias topdod_update update
 def initialize
  @energy_bar = Sprite_Energy_Bar.new
  topdod_init
 end
 def dispose
  topdod_dispose
  @energy_bar.dispose
 end
 def update
  topdod_update
  @energy_bar.update
 end
end
Â