switches implemented
This commit is contained in:
21
abad.lua
21
abad.lua
@@ -132,8 +132,8 @@ end
|
||||
function abad_state_jumping()
|
||||
abad.frame=3
|
||||
abad.wait=abad.wait+1
|
||||
print(abad.x,1,50)
|
||||
print(abad.y,10,50)
|
||||
--print(abad.x,1,50)
|
||||
--print(abad.y,10,50)
|
||||
if abad.wait==6 then
|
||||
abad.wait=0
|
||||
|
||||
@@ -146,7 +146,22 @@ function abad_state_jumping()
|
||||
if abad.y>0 then
|
||||
if check_tile(abad.hab,abad.x+4,abad.y-2)~=tiletype.block then
|
||||
if (abad.x+4)&7==0 or check_tile(abad.hab,abad.x+12,abad.y-2)~=tiletype.block then
|
||||
abad.y=abad.y-2
|
||||
|
||||
if check_tile(abad.hab,abad.x+4,abad.y-2)==tiletype.switch then
|
||||
-- Executar el switch
|
||||
local xx=min(11,max(0,flr((abad.x+4)/8)))
|
||||
local yy=min(5,max(0,flr((abad.y-2)/8)))
|
||||
switches.start(abad.hab,1+xx+yy*12)
|
||||
--cls(4)
|
||||
elseif (abad.x+4)&7~=0 and check_tile(abad.hab,abad.x+12,abad.y-2)==tiletype.switch then
|
||||
-- Executar el switch
|
||||
local xx=min(11,max(0,flr((abad.x+12)/8)))
|
||||
local yy=min(5,max(0,flr((abad.y-2)/8)))
|
||||
switches.start(abad.hab,1+xx+yy*12)
|
||||
--cls(4)
|
||||
else
|
||||
abad.y=abad.y-2
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
|
||||
2
game.ini
2
game.ini
@@ -2,4 +2,4 @@ title=Cacaus
|
||||
width=128
|
||||
height=96
|
||||
zoom=4
|
||||
files=score.lua,map.lua,mapa.lua,cacau.lua,caco.lua,zombie.lua,abad.lua,main.lua
|
||||
files=score.lua,switches.lua,map.lua,mapa.lua,cacau.lua,caco.lua,zombie.lua,abad.lua,main.lua
|
||||
|
||||
12
main.lua
12
main.lua
@@ -57,7 +57,7 @@ function _update()
|
||||
|
||||
if mode==modes.editing then
|
||||
draw_hab(abad.hab,0,0,true)
|
||||
text(abad.hab,100,10,2)
|
||||
text(abad.hab,120,1,2)
|
||||
|
||||
sspr(0,64,128,48,0,48)
|
||||
color(3)
|
||||
@@ -84,6 +84,11 @@ function _update()
|
||||
end
|
||||
|
||||
local mx,my=mousex(),mousey()
|
||||
if mx>>3 < 12 and my>>3 < 6 then
|
||||
text(mx>>3,100,10,2)
|
||||
text(my>>3,111,10,2)
|
||||
text((mx>>3)+(my>>3)*12,118,10,2)
|
||||
end
|
||||
if mbtn(1) then
|
||||
if my>=48 then
|
||||
seltile=(mx>>3)+((my-48)>>3)*16
|
||||
@@ -95,6 +100,10 @@ function _update()
|
||||
mapa_set_tile(abad.hab,mx>>3,my>>3,255)
|
||||
end
|
||||
end
|
||||
if mx>>3 < 12 and my>>3 < 6 then
|
||||
local tx,ty=(mx>>3)<<3,(my>>3)<<3
|
||||
rect(tx,ty,tx+8,ty+8,3)
|
||||
end
|
||||
else
|
||||
draw_hab(abad.hab,0,0)
|
||||
text(abad.hab,1,1,2)
|
||||
@@ -114,6 +123,7 @@ function _update()
|
||||
end
|
||||
end
|
||||
cacau.update()
|
||||
switches.update()
|
||||
|
||||
if btnp(KEY_RETURN) then
|
||||
mode=modes.editing
|
||||
|
||||
24
map.lua
24
map.lua
@@ -1,11 +1,11 @@
|
||||
mapa={
|
||||
-- 1
|
||||
{
|
||||
18,19,20,21,20,21,20,21,20,21,20,21,
|
||||
16,72,255,255,255,255,255,255,255,255,255,255,
|
||||
16,88,255,255,255,255,255,255,255,255,255,255,
|
||||
16,255,255,255,255,255,255,255,255,255,255,255,
|
||||
16,255,255,255,255,255,255,255,255,255,255,255,
|
||||
18,19,20,21,20,21,20,21,18,19,20,21,
|
||||
16,72,255,255,255,15,255,255,255,17,255,255,
|
||||
16,88,255,255,255,255,255,255,255,17,255,255,
|
||||
16,255,255,255,255,255,255,255,255,38,255,255,
|
||||
16,255,255,255,255,255,255,255,255,38,255,255,
|
||||
20,21,20,21,20,21,20,21,20,21,20,21,
|
||||
|
||||
},
|
||||
@@ -501,9 +501,9 @@ mapa={
|
||||
},
|
||||
-- 51
|
||||
{
|
||||
41,45,44,45,44,45,45,255,255,255,44,45,
|
||||
40,255,255,255,255,255,255,255,255,41,255,255,
|
||||
40,255,255,255,255,255,255,255,3,255,255,255,
|
||||
42,43,44,45,44,45,45,255,255,255,44,45,
|
||||
40,72,255,255,255,255,255,255,255,41,255,255,
|
||||
40,88,255,255,255,255,255,255,3,255,255,255,
|
||||
40,255,255,255,255,255,255,3,255,255,255,255,
|
||||
40,255,255,255,255,255,3,255,255,255,255,255,
|
||||
44,45,44,45,44,45,44,45,44,45,44,45,
|
||||
@@ -651,12 +651,12 @@ mapa={
|
||||
},
|
||||
-- 66
|
||||
{
|
||||
20,21,20,21,20,21,20,21,20,21,20,21,
|
||||
48,49,48,48,50,49,48,50,49,48,48,50,
|
||||
255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
255,255,255,255,255,255,255,255,255,255,255,255,
|
||||
20,21,20,21,20,21,20,21,20,21,20,21,
|
||||
42,43,42,43,42,43,255,255,255,255,255,255,
|
||||
255,255,255,255,42,43,3,255,255,255,255,255,
|
||||
255,255,255,255,42,43,42,43,42,43,42,43,
|
||||
|
||||
},
|
||||
-- 67
|
||||
|
||||
10
mapa.lua
10
mapa.lua
@@ -1,5 +1,5 @@
|
||||
--mapa={}
|
||||
tiletype={void=0,stair=1,half=2,block=3}
|
||||
tiletype={void=0,stair=1,switch=2,half=3,block=4}
|
||||
|
||||
function mapa_new()
|
||||
for my=0,7 do
|
||||
@@ -58,6 +58,10 @@ function mapa_set_tile(hab,x,y,tile)
|
||||
mapa[1+hab][1+x+y*12]=tile
|
||||
end
|
||||
|
||||
function mapa_set_tile_by_index(hab,index,tile)
|
||||
mapa[1+hab][index]=tile
|
||||
end
|
||||
|
||||
function mapa_get_tile(hab,x,y)
|
||||
return mapa[1+hab][1+x+y*12]
|
||||
end
|
||||
@@ -83,8 +87,10 @@ function check_tile(hab,x,y)
|
||||
local tile=mapa_get_tile(hab,xx,yy)
|
||||
if tile<8 then
|
||||
return tiletype.half
|
||||
elseif tile<16 then
|
||||
elseif tile<15 then
|
||||
return tiletype.stair
|
||||
elseif tile==15 then
|
||||
return tiletype.switch
|
||||
elseif tile<64 then
|
||||
return tiletype.block
|
||||
else
|
||||
|
||||
36
switches.lua
Normal file
36
switches.lua
Normal file
@@ -0,0 +1,36 @@
|
||||
switches={
|
||||
cooldown=0,
|
||||
wait=0,
|
||||
current_list=nil,
|
||||
current_index=-1,
|
||||
}
|
||||
switches[1]={}
|
||||
switches[1][18]={1, 57,45}
|
||||
|
||||
function switches.start(hab,tile)
|
||||
if switches.cooldown>0 then return end
|
||||
mapa_set_tile_by_index(hab,tile,57)
|
||||
switches.current_list=switches[hab+1][tile]
|
||||
print(tile)
|
||||
switches.current_index=2
|
||||
switches.wait=0
|
||||
switches.cooldown=60
|
||||
end
|
||||
|
||||
function switches.update()
|
||||
if switches.cooldown>0 then switches.cooldown=switches.cooldown-1 end
|
||||
if switches.current_list==nil then return end
|
||||
--cls(4)
|
||||
|
||||
switches.wait=switches.wait+1
|
||||
|
||||
if switches.wait==6 then
|
||||
switches.wait=0
|
||||
mapa_set_tile_by_index(switches.current_list[1]-1,switches.current_list[switches.current_index]+1,255)
|
||||
switches.current_index=switches.current_index+1
|
||||
if switches.current_index>#switches.current_list then
|
||||
switches.current_list=nil
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user