0 Members and 1 Guest are viewing this topic.
"welcome to the world of computers, where everything seems to be based on random number generators"
X = {-1,-1,0,1}Y = {-1,0,0,0}
For(I,1,4)Output(X(I)+S,Y(J)+T)End
X->ZY->X-Z->Y
Code: [Select]For(I,1,4)Output(X(I)+S,Y(J)+T)End
For 1-> I To 4PlotOn List 1[I]+s,List 2[I]+TNext
Code: [Select]X->ZX = YY = -Z
X->ZX = YY = -Z
CollisionsI am a bit unfamiliar with Casio homescreen text commands, so I will assume there is a way to detect whether a single space is filled. Whether you utilize some sort of Pixel Test function, or use a Matrix, the logic is the same. There are two conditions for a collision, you either move a piece into a wall, or rotate a piece into a wall. Assuming we have a way to detect whether a position is filled, collision checking is simple.First we merely move or rotate the object blindly, then loop through all positions of the new piece position and check if any of them are filled. If any of them are, we reverse the object operations and resume the game. Because of this, you will need a way to rotate both directions.
Line Detecting:Because of the size of the tetris field, it might be difficult to check every line every time a piece is placed, so instead we will check only the lines that possibly could have a completion, and these are the lines that the piece ends up in. The piece is made of 4 blocks, which means at a maximum we will have to check 4 lines. When we check for lines, we take the Y locations of the object, remove duplicated, and sort them from top to bottom. The we loop through each Y position from top to bottom. For each Y position we check all of the blocks in that line, if any of them are empty, we skip this Y position and go to the next. If we are at the last Y position, we move on to playing the game.If, however, all of the blocks are filled, we move onto the line clearing algorithm. It consists of mostly a line shifting algorithm, and this is how it works. If a filled Line was detected at location Y, we go through every block in that line and replace it with the one above. We then do that for every line above Y until we encounter an empty line, after which we are finished clearing and shifting.Once we check and clear every line we need to, we can choose the next piece (which can be done from a lookup table) and start the next turn!