Rod+Birds+Tetris+Clone

code format="vbnet" 'We have a 250x500 pixel playing area, tets are made up of four 'sprites each of 25x25 pixels. Tetdata holds the position of   'each of those sprites for each tet in each particular orientation 'as an offset from the top left corner. Rotation simply means 'redrawing the four sprites at their new offsets. 'The state of play is held in board(col,row) There is an extra 'row that defines the floor. 'The board is drawn with a combination of sprite 'drawing and bmp manipulation. Sprites are used while the 'tet falls. When it has reached it's resting place the 'board is grabbed as bmp slices, redrawn without full slices 'then grabbed as a single large bmp which becomes the background 'for the next tet to fall down. nomainwin WindowWidth = 400 WindowHeight = 600 UpperLeftX = Int((DisplayWidth - WindowWidth) / 2) UpperLeftY = Int((DisplayHeight - WindowHeight) / 2) button #main.play, "Play", [play], UL, 270,100,100,20 button #main.pause, "Pause", [pause], UL, 270,200,100,20 button #main.help, "Help", [help], UL, 270,300,100,20 graphicbox #main.g, 10, 20, 252, 502 textbox #main.score, 270, 40, 100,20 statictext #main.t, "Score",270,20, 100,20 Open "Tetris" for Window as #main #main, "Trapclose [exit]" dim tetdata(360) dim board(10,21) gosub [setup] wait

[play] 'set up board redim board(10,21) for n= 1 to 10 board(n,21)=1 next 'set current tet off if tet>0 then for n= 1 to 4 #main.g "spritevisible s";str$(tet);str$(n);" off" next end if   'clear the background #main.g "background blue" 'set the variables drop=.05                   'drop speed .01 - 1.0 tet=int(rnd(0)*7)+1        'tet shape IJLOSTZ 1-7 teto=1                     'tet orientation 1=N 2=E 3=S 4=W tetx=int(rnd(0)*4)*25+50   'tet starting x 10x25 pixel columns tety=-25                   'tet starting y    score=0 #main.score score 'add the x and y offsets for the tet to tetx and tety gosub [addoffsets] 'make it visible for n= 1 to 4 #main.g "spritevisible s";str$(tet);str$(n);" on" next 'set up an event to look for key presses #main.g "when characterInput [changemovement]" #main.g "setfocus"

[move] 'add the x and y offsets for each tet in it's current orientation gosub [addoffsets] 'position the four sprites at their offsets from tetx,tety #main.g "spritexy s";str$(tet);"1 ";x1;" ";y1 #main.g "spritexy s";str$(tet);"2 ";x2;" ";y2 #main.g "spritexy s";str$(tet);"3 ";x3;" ";y3 #main.g "spritexy s";str$(tet);"4 ";x4;" ";y4 'get the columns and rows the tets occupy bx1=int(x1/25)+1 bx2=int(x2/25)+1 bx3=int(x3/25)+1 bx4=int(x4/25)+1 by1=int(y1/25)+1 by2=int(y2/25)+1 by3=int(y3/25)+1 by4=int(y4/25)+1 'check if any tet is on the floor, if so stop falling if board(bx1,by1+1)=1 or board(bx2,by2+1)=1 or board(bx3,by3+1)=1 or board(bx4,by4+1)=1 then 'check if any tet is on the top row if by1=1 or by2=1 or by3=1 or by4=1 then [gameover] 'fill in the board array with new positions board(bx1,by1)=1 board(bx2,by2)=1 board(bx3,by3)=1 board(bx4,by4)=1 'draw the tets so we can capture them #main.g "drawsprites" 'grab the board in 20 bmp slices for by=1 to 20 #main.g "getbmp bak";str$(by);" 0 ";by*25-25;" 250 25" next 'now redraw the board in slices 'remove slices that are full bypos=20 bmpslice=20 while bypos>0 'sum the tets in the row tot=0 for bx= 1 to 10 tot=tot+board(bx,bypos) next 'draw incomplete rows if tot<>0 and tot<10 then #main.g "drawbmp bak";str$(bmpslice);" 0 ";bypos*25-25 bypos=bypos-1 bmpslice=bmpslice-1 end if           'remove completed rows if tot=10 then 'score it               score=score+100*(21-bypos) #main.score score 'compress the board array for z=bypos to 1 step -1 for f=1 to 10 board(f,z)=board(f,z-1) next next bmpslice=bmpslice-1 end if           'blank out empty rows if tot=0 then #main.g "drawbmp bak";str$(1);" 0 ";bypos*25-25 bypos=bypos-1 end if       wend 'grab the new background #main.g "getbmp bak 0 0 250 500" #main.g "background bak" 'make the old sprite invisible for n= 1 to 4 #main.g "spritevisible s";str$(tet);str$(n);" off" next 'choose next tet at random tet = int(rnd(0)*7+1) 'return drop to old speed if olddrop<>0 then drop = olddrop : olddrop=0 'make the new sprite visible for n= 1 to 4 #main.g "spritevisible s";str$(tet);str$(n);" on" next tety=-25 tetx=int(rnd(0)*4)*25+50 end if   'no tet is on the floor so keep falling tety=tety+drop #main.g "drawsprites" 'check for keyboard input diverting us to [changemovement] scan goto [move]

[pause] if pause then pause=0 #main.g "when characterInput [changemovement]" #main.g "setfocus" goto [move] else pause=1 #main.g "when characterInput " wait end if

[help] h$="Game Controls";chr$(13);"Use left and right to change column,";chr$(13) h$=h$+"up to rotate and Spc for a fast drop";chr$(13) h$=h$+"+ and - reduces or increases speed";chr$(13) notice h$   wait

[gameover] notice "Game Over ";score wait

[changemovement] w$=Inkey$ 'allow left and right movement 'if no tets are on the same rows if w$="4"or w$="6" then tot=0 for bx= 1 to 10 tot=tot+board(bx,by1+1) tot=tot+board(bx,by2+1) tot=tot+board(bx,by3+1) tot=tot+board(bx,by4+1) next if w$ = "6" and tetx+w<250 and tot=0 then tetx=tetx+25 if w$ = "4" and tetx>=25 and tot=0 then tetx=tetx-25 end if   ' rotate the tet through its four orientations if w$ = "8" then teto=teto+1 if teto>4 then teto=1

'reposition tety if height increases oldh=h gosub [addoffsets] tety=tety-abs(oldh-h) if tety<0 then tety =0

'reposition tetx if width beyond wall if tetx+w>250 then tetx=250-w end if   end if    'drop fast if w$=" " and drop <>1 then olddrop=drop drop=1 end if   'speed up or slow the drop if w$ = "+" then drop=drop+.01 if w$ = "-" then drop=drop-.01 if drop<.01 then drop =.01 if drop>1 then drop = 1 goto [move]

[addoffsets] pos=tet*40+teto*10 x1=tetx+tetdata(pos+0) x2=tetx+tetdata(pos+2) x3=tetx+tetdata(pos+4) x4=tetx+tetdata(pos+6) y1=tety+tetdata(pos+1) y2=tety+tetdata(pos+3) y3=tety+tetdata(pos+5) y4=tety+tetdata(pos+7) w=tetdata(pos+8) h=tetdata(pos+9) return

[setup] 'read tet data for t=1 to 7 'tet IJLOSTZ for o=1 to 4 'teto 1=N 2=E 3=S 4=W read x1           read y1            read x2            read y2            read x3            read y3            read x4            read y4            read w            read h            pos=t*40+o*10 tetdata(pos+0)=x1 tetdata(pos+1)=y1 tetdata(pos+2)=x2 tetdata(pos+3)=y2 tetdata(pos+4)=x3 tetdata(pos+5)=y3 tetdata(pos+6)=x4 tetdata(pos+7)=y4 tetdata(pos+8)=w tetdata(pos+9)=h next o   next t    'draw the sprite bmps #main.g "down ; fill black" #main.g "place 0 25" for n= 1 to 25 #main.g "color ";n*10;" 255 255" #main.g "box ";n;" ";n+25 #main.g "color darkgray ; box 25 50" next #main.g "getbmp s1 0 0 25 50" for n= 1 to 25 #main.g "color 255 ";n*10;" 255" #main.g "box ";n;" ";n+25 #main.g "color darkgray ; box 25 50" next #main.g "getbmp s2 0 0 25 50" for n= 1 to 25 #main.g "color 255 255 ";n*10 #main.g "box ";n;" ";n+25 #main.g "color darkgray ; box 25 50" next #main.g "getbmp s3 0 0 25 50" for n= 1 to 25 #main.g "color ";n*10;" ";n*10;" 255" #main.g "box ";n;" ";n+25 #main.g "color darkgray ; box 25 50" next #main.g "getbmp s4 0 0 25 50" for n= 1 to 25 #main.g "color 255 ";n*10;" ";n*10 #main.g "box ";n;" ";n+25 #main.g "color darkgray ; box 25 50" next #main.g "getbmp s5 0 0 25 50" for n= 1 to 25 #main.g "color ";n*10;" 255 ";n*10 #main.g "box ";n;" ";n+25 #main.g "color darkgray ; box 25 50" next #main.g "getbmp s6 0 0 25 50" for n= 1 to 25 #main.g "color ";n*10;" ";n*10;" ";n*10 #main.g "box ";n;" ";n+25 #main.g "color darkgray ; box 25 50" next #main.g "getbmp s7 0 0 25 50" 'add the sprites for t = 1 to 7 for o = 1 to 4 #main.g "addsprite s";str$(t);str$(o);" s";str$(t) #main.g "spritevisible s";str$(t);str$(o);" off" next o   next t    'add background #main.g "fill blue" #main.g "getbmp blue 0 0 250 500" #main.g "background blue" return

'I   data 0,0,25,0,50,0,75,0,100,25 data 0,0,0,25,0,50,0,75,25,100 data 0,0,25,0,50,0,75,0,100,25 data 0,0,0,25,0,50,0,75,25,100 'J   data 0,0,25,0,50,0,50,25,75,50 data 25,0,25,25,25,50,0,50,50,75 data 0,0,0,25,25,25,50,25,75,50 data 0,0,25,0,0,25,0,50,50,75 'L   data 0,0,25,0,50,0,0,25,75,50 data 0,0,25,0,25,25,25,50,50,75 data 0,25,25,25,50,25,50,0,75,50 data 0,0,0,25,0,50,25,50,50,75 'O   data 0,0,25,0,0,25,25,25,50,50 data 0,0,25,0,0,25,25,25,50,50 data 0,0,25,0,0,25,25,25,50,50 data 0,0,25,0,0,25,25,25,50,50 'S   data 0,25,25,0,25,25,50,0,75,50 data 0,0,0,25,25,25,25,50,50,75 data 0,25,25,0,25,25,50,0,75,50 data 0,0,0,25,25,25,25,50,50,75 'T   data 0,0,25,0,50,0,25,25,75,50 data 0,25,25,0,25,25,25,50,50,75 data 0,25,25,25,25,0,50,25,75,50 data 0,0,0,25,0,50,25,25,50,75 'Z   data 0,0,25,0,25,25,50,25,75,50 data 25,0,0,25,25,25,0,50,50,75 data 0,0,25,0,25,25,50,25,75,50 data 25,0,0,25,25,25,0,50,50,75

[exit] Close #main end

code