[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

@@ -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