Here is a simple health bar class that can be included as a dependency in one of your projects
--# Main
-- Health Bar
function setup()
parameter.number("value", 0,100,100)
h = HealthBar(10,HEIGHT/2,WIDTH-20,value,20)
end
function draw()
background(0)
h:draw(value)
end
--# HealthBar
HealthBar = class()
function HealthBar:init(x,y,w,v,s,n)
self.x = x
self.y = y
self.width = w
self.health = v
self.max = v
self.green = self.health / (self.max/255)
self.red = 255- self.health / (self.max/255)
self.strokewidth = s or 5
self.varname=n -- a string containing the name of the variable this watches(optional)
end
function HealthBar:draw(v)
self.health = v or loadstring("return "..self.varname)()
self.green = self.health / (self.max/255)
self.red = 255- self.green
pushStyle()
lineCapMode(SQUARE)
stroke(self.red,self.green,0)
strokeWidth(self.strokewidth)
line(self.x,self.y,self.x+(self.width/self.max*self.health),self.y)
popStyle()
end