[XP] Drago Growing Hud

Started by LiTTleDRAgo, March 20, 2013, 03:57:54 am

Previous topic - Next topic

LiTTleDRAgo

March 20, 2013, 03:57:54 am Last Edit: March 21, 2013, 09:00:02 am by LiTTleDRAgo
Drago Growing Hud
Authors: LiTTleDRAgo
Version: 1.00
Type: Misc Add-on
Key Term: Misc Add-on



Introduction

The hud bar will increase if player maxhp or maxsp is increased


Features


  • Screenshot can explain




Screenshots

Spoiler: ShowHide

Spoiler: ShowHide



Demo

Here


Instructions

Image needed in the demo


Compatibility

~


Credits and Thanks


  • LiTTleDRAgo




Author's Notes

Enjoy ~

Josey

Hi! :D

I would be very happy if there were still a possibility that the face changes depending on the HP stand.
Perhaps at 75%, 50%, 25% and 10%.
Would that be difficult to incorporate?

Best regards!

KK20

Replace entire script:
Spoiler: ShowHide

#==============================================================================
# DRG - Growing Hud
# Version : 1.00
# Author : LiTTleDRAgo
#==============================================================================
module LiTTleDRAgo
 
  HUD_POSITION       = [5,425]   # X and Y
  HUD_PRIORITY       = 1         # Hud Z
  DISABLE_HUD_SWITCH = 5         # Switch to disable hud
                                 # (enter false if there aren't)
  LAYOUT_IMAGE       = "Layout Wing"
 
end
#==============================================================================
# ** Spriteset_Map
#------------------------------------------------------------------------------
#  This class brings together map screen sprites, tilemaps, etc.
#  It's used within the Scene_Map class.
#==============================================================================
class Spriteset_Map
  #--------------------------------------------------------------------------
  # * Alias Listing
  #--------------------------------------------------------------------------
  unless method_defined?(:drg2032013_update)
    alias drg2032013_update update
    alias drg2032013_dispose dispose
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    drg2032013_update
    @hp_sprite.nil? ? create_hud : update_hud
  end
  #--------------------------------------------------------------------------
  # * Dispose
  #--------------------------------------------------------------------------
  def dispose
    drg2032013_dispose
    dispose_hud
  end
  #--------------------------------------------------------------------------
  # * dispose_hud
  #--------------------------------------------------------------------------
  def dispose_hud
    [@hud_face,@hp_sprite,@sp_sprite,@states,
    @hp_number_sprite,@sp_number_sprite].each {|s|s.dispose}
  end
  #--------------------------------------------------------------------------
  # * create_hud
  #--------------------------------------------------------------------------
  def create_hud
    @party_leader = $game_party.actors[0]
    return if @party_leader.nil?
    create_hud_face
    create_hp_meter
    create_hp_number
    create_sp_meter
    create_sp_number
    create_state
    update_visible_hud(false)
  end
  #--------------------------------------------------------------------------
  # * update_hud
  #--------------------------------------------------------------------------
  def update_hud
    return if @party_leader.nil?
    hp_flow_update
    hp_number_update
    sp_flow_update
    sp_number_update
    update_max_hp
    update_visible_hud
    update_states
  end
  #--------------------------------------------------------------------------
  # * Update States
  #--------------------------------------------------------------------------
  def update_states
      if @states_x != @party_leader.states.size
         @states_x = @party_leader.states.size
         @states.bitmap.clear
         @states_max = 0
         sta = []
         for i in @party_leader.states
           unless @states_max > 5
             sta.push($data_states[i].name)
             image = RPG::Cache.icon(sta[@states_max]) rescue RPG::Cache.icon('')
             cw = image.width
             ch = image.height
             @states.bitmap.blt(26 * @states_max, 0, image, Rect.new(0, 0, cw, ch))
             @states_max += 1
           end
         end 
       sta = nil
     end
   end
  #--------------------------------------------------------------------------
  # * update_max_hp
  #--------------------------------------------------------------------------
  def update_max_hp
    if @party_leader != $game_party.actors[0]
      dispose_hud
      create_hud
      return if @party_leader.nil?
    end
    if @maxhp_old != @party_leader.maxhp
      @maxhp_old = @party_leader.maxhp
      @hp_sprite.dispose
      create_hp_meter
      create_hud_face
    end
    if @maxsp_old != @party_leader.maxsp
      @maxsp_old = @party_leader.maxsp
      @sp_sprite.dispose
      create_sp_meter
    end
  end
  #--------------------------------------------------------------------------
  # * update_max_hp
  #--------------------------------------------------------------------------
  def update_visible_hud(value=nil)
    visible = hud_visible?
    visible = value if !value.nil?
    @hud_face.visible =
    @hp_sprite.visible =
    @sp_sprite.visible =
    @states.visible =
    @hp_number_sprite.visible =
    @sp_number_sprite.visible = visible
  end
  #--------------------------------------------------------------------------
  # * hud_visible?
  #-------------------------------------------------------------------------- 
  def hud_visible?
    sw = LiTTleDRAgo::DISABLE_HUD_SWITCH
    sw = sw.is_a?(Integer) ? $game_switches[sw] : false
    return false if $game_system.map_interpreter.running?
    return false if sw
    return true
  end
  #--------------------------------------------------------------------------
  # * Create State
  #--------------------------------------------------------------------------             
  def create_state
       @states_max = 0
       @states = Sprite.new
       @states.bitmap = Bitmap.new(156,24)
       @states_x = @party_leader.states.size
       @states_y = 0
       @states_f = false
       sta = []
       for i in @party_leader.states
          unless @states_max > 5
              sta.push($data_states[i].name)
              image = RPG::Cache.icon(sta[@states_max]) rescue RPG::Cache.icon('')
              cw = image.width
              ch = image.height
              @states.bitmap.blt(26 * @states_max, 0, image, Rect.new(0, 0, cw, ch))
              @states_max += 1
          end
       end 
       @states.x = @hp_sprite.x
       @states.y = @hp_sprite.y - 30
       @states.z = @hp_sprite.z             
   end 
  #--------------------------------------------------------------------------
  # * create_hud_face
  #-------------------------------------------------------------------------- 
  def create_hud_face
    @hud_face = Sprite.new
    bitmap_file = "Hud_Face#{@party_leader.id}"
    hp = @party_leader.hp * 100 / @party_leader.maxhp
    hp_name = case hp
              when 0..10 then "_10"
              when 11..25 then "_25"
              when 26..50 then "_50"
              when 51..75 then "_75"
              else
                ""
              end
    @face = RPG::Cache.windowskin(bitmap_file + hp_name) rescue RPG::Cache.windowskin(bitmap_file)
    lay = RPG::Cache.windowskin(LiTTleDRAgo::LAYOUT_IMAGE)
    text = RPG::Cache.windowskin("HP Text")
    @hud_face.bitmap = Bitmap.new(@face.height+250,@face.height+50)
    bit = Bitmap.new(200,50)
    bit.stretch_blt(bit.rect,lay,lay.rect)
    @hud_face.bitmap.blt(40,2,bit,bit.rect)
    @hud_face.bitmap.blt(5,5,@face,@face.rect)
    @hud_face.bitmap.blt(@face.height+1,8,text,text.rect)
    @hud_face.x = LiTTleDRAgo::HUD_POSITION[0]
    @hud_face.y = LiTTleDRAgo::HUD_POSITION[1]
    @hud_face.z = LiTTleDRAgo::HUD_PRIORITY
  end
  #--------------------------------------------------------------------------
  # * Create HP Number 
  #-------------------------------------------------------------------------- 
  def create_hp_number
    @hp_number_image = RPG::Cache.windowskin("Hud Number")
    @hp_number_bitmap = Bitmap.new(@hp_number_image.width,@hp_number_image.height)
    @hp_number_sprite = Sprite.new
    @hp_number_sprite.bitmap = @hp_number_bitmap
    @hp_number_sprite.x = @hp_sprite.x - 20
    @hp_number_sprite.y = @hp_sprite.y
    @hp_number_sprite.z = @hp_sprite.z + 1
    @im_cw = @hp_number_image.width / 10
    @im_ch = @hp_number_image.height / 2   
    @hp_src_rect = Rect.new(@im_cw,0, @im_cw, @im_ch)
    @hp_number_text = @party_leader.hp.abs.to_s.split(//)
    lowhp2 = @party_leader.maxhp * 30 / 100
    if @party_leader.hp < lowhp2
      @health2 = @im_ch
    else
      @health2 = 0
    end
    @hp_health = @health2
    for r in 0..@hp_number_text.size - 1         
      @hp_number_abs = @hp_number_text[r].to_i
      @hp_src_rect = Rect.new(@im_cw * @hp_number_abs, @hp_health, @im_cw, @im_ch)
      @hp_number_bitmap.blt(20 + ((@im_cw - 7) *  r), 0, @hp_number_image, @hp_src_rect)       
    end       
  end 
  #--------------------------------------------------------------------------
  # * hp_number_update
  #--------------------------------------------------------------------------
  def hp_number_update
    return unless @hp_old != @party_leader.hp
    create_hud_face
    @hp_refresh = true
    if @hp_old.nil? || @hp_old < @party_leader.hp
      @hp_ref = 5 * (@party_leader.hp - (@hp_old||0)) / 100
      @hp_ref = 1 if @hp_ref < 1
      @hp2032013 = (@hp||10000)+@hp_ref     
      if @hp_old.nil? || @hp2032013 >= @party_leader.hp
        @hp_old = @party_leader.hp
        @hp2032013 = @party_leader.hp   
        @hp_ref = 0
        hp_number_refresh
      end             
    elsif @hp_old > @party_leader.hp   
      @hp_refresh = true
      @hp_ref = 5 * (@hp_old - @party_leader.hp) / 100
      @hp_ref = 1 if @hp_ref < 1
      @hp2032013 -= @hp_ref               
      if @hp2032013 <= @party_leader.hp
        @hp_old = @party_leader.hp
        @hp2032013 = @party_leader.hp   
        @hp_ref = 0
        hp_number_refresh
      end           
    end 
    hp_number_refresh if @hp_refresh
  end     
  #--------------------------------------------------------------------------
  # * hp_number_refresh
  #--------------------------------------------------------------------------
  def hp_number_refresh
    @hp_number_sprite.bitmap.clear
    @hp2032013 = 0 if @party_leader.hp == 0
    @hp_number_text = @hp2032013.abs.to_s.split(//)
    lowhp2 = @party_leader.maxhp * (@low_hp||30) / 100
    if @party_leader.hp < lowhp2
      @health2 = @im_ch
    else
      @health2 = 0
    end
    @hp_health = @health2
    for r in 0..@hp_number_text.size - 1         
      @hp_number_abs = @hp_number_text[r].to_i
      @hp_src_rect = Rect.new(@im_cw * @hp_number_abs, @hp_health, @im_cw, @im_ch)
      @hp_number_bitmap.blt(20 + ((@im_cw - 7) *  r), 0, @hp_number_image, @hp_src_rect)       
    end 
    @hp_refresh = false if @hp2032013 == @party_leader.hp
  end
  #--------------------------------------------------------------------------
  # * Create HP Meter
  #--------------------------------------------------------------------------   
  def create_hp_meter
    @hp_bar = RPG::Cache.windowskin("HP Bar")
    @hp_image = RPG::Cache.windowskin("HP Meter")
    @hp_bitmap = Bitmap.new(@hp_bar.width,@hp_bar.height)
    @hp_range = @hp_bar.width
    @hp_width = @hp_range  * @party_leader.hp / @party_leader.maxhp 
    @hp_height = @hp_image.height
    hp_width_old = @hp_width
    hp_src_rect = Rect.new(0, 0, @hp_width, @hp_height)
    @hp_bitmap.blt(0,0, @hp_bar, @hp_bar.rect)
    @hp_bitmap.blt(3,2, @hp_image, hp_src_rect)
    width = [(@party_leader.maxhp/10).to_i,1].max
    hp_bitmap_true = Bitmap.new(width ,@hp_bar.height)
    hp_bitmap_true.stretch_blt(hp_bitmap_true.rect,@hp_bitmap,@hp_bitmap.rect)
    @hp_sprite = Sprite.new
    @hp_sprite.bitmap = hp_bitmap_true.dup
    @hp_sprite.x = @hud_face.x + @face.width + 25
    @hp_sprite.y = @hud_face.y + 8
    @hp_sprite.z = @hud_face.z + 1
    hp_bitmap_true.dispose
  end
  #--------------------------------------------------------------------------
  # * Create HP Meter
  #--------------------------------------------------------------------------   
  def create_sp_meter
    @sp_bar = RPG::Cache.windowskin("SP Bar")
    @sp_image = RPG::Cache.windowskin("SP Meter")
    @sp_bitmap = Bitmap.new(@sp_bar.width,@sp_bar.height)
    @sp_range = @sp_bar.width
    @sp_width = @sp_range  * @party_leader.sp / @party_leader.maxsp 
    @sp_height = @sp_image.height
    sp_width_old = @sp_width
    sp_src_rect = Rect.new(0, 0, @sp_width, @sp_height)
    @sp_bitmap.blt(0,0, @sp_bar, @sp_bar.rect)
    @sp_bitmap.blt(3,2, @sp_image, sp_src_rect)
    width = [(@party_leader.maxsp/10).to_i,1].max
    sp_bitmap_true = Bitmap.new(width ,@sp_bar.height)
    sp_bitmap_true.stretch_blt(sp_bitmap_true.rect,@sp_bitmap,@sp_bitmap.rect)
    @sp_sprite = Sprite.new
    @sp_sprite.bitmap = sp_bitmap_true.dup
    @sp_sprite.x = @hp_sprite.x
    @sp_sprite.y = @hp_sprite.y + @hp_sprite.bitmap.height + 6
    @sp_sprite.z = @hud_face.z + 1
    sp_bitmap_true.dispose
  end
  #--------------------------------------------------------------------------
  # * hp_flow_update
  #--------------------------------------------------------------------------
  def hp_flow_update
    return if @hp_bar.nil?
    @hp_flow = (@hp_flow||0) + 5
    @hp_flow = 0 if @hp_flow >= @hp_range*2
    @hp_width = @hp_range  * @party_leader.hp / @party_leader.maxhp 
    if @old_hp != (100 * @party_leader.hp) / @party_leader.maxhp
      @old_hp = (100 * @party_leader.hp) / @party_leader.maxhp
      @hp_bitmap.clear
      @hp_bitmap.blt(0,0, @hp_bar, @hp_bar.rect)
      if @old_hp < 30 && !@low_hp_warn
        @low_hp_warn = true
      elsif @old_hp >= 30 && @low_hp_warn
        @low_hp_warn = false
      end
    end
    hp_src_rect = Rect.new(@hp_flow, 0, @hp_width, @hp_height)
    @hp_bitmap.blt(3,2, @hp_image, hp_src_rect) 
    @hp_sprite.bitmap.stretch_blt(@hp_sprite.bitmap.rect,@hp_bitmap,
        @hp_bitmap.rect)
  end
  #--------------------------------------------------------------------------
  # * sp_flow_update
  #-------------------------------------------------------------------------- 
  def sp_flow_update
    return if @sp_bar.nil?
    @sp_flow = (@sp_flow||0) + 5
    @sp_flow = 0 if @sp_flow >= @sp_range*2
    @sp_width = @sp_range  * @party_leader.sp / @party_leader.maxsp 
    if @old_sp != (100 * @party_leader.sp) / @party_leader.maxsp
      @old_sp = (100 * @party_leader.sp) / @party_leader.maxsp
      @sp_bitmap.clear
      @sp_bitmap.blt(0,0, @sp_bar, @sp_bar.rect)
      if @old_sp < 30 && !@low_sp_warn
        @low_sp_warn = true
      elsif @old_sp >= 30 && @low_sp_warn
        @low_sp_warn = false
      end
    end
    sp_src_rect = Rect.new(@sp_flow, 0, @sp_width, @sp_height)
    @sp_bitmap.blt(3,2, @sp_image, sp_src_rect) 
    @sp_sprite.bitmap.stretch_blt(@sp_sprite.bitmap.rect,@sp_bitmap,
        @sp_bitmap.rect)
  end
  #--------------------------------------------------------------------------
  # * Create sp Number 
  #-------------------------------------------------------------------------- 
  def create_sp_number
    @sp_number_image = RPG::Cache.windowskin("Hud Number")
    @sp_number_bitmap = Bitmap.new(@sp_number_image.width,@sp_number_image.height)
    @sp_number_sprite = Sprite.new
    @sp_number_sprite.bitmap = @sp_number_bitmap
    @sp_number_sprite.x = @sp_sprite.x - 20
    @sp_number_sprite.y = @sp_sprite.y
    @sp_number_sprite.z = @sp_sprite.z + 2
    @im_cw = @sp_number_image.width / 10
    @im_ch = @sp_number_image.height / 2   
    @sp_src_rect = Rect.new(@im_cw,0, @im_cw, @im_ch)
    @sp_number_text = @party_leader.sp.abs.to_s.split(//)
    lowsp2 = @party_leader.maxsp * 30 / 100
    if @party_leader.sp < lowsp2
      @health2 = @im_ch
    else
      @health2 = 0
    end
    @sp_health = @health2
    for r in 0..@sp_number_text.size - 1         
      @sp_number_abs = @sp_number_text[r].to_i
      @sp_src_rect = Rect.new(@im_cw * @sp_number_abs, @sp_health, @im_cw, @im_ch)
      @sp_number_bitmap.blt(20 + ((@im_cw - 7) *  r), 0, @sp_number_image, @sp_src_rect)       
    end       
  end 
  #--------------------------------------------------------------------------
  # * sp_number_update
  #--------------------------------------------------------------------------
  def sp_number_update
    return unless @sp_old != @party_leader.sp
    @sp_refresh = true
    if @sp_old.nil? || @sp_old < @party_leader.sp
      @sp_ref = 5 * (@party_leader.sp - (@sp_old||0)) / 100
      @sp_ref = 1 if @sp_ref < 1
      @sp2032013 = (@sp||10000)+@sp_ref     
      if @sp_old.nil? || @sp2032013 >= @party_leader.sp
        @sp_old = @party_leader.sp
        @sp2032013 = @party_leader.sp   
        @sp_ref = 0
        sp_number_refresh
      end             
    elsif @sp_old > @party_leader.sp   
      @sp_refresh = true
      @sp_ref = 5 * (@sp_old - @party_leader.sp) / 100
      @sp_ref = 1 if @sp_ref < 1
      @sp2032013 -= @sp_ref               
      if @sp2032013 <= @party_leader.sp
        @sp_old = @party_leader.sp
        @sp2032013 = @party_leader.sp   
        @sp_ref = 0
        sp_number_refresh
      end           
    end 
    sp_number_refresh if @sp_refresh
  end     
  #--------------------------------------------------------------------------
  # * sp_number_refresh
  #--------------------------------------------------------------------------
  def sp_number_refresh
    @sp_number_sprite.bitmap.clear
    @sp2032013 = 0 if @party_leader.sp == 0
    @sp_number_text = @sp2032013.abs.to_s.split(//)
    lowsp2 = @party_leader.maxsp * (@low_sp||30) / 100
    if @party_leader.sp < lowsp2
      @health2 = @im_ch
    else
      @health2 = 0
    end
    @sp_health = @health2
    for r in 0..@sp_number_text.size - 1         
      @sp_number_abs = @sp_number_text[r].to_i
      @sp_src_rect = Rect.new(@im_cw * @sp_number_abs, @sp_health, @im_cw, @im_ch)
      @sp_number_bitmap.blt(20 + ((@im_cw - 7) *  r), 0, @sp_number_image, @sp_src_rect)       
    end 
    @sp_refresh = false if @sp2032013 == @party_leader.sp
  end
end

You can find where I made the changes to the HP intervals in the create_hud_face method. All you need to do is make the face graphics have names like Hud_Face1_50 to distinguish between the intervals. Currently, the intervals are set up to accept _10, _25, _50, and _75 as per requested.





   


   
   


   
   

Other Projects
RPG Maker XP AceUpgrade RMXP to RMVXA performance!
XPA TilemapTilemap rewrite with many features, including custom resolution!



Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Josey

April 17, 2016, 03:05:36 am #3 Last Edit: May 05, 2016, 06:30:51 pm by Josey
Awsome! :D
Thank you so much!
It is exactly as I had imagined! :D
(I use still the Google Translator _._)


I do not know if it's a bug, I have noticed until now. If you HP or SP increased or decreased and in the same event (action button or player touch -> http://www.fotos-hochladen.net/view/event2szvpox4me.png) is a wait, the graphics disappear for a moment. o.o (In a PP-Event the graphics dont disappear, despite a wait)
I hope, you understand my very bad english. XD°


Thank you! :3


Edit: There is another bug.
If I use a state which removes an other, the old still displayed in the HUD and the new not. Only when I call the menu and go back again to the map, the correct icon appears. A scriptcall "game_map_refresh" has not helped. :/


Its done :3