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.

A simple HUD

#================================================= =============================
# ** Scene_Map
#------------------------------------------------------------------------------
# This class performs map screen processing.
#================================================= =============================
class Scene_Map
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias tak_map_main main
alias tak_map_update update
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def main
@hud_sprite = Window_HUD.new
@hud_window = Window_HUDFACE.new
tak_map_main
@hud_sprite.dispose
@hud_window.dispose
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
@hud_sprite.update
@hud_window.update
tak_map_update
end
end


#================================================= ============================
# ** Game_Actor
#-----------------------------------------------------------------------------
# This small edit is made to show characetr exp as a bar
#================================================= ============================
class Game_Actor < Game_Battler
def now_exp
return @exp - @exp_list[@level]
end
def next_exp
return @exp_list[@level+1] > 0 ? @exp_list[@level+1] - @exp_list[@level] : 0
end
end

#================================================= =============================
# ** Window_HUDFACE
#------------------------------------------------------------------------------
# This window will draw the characters Image.-
#================================================= =============================
class Window_HUDFACE < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(-2, 360, 118, 124)
self.contents = Bitmap.new(width - 32, height - 32)
self.opacity = 0
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
@actor = $game_party.actors[0]
@old_image = @actor.name
suffix = "_face"
@bitmap = RPG::Cache.picture(@actor.name + suffix)
self.contents.blt(0, 0, @bitmap, Rect.new(0, 0, @bitmap.width, @bitmap.height))
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
refresh
end
end
#================================================= =============================
# ** Window_HUD
#------------------------------------------------------------------------------
# This window draws the HUD, with HP, SP and exp bar.
#================================================= =============================
class Window_HUD < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(-15, 350, 320, 160)
self.contents = Bitmap.new(width - 32, height - 32)
self.opacity = 0
@actor = $game_party.actors[0]
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
@old_hp = @actor.hp
@old_sp = @actor.sp
draw_bar(60, 60, @actor.hp, @actor.maxhp, 90, 8, Color.new(72, 216, 0, 255), Color.new(160, 248, 106, 255))
draw_bar(63, 70, @actor.sp, @actor.maxsp, 90, 8, Color.new(88, 200, 244, 255), Color.new(0, 56, 200, 255))
draw_bar(70, 80, @actor.now_exp, @actor.next_exp, 90, 8, Color.new(248, 240, 64, 255), Color.new(248, 96, 0, 255))
self.contents.font.size = 10
self.contents.font.color = Color.new(0, 0, 0)
self.contents.draw_text(149, 47, 150, 32, "HP")
self.contents.draw_text(151, 47, 150, 32, "HP")
self.contents.draw_text(149, 49, 150, 32, "HP")
self.contents.draw_text(151, 49, 150, 32, "HP")
self.contents.draw_text(153, 58, 150, 32, "SP")
self.contents.draw_text(155, 58, 150, 32, "SP")
self.contents.draw_text(153, 60, 150, 32, "SP")
self.contents.draw_text(155, 60, 150, 32, "SP")
self.contents.draw_text(159, 68, 150, 32, "EXP")
self.contents.draw_text(161, 68, 150, 32, "EXP")
self.contents.draw_text(159, 70, 150, 32, "EXP")
self.contents.draw_text(161, 70, 150, 32, "EXP")
self.contents.font.color = Color.new(248, 184, 0)
self.contents.draw_text(160, 69, 150, 32, "EXP")
self.contents.font.color = Color.new(160, 248, 104)
self.contents.draw_text(150, 48, 150, 32, "HP")
self.contents.font.color = Color.new(88, 200, 248)
self.contents.draw_text(154, 59, 150, 32, "SP")
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
if @old_hp != $game_party.actors[0].hp or
@old_sp != $game_party.actors[0].sp or
@old_exp != $game_party.actors[0].now_exp
refresh
@old_hp = $game_party.actors[0].hp
@old_sp = $game_party.actors[0].sp
@old_exp = $game_party.actors[0].now_exp
end
end
end
#================================================= =============================
# ** Window_Base
#------------------------------------------------------------------------------
# This class is for all in-game windows.
#================================================= =============================
class Window_Base < Window
#--------------------------------------------------------------------------
# * Draw Slant Bar(by SephirothSpawn)
#--------------------------------------------------------------------------
def draw_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))
# Draw Border
for i in 0..height
self.contents.fill_rect(x, y + height - i, width, 1, Color.new(50, 50, 50, 255))
end
# Draw Background
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, y + height - i, width, 1, Color.new(r, b, g, a))
end
# Draws Bar
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 - 1, y + height - j, 1, 1, Color.new(r, g, b, a))
end
end
end
end
works ok with Mr Mo ABS EvE, just tested it. ^_^

http://i21.photobucket.com/albums/b295/ ... howHUD.png[/IMG]

thats all...
ohh...it works with suffix too, if your character name is Cloud, it will search on Pictures folder for an image called "Cloud_face"
umm..these are the images i used:
http://i21.photobucket.com/albums/b295/ ... d_face.png[/IMG]

http://i21.photobucket.com/albums/b295/ ... a_face.png[/IMG]

hopw you like it!
 
yeah well, thank you very much =D
HUD's are like simple and very useful stuff, so it's a good place to start scripting, and im you liked it

remember to credit SephirothSpawn for the Gradient Bars!
 

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