[WIP] Treballant en el jefe. Barra d'energia

This commit is contained in:
2026-04-11 18:07:43 +02:00
parent 6497f02f3c
commit 2af80b121f
4 changed files with 110 additions and 8 deletions

61
data/bar_meter.lua Normal file
View File

@@ -0,0 +1,61 @@
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