Picture1.png 211.76K
139 downloadsThe script is free to use without restrictions like a Public Domain license so I am not asking for credit.
This is anti-lag meaning that only the necessary bitmaps will be redrawn upon change so don't mess with the variables and all will be smooth. I am considering using a mutex (cross-threading) for this to relieve the thread against lag but we will see how it goes.
Spoiler
If anyone wants to use this script for a hud or modify it you can. You can also use this Scene_Map override class to use it as a global instance.
module RPG
#global function to help get the rect according to Game_Actor::face_index
class << self
def get_face_rect(actor)
face_index = actor.face_index;
width = 96;
height = 96;
ox = 0;
oy = 0;
for i in 0...8
if (face_index == i)
_i = i;
if (face_index >= 4)
oy = height;
_i -= 4;
end
ox = (width * _i);
return Rect.new(ox, oy, width, height);
end
end
end
end
end
class Color
class << self
def red; Color.new(255, 0, 0); end;
def orange; Color.new(255, 165, 0); end;
def green; Color.new(0, 255, 0); end;
def blue; Color.new(0, 0, 255); end;
def yellow; Color.new(255,255,0); end;
def black; Color.new(0, 0, 0); end;
def white; Color.new(255,255,255); end;
def transparent; Color.new(255,255,255,255); end;
def purple; Color.new(95, 64, 186); end;
end
end
class BarContent
attr_accessor :rect;
def initialize(actor, bar_index, ox, oy, scale=1)
@bar_index = bar_index;
@actor = actor;
@color = nil;
@rect = nil;
set(ox, oy, scale);
end
def color()
return @color;
end
def set(x, y, scale)
dx = x;
dy = y;
bar_width = 96;
width = 0;
if(@bar_index ==0)
width =(bar_width*@actor.hp)/@actor.mhp;
div = (bar_width / 3);
if(width.to_f >= (div * 2).to_f)
@color = Color.red;
elsif (width.to_f >= div.to_f && width.to_f < (div * 2).to_f)
@color = Color.orange;
elsif (width.to_f < div.to_f)
@color = Color.yellow;
end
elsif (@bar_index == 1)
dy *= 2;
width = (bar_width*@actor.mp)/@actor.mmp;
@color = Color.blue;
elsif(@bar_index == 2)
dy *= 3;
width = 0;
if(@actor.tp > 0)
width = (bar_width*@actor.tp)/ 100;
@color = Color.green;
end
elsif (@bar_index == 3)
dy*= 4;
width = 0;
exp = @actor.exp();
if (exp > 0)
p "current experience" + exp.to_s;
width = (bar_width * exp) / @actor.next_level_exp();
@color = Color.purple;
end
end
@rect = Rect.new(dx, dy, width, 10);
end
end
#the actual HUD interface. We are using the Window class instead of Window_Base
#because we don't want any extra variable or pre-defined window background
#but rather only use a Custom Bitmap.
class HUD < Window
alias _initialize initialize
def initialize(x, y, actor_id)
raise('Game_Actor is nil') if $data_actors[actor_id] == nil;
@actor = $game_party.members[0];
@actor_image = Bitmap.new('Graphics/Faces/' + @actor.face_name);
@bar_image = Bitmap.new('Graphics/System/hudbar.png');
width = (128 + 48 + 4);
height = 96;
@offset_x = 52;
@levelup = false;
super(x,y, width,height);
self.contents = Bitmap.new(width,height);
@level = @actor.level;
#we only need the face_graphic and the name to be drawn once.
draw_face_graphics();
draw_name();
draw_level();
draw_bars();
#we need to have a few variables for checking if
#the stats have changed. If they have during the updata
#then we will only redraw that bar and text saving
#on the processor doing extra work causing lag.
end
def update()
refresh();
end
def refresh()
draw_level() if(@level != @actor.level);
draw_bars();
end
def draw_bars()
for i in 0...4
draw_bar(i, method(:get_bar_text)) if(has_changed(i));
end
end
def set_stat(stat)
case(stat)
when 0
@curhp = @actor.hp;
when 1
@curmp = @actor.mp;
when 2
@curtp = @actor.tp;
when 3
@curexp = @actor.exp;
@next_level_exp = @actor.next_level_exp;
end
end
def has_changed(stat)
case (stat)
when 0
return @curhp != @actor.hp;
when 1
return @curmp != @actor.mp;
when 2
return @curtp != @actor.tp;
when 3
return @curexp != @actor.exp;
end
end
def draw_bar(index, method_get_text)
#get the destination rectangle
#which we will use for any width and height offsets
#including getting the color data back
content = BarContent.new(@actor, index, @offset_x, 12);
drect = content.rect;
color = content.color;
set_stat(index);
srect = Rect.new(0, 0, @bar_image.width, @bar_image.height);
rect = Rect.new(drect.x, drect.y, 96, drect.height);
self.contents.stretch_blt(rect, @bar_image, srect);
if(color != nil)
bmp = Bitmap.new(drect.width, drect.height);
bmp.fill_rect(srect, color);
self.contents.blt(drect.x, drect.y, bmp, bmp.rect, 90);
end
text = method_get_text.call(index);
if (text != nil)
self.contents.font = Font.new('New Times Roman', 12);
drect.height = 12;
drect.width = 96;
self.contents.draw_text(drect, text, 1);
end
end
def draw_face_graphics()
drect = Rect.new(0,0, 48, 48);
srect = RPG::get_face_rect(@actor);
self.contents.stretch_blt(drect, @actor_image, srect, 200);
end
def get_bar_text(bar_index)
text = "";
case(bar_index)
when 0
text = "#{@actor.hp}/#{@actor.mhp}";
when 1
text = "#{@actor.mp}/#{@actor.mmp}";
when 2
text = (@actor.tp > 0) ? "#{@actor.tp}" : nil;
when 3
text = "#{@actor.exp}/#{@actor.next_level_exp}";
end
return text;
end
def set_level()
@level = @actor.level;
end
def draw_level()
set_level();
self.contents.font = Font.new('New Times Roman', 12);
text = "Level #{@level}";
self.contents.draw_text(Rect.new(0, 48, 48, 12), text, 1);
end
def draw_name()
self.contents.font = Font.new('New Times Roman', 12);
text = "#{@actor.name}-#{@actor.nickname}";
self.contents.draw_text(Rect.new(@offset_x, 0, 100, 16), text);
end
end
If anyone wants to use this script for a hud or modify it you can. You can also use this Scene_Map override class to use it as a global instance.
class Scene_Map < Scene_Base alias _start start alias _update update alias _terminate terminate def start() _start(); $hud=HUD.new(0, 0, 1); update(); end def terminate() $hud.dispose(); _terminate(); end def update() _update(); $hud.update(); end end
Here's a screen shot of what is looks like. The tp I am having an issue with but I will get there. I am currently working on a Quest Script class which is quit huge but when I have it fully operational in RPG Maker VX Ace, I will post it.
Edited by Celianna, 27 August 2012 - 08:32 PM.

This topic is locked











