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.

Modifying this little HUD..

Status
Not open for further replies.
Could someone please modify this HUD so that it only displays the 'leading actor' (actor1), because I've edit the things I want to, but now it's a complete mess when another actor comes in the party.

Thanks in advance. ;)

Code:
SHOW_SWITCH = 43 #change to your switch, don't put in any leading zeros!
class Game_Actor
#--------------------------------------------------------------------------
# * Get the current EXP
#--------------------------------------------------------------------------
def now_exp
return @exp - @exp_list[@level]
end
#--------------------------------------------------------------------------
# * Get the next level's EXP
#--------------------------------------------------------------------------
def next_exp
return @exp_list[@level+1] > 0 ? @exp_list[@level+1] - @exp_list[@level] : 0
end
end

#==============================================================================
# ** Window_HUD
#------------------------------------------------------------------------------
# This class is used to display HP, SP and Gold on the map.
#==============================================================================
class Window_HUD < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(-16, 404, 640, 480)
self.contents = Bitmap.new(width-32, height-32)
self.opacity = 0
self.contents.font.size = 14
self.visible = $game_switches[SHOW_SWITCH]
@actors = []
@old_hp = []
@old_sp = []
@old_exp = []
@old_level = []
for i in 0...$game_party.actors.size
@actors.push($game_party.actors[i])
@old_hp.push(@actors[i].hp)
@old_sp.push(@actors[i].sp)
@old_exp.push(@actors[i].now_exp)
@old_level.push(@actors[i].level)
end
@old_gold = $game_party.gold
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
self.contents.font.color = system_color
self.contents.font.color = normal_color

#Images ------------------------------------------------------------------
case @actors.size
when 1
bitmap = RPG::Cache.picture("base1")
self.contents.blt(0, 0, bitmap, Rect.new(0, 10, 565, 565))
end

bitmap = RPG::Cache.icon("Game - HUD HP Symbol")
self.contents.blt(213, 21, bitmap, Rect.new(0, 0, 24, 24))
bitmap = RPG::Cache.icon("Game - HUD SP Symbol")
self.contents.blt(214, 38, bitmap, Rect.new(0, 0, 24, 24))
bitmap = RPG::Cache.icon("Game - HUD Mesos Symbol")
self.contents.blt(80, 43, bitmap, Rect.new(0, 0, 24, 24))
#--------------------------------------------------------------------------
x = 240
for i in 0...@actors.size
y = 15
self.contents.font.size = 16
self.contents.draw_text(80, 20, 60, 28, @actors[i].name)
self.contents.font.size = 25
self.contents.draw_text(10, 30, 60, 28, "#{@actors[i].level}", 2)
y += 16
draw_hp_bar(@actors[i], x, y, 310, 5)
y += 16
draw_sp_bar(@actors[i], x, y, 310, 5)
y += 19
x += 130
end
x = 32
self.contents.font.size = 16
self.contents.draw_text(97, 37, 60, 28, $game_party.gold.to_s)
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
super
self.visible = $game_switches[SHOW_SWITCH]
if @actors.size != $game_party.actors.size
@actors = []
for i in 0...$game_party.actors.size
@actors.push($game_party.actors[i])
end
refresh
return
end
for i in 0...@actors.size
if @old_hp[i] != @actors[i].hp or
@old_sp[i] != @actors[i].sp or
@old_exp[i] != @actors[i].now_exp or
@old_level[i] != @actors[i].level or
@old_gold != $game_party.gold
refresh
@old_hp[i] = @actors[i].hp
@old_sp[i] = @actors[i].sp
@old_exp[i] = @actors[i].now_exp
@old_level[i] = @actors[i].level
@old_gold = $game_party.gold
end
end
end
#--------------------------------------------------------------------------
# * Draw HP Bar
#--------------------------------------------------------------------------
def draw_hp_bar(actor, x, y, length, thick)
width = length
height = thick
c1 = Color.new(255, 0, 0)
c2 = Color.new(155, 0, 0)
e1 = actor.hp
e2 = actor.maxhp
self.contents.fill_rect(x-1, y - 1, width+2, height + 3, Color.new(255, 255, 255, 255))
self.contents.fill_rect(x, y, width, height + 1, Color.new(0, 0, 0, 255))
w = width * e1 / e2
for i in 0..height
r = c1.red + (c2.red - c1.red) * (height -i)/height + 0 * i/height
g = c1.green + (c2.green - c1.green) * (height -i)/height + 0 * i/height
b = c1.blue + (c2.blue - c1.blue) * (height -i)/height + 0 * i/height
a = c1.alpha + (c2.alpha - c1.alpha)* (height -i)/height + 255 * i/height
self.contents.fill_rect(x, y+i, w, 1, Color.new(r, g, b, a))
end
end
#--------------------------------------------------------------------------
# * Draw SP Bar
#--------------------------------------------------------------------------
def draw_sp_bar(actor, x, y, length, thick)
width = length
height = thick
c1 = Color.new(0, 0, 255)
c2 = Color.new(0, 0, 155)
e1 = actor.sp
e2 = actor.maxsp
self.contents.fill_rect(x-1, y - 1, width+2, height + 3, Color.new(255, 255, 255))
self.contents.fill_rect(x, y, width, height + 1, Color.new(0, 0, 0))
w = width * e1 / e2
for i in 0..height
r = c1.red + (c2.red - c1.red) * (height -i)/height + 0 * i/height
g = c1.green + (c2.green - c1.green) * (height -i)/height + 0 * i/height
b = c1.blue + (c2.blue - c1.blue) * (height -i)/height + 0 * i/height
a = c1.alpha + (c2.alpha - c1.alpha)* (height -i)/height + 255 * i/height
self.contents.fill_rect(x, y+i, w, 1, Color.new(r, g, b, a))
end
end
#--------------------------------------------------------------------------
# * Draw EXP Bar
#--------------------------------------------------------------------------
def draw_exp_bar(actor, x, y, length, thick)
width = length
height = thick
c1 = Color.new(158, 208, 9)
c2 = Color.new(58, 108, 0)
e1 = actor.now_exp
e2 = actor.next_exp
if actor.next_exp == 0
e1 = 1
e2 = 1
end
self.contents.fill_rect(x-1, y - 1, width+2, height + 3, Color.new(255, 255, 255, 255))
self.contents.fill_rect(x, y, width, height + 1, Color.new(0, 0, 0, 255))
w = width * e1 / e2
for i in 0..height
r = c1.red + (c2.red - c1.red) * (height -i)/height + 0 * i/height
g = c1.green + (c2.green - c1.green) * (height -i)/height + 0 * i/height
b = c1.blue + (c2.blue - c1.blue) * (height -i)/height + 0 * i/height
a = c1.alpha + (c2.alpha - c1.alpha)* (height -i)/height + 255 * i/height
self.contents.fill_rect(x, y+i, w, 1, Color.new(r, g, b, a))
end
end
end
#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
# This class performs map screen processing.
#==============================================================================
class Scene_Map
#--------------------------------------------------------------------------
# * Object Aliasing
#--------------------------------------------------------------------------
alias hud_scene_map_main main
alias hud_scene_map_update update
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def main
@HUD = Window_HUD.new
hud_scene_map_main
@HUD.dispose
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
@HUD.update
hud_scene_map_update
end
end
 

arev

Sponsor

Here's a quickie:
Code:
SHOW_SWITCH = 43 #change to your switch, don't put in any leading zeros!
class Game_Actor
#--------------------------------------------------------------------------
# * Get the current EXP
#--------------------------------------------------------------------------
def now_exp
return @exp - @exp_list[@level]
end
#--------------------------------------------------------------------------
# * Get the next level's EXP
#--------------------------------------------------------------------------
def next_exp
return @exp_list[@level+1] > 0 ? @exp_list[@level+1] - @exp_list[@level] : 0
end
end

#==============================================================================
# ** Window_HUD
#------------------------------------------------------------------------------
# This class is used to display HP, SP and Gold on the map.
#==============================================================================
class Window_HUD < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(-16, 404, 640, 480)
self.contents = Bitmap.new(width-32, height-32)
self.opacity = 0
self.contents.font.size = 14
self.visible = $game_switches[SHOW_SWITCH]
@actor = $game_party.actors[0]
@old_hp = @actor.hp
@old_sp = @actor.sp
@old_exp = @actor.now_exp
@old_level = @actor.level
@old_gold = $game_party.gold
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
self.contents.font.color = system_color
self.contents.font.color = normal_color

#Images ------------------------------------------------------------------
bitmap = RPG::Cache.picture("base1")
self.contents.blt(0, 0, bitmap, Rect.new(0, 10, 565, 565))

bitmap = RPG::Cache.icon("Game - HUD HP Symbol")
self.contents.blt(213, 21, bitmap, Rect.new(0, 0, 24, 24))
bitmap = RPG::Cache.icon("Game - HUD SP Symbol")
self.contents.blt(214, 38, bitmap, Rect.new(0, 0, 24, 24))
bitmap = RPG::Cache.icon("Game - HUD Mesos Symbol")
self.contents.blt(80, 43, bitmap, Rect.new(0, 0, 24, 24))
#--------------------------------------------------------------------------
x = 240
y = 15
self.contents.font.size = 16
self.contents.draw_text(80, 20, 60, 28, @actor.name)
self.contents.font.size = 25
self.contents.draw_text(10, 30, 60, 28, "#{@actor.level}", 2)
y += 16
draw_hp_bar(@actor, x, y, 310, 5)
y += 16
draw_sp_bar(@actor, x, y, 310, 5)
y += 19
x += 130
x = 32
self.contents.font.size = 16
self.contents.draw_text(97, 37, 60, 28, $game_party.gold.to_s)
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
  def update
    super
    self.visible = $game_switches[SHOW_SWITCH]
    if @old_hp != @actor.hp or
      @old_sp != @actor.sp or
      @old_exp != @actor.now_exp or
      @old_level != @actor.level or
      @old_gold != $game_party.gold
      refresh
      @old_hp = @actor.hp
      @old_sp = @actor.sp
      @old_exp = @actor.now_exp
      @old_level = @actor.level
      @old_gold = $game_party.gold
    end
  end
#--------------------------------------------------------------------------
# * Draw HP Bar
#--------------------------------------------------------------------------
def draw_hp_bar(actor, x, y, length, thick)
width = length
height = thick
c1 = Color.new(255, 0, 0)
c2 = Color.new(155, 0, 0)
e1 = actor.hp
e2 = actor.maxhp
self.contents.fill_rect(x-1, y - 1, width+2, height + 3, Color.new(255, 255, 255, 255))
self.contents.fill_rect(x, y, width, height + 1, Color.new(0, 0, 0, 255))
w = width * e1 / e2
for i in 0..height
r = c1.red + (c2.red - c1.red) * (height -i)/height + 0 * i/height
g = c1.green + (c2.green - c1.green) * (height -i)/height + 0 * i/height
b = c1.blue + (c2.blue - c1.blue) * (height -i)/height + 0 * i/height
a = c1.alpha + (c2.alpha - c1.alpha)* (height -i)/height + 255 * i/height
self.contents.fill_rect(x, y+i, w, 1, Color.new(r, g, b, a))
end
end
#--------------------------------------------------------------------------
# * Draw SP Bar
#--------------------------------------------------------------------------
def draw_sp_bar(actor, x, y, length, thick)
width = length
height = thick
c1 = Color.new(0, 0, 255)
c2 = Color.new(0, 0, 155)
e1 = actor.sp
e2 = actor.maxsp
self.contents.fill_rect(x-1, y - 1, width+2, height + 3, Color.new(255, 255, 255))
self.contents.fill_rect(x, y, width, height + 1, Color.new(0, 0, 0))
w = width * e1 / e2
for i in 0..height
r = c1.red + (c2.red - c1.red) * (height -i)/height + 0 * i/height
g = c1.green + (c2.green - c1.green) * (height -i)/height + 0 * i/height
b = c1.blue + (c2.blue - c1.blue) * (height -i)/height + 0 * i/height
a = c1.alpha + (c2.alpha - c1.alpha)* (height -i)/height + 255 * i/height
self.contents.fill_rect(x, y+i, w, 1, Color.new(r, g, b, a))
end
end
#--------------------------------------------------------------------------
# * Draw EXP Bar
#--------------------------------------------------------------------------
def draw_exp_bar(actor, x, y, length, thick)
width = length
height = thick
c1 = Color.new(158, 208, 9)
c2 = Color.new(58, 108, 0)
e1 = actor.now_exp
e2 = actor.next_exp
if actor.next_exp == 0
e1 = 1
e2 = 1
end
self.contents.fill_rect(x-1, y - 1, width+2, height + 3, Color.new(255, 255, 255, 255))
self.contents.fill_rect(x, y, width, height + 1, Color.new(0, 0, 0, 255))
w = width * e1 / e2
for i in 0..height
r = c1.red + (c2.red - c1.red) * (height -i)/height + 0 * i/height
g = c1.green + (c2.green - c1.green) * (height -i)/height + 0 * i/height
b = c1.blue + (c2.blue - c1.blue) * (height -i)/height + 0 * i/height
a = c1.alpha + (c2.alpha - c1.alpha)* (height -i)/height + 255 * i/height
self.contents.fill_rect(x, y+i, w, 1, Color.new(r, g, b, a))
end
end
end
#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
# This class performs map screen processing.
#==============================================================================
class Scene_Map
#--------------------------------------------------------------------------
# * Object Aliasing
#--------------------------------------------------------------------------
alias hud_scene_map_main main
alias hud_scene_map_update update
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def main
@HUD = Window_HUD.new
hud_scene_map_main
@HUD.dispose
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
@HUD.update
hud_scene_map_update
end
end

Next time make sure you also post required images ;)
 

arev

Sponsor

This topic has been resolved. If Marcel_Makkink or any other users have any questions or further problems regarding this topic, please create a new thread about them.

Thank you!
 
Status
Not open for further replies.

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