8-16bit Zelda Hearts for Blizz ABS?

Started by shintashi, October 07, 2012, 12:32:49 am

Previous topic - Next topic

shintashi

Hi!

I want to be able to modify the ABS health display so it displays zelda style hearts in place of a standard life bar. I wanted to begin with 3 hearts, and have each heart represent approximately 100 hit points, with something like half a heart being 50 hit points. Basically, I want the computer to round to the nearest block of 50 and display half and whole hearts in red (healthy/fill) and pink (injured/unfilled). Every 50 hit points or fraction thereof would be another heart segment displayed, in rows of 10 hearts per 1000 hit points.

Each heart would be around 12-24 pixels wide/tall with minimal spacing so a full row of 10 might be 1/5th to 1/3rd of the screen width. It's been a while since I tried importing pictures, but it may be possible with draw tools and fill (I'm not proficient at this and never was good at programmed drawing).

I believe this code below is part of the section that would be amended:

Spoiler: ShowHide
#----------------------------------------------------------------------------
 # create_health_sprite
 #  Creates a health sprite.
 #----------------------------------------------------------------------------
 def create_health_sprite
   # if health bars active and observing enemy
   if BlizzABS::Config::ENEMY_HEALTH_BARS > 0 &&
       @character.is_a?(Map_Enemy) && !@character.hide_health &&
       @character.opacity > 0
     # create a sprite
     @health = Sprite.new(@viewport)
     # whether ENEMY_HEALTH_BARS_MATCH_WIDTH is active and tile graphic
     if @character.tile_id < 384 &&
         BlizzABS::Config::ENEMY_HEALTH_BARS_MATCH_WIDTH
       # set the width
       width = @sprite.bitmap.width / 4
     else
       # set the width to default
       width = 32
     end
     # x offset
     @health.ox = width / 2
     # create bitmap
     @health.bitmap = Bitmap.new(width, 6)
     # fill bitmap background for better display
     @health.bitmap.fill_rect(0, 0, width, 6, Color.new(0, 26, 0))
     # set health bar z coordinate
     @health.z = 1
     # set health bar opacity
     @health.opacity = BlizzABS::Config::ENEMY_HEALTH_BARS
   end
 end
 #----------------------------------------------------------------------------
 # update_health
 #  Handles health sprite updating.
 #----------------------------------------------------------------------------
 def update_health
   # move health sprite along with sprite
   @health.x = @sprite.x
   @health.y = @sprite.y - @sprite.oy - 6
   @health.z = @sprite.z + 1
   # if enemy HP have changed
   if @hp != @character.battler.hp || @battler_id != @character.battler_id
     # rate of filling
     rate = @character.battler.hp.to_f / @character.battler.maxhp
     # get empty bar bitmap
     bitmaps = [$BlizzABS.cache.image('empty_enemy_bar'),
         $BlizzABS.cache.image('enemy_bar')]
     # change hue of bar bitmap
     bitmaps[1].hue_change((rate / 0.8 - 1.25) * 120)
     # temporary variable
     width = @health.bitmap.width - 2
     # draw empty bar bitmap
     @health.bitmap.stretch_blt(Rect.new(1, 0, width, 6), bitmaps[0],
         Rect.new(0, 0, 1, 6))
     # draw bar bitmap
     @health.bitmap.stretch_blt(Rect.new(1, 0, rate * width, 6), bitmaps[1],
         Rect.new(0, 0, 1, 6))
     # store new values
     @hp, @battler_id = @character.battler.hp, @character.battler_id
   end
 end



Zexion

To be honest it would be WAY simpler to just event something like this, and disable the default hud with blizz-abs. You could try that z-hud script, but even then events would just be easier because it wouldn't require scripting at all.
BTW if you are making a zelda game, you might want to check out the Project Zelda starter kit.

G_G


shintashi

Quote from: gameus on October 07, 2012, 01:23:41 am
It's called Z-Hud.
http://forum.chaos-project.com/index.php/topic,4284.0.html


i installed it and created icons, reset my hit points to discretionary blocks of 100 (300hp = 3 hearts), and all that works,
but is there a way to set it up so the hit point containers themselves drain from right to left, instead of top to bottom?

I tried messing with the parameters below, but only got a bunch of different kinds of mess.
Spoiler: ShowHide


  def draw_hp
    @hp, @maxhp = actor.hp, actor.maxhp
    rate = (@maxhp > 0 ? @hp.to_f / @maxhp : 0)
    b1 = RPG::Cache.picture(BlizzCFG::Z_HP_FILE)
    b2 = RPG::Cache.picture(BlizzCFG::Z_HP_FILE_EMPTY)
    if BlizzCFG::Z_HP_TILING
      tiles = @maxhp / BlizzCFG::Z_HP_PER_TILE
      rows = (tiles.to_f / BlizzCFG::Z_HP_TILE_COLUMNS).ceil
      w, h = b1.width, b1.height
      self.bitmap.fill_rect(@hp_x, @hp_y, w * BlizzCFG::Z_HP_TILE_COLUMNS,
          h * rows, Color.new(0, 0, 0, 0))
      full_tiles = (rate * tiles).to_i
      semi_full = ((rate * tiles != full_tiles) ? 1 : 0)
      (0...full_tiles).each {|i|
          x = @hp_x + (i % BlizzCFG::Z_HP_TILE_COLUMNS) * w
          y = @hp_y + (i / BlizzCFG::Z_HP_TILE_COLUMNS) * h
          self.bitmap.blt(x, y, b1, Rect.new(0, 0, w, h))}
      if semi_full > 0
        x = @hp_x + (full_tiles % BlizzCFG::Z_HP_TILE_COLUMNS) * w
        y = @hp_y + (full_tiles / BlizzCFG::Z_HP_TILE_COLUMNS) * h
        if BlizzCFG::Z_HP_FILL_UP
          h2 = ((1 - rate * tiles + full_tiles) * h).to_i
          self.bitmap.blt(x, y, b2, Rect.new(0, 0, w, h2))
          self.bitmap.blt(x, y + h2, b1, Rect.new(0, h2, w, h - h2))
        else
          w2 = ((rate * tiles - full_tiles) * w).to_i
          self.bitmap.blt(x, y, b1, Rect.new(0, 0, w2, h))
          self.bitmap.blt(x + w2, y, b2, Rect.new(w2, 0, w - w2, h))
        end
      end
      ((full_tiles + semi_full)...tiles).each {|i|
          x = @hp_x + (i % BlizzCFG::Z_HP_TILE_COLUMNS) * w
          y = @hp_y + (i / BlizzCFG::Z_HP_TILE_COLUMNS) * h
          self.bitmap.blt(x, y, b2, Rect.new(0, 0, w, h))}
    else
      w1 = (b1.width * rate).to_i
      w2 = b2.width - w1
      self.bitmap.fill_rect(@hp_x, @hp_y, b1.width, b1.height, Color.new(0, 0, 0, 0))
      self.bitmap.blt(@hp_x, @hp_y, b1, Rect.new(0, 0, w1, b1.height))
      self.bitmap.blt(@hp_x + w1, @hp_y, b2, Rect.new(w1, 0, w2, b2.height))
    end
    draw_sp
  end



shintashi

Quote from: shintashi on October 08, 2012, 05:12:22 pm
Quote from: gameus on October 07, 2012, 01:23:41 am
It's called Z-Hud.
http://forum.chaos-project.com/index.php/topic,4284.0.html


i installed it and created icons, reset my hit points to discretionary blocks of 100 (300hp = 3 hearts), and all that works,
but is there a way to set it up so the hit point containers themselves drain from right to left, instead of top to bottom?

I tried messing with the parameters below, but only got a bunch of different kinds of mess.
Spoiler: ShowHide


  def draw_hp
    @hp, @maxhp = actor.hp, actor.maxhp
    rate = (@maxhp > 0 ? @hp.to_f / @maxhp : 0)
    b1 = RPG::Cache.picture(BlizzCFG::Z_HP_FILE)
    b2 = RPG::Cache.picture(BlizzCFG::Z_HP_FILE_EMPTY)
    if BlizzCFG::Z_HP_TILING
      tiles = @maxhp / BlizzCFG::Z_HP_PER_TILE
      rows = (tiles.to_f / BlizzCFG::Z_HP_TILE_COLUMNS).ceil
      w, h = b1.width, b1.height
      self.bitmap.fill_rect(@hp_x, @hp_y, w * BlizzCFG::Z_HP_TILE_COLUMNS,
          h * rows, Color.new(0, 0, 0, 0))
      full_tiles = (rate * tiles).to_i
      semi_full = ((rate * tiles != full_tiles) ? 1 : 0)
      (0...full_tiles).each {|i|
          x = @hp_x + (i % BlizzCFG::Z_HP_TILE_COLUMNS) * w
          y = @hp_y + (i / BlizzCFG::Z_HP_TILE_COLUMNS) * h
          self.bitmap.blt(x, y, b1, Rect.new(0, 0, w, h))}
      if semi_full > 0
        x = @hp_x + (full_tiles % BlizzCFG::Z_HP_TILE_COLUMNS) * w
        y = @hp_y + (full_tiles / BlizzCFG::Z_HP_TILE_COLUMNS) * h
        if BlizzCFG::Z_HP_FILL_UP
          h2 = ((1 - rate * tiles + full_tiles) * h).to_i
          self.bitmap.blt(x, y, b2, Rect.new(0, 0, w, h2))
          self.bitmap.blt(x, y + h2, b1, Rect.new(0, h2, w, h - h2))
        else
          w2 = ((rate * tiles - full_tiles) * w).to_i
          self.bitmap.blt(x, y, b1, Rect.new(0, 0, w2, h))
          self.bitmap.blt(x + w2, y, b2, Rect.new(w2, 0, w - w2, h))
        end
      end
      ((full_tiles + semi_full)...tiles).each {|i|
          x = @hp_x + (i % BlizzCFG::Z_HP_TILE_COLUMNS) * w
          y = @hp_y + (i / BlizzCFG::Z_HP_TILE_COLUMNS) * h
          self.bitmap.blt(x, y, b2, Rect.new(0, 0, w, h))}
    else
      w1 = (b1.width * rate).to_i
      w2 = b2.width - w1
      self.bitmap.fill_rect(@hp_x, @hp_y, b1.width, b1.height, Color.new(0, 0, 0, 0))
      self.bitmap.blt(@hp_x, @hp_y, b1, Rect.new(0, 0, w1, b1.height))
      self.bitmap.blt(@hp_x + w1, @hp_y, b2, Rect.new(w1, 0, w2, b2.height))
    end
    draw_sp
  end





never mind, if i set 'tile fill up" to false, it fills sideways like I wanted :)