I'm not 100% sure... sparkly(x,y) is recording which atoms are getting checked and then im lost :( how is it different from checked(x,y)? atom>peg fix -- you're right, it works much better now :) [code] Graphics 640,400,0,2 Graphics 320,200,0,3 AppTitle "Atomino - Blitz" background = CreateImage( 320,200) SetBuffer ImageBuffer(background) Color 192,192,192 Rect 63,15,194,170,0 ;background = LoadImage("background.bmp") atom_sprites = LoadAnimImage("atoms.bmp",24,24,0,9) electron_sprites = CreateImage(24,24,128) For t# = 0 To 127 x = 10.5 + 10.5 * Sin(t# * 2.8125) y = 10.5 + 10.5 * Cos(t# * 2.8125) SetBuffer ImageBuffer(electron_sprites,127-t#) DrawBlock atom_sprites,x,y,8 Next SetBuffer BackBuffer() Dim atom(7,8) ; which atom is where (1-4) Dim peg(7,8) ; which sides are connected Dim checked(7,8) Global space = 24 Global PUP = 1, PLEFT = 2, PDOWN = 4, PRIGTH = 8 Global nextAtom = 1 Global TotallyClean ;********************************************** Dim Sparkly(7,8) While Not KeyHit(1) mx = MouseX() my = MouseY() ;Cls ;Color 192,192,192 ;Rect 63,15,194,170,0 DrawBlock background,0,0 DrawImage atom_sprites,280,140,nextAtom-1 ;DrawBlock atom_sprites,0,0,nextAtom-1 If mx>63 And mx<253 And my>15 And my<183 Then cx = (MX-64)/space cy = (MY-16)/space DrawBlock atom_sprites,64+Floor(cx)*space,16+Floor(cy)*space,nextAtom-1 ; draw current atom at mouse position (cursor) If MouseHit(1) And atom(cx,cy)=0 Then atom(cx,cy)=nextAtom ; or whatever atom number nextAtom = Rnd(1,2) a$=Bin$(peg(cx ,cy)) total=0 For temp = 1 To Len(a$) If Mid$(a$,temp,1)=1 Then total = total+1 Next If cy>0 And atom(cx,cy) > total Then ; check UP a$=Bin$(peg(cx ,cy-1)) total=0 For temp = 1 To Len(a$) If Mid$(a$,temp,1)=1 Then total = total+1 Next If total < atom(cx,cy-1) peg(cx,cy-1)=peg(cx,cy-1) Or PDOWN peg(cx,cy)=peg(cx,cy) Or PUP End If End If ; cy>0 a$=Bin$(peg(cx ,cy)) total=0 For temp = 1 To Len(a$) If Mid$(a$,temp,1)=1 Then total = total+1 Next If cx>0 And atom(cx,cy) > total Then ; check LEFT a$=Bin$(peg(cx-1 ,cy)) total=0 For temp = 1 To Len(a$) If Mid$(a$,temp,1)=1 Then total = total+1 Next If total < atom(cx-1,cy) peg(cx-1,cy)=peg(cx-1,cy) Or PRIGTH peg(cx,cy)=peg(cx,cy) Or PLEFT End If End If ; cx>0 a$=Bin$(peg(cx ,cy)) total=0 For temp = 1 To Len(a$) If Mid$(a$,temp,1)=1 Then total = total+1 Next If cy<6 And atom(cx,cy) > total Then ; check DOWN a$=Bin$(peg(cx ,cy+1)) total=0 For temp = 1 To Len(a$) If Mid$(a$,temp,1)=1 Then total = total+1 Next If total < atom(cx,cy+1) peg(cx,cy+1)=peg(cx,cy+1) Or PUP peg(cx,cy)=peg(cx,cy) Or PDOWN End If End If ; cy<6 a$=Bin$(peg(cx ,cy)) total=0 For temp = 1 To Len(a$) If Mid$(a$,temp,1)=1 Then total = total+1 Next If cx<7 And atom(cx,cy) > total Then ; check RIGHT a$=Bin$(peg(cx+1 ,cy)) total=0 For temp = 1 To Len(a$) If Mid$(a$,temp,1)=1 Then total = total+1 Next If total < atom(cx+1,cy) peg(cx+1,cy)=peg(cx+1,cy) Or PLEFT peg(cx,cy)=peg(cx,cy) Or PRIGTH End If End If ; cx>0 For y = 0 To 6 For x = 0 To 7 checked(x,y)=0 Next Next ;If checkpoint(cx,cy, 0) = 0 Then checkpoint(cx,cy,1) Checkpoint(cx,cy,1,1) ; ********************************************************* If TotallyClean=1 For fx=0 To 7 For fy=0 To 6 If Sparkly(fx,fy)=1 Then atom(fx,fy)=0:peg(fx,fy)=0 Next Next EndIf End If ; mousedown End If For y=0 To 6 For x = 0 To 7 If atom(x,y)>0 Then a$=Bin$(peg(x,y)) total=0 For temp = 1 To Len(a$) If Mid$(a$,temp,1)=1 Then total = total+1 Next If atom(x,y)-total > 0 Then For t = 1 To atom(x,y)-total DrawImage electron_sprites, 64+x*space,16+y*space, (electron_frame + 128/(atom(x,y)-total)*t)And 127 Next End If DrawImage atom_sprites, 64+x*space,16+y*space,atom(x,y)-1 If peg(x,y) And PUP Then DrawImage atom_sprites, 64+x*space,16+y*space,4 If peg(x,y) And PLEFT Then DrawImage atom_sprites, 64+x*space,16+y*space,5 If peg(x,y) And PDOWN Then DrawImage atom_sprites, 64+x*space,16+y*space,6 If peg(x,y) And PRIGTH Then DrawImage atom_sprites, 64+x*space,16+y*space,7 End If Next Next If mx>63 And mx<253 And my>15 And my<183 Then DrawImage atom_sprites,64+Floor(cx)*space,16+Floor(cy)*space,nextAtom-1 ; draw current atom at mouse position (cursor) End If Flip electron_frame = electron_frame + 3 ; adjust for animation speed electron_frame = electron_frame And 127 Wend End Function checkpoint(x,y,clean,startpoint=0) ; ********************************** If startpoint=1 TotallyClean=1 For fx=0 To 7 For fy=0 To 6 Sparkly(fx,fy)=0 Next Next EndIf Sparkly(x,y)=1 number = 0 ; 0 = all connections made Color 255,255,255 Rect 64+x*space,16+y*space,24,24,0 Flip proceed=1 If atom(x,y)>0 Then ; find how many sides are connected a$=Bin$(peg(x,y)) total=0 For temp = 1 To Len(a$) If Mid$(a$,temp,1)=1 Then total = total+1 Next ; if less sides than atom number, then forget everything If atom(x,y)-total > 0 Then proceed = 0: TotallyClean=0 End If If checked(x,y)=1 Then proceed = 0 number=1 If proceed = 1 checked(x,y)=1 ; if completely connected, then check each connected side If (peg(x,y) And PUP) Then number = checkpoint(x,y-1,clean) If (peg(x,y) And PDOWN) Then number = checkpoint(x,y+1,clean) If (peg(x,y) And PLEFT) Then number = checkpoint(x-1,y,clean) If (peg(x,y) And PRIGTH) Then number = checkpoint(x+1,y,clean) End If ; If clean = 1 Then atom(x,y) = 0 Return number End Function[/code] This post is from -- http://socoder.net/index.php?topic=2120