[WIP] Cacauaes començant a funcionar
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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)<tiletype.block then
|
||||
if arc_check_tile(cacau.shot[ns].x,cacau.shot[ns].y)<tiletype.block then
|
||||
local step=3
|
||||
if cacau[ns].flip then step=-step end
|
||||
cacau[ns].x=cacau[ns].x+step
|
||||
if cacau.shot[ns].flip then step=-step end
|
||||
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
|
||||
cacau[ns].alive=false
|
||||
if viewp:inside(cacau.shot[ns].x, cacau.shot[ns].y, cacau.shot[ns].w, cacau.shot[ns].h)==false then
|
||||
cacau.shot[ns].alive=false
|
||||
break
|
||||
end
|
||||
else
|
||||
cacau[ns].hab=-1
|
||||
cacau[ns].alive = false
|
||||
cacau.shot[ns].hab=-1
|
||||
cacau.shot[ns].alive = false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
arcade_config = require("arcade_config")
|
||||
viewport= require("viewport")
|
||||
|
||||
require "fps"
|
||||
require "mapa"
|
||||
require "abad"
|
||||
require "cacau"
|
||||
require "caco"
|
||||
@@ -189,7 +185,18 @@ function update_game()
|
||||
-- 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
|
||||
|
||||
cacau.update()
|
||||
switches.update()
|
||||
|
||||
@@ -265,42 +272,10 @@ function update_game()
|
||||
-- end
|
||||
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)
|
||||
function collision(a, b)
|
||||
return (a.x+a.bb.x+a.bb.w >= 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
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user