Thought up an idea for a game over the weekend,and figured I'd finally put together a maze generator in AGk

`change these 2 variables to change the size of the maze
maxx=40
maxy=30
SetVirtualResolution ( maxx*40, maxy*40 )
dim mazexy[maxx+1,maxy+1]
dim mazeok[(maxx+1)*(maxy+1),2]
x=random(3,maxx-2)
y=random(3,maxy-2)
success=1
mazeok[success,1]=x
mazeok[success,2]=y
mazexy[x,y]=1
gosub border
gosub createsprites
do
hj=0
stuck=stuck+1
if stuck>20 and stuck<850 then gosub branch
if stuck>850 then gosub savestuff
direc=random(1,4)
if direc=1
y2=y
y=y-1
if y<1 then y=y2
if mazexy[x-1,y] =1 or mazexy[x,y-1] =1 or mazexy[x+1,y] =1 or mazexy[x,y] =1 or mazexy[x-1,y-1] =1 or mazexy[x+1,y-1] =1
y=y2
else
stuck=0
success=success+1
mazeok[success,1]=x
mazeok[success,2]=y
endif
endif
if direc=2
y2=y
y=y+1
if y>maxy then y=y2
if mazexy[x-1,y] =1 or mazexy[x,y+1] =1 or mazexy[x+1,y] =1 or mazexy[x,y] =1 or mazexy[x-1,y+1] =1 or mazexy[x+1,y+1] =1
y=y2
else
stuck=0
success=success+1
mazeok[success,1]=x
mazeok[success,2]=y
endif
endif
if direc=3
x2=x
x=x-1
if x<1 then x=x2
if mazexy[x,y-1] =1 or mazexy[x-1,y] =1 or mazexy[x,y+1] =1 or mazexy[x,y] =1 or mazexy[x-1,y-1] =1 or mazexy[x-1,y+1] =1
x=x2
else
stuck=0
success=success+1
mazeok[success,1]=x
mazeok[success,2]=y
endif
endif
if direc=4
x2=x
x=x+1
if x>maxx then x=x2
if mazexy[x,y-1] =1 or mazexy[x+1,y] =1 or mazexy[x,y+1] =1 or mazexy[x,y] =1 or mazexy[x+1,y-1] =1 or mazexy[x+1,y+1] =1
x=x2
else
stuck=0
success=success+1
mazeok[success,1]=x
mazeok[success,2]=y
endif
endif
mazexy[x,y]=1
Print(stuck)
Print(success)
for t2= 0 to maxy-1
for t= 1 to maxx
if mazexy[t,t2+1]=1
SetSpriteColorAlpha(t+(maxx*t2),100)
else
SetSpriteColorAlpha(t+(maxx*t2),255)
endif
next t
next t2
Sync()
loop
restartit:
for t = 1 to maxy
for t2=1 to maxx
mazexy[t2,t]=0
next t2
next t
success=0
stuck=0
gosub border
return
border:
for t = 1 to maxy
mazexy[1,t]=1
next t
for t = 1 to maxy
mazexy[maxx,t]=1
next t
for t = 1 to maxx
mazexy[t,1]=1
next t
for t = 1 to maxx
mazexy[t,maxy]=1
next t
return
createsprites:
for t=1 to maxx*maxy
CreateSprite ( t, 0 )
SetSpriteSize(t,40,40)
SetSpriteColorAlpha( t, 255 )
next t
for t2= 0 to maxy-1
for t= 1 to maxx
SetSpritePositionbyoffset ( t+(maxx*t2), (t*40)-20 , (40*t2)+20 )
next t
next t2
return
branch:
a=random(1,success)
x=mazeok[a,1]
y=mazeok[a,2]
return
savestuff:
saves=saves+1
file$=str(saves)
OpenToWrite ( 1, file$+"a.dat",0 )
for t2=1 to maxx+1
for t=1 to maxy+1
WriteInteger ( 1, mazexy[t2,t])
next t
next t2
CloseFile ( 1 )
gosub restartit
return

Careful, I'm not much of a programmer

yo