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.

Very Basic KH HUD

Status
Not open for further replies.
Kingdom Hearts HUD + Addon

Introduction

This is a very basic script, all it does is make the health and magic bar rounded.

Plus the addon adds a window for more information/stats.

Features

Round Health and Magic Display
Editable placement for HUD

Screenshots

since I know people will ask...
http://i92.photobucket.com/albums/l14/i ... /KHHUD.jpg[/IMG]
And for the addon..
http://i92.photobucket.com/albums/l14/i ... /addon.jpg[/IMG]
Demo

Not needed

Script

Code:
#==============================================================================
# â–  Kingdom Hearts HUD
#------------------------------------------------------------------------------
# by Skive
# skivedaft@yahoo.com
#
# --
#
# released on 5th March 2006
#==============================================================================

#==============================================================================
# â–  Sprite_HP
#------------------------------------------------------------------------------
#  the HUD's hp bar
#==============================================================================

class Sprite_HP < Sprite
#--------------------------------------------------------------------------
# ● instances
#--------------------------------------------------------------------------
attr_writer :actor
#--------------------------------------------------------------------------
# ● initialize
#--------------------------------------------------------------------------
def initialize(actor = nil)
super(nil)
self.z = 202
self.bitmap = Bitmap.new(60, 26)
@actor = actor
if !@actor.nil?
@hp = @actor.hp
@maxhp = @actor.maxhp
end
refresh
end
#--------------------------------------------------------------------------
# ● refresh
#--------------------------------------------------------------------------
def refresh
self.bitmap.clear
return if @actor.nil?
@hp = @actor.hp
@maxhp = @actor.maxhp
draw_bar(20, 6)
self.angle = 270
end
#--------------------------------------------------------------------------
# ● update
#--------------------------------------------------------------------------
def update
super
if @actor.nil?
self.bitmap.clear
return
end
if @hp != @actor.hp or @maxhp != @actor.maxhp
refresh
end
end
#--------------------------------------------------------------------------
# ● draw_bar
#--------------------------------------------------------------------------
def draw_bar(radius, width)
max = (@actor.hp * 360) / @actor.maxhp
for j in 1..width
for i in 0..max
bx = Math.cos( (i * Math::PI) / 360) * (radius + j)
by = Math.sin( (i * Math::PI) / 360) * (radius + j)
case j
when 1
color = Color.new(74, 112, 29)
when 2
color = Color.new(77, 120, 29)
when 3
color = Color.new(80, 131, 28)
when 4
color = Color.new(85, 144, 27)
when 5
color = Color.new(89, 156, 26)
when 6
color = Color.new(93, 167, 26)
end
self.bitmap.set_pixel(30 + bx, by, color)
end
end
end
end

#==============================================================================
# â–  Sprite_SP
#------------------------------------------------------------------------------
#  the HUD's sp bar
#==============================================================================

class Sprite_SP < Sprite
#--------------------------------------------------------------------------
# ● instances
#--------------------------------------------------------------------------
attr_writer :actor
#--------------------------------------------------------------------------
# ● initialize
#--------------------------------------------------------------------------
def initialize(actor = nil)
super(nil)
self.z = 202
self.bitmap = Bitmap.new(60, 26)
@actor = actor
if !@actor.nil?
@sp = @actor.sp
@maxsp = @actor.maxsp
end
refresh
end
#--------------------------------------------------------------------------
# ● refresh
#--------------------------------------------------------------------------
def refresh
self.bitmap.clear
return if @actor.nil?
@sp = @actor.sp
@maxsp = @actor.maxsp
draw_bar(20, 6)
self.angle = 90
self.mirror = true
end
#--------------------------------------------------------------------------
# ● update
#--------------------------------------------------------------------------
def update
super
if @actor.nil?
self.bitmap.clear
return
end
if @sp != @actor.sp or @maxsp != @actor.maxsp
refresh
end
end
#--------------------------------------------------------------------------
# ● draw_bar
#--------------------------------------------------------------------------
def draw_bar(radius, width)
max = (@actor.sp * 360) / @actor.maxsp
for j in 1..width
for i in 0..max
bx = Math.cos( (i * Math::PI) / 360) * (radius + j)
by = Math.sin( (i * Math::PI) / 360) * (radius + j)
case j
when 1
color = Color.new(29, 82, 112)
when 2
color = Color.new(29, 86, 120)
when 3
color = Color.new(28, 90, 131)
when 4
color = Color.new(27, 96, 144)
when 5
color = Color.new(26, 102, 156)
when 6
color = Color.new(26, 106, 167)
end
self.bitmap.set_pixel(30 + bx, by, color)
end
end
end
end

#==============================================================================
# â–  Sprite_HUD
#------------------------------------------------------------------------------
#  draws the HUD on the map
#==============================================================================

class Sprite_HUD < Sprite
#--------------------------------------------------------------------------
# ● initialize
#--------------------------------------------------------------------------
def initialize(corner = 4)
super(nil)
self.z = 200
for actor in $game_party.actors
next if actor.dead?
@actor = actor
@actor_index = $game_party.actors.index(@actor)
break
end
@hp_sprite = Sprite_HP.new(@actor)
@sp_sprite = Sprite_SP.new(@actor)
self.bitmap = Bitmap.new(60, 60)
case corner
when 1
x = 16
y = 16
when 2
x = 640 - 52 - 16
y = 16
when 3
x = 16
y = 480 - 52 - 16
when 4
x = 640 - 52 - 16
y = 480 - 52 - 16
end
self.x = x
self.y = y
@hp_sprite.x = x + 27
@hp_sprite.y = y - 3
@sp_sprite.x = x + 27 - 1
@sp_sprite.y = y - 3 - 1 + 60
refresh
end
#--------------------------------------------------------------------------
# ● refresh
#--------------------------------------------------------------------------
def refresh
self.bitmap.clear
return if @actor.nil?
bmp = RPG::Cache.character(@actor.character_name, @actor.character_hue)
rect = Rect.new(0, 0, bmp.width / 4, (bmp.height / 4))
self.bitmap.blt(27 - bmp.width / 8, 5, bmp, rect)
self.bitmap.blt(0, 0, RPG::Cache.picture("hud"), Rect.new(0, 0, 60, 60))
end
#--------------------------------------------------------------------------
# ● update
#--------------------------------------------------------------------------
def update
super
@hp_sprite.update
@sp_sprite.update
if @actor != $game_party.actors[@actor_index]
@actor = $game_party.actors[@actor_index]
@hp_sprite.actor = @actor
@sp_sprite.actor = @actor
@hp_sprite.refresh
@sp_sprite.refresh
refresh
end
end
end

#==============================================================================
# â–  Scene_Map
#------------------------------------------------------------------------------
#  draws the hud on the map screen
# @khhud_corner is the corner you want the hud to be displayed in.
# 1 is upper left, 2 is upper right, 3 is bottom left and 4 is bottom right
#==============================================================================

class Scene_Map
alias main_khhud main
alias update_khhud update
alias transfer_khhud transfer_player
#--------------------------------------------------------------------------
# ● initialize
#--------------------------------------------------------------------------
def initialize
@khhud_corner = 4 # 1 or 2 or 3 or 4
end
#--------------------------------------------------------------------------
# ● main
#--------------------------------------------------------------------------
def main
@hud = Sprite_HUD.new(@khhud_corner)
main_khhud
@hud.dispose
end
#--------------------------------------------------------------------------
# ● update
#--------------------------------------------------------------------------
def update
@hud.update
update_khhud
end
end


Code:
#==============================================================================
#  Basic HUD Window
#------------------------------------------------------------------------------
# By Italianstal1ion, based around Skive's HUD
# 
# Just wanted to make a basic HUD for people that wanted to use the round health bars
# Skive made but didnt like how bland it was.
# Note: I did not edit Skive's part of the script at all, just added the window around it.
# If you do use the picture, it needs to be about 180x120 and in your pictures folder
#==============================================================================


class Window_KHUD < Window_Base
  def initialize
    super(440, 350, 200, 130)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.back_opacity = 145 #Change to 0 if you use a picture
    refresh
  end
  def refresh
    self.contents.clear

   #Uncomment these lines if you want a picture instead of window
  #  bitmap = RPG::Cache.picture("khud")
   # self.contents.blt(0, 0, bitmap, Rect.new(0, 10, 175, 175))


    # Displays Gold, Map, and unchanged words
    self.contents.font.size = 14 
    self.contents.font.color = normal_color
    self.contents.draw_text(-32, 54, 120, 32, $game_party.gold.to_s, 2)
    #Show Map Name
    map_infos = load_data("Data/MapInfos.rxdata")
    name = map_infos[$game_map.map_id].name.to_s
    self.contents.draw_text(28, 22, 400, 32, name.to_s)
    self.contents.font.color = system_color
    self.contents.draw_text(-96, 54, 120, 32, $data_system.words.gold, 2)
    self.contents.draw_text(0, 22, 120, 32, "Map")
    self.contents.draw_text(0, 38, 120, 32, "Status")
    
    reset_variables
    return if !@actor
    # Displays actors state, level, EXP and name
    draw_actor_level(@actor, 0, 6)
    draw_actor_state(@actor, 44, 38, width = 120)
    self.contents.font.size = 18
    draw_actor_name(@actor, 0, -10)
    self.contents.font.size = 14
    self.contents.font.color = system_color
    self.contents.draw_text(72, 6, 48, 32, "EXP")
    self.contents.font.color = normal_color
    self.contents.draw_text(76, 6, 84, 32, @actor.exp_s, 2)
  end
  def reset_variables
    @actor = $game_party.actors[0]
    @old_level = @actor ? @actor.level : 0
    @old_exp = @actor ? @actor.exp : 0
  end
  def update
    super
    refresh if (@actor = $game_party.actors[0] or
                @old_level = @actor ? @actor.level : 0 or
                @old_exp = @actor ? @actor.exp : 0 )

  end
end


class Scene_Map
  alias khud_main main
  alias khud_update update
  def main
    @khud = Window_KHUD.new
    khud_main
    @khud.dispose
  end
  def update
    @khud.update
    khud_update
  end
end




Note: Both scripts are independent. I did not make any changes to Skive's script for the addon. Either one can work without the other.
Instructions

Place above main, below all other scripts. Addon can go above or below Skive's script.
To change the corner its displayed find
Code:
@khhud_corner
and change the number it equals to whatever corner you want.
(1 is upper left, 2 is upper right, 3 is bottom left and 4 is bottom right, if you move the bars, you'll have to edit the addon window's x and y coordinates).

Don't forget to put this in your Pictures folder:
http://i92.photobucket.com/albums/l14/i ... on/hud.png[/IMG]

Also, for the picture, it needs to be a pic about 180x120 and in your pictures folder. Yes I realize the picture cuts off, its because I drew it in the window. Just use this for now, Ill figure out how to draw the picture outside the window, shouldnt be too hard.

OR, you could make an event having it Show Picture, and set it x and y coordinates to the map, I know its not scripting, but its faster and easier :p

FAQ

Nothing yet

Compatibility

Works with SDK, untested with anything else.
This script is made for an ABS ONLY. If you try using it for a normal battle, the health/magic bars will show through. Also note this is for any window, so it will show in menu also.

Credits and Thanks

Skive made the script, I only made the addon. Many thanks to Yeyinde for the HUD tutorial!
 
Hey, nice script find Italian ^_^ I think you forgot to upload the picture though because in the script, it looks for pictures/graphics/hud. If that's the case, then this actually only is a picture. Well, hope you upload it ;)
Dylan
 

Skive

Member

Oh wow,
Squall just told me that this has been reposted.
I stopped playing around with rmxp quite some time ago and I gave all my work and scripts to Squall, not to mention that he helped me a lot to make this script.
So check with him.
 
Selwyn are you thinking of updating this script? or Skive? :p It'd be nice to have a full HUD instead of just the health bars, but I could add that myself if you don't mind.
 
I suppose you can edit it, as I really don't have time to do that.
But be sure to credit Skive as the original author.
 
Great, the pic is uploaded ^_^ The only thing I don't like is that it only fits rtp basically. I wish you could use HK or even face sets lake the normal KH. Well, if you are gonna update this, hope that helps so far ;)
 
There might be a nice way to do this for the overlap feature, thought you need to configure it to show a new half-ring empty or full, depending on how much hp/sp the player has. But you could define when it first starts to show this new bar at 300 HP add a new bar, at 150SP add a new bar, so every 300+ HP and/or 150 SP it would add a new bar, etc. Just a neat concept you could add :P
 
Hey Italian, nice update ^_^ It's looking nice. Also maybe you should add a
"Things Being Considered" subject in the first post. I have a consideration too ^_^ Hope you try it ;)
Can you add a feature that allows you to show party members too? This would be a customization option for anyone that wants it :)
Dylan
 
I just added a window ':| Really, my scripting abilities aren't all too great. About the bar adding every 300 HP and stuff, I really don't think I could do that. That would be a lot of bars later on wouldn't it ??

As for showing the party members...I'll try but I'm not sure how..
 
ughh...I know what you mean. :yes: scripting is everything but easy >< maybe you can find out in the rgss support section :) good luck
Dylan
 
Testing the script I noticed that the party member it shows is always the first one BUT if that hero dies it will show the second one. This would probably work good with (Dargor's?) "Death Switch" where the main actor changes to the next when the first dies.

Although, when the first hero dies, the HUD window will say the same info about the first actor..
 
If you need any kind of help, I have a HUD of my own I've been helping make for MrMo's ABS for the longest time, if you want a screenshot of what I've done, here is the newest and most custom one for my game (Which is not publicly being released).
http://i22.photobucket.com/albums/b347/ ... enshot.png[/IMG]
As well the 300 was just an example...

(Note: Graphics recolored and used in my huds are credited in the game.)
 
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