Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

==Really== Simple HUD request

I need a HUD that's like this:

--------------------------------------
' (Name of the first actor in party)
' (current hp) / (max hp)
' (current sp) / (max sp)
' (currency name) (amount)
'--------------------------------------

Nothing flashy, just this.

It should be in the lower right corner, using the windowskin usd by the game.
Thank you very much.

I tried using some other huds but they are too complicated for what I need.
 

arev

Sponsor

Here, paste this code in a new tab over the "Main":
Code:
class Window_HUD < Window_Base
  def initialize
    super(468,368,176,112)
    self.contents = Bitmap.new(140,80)
    self.contents.font.size = 20
    self.back_opacity = 160
    refresh
  end
  def refresh
    self.contents.clear
    @actor = $game_party.actors[0]
    self.contents.draw_text(4,0,132,20,@actor.name.to_s,1)
    draw_actor_hp(@actor,4,16)
    draw_actor_sp(@actor,4,36)
    self.contents.draw_text(4,60,132,20,$game_party.gold.to_s,2)
    self.contents.draw_text(4,60,132,20,$data_system.words.gold + ":")
  end
end
class Scene_Map
  alias hud_main main
  alias hud_update update
  def main
    @hud = Window_HUD.new
    hud_main
    @hud.dispose
  end
  def update
    @hud.refresh
    hud_update
  end
end
 
That could cause lag though because you are updating every frame.

It would be a little better if you didn't ever call refresh every frame. That should reserved for update. Instead, in the update method, you should check flags. If they are different, then call the refresh method. In the refresh method, save your flags. That's it.
 
Thank you very much, both of you.
I'm not going to have a lag problem, the hud is actually for a menu-map.

One more thing, please. Hoe could I turn the HUD on or off? I tried to mimic the way Blizzard did it in his tons of addons, but object oriented languages aren't my best point...
 

arev

Sponsor

@SS: I'm well aware of what you've said. I just dont think that drawing that little data will really have some effect on the FPS. Sure, it's really good when it comes to more complex content (gradient bars and stuff), but with something like this I felt I could just let it go :]
@Ravenith: I could make it so the HUD hides/shows after a certain button is pressed, or a switch is ON/OFF. Which one would you prefer? I'd recommend the switch, as it comes handy in the cutscenes.
 

arev

Sponsor

Code:
class Window_HUD < Window_Base
  def initialize
    super(640,480,176,112)
    self.contents = Bitmap.new(140,80)
    self.contents.font.size = 20
    self.back_opacity = 160
    refresh
  end
  def refresh
    self.contents.clear
    @actor = $game_party.actors[0]
    self.contents.draw_text(4,0,132,20,@actor.name.to_s,1)
    draw_actor_hp(@actor,4,16)
    draw_actor_sp(@actor,4,36)
    self.contents.draw_text(4,60,132,20,$game_party.gold.to_s,2)
    self.contents.draw_text(4,60,132,20,$data_system.words.gold + ":")
  end
end
class Scene_Map
  alias hud_main main
  alias hud_update update
  def main
    @hud = Window_HUD.new
    hud_main
    @hud.dispose
  end
  def update
    @hud.refresh
    if $game_switches[1] and @hud.x > 468
      @hud.x -= 11
      @hud.y -= 7
    end
    if $game_switches[1] == false and @hud.x < 640
      @hud.x += 11
      @hud.y += 7
    end
    hud_update
  end
end
Toggle Switch 1 to show/hide the window : )

p.s. Is this for the DEA? It looks promissing ; )
 
Mind if I ask something in here?
*asks question before anyone could answer, lol*

Can I have that HUD but showing all four members, and is it possible have it show up during certain points in the game? (something to open and disable it basically)
Thanks.
P.S: Sorry, I didn't want to make an extra thread since this is somewhat what I'm looking for.
 

arev

Sponsor

For all party members I have something like this:
Code:
class Window_HUD < Window_Base
  attr_reader :origin
  attr_reader :hide
  def initialize(act=0)
    @act = act
    @hide = -160 + @act*240
    @origin = @act*160
    super(@act*160,0,160,96)
    self.contents = Bitmap.new(128,64)
    self.contents.font.size = 20
    self.back_opacity = 160
    if $game_switches[1] == false
      self.x = @hide
      self.y = -128
    end
    @hp = 0
    @sp = 0
    @maxhp = 0
    @maxsp = 0
    @name = ""
    refresh
  end
  def refresh
    @actor = $game_party.actors[@act]
    return unless (@hp != @actor.hp or @sp != @actor.sp or @maxhp != @actor.maxhp or @maxsp !=@actor.maxsp or @name != @actor.name)
    self.contents.clear
    self.contents.font.bold = true
    self.contents.fill_rect(0,38,128,4,Color.new(224,224,224))
    self.contents.fill_rect(1,39,126,2,Color.new(32,32,32))
    self.contents.fill_rect(0,60,128,4,Color.new(224,224,224))
    self.contents.fill_rect(1,61,126,2,Color.new(32,32,32))
    life = 126 * @actor.hp / @actor.maxhp
    self.contents.fill_rect(1,39,life,2,Color.new(255,128,128))
    mana = 126 * @actor.sp / @actor.maxsp
    self.contents.fill_rect(1,61,mana,2,Color.new(128,128,255))
    self.contents.font.color = Color.new(0,0,0)
    self.contents.draw_text(1,1,128,20,@actor.name.to_s,1)
    self.contents.draw_text(1,23,128,20,$data_system.words.hp)
    self.contents.draw_text(1,45,128,20,$data_system.words.sp)
    self.contents.draw_text(1,23,128,20,@actor.hp.to_s + "/" + @actor.maxhp.to_s,2)
    self.contents.draw_text(1,45,128,20,@actor.sp.to_s + "/" + @actor.maxsp.to_s,2)
    self.contents.font.color = system_color
    self.contents.draw_text(0,22,128,20,$data_system.words.hp)
    self.contents.draw_text(0,44,128,20,$data_system.words.sp)
    self.contents.font.color = Color.new(255,255,255)
    self.contents.font.color = Color.new(255,255,255)
    self.contents.draw_text(0,0,128,20,@actor.name.to_s,1)
    self.contents.draw_text(0,22,128,20,@actor.hp.to_s + "/" + @actor.maxhp.to_s,2)
    self.contents.draw_text(0,44,128,20,@actor.sp.to_s + "/" + @actor.maxsp.to_s,2)
    @hp = @actor.hp
    @sp = @actor.sp
    @maxhp = @actor.maxhp
    @maxsp =@actor.maxsp
    @name = @actor.name
  end
end
class Scene_Map
  alias hud_main main
  alias hud_update update
  def main
    @huds = []
    for i in 0..$game_party.actors.size-1
      @huds << Window_HUD.new(i)
    end
    hud_main
    @huds.each{ |h| h.dispose}
  end
  def update
    @huds.each{ |h| h.refresh}
    if $game_switches[1] and @huds[0].x < 0
      @huds.each{ |h|
        h.x += (h.origin-h.hide)/16
        h.y += 8}
    end
    if $game_switches[1] == false and @huds[0].x >= -160
      @huds.each{ |h|
        h.x -= (h.origin-h.hide)/16
        h.y -= 8}
      end
    hud_update
  end
end

Shows/hides with switch #1.
Good enough?
 
Thanks Raziel....wait, Raziel?....RAZIEL!!! (lol, I was having a problem with downloading something...go to your HP Bar thread)

Err...sorry about that...lol

EDIT: It works pretty well so far, but is it possible to replace the sprites with the battler graphics? (or will this slow it down...I hope not, lol)
 
Nah, it shouldn't slow down a bit. :p
Here's the code:

Code:
#==============================================================================
# ** Hud Menu
#==============================================================================
# Raziel
# Version 2.0
# 2007-08-18
#------------------------------------------------------------------------------
class Window_Base
  def draw_actor_battler(actor, x, y, opacity = 255)
    battler = RPG::Cache.battler(actor.battler_name, actor.battler_hue)
    self.contents.blt(x, y, battler, Rect.new(0, 0, battler.width, battler.height), opacity)
  end
end
#===============================================================================
# * Module Raz_Hud
#===============================================================================

module Raz_Hud
  #switch to show/hide the hud
  SWITCH_ID = 1 
  #set it to true to center the hud if there are less than four party members
  Center_hud = true
end
#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
#  This class performs map screen processing.
#==============================================================================

class Scene_Map 
  #----------------------------------------------------------------------------
  # * Alias Listings
  #----------------------------------------------------------------------------
  alias raz_hud_main main 
  alias raz_hud_update update 
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main 
    @hud_dummy = [] 
    for i in 0...$game_party.actors.size
      @hud_dummy[i] = Window_Dummy.new(i)
    end 
    @hud_window = Window_HUD.new
    raz_hud_main 
    @hud_window.dispose 
    @hud_dummy.each { |hud| hud.dispose }
  end 
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update 
    @hud_dummy.each {|hud| hud.visible = $game_switches[Raz_Hud::SWITCH_ID]}
    if @hud_dummy[$game_party.actors.size] != nil
      @hud_dummy.each{|hud| hud.dispose} 
      @hud_dummy = []
      for i in 0...$game_party.actors.size
        @hud_dummy[i] = Window_Dummy.new(i)
      end 
    end
    @hud_window.update 
    raz_hud_update 
  end 
end 
#===============================================================================
# * Window_HUD
#===============================================================================

class Window_HUD < Window_Base 
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize 
    super(0, 0, 800, 600) 
    self.contents = Bitmap.new(width - 32, height - 32) 
    self.opacity = 0 
    self.visible = $game_switches[Raz_Hud::SWITCH_ID]
    refresh 
  end 
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh 
    self.contents.clear 
    @old_hp, @old_sp, @old_exp, @old_size = [],[],[],$game_party.actors.size
    for actor in $game_party.actors
      @old_hp << actor.hp; @old_sp << actor.sp; @old_exp << actor.exp
      a = $game_party.actors.size - 1 
      center = Raz_Hud::Center_hud == true ? (240 - (a * 80)) : 0
      x = ($game_party.actors.index(actor) * 160 + 25) + center
      draw_actor_battler(actor, x - 15, 295) 
      self.contents.font.size = 21 
      self.contents.font.color = normal_color 
      self.contents.draw_text(x - 25, 360, 100, 32, actor.name) 
      draw_slant_bar(x + 8, 396, actor.hp, actor.maxhp, 100, 6) 
      draw_slant_bar(x + 8, 416, actor.sp, actor.maxsp, 100, 6, Color.new(0, 0, 150), Color.new(60, 155, 155)) 
      now_exp = actor.level == 99 ? 1 : actor.now_exp
      next_exp = actor.level == 99 ? 1 : actor.next_exp
      draw_slant_bar(x + 8, 436, now_exp, next_exp, 100, 6, Color.new(0, 150, 0), Color.new(60, 255, 60)) 
      self.contents.font.size = 16 
      draw_actor_state(actor, x + 45, 360) 
      self.contents.font.color = normal_color 
      self.contents.font.bold = true 
      self.contents.font.color = actor.hp == 0 ? knockout_color : actor.hp <= actor.maxhp / 4 ? crisis_color : normal_color 
      self.contents.draw_text(x + 16, 382, 100, 32, "#{actor.hp}/#{actor.maxhp}", 1) 
      self.contents.font.color = actor.sp == 0 ? crisis_color : actor.sp <= actor.maxsp / 4 ? crisis_color : normal_color 
      self.contents.draw_text(x + 16, 402, 100, 32, "#{actor.sp}/#{actor.maxsp}", 1) 
      self.contents.font.color = system_color 
      self.contents.font.size = 20 
      self.contents.font.bold = false 
      self.contents.draw_text(x, 384, 50, 32, $data_system.words.hp) 
      self.contents.draw_text(x, 404, 50, 32, $data_system.words.sp) 
      self.contents.draw_text(x, 424, 50, 32, "Exp") 
    end 
  end 
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update 
    refresh if @old_size != $game_party.actors.size
    @old_hp.each_with_index {|hp, index| refresh if hp != $game_party.actors[index].hp}    
    @old_sp.each_with_index {|sp, index| refresh if sp != $game_party.actors[index].sp}    
    @old_exp.each_with_index {|exp, index| refresh if exp != $game_party.actors[index].exp}
    self.visible = $game_switches[Raz_Hud::SWITCH_ID]
  end 
end 
#===============================================================================
# * Window_Dummy
#===============================================================================

class Window_Dummy < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #   size: Party's size
  #--------------------------------------------------------------------------
  def initialize(size)
    @old_size = $game_party.actors.size
    x = Raz_Hud::Center_hud == true ? 240 - ($game_party.actors.size - 1) * 80 : 0
    super(160 * size + x, 372,160, 108)
    self.visible = $game_switches[Raz_Hud::SWITCH_ID]
    self.opacity = 200
  end
end
#==============================================================================
# ** Window_Base
#------------------------------------------------------------------------------
#  This class is for all in-game windows.
#==============================================================================

class Window_Base < Window 
  #--------------------------------------------------------------------------
  # * Draw Slant Bar (by SephirothSpawn)
  #--------------------------------------------------------------------------
  def draw_slant_bar(x, y, min, max, width = 152, height = 6, 
  bar_color = Color.new(150, 0, 0, 255), end_color = Color.new(255, 255, 60, 255)) 
    for i in 0..height 
      self.contents.fill_rect(x + i, y + height - i, width + 1, 1, Color.new(50, 50, 50, 255)) 
    end 
    for i in 1..(height - 1) 
      r = 100 * (height - i) / height + 0 * i / height 
      g = 100 * (height - i) / height + 0 * i / height 
      b = 100 * (height - i) / height + 0 * i / height 
      a = 255 * (height - i) / height + 255 * i / height 
      self.contents.fill_rect(x + i, y + height - i, width, 1, Color.new(r, b, g, a)) 
    end 
    for i in 1..( (min / max.to_f) * width - 1) 
      for j in 1..(height - 1) 
        r = bar_color.red * (width - i) / width + end_color.red * i / width 
        g = bar_color.green * (width - i) / width + end_color.green * i / width 
        b = bar_color.blue * (width - i) / width + end_color.blue * i / width 
        a = bar_color.alpha * (width - i) / width + end_color.alpha * i / width 
        self.contents.fill_rect(x + i + j, y + height - j, 1, 1, Color.new(r, g, b, a)) 
      end 
    end 
  end 
end 
#==============================================================================
# ** Game_Actor
#------------------------------------------------------------------------------
#  This class handles the actor. It's used within the Game_Actors class
#  ($game_actors) and refers to the Game_Party class ($game_party).
#==============================================================================

class Game_Actor 
  #--------------------------------------------------------------------------
  # * Now Exp
  #--------------------------------------------------------------------------
  def now_exp 
    return @exp - @exp_list[@level] 
  end 
  #--------------------------------------------------------------------------
  # * Next Exp
  #--------------------------------------------------------------------------
  def next_exp 
    return @exp_list[@level+1] > 0 ? @exp_list[@level+1] - @exp_list[@level] : 0 
  end 
end
 
Ravenith;246359 said:
I need a HUD that's like this:

--------------------------------------
' (Name of the first actor in party)
' (current hp) / (max hp)
' (current sp) / (max sp)
' (currency name) (amount)
'--------------------------------------

I would prefer having the class displayed under the actor name.
And yes, I would like to keep it single player.
Like someone else already said, sorry from detracting from your request, Ravenith.
 

arev

Sponsor

Code:
class Window_HUD < Window_Base
  def initialize
    super(640,480,176,128)
    self.contents = Bitmap.new(140,96)
    self.contents.font.size = 20
    self.back_opacity = 160
    refresh
  end
  def refresh
    self.contents.clear
    @actor = $game_party.actors[0]
    self.contents.font.color = Color.new(0,0,0,255)
    self.contents.draw_text(5,1,132,20,@actor.name.to_s,1)
    self.contents.draw_text(5,21,132,20,@actor.class_name.to_s,1)
    self.contents.font.color = system_color
    self.contents.draw_text(4,20,132,20,@actor.class_name.to_s,1)
    self.contents.font.color = normal_color
    self.contents.draw_text(4,0,132,20,@actor.name.to_s,1)
    draw_actor_hp(@actor,4,34)
    draw_actor_sp(@actor,4,52)
    self.contents.draw_text(4,76,132,20,$game_party.gold.to_s,2)
    self.contents.draw_text(4,76,132,20,$data_system.words.gold + ":")
  end
end
class Scene_Map
  alias hud_main main
  alias hud_update update
  def main
    @hud = Window_HUD.new
    hud_main
    @hud.dispose
  end
  def update
    @hud.refresh
    if $game_switches[1] and @hud.x > 468
      @hud.x -= 11
      @hud.y -= 8
    end
    if $game_switches[1] == false and @hud.x < 640
      @hud.x += 11
      @hud.y += 8
    end
    hud_update
  end
end
Paste over "Main" : )
 
Dude, it looks great. Thanks a lot.
Now people have a bunch of options of what to choose from.

Plus good job on the spacing. i put "LONGESTCLASSICOULDTHINKOF" as the class, lol, and your script still tried to centralize.

Good job.
Btw: I'm assuming this line:
self.contents.draw_text(5,21,132,20,@actor.class_name.to_s,1)
self.contents.font.color = system_color


controls what color the class comes out in?
How would I change that? with the RBY Code? where would i put that.

Thanks again for taking up my request.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top