[WIP] Treballant en el jefe. Super al 50%

This commit is contained in:
2026-04-11 23:22:50 +02:00
parent 2af80b121f
commit 91db8e40be
4 changed files with 152 additions and 44 deletions

View File

@@ -1,6 +1,9 @@
bar_meter={}
function bar_meter.new(scr_x, scr_y, width, height, _value, _max_value, _actor)
function bar_meter.new(scr_x, scr_y, width, height, _value, _max_value, _actor, _color_ok, _color_warn, _color_danger)
_color_ok = _color_ok or 10; -- verd
_color_warn = _color_warn or 8; -- groc
_color_danger = _color_danger or 3; -- roig
return {
x = scr_x,
y = scr_y,
@@ -10,6 +13,9 @@ function bar_meter.new(scr_x, scr_y, width, height, _value, _max_value, _actor)
max_value = _max_value,
draw=bar_meter.draw,
actor=_actor,
color_ok = _color_ok,
color_warn = _color_warn,
color_danger = _color_danger,
}
end
@@ -37,25 +43,29 @@ function bar_meter:draw()
if self.value>self.max_value/2 then
-- 50%
color = 10; -- verd
color = self.color_ok
elseif self.value>self.max_value/3 then
-- 33%
color = 8; -- groc
color = self.color_warn
else
color = 3; -- roig
color = self.color_danger
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))
local lifebar_w = w-3
local segment_w = lifebar_w/self.max_value
local life_w = math.floor(lifebar_w*(self.value/self.max_value))
-- if self.value==self.max_value then curr_width=curr_width-2 end
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 );
draw.rectf( x+2, y+2, life_w, 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)
for n_segment=1,self.value-1 do
x_segment = math.floor((x+2)+segment_w*n_segment)
-- if n_segment==self.max_value then
-- x_segment=x+w-2
-- end
draw.vline( x_segment, y+2, y+h-2, 16)
end
-- draw.vline( x+2+segment_w*n_segment, y+2, y+h-2, 16)
end
end