Tetris Line Check - Which mehtod is Optimal?
by Jeremy Tilton · in Torque Game Builder · 03/18/2005 (10:26 pm) · 0 replies
All movement in my tetris game is done. Finally solved the beast regarding when to allow rotations, movement, etc. Next up, is line checks. I've come up with two ways of checking for if the player has a complete line. I think I already know the answer to which method would be less intensive on the hardware, but watned to double-check with the experts:
Method 1 (I think better): Maintain a double array. Every time a piece drops into position, update the double array (1 for "block is present" 0 for "empty"). After those actions are complete, run a check on each row. return true if every bit in the row is 1, false if not.
Method 2 (less overhead, but more work on system): Do a pickRay() on each row, and make sure each row consists of a set piece. Assuming I implemented the code right, every block of space in the game area will consist of either nothing or 1 block, never multiple, so I could do a simple check on the number of blocks returned by the pickRay() function, and if that = the number of rows, we have a line.
I think method 2 would be easier on me to implement and less data to keep track of, but I'm not sure how intensive the collision test would be every time a piece is set into place. Thoughts?
Method 1 (I think better): Maintain a double array. Every time a piece drops into position, update the double array (1 for "block is present" 0 for "empty"). After those actions are complete, run a check on each row. return true if every bit in the row is 1, false if not.
Method 2 (less overhead, but more work on system): Do a pickRay() on each row, and make sure each row consists of a set piece. Assuming I implemented the code right, every block of space in the game area will consist of either nothing or 1 block, never multiple, so I could do a simple check on the number of blocks returned by the pickRay() function, and if that = the number of rows, we have a line.
I think method 2 would be easier on me to implement and less data to keep track of, but I'm not sure how intensive the collision test would be every time a piece is set into place. Thoughts?
About the author