Rotation...

Started by
4 comments, last by Joppe 22 years, 3 months ago
What is the best way to do rotation in a tetris game? Thanks
Got gum?
Advertisement
Anyone? *crying*

thanks.
Got gum?
Well, you shouldn''t have to rotate when you''re building your shapes. Most people make a primitive of a single block and then build up the shapes for it in code. That way, you don''t have to rotate anything, just blit the blocks at different locations.

Anesthesia"If you like heaven so much, GO THERE! Leave me the hell alone!"
Use a 3D API such as OpenGL or Direct3d. Make your sprites texture mapped quads. It''s a great way to get started with 3d programming and lot more fun than rotating a bitmaps pixels. :o)
I recently wrote a tetris clone and found rotating the blocks to be the most challenging part. I ended up with obscure routines different for each shape, that can''t really be gotten into here. If you''d like, send me an email and I''ll be happy to give you the full code, but I really don''t think that my way is the best, or for that matter, even a good way to do it.
Maintain a 4x4 grid in "object space" which indicates which particular cells are filled. The filled cells must be contiguous, have a length no greater that 4 and define the tetrii.

Example cell structure:
0 | 0 | 0 | 01 | 1 | 1 | 10 | 0 | 0 | 00 | 0 | 0 | 0 

The above is the familiar 4-in-a-line tetris.

You can then write two simple routines to rotate left and right (since all rotations are by 90 degrees). Presto.

On the other hand, using 3D APIs gives you a lot more possibilities and flexibility in terms of graphical effects and pizzazz. But I suppose this is more of a learning effort anyway...

[ GDNet Start Here | GDNet FAQ | MS RTFM | STL | Google ]
Thanks to Kylotan for the idea!

This topic is closed to new replies.

Advertisement