Hp/SP Bar - shiroun - 11-04-2007
Hp/SP Bar
shiroun
Nov 4 2007
This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given. If you are the owner of the thread, please contact administration.
Well, I know this may have already been released, but it's a great type of script to create.
I created this one, and although it may seem like others, it is because it is an easy script to make.
Hp/Sp bar
Code: #-----------------------------------------------------------------
class Scene_Map
# Author: Shiroun
# Version Final
# 10/11/2007
# Evaluation: No lag anymore, high text resource consuming was fixed
#-----------------------------------------------------------------
alias sk_bar_main main
def main
@bars = Window_Sk_Bars.new
sk_bar_main
@bars.dispose if @bars != nil
end
#-----------------------------------------------------------------
def refresh
self.contents.clear
reset_variables
return if !@actor
draw_actor_hp(actor, x, y)
draw_actor_sp(actor, x, y)
end
#-----------------------------------------------------------------
alias sk_bar_update update
def update
@bars.update
sk_bar_update
end
#-----------------------------------------------------------------
end
#-----------------------------------------------------------------
class Window_Base < Window
#-----------------------------------------------------------------
def sk_initialize(font=0,size=20)
font = "Western" if font == 0
self.contents = Bitmap.new(self.width-32,self.height-32)
self.contents.font.name = font
self.contents.font.size = size
end
#-----------------------------------------------------------------
def draw_text_outline(x,y,w,h,str,c=normal_color,a=0)
self.contents.font.color = Color.new(235,175,125,155)
self.contents.draw_text(x-2,y,w,h,str,a)
self.contents.draw_text(x+2,y,w,h,str,a)
self.contents.draw_text(x,y+3,w,h,str,a)
self.contents.draw_text(x,y-3,w,h,str,a)
self.contents.font.color = c
self.contents.draw_text(x,y,w,h,str,a)
end
#-----------------------------------------------------------------
end
#-----------------------------------------------------------------
class Window_Sk_Bars < Window_Base
#-----------------------------------------------------------------
def initialize
super(444,-8,206,96)
sk_initialize("Tahoma")
self.opacity = 25
end
#-----------------------------------------------------------------
def update
self.contents.clear
actor = $game_party.actors[0]
draw_text_outline(0,-4,64,56,"Health")
draw_text_outline(0,24,64,56,"Status")
draw_actor_mp(actor,30,28)
draw_actor_hp(actor,30,0)
end
#-----------------------------------------------------------------
def draw_actor_hp(actor,x,y)
width = 128
y += 4
white = Color.new(255,105,103,215)
black = Color.new(0,0,0,255)
seagreen = Color.new(115,200,175,155)
w = width * actor.hp / actor.maxhp
# White border
self.contents.fill_rect(x+1, y-1, width-2, 1, black)
self.contents.fill_rect(x, y, width, 1, white)
self.contents.fill_rect(x-1, y+1, width+2, 9, seagreen)
self.contents.fill_rect(x, y+10, width, 1, white)
self.contents.fill_rect(x+1, y+11, width-2, 1, black)
# Black back
self.contents.fill_rect(x+2, y, width-4, 1, white)
self.contents.fill_rect(x+1, y+1, width-2, 1, black)
self.contents.fill_rect(x, y+2, width, 7, white)
self.contents.fill_rect(x+1, y+9, width-2, 1, black)
self.contents.fill_rect(x+2, y+10, width-4, 1, white)
# Generating the color
val = 255 * ((actor.hp*100)/actor.maxhp)
green = 255 - val/100
color = Color.new(400,green,55,255)
w_color = Color.new(255,green+155,96,255)
if green > 64 then green -= 32
elsif green > 128 then green -= 64 end
b_color = Color.new(172,green,0,255)
# Making the bar
self.contents.fill_rect(x+2, y, w-4, 1, w_color)
self.contents.fill_rect(x+1, y+1, w-2, 1, w_color)
self.contents.fill_rect(x, y+2, w, 7, color)
self.contents.fill_rect(x+1, y+9, w-2, 1, color)
self.contents.fill_rect(x+2, y+10, w-4, 1, b_color)
end
def draw_actor_mp(actor,x,y)
width = 128
y += 4
white = Color.new(235,115,255,155)
black = Color.new(0,0,0,255)
w = width * actor.sp / actor.maxsp
# White border
self.contents.fill_rect(x+1, y-1, width-2, 1, black)
self.contents.fill_rect(x, y, width, 1, white)
self.contents.fill_rect(x-1, y+1, width+2, 9, black)
self.contents.fill_rect(x, y+10, width, 1, white)
self.contents.fill_rect(x+1, y+11, width-2, 1, black)
# White back
self.contents.fill_rect(x+2, y, width-4, 1, white)
self.contents.fill_rect(x+1, y+1, width-2, 1, black)
self.contents.fill_rect(x, y+2, width, 7, white)
self.contents.fill_rect(x+1, y+9, width-2, 1, black)
self.contents.fill_rect(x+2, y+10, width-4, 1, white)
# Generating the color
val = 155 * ((actor.sp*100)/actor.maxsp)
green = 50 - val/100
color = Color.new(400,green,50,255)
w_color = Color.new(255,green+32,96,255)
if green > 64 then green -= 32
elsif green > 128 then green -= 64 end
b_color = Color.new(172,green,0,255)
# Making the bar
self.contents.fill_rect(x-2, y, w-4, 1, w_color)
self.contents.fill_rect(x-1, y+1, w-2, 1, w_color)
self.contents.fill_rect(x, y+2, w, 7, color)
self.contents.fill_rect(x+1, y+8, w-2, 1, color)
self.contents.fill_rect(x+2, y+10, w-4, 1, b_color)
end
#-----------------------------------------------------------------
end
#-----------------------------------------------------------------
Anyway, that creates a hp/sp bar counter in the top right of your screen.
Enjoy =D
|