I quit becuase this project bores me.
Here are da codez:
global lx
global ly
global dim level(lx,ly)
global ss
ss=1
global dim snakex(ss)
global dim snakey(ss)
`/init
load(l)
`main loop
placea()
do
cls
if escapekey()=1 then goto menu
if leftkey()=1 then movesnake(-1,0)
if rightkey()=1 then movesnake(1,0)
if upkey()=1 then movesnake(0,-1)
if downkey()=1 then movesnake(0,1)
if spacekey()=1 then growsnake(1) : space=1
if spacekey()=0 then space=0
col=collision()
if col=1 or col=5 then goto game
if col=3 then level(snakex(1),snakey(1))=0
if col=2 then placea() : growsnake(1) : level(snakex(1),snakey(1))=0
if col=6 then l=l+1 : goto game
if col=4 then deleteall(5)
ink rgb(255,0,0),rgb(255,0,0)
text 20,20,str$(snakex(ss))+" "+str$(snakey(ss))
drawlevel()
sync
loop
`functions
`draw level to screen
function drawlevel()
wid=screen width()/lx
hit=screen height()/ly
for x=0 to lx
for y=0 to ly
ink 0,0
if level(x,y)=1 then ink rgb(255,255,255),0
if level(x,y)=2 then ink rgb(255,0,0),0
if level(x,y)=3 then ink rgb(200,200,200),0
if level(x,y)=4 then ink rgb(0,128,128),0
if level(x,y)=5 then ink rgb(255,255,255),0
if level(x,y)=6 then ink rgb(10,200,50),0
`4=key
`5=door
`6=exit
box wid*x,hit*y,(wid*x)+wid,(hit*y)+hit
next y
next x
ink rgb(0,255,0),0
for s=1 to ss
x2=snakex(s)
y2=snakey(s)
box wid*x2,hit*y2,(wid*x2)+wid,(hit*y2)+hit
next s
endfunction
`load level
`before loading level, global dim snakex(1) and snakey(1) and set ss to 1
function load(level)
load image "level"+str$(level)+".bmp",1
sprite 1,0,0,1
lx=sprite width(1)
ly=sprite height(1)
delete sprite 1
dim level(lx,ly)
paste image 1,0,0
for x=0 to lx
for y=0 to ly
tmp=POINT(x,y)
tmpr=rgbr(tmp)
tmpg=rgbg(tmp)
tmpb=rgbb(tmp)
if tmpr=255 and tmpg=255 and tmpb=255 then level(x,y)=1
if tmpr=255 and tmpg=0 and tmpb=0 then level(x,y)=2
if tmpr=0 and tmpg=255 and tmpb=0 then level(x,y)=3
if tmpr=0 and tmpg=0 and tmpb=255 then level(x,y)=4
if tmpr=0 and tmpg=255 and tmpb=255 then level(x,y)=5
if tmpr=255 and tmpg=255 and tmpb=0 then level(x,y)=6
if tmpr=128 and tmpg=128 and tmpb=128 then skipos=1 : skx=x : sky=y
next y
next x
delete image 1
if skipos=0
for x=1 to lx
for y=1 to ly
if level(x,y)=0
snakex(1)=x
snakey(1)=y
exit
endif
goto endload
next y
next x
else
snakex(1)=skx
snakey(1)=sky
endif
endload:
cls
endfunction
`Move snake by x and y values
function movesnake(x,y)
if x=0 and y=0 then exit
if ss>1
for ts=ss to 2 step -1
snakex(ts)=snakex(ts-1)
snakey(ts)=snakey(ts-1)
next ts
endif
if y>0 then snakey(1)=snakey(1)+1
if y<0 then snakey(1)=snakey(1)-1
if x>0 then snakex(1)=snakex(1)+1
if x<0 then snakex(1)=snakex(1)-1
if y>1 then ty=y-1
if y<-1 then ty=y+1
if x>1 then tx=x-1
if x<-1 then tx=x+1
if tx<>0 and ty<>0 then movesnake(tx,ty)
endfunction
`Grow the snake by 1
function growsnake(amt)
`if amt=<0 then exit
ss=ss+1
ARRAY INSERT AT BOTTOM snakex(1)
ARRAY INSERT AT BOTTOM snakey(1)
`if ss>2
`tx=snakex(ss-1)
`ty=snakey(ss-1)
`tx2=snakex(ss-2)
`ty2=snakey(ss-2)
`x=tx2-tx
`y=ty2-ty
`snakex(ss)=tx+x
`snakey(ss)=ty+y
`else
snakex(ss)=snakex(ss-1)
snakey(ss)=snakey(ss-1)
`endif
`if amt>1 then growsnake(amt-1)
endfunction
`collision
`will return block type if colliding with level and -1 if colliding with snake
function collision()
col=level(snakex(1),snakey(1))
`for tmp=2 to ss
`if snakex(1)=snakex(tmp) or snakey(1)=snakey(tmp) then col=-1
`next tmp
endfunction col
`place apple on random blank space
function placea()
endfunction
function deleteall(block)
for x=1 to lx step 1
for y=1 to ly step 1
if level(x,y)=block then level(x,y)=0
next y
next x
endfunction
Instructions:
You make levels called level-.bmp.
They should be 64x64 and 16 color.
- is the level number, which starts at 0.
White is a wall.
Black is an empty space.
Yellow is the next-level zone.
Blue is the key.
Gray is the spawn point.
Green is blocks that do nothing.
(I've added a level bitmap in the code button)
Use the arrowkeys to move.
The test level is insanly hard.
This code can easily be modified.
Well, I didn't exactly quit, so you can't use this code in your projects.