Author |
Message |
lespaul93
|
Posted: Sun Jan 13, 2008 9:02 pm Post subject: Tetris help |
|
|
Im trying to make a tetris game myself. But am having lots of trouble
i looked over the tetris submissions on this site and am trying to understand how they work
i know arrays are used a lot for tetris but i dont exactly understand for what
would someone kindly tell me where i should start and what i need to concentrate on in order to code a very simple tetris game
(explain how the code works in parts please) |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Tony
|
Posted: Sun Jan 13, 2008 9:14 pm Post subject: RE:Tetris help |
|
|
first, simplify the problem to having just once piece. Have a screen with nothing but a single tetris piece (pick anything but the square) in the middle of the screen.
Figure out how to store that piece in memory.
Figure out how to move that piece on screen (left, right, down... don't bother with it falling just yet)
This is a bit more complicated -- figure out how to rotate the piece.
Once you have this little demonstration of a single piece floating around, adding the rest is simple. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
lespaul93
|
Posted: Tue Jan 15, 2008 7:54 pm Post subject: Re: Tetris help |
|
|
I have all the shapes using arrays and am able to move them left right down and are always free falling, and the program randomly generates the shape, my problems are the following:
1. I do not get how to rotate the piece.
2. I still do not have any collision detection and the blocks will overlap another
and what do you mean by put the piece into memory? |
|
|
|
|
|
syntax_error
|
Posted: Tue Jan 15, 2008 9:09 pm Post subject: Re: Tetris help |
|
|
lespaul93 wrote:
2. I still do not have any collision detection and the blocks will overlap another
and what do you mean by put the piece into memory?
tony, im geuss here you mean have the whole game screen as an 2D array so that when ever something is there the value becomes true and then you cant not add anytihng to that therefore the "stacking" may occur |
|
|
|
|
|
lespaul93
|
Posted: Tue Jan 15, 2008 9:13 pm Post subject: Re: Tetris help |
|
|
But how do you make it so that when anything occupies the space the variable becomes true and nothing can go ontop of it? |
|
|
|
|
|
syntax_error
|
Posted: Tue Jan 15, 2008 9:20 pm Post subject: Re: Tetris help |
|
|
if its true then you cant place anything in the index of that array anymore make it look for only false indices simple no? (well in theory ya///) |
|
|
|
|
|
ericfourfour
|
Posted: Tue Jan 15, 2008 9:41 pm Post subject: Re: Tetris help |
|
|
You can store each piece in a file. Have some way to represent tetris pieces. Then allow a line break between each piece in the text file for the next clockwise rotation. Make sure you have a way to read the pieces from a file first. If you make it well enough, players might be able to add their own custom pieces.
edit: this is to answer question 1 |
|
|
|
|
|
Tony
|
Posted: Tue Jan 15, 2008 9:43 pm Post subject: Re: Tetris help |
|
|
syntax_error @ Tue Jan 15, 2008 9:09 pm wrote: tony, im geuss here you mean have the whole game screen as an 2D array so that when ever something is there the value becomes true
That's one way to approach this, yes.
2D boolean map is an excellent way to store the game field state. The way I've implemented Tetris is that I would have another smaller (just large enough for a single piece) boolean map over top. In essence there are always two game pieces -- falling block and everything else. When the block lands, it's shape is merged into the latter, and it's checked for full lines.
ericfourfour -- you are right, rotations can be pre-calculated this way. Though tiny-scale matrix rotations are not that difficult. Actually it would be the same single rotational step each time, if you include the empty space around the piece. In such a manner, it's the rotational function that is "pre-calculated" |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Sponsor Sponsor
|
|
|
|