227 lines
6.9 KiB
Lua
227 lines
6.9 KiB
Lua
SIZE = 64
|
|
mapa = {}
|
|
|
|
hero = {
|
|
x=4,
|
|
y=3
|
|
}
|
|
sprites = {
|
|
{color=0x70, data={32,97,101,32,98,102,99,100,103}}
|
|
}
|
|
function init()
|
|
mode(3)
|
|
setchar(97,0,60,126,123,126,60,24,126)
|
|
setchar(98,126,90,58,25,63,60,36,34)
|
|
setchar(99,0,0,0,0,0,1,0,0)
|
|
setchar(100,33,32,32,64,128,0,192,0)
|
|
setchar(101,0,0,0,0,0,0,2,4)
|
|
setchar(102,8,16,32,64,128,0,0,0)
|
|
setchar(103,0,128,64,64,64,64,112,0)
|
|
|
|
--mapa = newsurf((SIZE+1)*2, (SIZE+1)*2)
|
|
for i=0,(SIZE*SIZE)-1 do
|
|
mapa[i] = 1
|
|
end
|
|
|
|
local startx = 1+flr(rnd((SIZE/2)-2))*2
|
|
local starty = 1+flr(rnd((SIZE/2)-2))*2
|
|
--pset(startx-1, starty-1, 7)
|
|
--pset(startx-1, starty, 7)
|
|
--pset(startx-1, starty+1, 7)
|
|
--pset(startx+1, starty-1, 7)
|
|
--pset(startx+1, starty, 7)
|
|
--pset(startx+1, starty+1, 7)
|
|
--pset(startx, starty-1, 7)
|
|
--pset(startx, starty+1, 7)
|
|
--local rando = flr(rnd(2))
|
|
currentx,currenty=startx,starty--1
|
|
--if rando == 0 then
|
|
-- pset(startx+2, currenty, 7)
|
|
-- pset(startx+3, currenty, 7)
|
|
-- currentx=startx+3
|
|
--elseif rando == 1 then
|
|
-- pset(startx-2, currenty, 7)
|
|
-- pset(startx-3, currenty, 7)
|
|
-- currentx=startx-3
|
|
--end
|
|
|
|
create()
|
|
tomap()
|
|
--settrans(255)
|
|
--poke(32,65)
|
|
end
|
|
|
|
mazedone = false
|
|
longest_path = 1
|
|
current_path = 1
|
|
lx = 0
|
|
ly = 0
|
|
|
|
function pget(x,y)
|
|
return mapa[(x%SIZE)+(y%SIZE)*65]
|
|
end
|
|
|
|
function pset(x,y,val)
|
|
mapa[(x%SIZE)+(y%SIZE)*65] = val
|
|
end
|
|
|
|
function create()
|
|
local LIMIT = SIZE-2
|
|
while mazedone == false do
|
|
local val = pget(currentx, currenty)
|
|
local paths = {}
|
|
local numpaths = 0
|
|
if (currentx > 2) and (pget(currentx-2, currenty)==1) then
|
|
paths[numpaths] = 0
|
|
numpaths = numpaths + 1
|
|
end
|
|
if (currentx < LIMIT) and (pget(currentx+2, currenty)==1) then
|
|
paths[numpaths] = 1
|
|
numpaths = numpaths + 1
|
|
end
|
|
if (currenty > 2) and (pget(currentx, currenty-2)==1) then
|
|
paths[numpaths] = 2
|
|
numpaths = numpaths + 1
|
|
end
|
|
if (currenty < LIMIT) and (pget(currentx, currenty+2)==1) then
|
|
paths[numpaths] = 3
|
|
numpaths = numpaths + 1
|
|
end
|
|
if numpaths > 0 then
|
|
current_path = current_path + 1
|
|
local option = paths[flr(rnd(numpaths))]
|
|
if option == 0 then
|
|
pset(currentx-1, currenty, 7)
|
|
currentx = (currentx - 2)%SIZE
|
|
pset(currentx, currenty, 7)
|
|
elseif option == 1 then
|
|
pset(currentx+1, currenty, 7)
|
|
currentx = (currentx + 2)%SIZE
|
|
pset(currentx, currenty, 7)
|
|
elseif option == 2 then
|
|
pset(currentx, currenty-1, 7)
|
|
currenty = (currenty - 2)%SIZE
|
|
pset(currentx, currenty, 7)
|
|
elseif option == 3 then
|
|
pset(currentx, currenty+1, 7)
|
|
currenty = (currenty + 2)%SIZE
|
|
pset(currentx, currenty, 7)
|
|
end
|
|
else
|
|
if longest_path < current_path then
|
|
longest_path = current_path
|
|
lx = currentx
|
|
ly = currenty
|
|
end
|
|
current_path = current_path - 1
|
|
pset(currentx, currenty, 8)
|
|
if (currentx > 2) and (pget(currentx-1, currenty)==7) and (pget(currentx-2, currenty)==7) then
|
|
pset(currentx-1, currenty, 8)
|
|
currentx = (currentx-2)%SIZE
|
|
elseif (currentx < LIMIT) and (pget(currentx+1, currenty)==7) and (pget(currentx+2, currenty)==7) then
|
|
pset(currentx+1, currenty, 8)
|
|
currentx = (currentx+2)%SIZE
|
|
elseif (currenty > 2) and (pget(currentx, currenty-1)==7) and (pget(currentx, currenty-2)==7) then
|
|
pset(currentx, currenty-1, 8)
|
|
currenty = (currenty-2)%SIZE
|
|
elseif (currenty < LIMIT) and (pget(currentx, currenty+1)==7) and (pget(currentx, currenty+2)==7) then
|
|
pset(currentx, currenty+1, 8)
|
|
currenty = (currenty+2)%SIZE
|
|
else
|
|
while pget(lx, ly-1) ~= 1 do ly = ly - 1 end
|
|
pset(lx, ly, 9)
|
|
mazedone = true
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
function mset(x, y, val)
|
|
local addr = x+y*32
|
|
poke(addr, 32) addr=addr+1
|
|
poke(addr, 32) addr=addr+1
|
|
poke(addr, 32) addr=addr+30
|
|
poke(addr, 32) addr=addr+1
|
|
poke(addr, 32) addr=addr+1
|
|
poke(addr, 32) addr=addr+30
|
|
poke(addr, 32) addr=addr+1
|
|
poke(addr, 32) addr=addr+1
|
|
poke(addr, 32) addr=0x300+x+y*32
|
|
poke(addr, val) addr=addr+1
|
|
poke(addr, val) addr=addr+1
|
|
poke(addr, val) addr=addr+30
|
|
poke(addr, val) addr=addr+1
|
|
poke(addr, val) addr=addr+1
|
|
poke(addr, val) addr=addr+30
|
|
poke(addr, val) addr=addr+1
|
|
poke(addr, val) addr=addr+1
|
|
poke(addr, val)
|
|
end
|
|
|
|
function mset2(x, y, val)
|
|
poke(x+y*32, 32)
|
|
poke(0x300+x+y*32, val)
|
|
end
|
|
|
|
function draw_sprite(x,y,num)
|
|
local addr = (x*3)+(y*3)*32
|
|
poke(addr, sprites[num].data[1]) addr=addr+1
|
|
poke(addr, sprites[num].data[2]) addr=addr+1
|
|
poke(addr, sprites[num].data[3]) addr=addr+30
|
|
poke(addr, sprites[num].data[4]) addr=addr+1
|
|
poke(addr, sprites[num].data[5]) addr=addr+1
|
|
poke(addr, sprites[num].data[6]) addr=addr+30
|
|
poke(addr, sprites[num].data[7]) addr=addr+1
|
|
poke(addr, sprites[num].data[8]) addr=addr+1
|
|
poke(addr, sprites[num].data[9]) addr=0x300+(x*3)+(y*3)*32
|
|
poke(addr, sprites[num].color) addr=addr+1
|
|
poke(addr, sprites[num].color) addr=addr+1
|
|
poke(addr, sprites[num].color) addr=addr+30
|
|
poke(addr, sprites[num].color) addr=addr+1
|
|
poke(addr, sprites[num].color) addr=addr+1
|
|
poke(addr, sprites[num].color) addr=addr+30
|
|
poke(addr, sprites[num].color) addr=addr+1
|
|
poke(addr, sprites[num].color) addr=addr+1
|
|
poke(addr, sprites[num].color)
|
|
end
|
|
|
|
camx = 0
|
|
camy = 0
|
|
|
|
function tomap()
|
|
for y=0,7 do
|
|
for x=0,9 do
|
|
local val = 0x77
|
|
if pget(x+camx,y+camy) == 1 then val = 0x11 end
|
|
mset(x*3, y*3, val)
|
|
end
|
|
end
|
|
end
|
|
|
|
snd=100
|
|
function update()
|
|
if cnt() >= 6 then
|
|
rst()
|
|
if btn(KEY_LEFT) and pget(hero.x-1,hero.y) ~= 1 then
|
|
hero.x = hero.x-1
|
|
sound(snd,5) if snd==100 then snd=120 else snd=100 end
|
|
end
|
|
if btn(KEY_RIGHT) and pget(hero.x+1,hero.y) ~= 1 then
|
|
hero.x = hero.x+1
|
|
sound(snd,5) if snd==100 then snd=120 else snd=100 end
|
|
end
|
|
if btn(KEY_UP) and pget(hero.x,hero.y-1) ~= 1 then
|
|
hero.y = hero.y-1
|
|
sound(snd,5) if snd==100 then snd=120 else snd=100 end
|
|
end
|
|
if btn(KEY_DOWN) and pget(hero.x,hero.y+1) ~= 1 then
|
|
hero.y = hero.y+1
|
|
sound(snd,5) if snd==100 then snd=120 else snd=100 end
|
|
end
|
|
camx = hero.x-4
|
|
camy = hero.y-3
|
|
tomap()
|
|
draw_sprite(4,3,1)
|
|
end
|
|
end
|