diff --git a/data/abad.lua b/data/abad.lua index 5a8d31b..0b55b5b 100644 --- a/data/abad.lua +++ b/data/abad.lua @@ -29,25 +29,6 @@ abad={} function abad_nop() 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() abad={ name="abad", x=40, y=24, diff --git a/data/cacau.lua b/data/cacau.lua index acdce30..ed253cb 100644 --- a/data/cacau.lua +++ b/data/cacau.lua @@ -3,9 +3,11 @@ type_shot={linear=1, rear=2, way3=3} cacau={ - { 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="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 } + 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="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 } + } } -- function cacau.init(_hab,_x,_y,_flip) @@ -17,15 +19,20 @@ cacau={ -- cacau.alive = true -- end +function cacau.shots() + -- print(cacau[1].name) + return cacau.shot +end + function cacau.init(_x,_y,_flip,_power,_num_shots,_type_shot) if _type_shot==type_shot.linear then for ns=1,_num_shots do - if cacau[ns].alive == true then break end - cacau[ns].x=_x - cacau[ns].y=_y - cacau[ns].flip=_flip - cacau[ns].alive = true - cacau[ns].power = _power + if cacau.shot[ns].alive == true then break end + cacau.shot[ns].x=_x + cacau.shot[ns].y=_y + cacau.shot[ns].flip=_flip + cacau.shot[ns].alive = true + cacau.shot[ns].power = _power end elseif _type_shot==type_shot.rear then @@ -38,7 +45,7 @@ function cacau:available(_num_shots,_type_shot) local avail_shots = false if _type_shot==type_shot.linear then 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 elseif _type_shot==type_shot.rear then @@ -49,10 +56,14 @@ function cacau:available(_num_shots,_type_shot) return avail_shots end +function cacau:kill(shot) + shot.alive = false +end + function cacau.draw() for ns=1,3 do - if cacau[ns].alive==true then - local cx, cy = viewp:screen_coords(cacau[ns].x, cacau[ns].y) + if cacau.shot[ns].alive==true then + local cx, cy = viewp:screen_coords(cacau.shot[ns].x, cacau.shot[ns].y) draw.circf( cx, cy, 4,16) draw.circf( cx+4, cy, 4,16) draw.circf( cx , cy, 2,6) @@ -63,30 +74,30 @@ end function cacau.update() for ns=1,3 do - if cacau[ns].alive==true then - if viewp:inside(cacau[ns].x, cacau[ns].y, cacau[ns].w, cacau[ns].h)==false then - cacau[ns].hab=-1 - cacau[ns].alive=false + if cacau.shot[ns].alive==true then + if viewp:inside(cacau.shot[ns].x, cacau.shot[ns].y, cacau.shot[ns].w, cacau.shot[ns].h)==false then + cacau.shot[ns].hab=-1 + cacau.shot[ns].alive=false break 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)= b.x+b.bb.x) + and (a.x+a.bb.x <= b.x+b.bb.x+b.bb.w) + and (a.y+a.bb.y+a.bb.h >= b.y+b.bb.y) + and (a.y+a.bb.y <= b.y+b.bb.y+b.bb.h) 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 \ No newline at end of file diff --git a/data/main.lua b/data/main.lua index d9a0cdc..d8bab98 100644 --- a/data/main.lua +++ b/data/main.lua @@ -1,17 +1,21 @@ +debug = require "debug" arcade_config = require("arcade_config") coords = require "coords" require "fps" require "fade" require "audio" -require "mapa" require "map" +require "mapa" require "logo" require "intro" require "game" require "switches" -- require "scenes" + + + coords.set_config({ tiles_width = arcade_config.tiles_width, 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) surf.source(curr_surf_src) 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 +