[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

View File

@@ -16,6 +16,7 @@ require "score"
require "trigger"
require "imp"
require "fireball"
require "bar_meter"
require "stage1"
require "remote_view"
@@ -31,10 +32,18 @@ local view_tile_id = false
local view_checking_tile = false
local stage= 1
local stage_loaded = 0
stage_update = foo
stage_draw_back = foo
stage_draw_middle = foo
stage_draw_front = foo
viewp = viewport.new(arcade_config.resolucion.width, arcade_config.resolucion.height)
viewp:position(0,0)
function foo()
print("foo")
end
function actor_warp_draw(actor)
local shrink_w = actor.w*actor.shrink
local shrink_h = actor.h*actor.shrink
@@ -140,6 +149,10 @@ end
function load_boss_stage()
local stage_boss = stages["stage"..stage.."_boss"]
if stage_boss and not scene_running and not stages.loaded_boss then
stage_update = stages["stage"..stage.."_update"]
stage_draw_back = stages["stage"..stage.."_draw_back"]
stage_draw_middle = stages["stage"..stage.."_draw_middle"]
stage_draw_front = stages["stage"..stage.."_draw_front"]
stage_boss()
print("Stage "..stage.." Boss loaded")
else
@@ -190,9 +203,15 @@ function world_update()
end
end
if stages.boss_loaded then
stage_update()
else
-- print("NO BOSS")
end
-- Actualizar el que queda
cacau.update()
fireball.update()
-- switches.update()
warp.update_all()
end
@@ -200,7 +219,7 @@ end
function world_draw()
-- Pintar la finestra del mon
render_map(sf_mapa, tiles, viewp.x, viewp.y)
if stages.boss_loaded then stage_draw_back() end
-- pintar warps
for key,warp in pairs(warp.warp_list) do
if viewp:inside(warp.x, warp.y, warp.w, warp.h) then
@@ -215,8 +234,10 @@ function world_draw()
end
end
if stages.boss_loaded then stage_draw_middle() end
cacau:draw()
fireball.draw()
if stages.boss_loaded then stage_draw_front() end
remote_view_draw()
end

View File

@@ -26,8 +26,8 @@ function imp.new(_hab, _x, _y)
frame=28,
wait=0,
vides=1,
energia=6,
max_energia=6,
energia=21,
max_energia=21,
falling=0,
step=0,
hurting=0,
@@ -499,7 +499,7 @@ if DEBUG_FN_NAME then print("shot") end
-- self:reset_fight_mode_cooldown(1)
self:do_flip(abad)
self.flip_wait=100
print("FIREBALL!!")
-- print("FIREBALL!!")
local flip = false
local x_ini = self.x+self.bb.x+self.bb.w+4
@@ -594,7 +594,7 @@ if DEBUG_FN_NAME then print("pattern_next_target") end
self.path = self.paths[from][next_path_idx]
self.path_curr_action = 1
self.target = self.hot_points[self.path.next]
print("Next pattern target => "..self.path.next)
-- print("Next pattern target => "..self.path.next)
end
function imp:path_next_action( from )

View File

@@ -29,6 +29,7 @@ function stages.stage1_init()
boss = imp.new(55,4,3)
table.insert( actors, boss )
boss_meter = bar_meter.new(64,176,128,8,1,1,boss)
--batman
@@ -118,8 +119,27 @@ function stages.stage1_init()
stages.boss_loaded = false
end
function stages.stage1_update()
-- print("stage1_update")
fireball.update()
end
function stages.stage1_draw_back()
-- print("stage1_draw_back")
end
function stages.stage1_draw_middle()
-- print("stage1_draw_middle")
end
function stages.stage1_draw_front()
-- print("stage1_draw_front")
fireball.draw()
boss_meter:draw()
end
function stages.stage2_init()
print("stage 2 init")
-- print("stage 2 init")
end
function stages.stage1_boss_ready()