bar_meter={} function bar_meter.new(scr_x, scr_y, width, height, _value, _max_value, _actor) return { x = scr_x, y = scr_y, w = width, h = height, value = _value, max_value = _max_value, draw=bar_meter.draw, actor=_actor, } end function bar_meter:draw() if self.actor~=nil and not empty_table(self.actor) then self.value=self.actor.energia self.max_value=self.actor.max_energia end -- local x = 0 -- local y = 2 -- local w = 6 -- local h = 7 local x = self.x local y = self.y local w = self.w local h = self.h -- borde blau draw.hline(x+1, y, x+w-1, 15) draw.hline(x+1, y+h, x+w-1, 15) draw.vline(x , y+1, y+h-1, 15) draw.vline(x+w, y+1, y+h-1, 15) draw.rectf(x+1, y+1, w-1, h-1, 16 ); -- fons negre if self.value>self.max_value/2 then -- 50% color = 10; -- verd elseif self.value>self.max_value/3 then -- 33% color = 8; -- groc else color = 3; -- roig end local segment_w = math.floor((w-2)/self.max_value) local full_width = w-2 local curr_width = math.floor((w-2)*(self.value/self.max_value)) if self.value>0 then -- -- fons negre -- draw.rectf( x+2, y+2, w-4, h-4, 2 ); -- barra de vida draw.rectf( x+2, y+2, curr_width-1, h-3, color ); -- segments for n_segment=1,self.max_value-1 do draw.vline( x+2+segment_w*n_segment, y+2, y+h-2, 16) end end end