GraphicsWindow.ShowMessage("invalid parameter", "Error") Sub CopyPiece 'in basetemplate, template, rotationįor i = 0 to BOXES - 1 ' x' = y y' = L - 1 - xįor i = 0 to BOXES - 1 ' x' = L - 1 - y y' = xĪrray.SetValue(template, i, Array.GetValue(basetemplate, i)) ' creates template that's a rotated basetemplate YOFFSET = YOFFSET + Array.GetValue(Array.GetValue(h, -1), "pviewy") ' Array.GetValue(h, -1) = the template name XOFFSET = XOFFSET + Array.GetValue(Array.GetValue(h, -1), "pviewx") ' Array.GetValue(h, -1) = the template name While yposdelta = 0 And Math.Abs(xposbk - xpos) 0 ThenĪrray.SetValue(h, -1, basetemplate) ' Array.GetValue(h, -1) = the template name ' See if it can be moved so that it will rotate.
If GraphicsWindow.LastKey = "Down" or GraphicsWindow.LastKey = "Space" Thenīasetemplate = Array.GetValue(h, -1) ' Array.GetValue(h, -1) = the template nameĬopyPiece() 'in basetemplate, template, rotationĪrray.SetValue(h, -1, template) ' Array.GetValue(h, -1) = the template name ValidateMove() ' in: ypos, xpos, h, moveDirection ret: invalidMove = 1 or -1 or 2 if move is invalid, otherwise 0 If GraphicsWindow.LastKey = "Escape" Then Ypos = ypos + 1 ' otherwise, move the piece down. Yposdelta = yposdelta - 1 ' used to create freespin, when the piece is rotated ' Delay, but break if the delay get set to 0 if the piece gets dropped Template = Text.Append("template", Math.GetRandomNumber(7))ĬheckStop() ' in: ypos, xpos, h ret: done GraphicsWindow.ShowMessage( "Game Over", "Small Basic Tetris" ) GraphicsWindow.Title = "Small Basic Tetris" YOFFSET = 40 ' Screen Y offset in pixels of where the board startsĬWIDTH = 10 ' Canvas Width, in number of boxesĬHEIGHT = 20 ' Canvas Height, in number of boxes. XOFFSET = 40 ' Screen X offset in pixels of where the board starts GraphicsWindow.BackgroundColor = GraphicsWindow.GetColorFromRGB( 253, 252, 251 )
#TETRIS SHAPES CODE#
Original code by visiting the links above. So this article was updated to be executed with the current versions. It became incompatible with the current versions (1.0 and 1.1). New Version : this code was originally written with an older version of Small Basic.
#TETRIS SHAPES DOWNLOAD#
If you want to just run the program, you can download the self-contained EXE here: Now since we know where the block starts in the 2-D array index (0,2), we can shift the entire block to the right like this ->Ġ0000 Blit green block at x,y coords, or if 2 was detected in playingField, then blit red block at x,y coords, or if 0 detected then empty space is found etc.It's a litte hard to digest but this is only one way to tackle the problem.Here's a simple Tetris game written in Microsoft Small Basic. Now when the long block is first dropped the grid (2-D array)will look like this ->ĭo you notice how the long block is represented by the 1's? How do we do this? Well lets say our 5x5 grid looks like this and "0" means empty space -> Lets say the player wants to shift the block right. You know the one that looks like this "1111" (Excuse the graphics). Now imagine that your prog randomly selected the long block to drop next.
How can we implement this grid in code? By means of a 2-D array (playingField). The way I solved the changing of the blocks is like this -> Imagine that the playing field to which the blocks are dropped is one big grid. I plan to pick it up in a couple of weeks. I was working on a tetris clone a while ago.