Jump to content
Simba451

Zelda Hearts System Script

Recommended Posts

Hi,

 

I'm new here, so forgive me for any "noobish" things I do.

 

Anyways, I've been trying to recreate the heart system found in the Legend of Zelda series and I came across this script:

 

 

# By Pyro17 : http://www.rpgmakervxace.net/topic/14566-zelda-hearts-system/#entry100293

# bitmap file must placed into Graphics/System/Hud
 
module Cache
  #--------------------------------------------------------------------------
  # * Gets Gauge Graphics
  #--------------------------------------------------------------------------
  def self.hud(filename, hue=0)
    load_bitmap("Graphics/System/Hud/", filename, hue)
  end
end
 
class ZeldaHearts < Window_Base
  #--------------------------------------------------------------------------
  # * Changeable Area
  #--------------------------------------------------------------------------
 
  # Enter your switch number here
  def switch
    1
  end
 
  def hud_x
    0
  end
 
  def hud_y
    0
  end
 
  def hud_width
    400
  end
 
  def hud_height
    240
  end
 
  def heart_padding
    3
  end
 
  def heart_row
    10
  end
 
  def hp_per_heart
    100
  end
 
  def heart_pieces
    4
  end
 
  #--------------------------------------------------------------------------
  # * Fixed Area
  #--------------------------------------------------------------------------
 
  # Constructor. Loads the image and draws the gauge if switch is on
  # TODO: add input arguments for coordinates (and maybe width/height ?)
  def initialize
    super(hud_x, hud_y, hud_width, hud_height)
    self.windowskin = nil
   
    @switch = $game_switches[switch]
    @bitmaps = Array.new(heart_pieces + 1)
   
    if @switch
      for i in 0..heart_pieces
        @bitmaps = Cache.hud("hearts" + i.to_s + ".png")
      end
     
      draw_hearts
    end
  end
 
 
  def draw_hearts
    @lhearts = @hearts
    @lmaxHearts = @maxHearts
   
    # Gets the number of hearts to draw depending on the HP
    @hearts = calc_hearts(get_hp)
   
    # Gets the max number of hearts depending on the HP max
    @maxHearts = calc_hearts(get_maxhp).to_i
   
    fullHearts = @hearts.to_i
    partHearts = @hearts - fullHearts
    i = 0
   
    if fullHearts
      for i in 0..@maxHearts-1 do
        # Draws full hearts
        if i < fullHearts
          get_heart_image(i, heart_pieces)
        # Draws the pieces of he last filled heart
        elsif i == fullHearts
          get_heart_image(i, (partHearts*heart_pieces).round(0))
        # Draws empty hearts
        else
          get_heart_image(i,0)
        end
      end
    end
  end
 
  # Fills hearts piece by piece (yeah, this sounds weird)
  def get_heart_image(heartIndex, fileIndex)
    bitmap = @bitmaps[fileIndex]
    posx = heartIndex.modulo(heart_row) * (bitmap.width + heart_padding)
    posy = (heartIndex/heart_row) * (bitmap.height + heart_padding)
   
    contents.blt(posx, posy, bitmap, Rect.new(0, 0, bitmap.width, bitmap.height), 255)
  end
 
  def get_hp
    $game_party.members[0].hp
  end
 
  def get_maxhp
    $game_party.members[0].mhp
  end
 
  # Gets the number of filled hearts based on the HP, rounded to 2 decimals.
  # e.g. if max HP is 97 and max hearts is 5, if current HP is 75 then we'll have 3.87 hearts filled (97 * 5 / 75 = 3.8659...)
  def calc_hearts(hp)
    Float hearts = hp.to_f / hp_per_heart
    hearts.round(2)
  end
 
  def refresh
    contents.clear
    draw_hearts
  end
 
  # Overrides Windows_Base's update.
  def update
    super
    if @switch
      refresh
    end
  end
 
  # Overrides Windows_Base's dispose. Basically destroys used resources.
  def dispose
    super
    for b in @bitmaps
      if !b.nil?
        b.dispose
      end
    end
  end
end
 
class Scene_Map < Scene_Base
  alias start_window start
  alias term_window terminate
  alias update_window update
 
  attr_reader :hearthud
 
  def start
    start_window
    @hearthud = ZeldaHearts.new
    update
  end
 
  def terminate
    @hearthud.dispose
    term_window
  end
 
  def update
    update_window
    @hearthud.update
  end
end
 
 

# TODO: Scene_Battle override

 

 

Everything works out fine. The script draws out the hearts perfectly (files are in attachments), but whenever my actor receives damage, the hearts remain unchanged.

 

Also, I am using the following additional scripts:

 

1) Pearl ABS Liquid V2 (can be found here)

2) Yanfly Save Engine (can be found here)

3) Script by Gambit.

 

 

if $imported["YEA-SaveEngine"]

#==============================================================================
# ?! Window_FileStatus
#==============================================================================
 
class Window_FileStatus < Window_Base
  
  #--------------------------------------------------------------------------
  # refresh
  #--------------------------------------------------------------------------
  def refresh
    contents.clear
    reset_font_settings
    @hearthud.dispose if @hearthud
    @header = DataManager.load_header(@file_window.index)
    p @header
    if @header.nil?
      draw_empty
    else
      draw_save_contents
    end
  end
  
  #--------------------------------------------------------------------------
  # draw_save_characters
  #--------------------------------------------------------------------------
  def draw_save_characters(dx, dy)
    return if @header[:party].nil?
    reset_font_settings
    make_font_smaller
    dw = (contents.width - dx) / @header[:party].max_battle_members
    dx += dw/2
    for member in @header[:party].battle_members
      next if member.nil?
      member = @header[:actors][member.id]
      change_color(normal_color)
      draw_actor_graphic(member, dx, dy)
      text = member.name
      draw_text(dx-dw/2, dy, dw, line_height, text, 1)
      if member.id == 1
        @hearthud = ZeldaHearts.new(member.hp, member.mhp)
        @hearthud.x = self.x + standard_padding + dx-dw/2
        @hearthud.y = self.y + standard_padding + dy + line_height / 2
      end
      text = member.level.group
      draw_text(dx-dw/2, dy-line_height, dw-4, line_height, text, 2)
      cx = text_size(text).width
      change_color(system_color)
      text = Vocab::level_a
      draw_text(dx-dw/2, dy-line_height, dw-cx-4, line_height, text, 2)
      dx += dw
    end
  end
  
  #--------------------------------------------------------------------------
  # dispose
  #--------------------------------------------------------------------------
  def dispose
    @hearthud.dispose if @hearthud
    super
  end
end # Window_FileStatus
 
class ZeldaHearts < Window_Base
  
  def initialize(save_hp = false, save_mhp = false)
    super(hud_x, hud_y, hud_width, hud_height)
    self.windowskin = nil
    @bitmaps = Array.new(heart_pieces + 1)
    for i in 0..heart_pieces
      @bitmaps = Cache.hud("hearts" + i.to_s + ".png")
    end
    @save_hp, @save_mhp = save_hp, save_mhp
    draw_hearts
  end
  
  def get_hp
    !@save_mhp ? $game_party.members[0].hp : @save_hp
  end
 
  def get_maxhp
    !@save_mhp ? $game_party.members[0].mhp : @save_mhp
  end
end

end

 

 

Basically what I'm asking here, is why don't the hearts disappear when my actor loses hp?

 

post-34731-0-08329900-1381195252.png

post-34731-0-55424700-1381195223.png

post-34731-0-15337000-1381195223.png

post-34731-0-70624300-1381195222.png

post-34731-0-22053600-1381195222.png

Share this post


Link to post
Share on other sites

I was browsing mog scripts looking for a hud and found this,I hope you find this useful!  (Just scroll down or Ctrn+F Zelda)

Share this post


Link to post
Share on other sites

I was browsing mog scripts looking for a hud and found this,I hope you find this useful!  (Just scroll down or Ctrn+F Zelda)

As nice as this looks, there are a couple things wrong with it:

 

1) It's in Portugese, so I can't read about 90% of it. Even if I could put it in google translate, there's no guarantee that the information would be completely accurate.

 

2) The script uses whole hearts and not half hearts. Traditionally, in Zelda games, the player loses hp in increments of 1/2 a heart.

 

EDIT: Wow, do I feel stupid! At the bottom of the first script I posted it says:

 

def update

update_window

@hearthud.update

end

end

 

Really, it should say this:

 

def update

update_window

@hearthud.refresh

end

end

 

This can be closed now

Edited by Simba451

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

  • Recently Browsing   0 members

    No registered users viewing this page.

×