Skip to main content
gamedev.net
🔒 Locked

Tetris...

Started by Spur4 5 replies 900+ views
Original Post
Spur4
Spur4
Hi all, I''m not usually fond of graphics, but big fan of Tetris. Recently, I started writing a Tetris clone in C++... Everything went well, I''m experienced in C++, created a point class, a block class etc... Well, I stumbled upon a problem... When I rotate a figure, I should know each location, right ? So, if my clone has for example 10 figures, each having 4 possible orientations, I just should program all these possible positions ? Is there an easier way to do that ? Seems like its a hell lot of hard black work !
Ridcully
Ridcully
some time ago i also programmed tetris to test my ddraw engine, and i did it excactly as you said.
just hardcode the 4 position of each tile, i think that''s the easiest way, unless you want to have dynamic tiles. then you would have to code a little rotation function, which shouldn''t be too difficult (hint: store a pivot point for each tile)

rid
mbarela
mbarela
Hard coding things makes programs more complex and hard to read and extend. Even on a simple game like Tetris you should take the time to write a method that can rotate a point through 2d space. It will save you a lot of time in the long run. There are several examples on the net available but if your still stumped after looking at them drop me an e-mail at MikeB@yaya.com and i''ll help you out.

Mike Barela
mbarela@earthlink.net
Mike BarelaMikeB@yaya.com
Spur4
Spur4
Can you please post some links where I can find
info on how to write a 2D rotation function.
MadButch
MadButch
I'm working on my very first game, also a Tetris clone, at this very moment.

I choose for the following solution.
The block which falls down has one origin block (around which it rotates) and 3 side blocks.
My CBlock class has an m_iaXPos[4] and a m_iaYPos[4] member variable, which store the relative position of each sub-block. Item 0 is the origin block in each shape.
For example:
the T block would be
X:0,-1,0,1
Y:0, 0,1,0

At first I used a rotation function, which was easy, because since you only rotate 90 degrees you can do a simple matrix multiply.

Then it bugged me that the Z shaped block had 4 different positions while rotating, but it actually only has 2 (shape 3 and 4 are the same as 1 and 2). I changed the code and gave each block type a max. shapes (m_iMaxShapes). And I stored all possible shapes by making the m_iaXPos and m_iaYpos a 2 dimensional array.
The only thing the rotation code now does, is switch to the next shape (m_iCurrentShape).

I hope it's clear what I'm telling here
Just wanted to let you know how I tackled the problem...

My clone is called Hacker, and the demo can be downloaded at http://play.as/madbutch

Keep in mind that this is my first game ever, and that I only started games programming july this year!

Good luck!!

Edited by - MadButch on September 25, 2000 3:08:52 AM
Check my games out at:http://www.GamePlayHeaven.com

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.