screenwidth=800:screenheight=800 Graphics screenwidth,screenheight,32,2 SetBuffer BackBuffer() SeedRnd MilliSecs() Global spaceextent=4 Dim space(spaceextent*2+1,spaceextent*2+1) Dim newspace(spaceextent*2+1,spaceextent*2+1) Dim pill(spaceextent*2+1,spaceextent*2+1) Dim newpill(spaceextent*2+1,spaceextent*2+1) Global dx=0,dy=1 Global sight#=2,sanity#=1 Function move() For x=0 To spaceextent*2 If x+dx>=0 And x+dx<=spaceextent*2 For y=0 To spaceextent*2 If y+dy>=0 And y+dy<=spaceextent*2 newspace(x,y)=space(x+dx,y+dy) newpill(x,y)=pill(x+dx,y+dy) EndIf Next EndIf Next If dx=0 For off=0 To spaceextent-sight-1;Floor(sight)-1 y=spaceextent*(1+dy)-off*dy For x=0 To spaceextent*2 newspace(x,y)=Rand(0,1) If newspace(x,y)=0 Then newpill(x,y)=Rand(0,1) Else newpill(x,y)=0 Next Next Else For off=0 To spaceextent-sight-1;Floor(sight)-1 x=spaceextent*(1+dx)-off*dx For y=0 To spaceextent*2 newspace(x,y)=Rand(0,1) If newspace(x,y)=0 Then newpill(x,y)=Rand(0,1) Else newpill(x,y)=0 Next Next EndIf For x=0 To spaceextent*2 For y=0 To spaceextent*2 space(x,y)=newspace(x,y) pill(x,y)=newpill(x,y) Next Next If pill(spaceextent,spaceextent)=1 pill(spaceextent,spaceextent)=0 If sanity=1 sight=sight+Rnd(0.1,0.2) If sight>spaceextent Then sight=spaceextent Else sanity=sanity+0.2 If sanity>1 Then sanity=1 EndIf EndIf End Function For x=0 To spaceextent*2 For y=0 To spaceextent*2 space(x,y)=Rand(0,1) Next Next space(spaceextent,spaceextent)=0 space(spaceextent,spaceextent-1)=0 wobble#=0 tick=0 time#=0 oldms=MilliSecs() While Not KeyDown(1) wobble=wobble+.005 If KeyDown(200) If space(spaceextent,spaceextent-1)=0 If dx<>0 Or dy<>-1 Then tick=0 dx=0 dy=-1 EndIf ElseIf KeyDown(208) If space(spaceextent,spaceextent+1)=0 If dx<>0 Or dy<>1 Then tick=0 dx=0 dy=1 EndIf ElseIf KeyDown(203) If space(spaceextent-1,spaceextent)=0 If dx<>-1 Or dy<>0 Then tick=0 dx=-1 dy=0 EndIf ElseIf KeyDown(205) If space(spaceextent+1,spaceextent)=0 If dx<>1 Or dy<>0 Then tick=0 dx=1 dy=0 EndIf EndIf If KeyHit(57) dx=0 dy=0 tick=0 EndIf For x=0 To spaceextent*2 For y=0 To spaceextent*2 xdist=Abs(x-spaceextent) ydist=Abs(y-spaceextent) If xdist>ydist Then dist=xdist Else dist=ydist If dist>Floor(sight)+1 light#=0 ElseIf dist>Floor(sight) light#=sight-Floor(sight) Else light#=1 EndIf cx=(x-spaceextent)*50+screenwidth/2-tick*dx cy=(y-spaceextent)*50+screenheight/2-tick*dy If space(x,y): If light>0 Color 255*light,0,0 Rect cx-25,cy-25,50,50 Color 0,255*light,0 o1=((wobble*25+x*19+y*13) Mod 3)-1 o2=((wobble*27+x*17+y*11) Mod 3)-1 If x>0 And space(x-1,y)=0 Then Line cx-25-o1,cy-25,cx-25-o2,cy+25 If x0 And space(x,y-1)=0 Then Line cx-25,cy-25,cx+25,cy-25 If y0 Color 0,0,255*light Oval (x-spaceextent)*50+screenwidth/2-tick*dx-10,(y-spaceextent)*50+screenheight/2-tick*dy-10,20,20 EndIf EndIf Next Next Text 0,0,dx Text 0,12,dy Color 255*sanity,255*sanity,0 Oval screenwidth/2-15,screenheight/2-15,30,30,0 sight=sight-0.005 If sight<0 sight=0 sanity=sanity-0.01 If sanity<=0 wobble#=Rnd(360) fade#=0 For c=1 To 255 ClsColor 255-c,255-c,255-c Cls Flip Next FlushKeys() While Not GetKey() Cls fade=fade+.005 If fade>1 Then fade=1 wobble=wobble+Rnd(.2) Color (Sin(wobble)*.5+.5)*255*fade,(Sin(wobble*4)*.5+.5)*255*fade,(Sin(wobble*.6+70)*.5+.5)*255*fade Text screenwidth/2,screenheight/2,"You kept your sanity for "+Str(time)+" seconds",1,1 Flip Wend End EndIf EndIf ms=MilliSecs() t#=(ms-oldms)/1000.0 oldms=ms tsense#=1.0/sight If tsense>10 Then tsense#=10 time=time+t*tsense Text 0,0,time If dx<>0 Or dy<>0 If space(spaceextent+dx,spaceextent+dy)=0 tick=tick+5 EndIf If tick=50 move() tick=0 EndIf EndIf Flip Cls Wend