Advertisement

Tetris game (help please)

Started by November 12, 2004 03:39 AM
7 comments, last by GameDev.net 20 years ago
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
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.
www.stickskate.com -> check it out, some gnarly stick skating movies
Advertisement
uhmm.. ok i understood 0.0000000000005% of what u said.. but yeah
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.
um ok, still don't know how to move an object... give me code example please? or at least a tutorial
http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=21
Advertisement
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.
www.stickskate.com -> check it out, some gnarly stick skating movies
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
----------------------------

http://djoubert.co.uk
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 :)

This topic is closed to new replies.

Advertisement