Sign in to follow this  
Noxir

Tetris game (help please)

Recommended Posts

I know how to 'build' the stuff in my tetris game and how to rotate it when you press right and left, but how do I change the position so it moves down? thanks

Share this post


Link to post
Share on other sites
have three arrays holding x,y position and a bool (falling or not), of the center or left top corner or anything else you want also when you press left, run through the falling array, if true then decrease the x value by a set amount. Its the same for the down movement, except you change the y value for all falling objects, every 1/2 sec say (se a timer function). Finally draw all the objects.

Share this post


Link to post
Share on other sites
He's just saying that you need to store the positions (x,y coordinates) of the tetris pieces/blocks, and every second or so (depending on how fast it's moving) change the positions

You then draw all the blocks/pieces depending on what position they are currently at.

Share this post


Link to post
Share on other sites
If you dont understand this you are not ready to m,ake a tetris game. These are only the simple things. Have you thought about how to tell if you can turn the block or not(if next to wall or blocks)., or how to check whether the block will land there etc... it is quite a complicated process. I reccomend starting with the nehe lessonms, and probably getting a good book on c++, I like Microsoft c++ .net step by step guide.

Share this post


Link to post
Share on other sites
U know snake is proparbly the most basic to make of em all or space invaders.

Start there, for snake i can give u a headstart as for space invaders arrays is the keys!

As for Tetris it's quite involved.

I started by just making single bocks

Struct Block
{
pos x,pos y;
color col;
void checkCollisionTarget(Pos x,Pos y)
}

and once i got it working i moved on to objects
struct BlockSet
{
Block *block;
void CheckBlocksCollisionTarget(Pos x,Pos y) // Where x,y are relative to the blocks origin

}

// as for rotation, i kept 4 diffrent objects per Real object
// so as to reload the entire thing for another rotation of the object

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I wrote the internals to a tetris game and never got around to writing the renderer.

This is how I layed out my engine.

A class to handle the piece (the playing object) that handles stuff like current coords and will rotate the piece. I make up 1 block in the piece that is the rotation point. It also calculates the boundries, i.e. the furthest left block coord.

A class to handle a line. The line is just a collection of blocks that are either on or off. This then has functions like is the line complete.

The main program then has a collection of lines and all you do it test piece against the lines. So when user presses down, you move the piece down 1 and check for collisions. If it collided then move the piece back up 1 and set the relevant blocks in the line.
Do the same for the auto-drop.

When a piece has been placed into the lines, then check for complete lines and remove them. Then update the lines using either pointers or by copying the entire lines down 1.

Some things I implemented into the engine...
gridWidth,
gridHeight,
canRotateLeft,
canRotateRight,
downIsFullDrop,
canPushFromWall,
droptimeStart,
droptimeReduction,
linesPerLevel,
pointsPerPiece,
pointsPerLine,
pointsPerBonusLine

Then I got bored and never wrote a rendering engine :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this