http://GameProgrammer.Com

Programming

GP Mailing List
     Thread Index
     Date Index

ATXGPSIG List
     Thread Index
     Date Index

Google
>

Home

Wise2Food



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Algorithm to Rotate a piece in Tetris?



In a message dated 4/15/00 11:32:47 PM Central Daylight Time, 
excuseme32@hotmail.com writes:

<< I am creating a Tetris clone, and I was wondering if there is anyone who 
has 
 made this game in the past that has a good algorithm for rotating a piece. >>

When I made a Tetris clone for the TI-82 a few years back, I just stored the 
different rotations. For example, for the "L" game piece:

O
O
OO

(Sorry for the crappy illustrations.) I stored the various rotations:

OOO
O

OOO
     O

OO
  O
  O

OO
O
O

  O
  O
OO

And I flipped through each of them. It took more memory than manually 
rotating the functions, but it was faster - fast enough that it worked on the 
TI-82. However, it is indeed feasible to rotate it using simple 
flip/rotate/inverse calculations (without using complex rotation algorithms). 
For example, with:

OOO
O

Let's say this is defined in the cartesian coordinates <0,1>, <1,1>, <2,1>, 
and <0,0>. If you exchange the x's and y's, you get: <1,0>, <1,1>, <1,2>, and 
<0,0>, which looks like:
  O
  O
OO

Hey, look! That's a 90-degree rotation to the left! That's how you inverse 
the original bitmap.

Let's take the original <0,1>, <1,1>, <2,1>, and <0,0> shape. Now, flip the 
y-coordinates, meaning when the y-coordinate is 1, make it 0, and when the 
y-coordiante is 0, make it 1. It becomes: <0,0>,<1,0>,<2,0>, and <0,1>, which 
looks like:

O
OOO

You just flipped it vertically. If you exchange the x-coordinates instead, 
you flip it horizontally. Using these really simple calculations, you can 
make a Tetris clone.

Hope this helps.
-Ender Wiggin
=================================================================
The GameProgrammer.Com mailing list is for the open discussion
of any topic related to the art, science, and business of
programming games. This list is especially tolerant of beginners.
We were all beginners once

To SUBSCRIBE or UNSUBSCRIBE please visit:
http://gameprogrammer.com/mailinglist.html