[WIP] Cacauaes començant a funcionar

This commit is contained in:
2026-03-29 19:15:17 +02:00
parent 7f4f29ecc2
commit fa74a841e7
4 changed files with 118 additions and 86 deletions

View File

@@ -29,25 +29,6 @@ abad={}
function abad_nop() function abad_nop()
end end
-- Imprime cualquier valor, incluyendo tablas anidadas
local function dump(value, indent)
indent = indent or ""
if type(value) ~= "table" then
return tostring(value)
end
local parts = {"{"}
for k, v in pairs(value) do
local key = (type(k) == "string") and k or "["..tostring(k).."]"
table.insert(parts,
string.format("%s %s = %s,",
indent, key, dump(v, indent.." ")))
end
table.insert(parts, indent.."}")
return table.concat(parts, "\n")
end
function abad_init() function abad_init()
abad={ name="abad", abad={ name="abad",
x=40, y=24, x=40, y=24,

View File

@@ -3,10 +3,12 @@
type_shot={linear=1, rear=2, way3=3} type_shot={linear=1, rear=2, way3=3}
cacau={ cacau={
shot={
{ name="cacau1", hab=-1, x=0, y=0, w=12 ,h=8 ,wait=0, flip=false, bb={x=0,y=0,w=4,h=4}, alive=false, power=1 }, { name="cacau1", hab=-1, x=0, y=0, w=12 ,h=8 ,wait=0, flip=false, bb={x=0,y=0,w=4,h=4}, alive=false, power=1 },
{ name="cacau2", hab=-1, x=0, y=0, w=12 ,h=8 ,wait=0, flip=false, bb={x=0,y=0,w=4,h=4}, alive=false, power=1 }, { name="cacau2", hab=-1, x=0, y=0, w=12 ,h=8 ,wait=0, flip=false, bb={x=0,y=0,w=4,h=4}, alive=false, power=1 },
{ name="cacau3", hab=-1, x=0, y=0, w=12 ,h=8 ,wait=0, flip=false, bb={x=0,y=0,w=4,h=4}, alive=false, power=1 } { name="cacau3", hab=-1, x=0, y=0, w=12 ,h=8 ,wait=0, flip=false, bb={x=0,y=0,w=4,h=4}, alive=false, power=1 }
} }
}
-- function cacau.init(_hab,_x,_y,_flip) -- function cacau.init(_hab,_x,_y,_flip)
-- if cacau.hab ~= -1 then return end -- if cacau.hab ~= -1 then return end
@@ -17,15 +19,20 @@ cacau={
-- cacau.alive = true -- cacau.alive = true
-- end -- end
function cacau.shots()
-- print(cacau[1].name)
return cacau.shot
end
function cacau.init(_x,_y,_flip,_power,_num_shots,_type_shot) function cacau.init(_x,_y,_flip,_power,_num_shots,_type_shot)
if _type_shot==type_shot.linear then if _type_shot==type_shot.linear then
for ns=1,_num_shots do for ns=1,_num_shots do
if cacau[ns].alive == true then break end if cacau.shot[ns].alive == true then break end
cacau[ns].x=_x cacau.shot[ns].x=_x
cacau[ns].y=_y cacau.shot[ns].y=_y
cacau[ns].flip=_flip cacau.shot[ns].flip=_flip
cacau[ns].alive = true cacau.shot[ns].alive = true
cacau[ns].power = _power cacau.shot[ns].power = _power
end end
elseif _type_shot==type_shot.rear then elseif _type_shot==type_shot.rear then
@@ -38,7 +45,7 @@ function cacau:available(_num_shots,_type_shot)
local avail_shots = false local avail_shots = false
if _type_shot==type_shot.linear then if _type_shot==type_shot.linear then
for ns=1,_num_shots do for ns=1,_num_shots do
if cacau[ns].alive == false then avail_shots = true end if cacau.shot[ns].alive == false then avail_shots = true end
end end
elseif _type_shot==type_shot.rear then elseif _type_shot==type_shot.rear then
@@ -49,10 +56,14 @@ function cacau:available(_num_shots,_type_shot)
return avail_shots return avail_shots
end end
function cacau:kill(shot)
shot.alive = false
end
function cacau.draw() function cacau.draw()
for ns=1,3 do for ns=1,3 do
if cacau[ns].alive==true then if cacau.shot[ns].alive==true then
local cx, cy = viewp:screen_coords(cacau[ns].x, cacau[ns].y) local cx, cy = viewp:screen_coords(cacau.shot[ns].x, cacau.shot[ns].y)
draw.circf( cx, cy, 4,16) draw.circf( cx, cy, 4,16)
draw.circf( cx+4, cy, 4,16) draw.circf( cx+4, cy, 4,16)
draw.circf( cx , cy, 2,6) draw.circf( cx , cy, 2,6)
@@ -63,30 +74,30 @@ end
function cacau.update() function cacau.update()
for ns=1,3 do for ns=1,3 do
if cacau[ns].alive==true then if cacau.shot[ns].alive==true then
if viewp:inside(cacau[ns].x, cacau[ns].y, cacau[ns].w, cacau[ns].h)==false then if viewp:inside(cacau.shot[ns].x, cacau.shot[ns].y, cacau.shot[ns].w, cacau.shot[ns].h)==false then
cacau[ns].hab=-1 cacau.shot[ns].hab=-1
cacau[ns].alive=false cacau.shot[ns].alive=false
break break
end end
end end
cacau[ns].wait=cacau[ns].wait+1 cacau.shot[ns].wait=cacau.shot[ns].wait+1
if cacau[ns].wait == 3 then cacau[ns].wait = 0 end if cacau.shot[ns].wait == 3 then cacau.shot[ns].wait = 0 end
if arc_check_tile(cacau[ns].x,cacau[ns].y)<tiletype.block then if arc_check_tile(cacau.shot[ns].x,cacau.shot[ns].y)<tiletype.block then
local step=3 local step=3
if cacau[ns].flip then step=-step end if cacau.shot[ns].flip then step=-step end
cacau[ns].x=cacau[ns].x+step cacau.shot[ns].x=cacau.shot[ns].x+step
if viewp:inside(cacau[ns].x, cacau[ns].y, cacau[ns].w, cacau[ns].h)==false then if viewp:inside(cacau.shot[ns].x, cacau.shot[ns].y, cacau.shot[ns].w, cacau.shot[ns].h)==false then
cacau[ns].alive=false cacau.shot[ns].alive=false
break break
end end
else else
cacau[ns].hab=-1 cacau.shot[ns].hab=-1
cacau[ns].alive = false cacau.shot[ns].alive = false
end end
end end
end end

View File

@@ -1,8 +1,4 @@
arcade_config = require("arcade_config")
viewport= require("viewport") viewport= require("viewport")
require "fps"
require "mapa"
require "abad" require "abad"
require "cacau" require "cacau"
require "caco" require "caco"
@@ -189,7 +185,18 @@ function update_game()
-- end -- end
-- end -- end
--end --end
if viewp:inside(actor.x, actor.y, actor.w, actor.h) and actor~=abad then
for _, cacau_shot in pairs(cacau.shots()) do
if cacau_shot.alive and collision(actor,cacau_shot) then
if actor.hit ~= nil then
actor:hit()
cacau:kill(cacau_shot)
end end
end
end
end
end
cacau.update() cacau.update()
switches.update() switches.update()
@@ -265,42 +272,10 @@ function update_game()
-- end -- end
end end
function msg_print(x, y, msg, direct_print ) function collision(a, b)
local scr_x, scr_y return (a.x+a.bb.x+a.bb.w >= b.x+b.bb.x)
direct_print = direct_print or false and (a.x+a.bb.x <= b.x+b.bb.x+b.bb.w)
if direct_print then and (a.y+a.bb.y+a.bb.h >= b.y+b.bb.y)
scr_x = x and (a.y+a.bb.y <= b.y+b.bb.y+b.bb.h)
scr_y = y
else
scr_x, scr_y = viewp:screen_coords(x, y)
end
draw.rectf(scr_x,scr_y,45,7,16)
draw.text(msg,scr_x+1,scr_y+1,2)
end end
function view_coord(x, y, w, h, color)
local scr_x, scr_y = viewp:screen_coords(x, y)
draw.rect(scr_x, scr_y, w, h, color)
end
function write_tile(x, y, yplus, print_type, align )
local scr_x, scr_y = viewp:screen_coords(x, y)
local hab, xx, yy = coords.world_to_tile(x, y)
yplus = yplus or 0
print_type = print_type or false
align = align or "R"
local txt_offset = -7
if align=="R" then txt_offset = -14
elseif align=="L" then txt_offset = 0
end
draw.rectf(scr_x+txt_offset,scr_y+yplus,14,7,16)
-- local msg = mapa_get_tile(hab,xx,yy)
local msg = arc_get_tile(x,y)
if print_type then
msg = msg.." "..arc_check_tile(x, y)
end
draw.text(msg,scr_x+txt_offset+1,scr_y+1+yplus,2)
end

View File

@@ -1,17 +1,21 @@
debug = require "debug"
arcade_config = require("arcade_config") arcade_config = require("arcade_config")
coords = require "coords" coords = require "coords"
require "fps" require "fps"
require "fade" require "fade"
require "audio" require "audio"
require "mapa"
require "map" require "map"
require "mapa"
require "logo" require "logo"
require "intro" require "intro"
require "game" require "game"
require "switches" require "switches"
-- require "scenes" -- require "scenes"
coords.set_config({ coords.set_config({
tiles_width = arcade_config.tiles_width, tiles_width = arcade_config.tiles_width,
tiles_height = arcade_config.tiles_height, tiles_height = arcade_config.tiles_height,
@@ -178,3 +182,64 @@ function arc_textB(str, x, y, col, colB)
draw.surf(0,0,sw,sh,x,y,dw,dh) draw.surf(0,0,sw,sh,x,y,dw,dh)
surf.source(curr_surf_src) surf.source(curr_surf_src)
end end
-- DEBUG
-- Imprime cualquier valor, incluyendo tablas anidadas
function dump(value, indent)
indent = indent or ""
if type(value) ~= "table" then
return tostring(value)
end
local parts = {"{"}
for k, v in pairs(value) do
local key = (type(k) == "string") and k or "["..tostring(k).."]"
table.insert(parts,
string.format("%s %s = %s,",
indent, key, dump(v, indent.." ")))
end
table.insert(parts, indent.."}")
return table.concat(parts, "\n")
end
function msg_print(x, y, msg, direct_print )
local scr_x, scr_y
direct_print = direct_print or false
if direct_print then
scr_x = x
scr_y = y
else
scr_x, scr_y = viewp:screen_coords(x, y)
end
draw.rectf(scr_x,scr_y,45,7,16)
draw.text(msg,scr_x+1,scr_y+1,2)
end
function view_coord(x, y, w, h, color)
local scr_x, scr_y = viewp:screen_coords(x, y)
draw.rect(scr_x, scr_y, w, h, color)
end
function debug.write_tile(x, y, yplus, print_type, align )
local scr_x, scr_y = viewp:screen_coords(x, y)
local hab, xx, yy = coords.world_to_tile(x, y)
yplus = yplus or 0
print_type = print_type or false
align = align or "R"
local txt_offset = -7
if align=="R" then txt_offset = -14
elseif align=="L" then txt_offset = 0
end
draw.rectf(scr_x+txt_offset,scr_y+yplus,14,7,16)
-- local msg = mapa_get_tile(hab,xx,yy)
local msg = arc_get_tile(x,y)
if print_type then
msg = msg.." "..arc_check_tile(x, y)
end
draw.text(msg,scr_x+txt_offset+1,scr_y+1+yplus,2)
end