Advertisement

Read from textfile(tetris)

Started by November 28, 2002 09:20 AM
3 comments, last by Evol970 21 years, 11 months ago
I'm currently trying to develop a Tetris-like game in OpenGL. I did a block(1 square) falling down the screen and stop at the bottom. I've done the basic controls(move side,speed up with down key and rotate with up key). I looked at some free code over the net and see that many people use a textfile to define the blocks. I want to know how to display the block that match the file... ex : 0000 0110 0110 0000 will display a square. I know how to draw blocks with the glBegin(GL_QUADS) func and I know how to read a text file but don't have an idea how to display four blocks at the time in a position define in a textfile. Any suggestions ? [edited by - Evol970 on November 28, 2002 10:22:33 AM]
Use an algorithm saying that a number value of say, 1 is equal to a certain color (Could have it random). And all of the 2''s equal to another color. And have only one number for your background (probably 0). Just a suggestion.

tcache
Contact Me


Formerly known as Wachar <- Thrander <- Tazel
tcacheContact Me-----------AH! MY BRAIN IS GOING TO SELF-DETONATE! -- Yours Truly (Jan, 2003)
Advertisement
yeah I already did that but what I mean is how

0100
0100
0100
0100 will display |

0000
1111
0000
0000 will display -

0010
0010
0010
0010 will display |

0000
0000
1111 will display -
0000

this as no mathers with color but with shape
It would be easier to have all your block types pre-defined (there aren''t too much in a tetris game), number them and select them by reading a single value from your textfile.
You current approach demands you have to build up the geometry manually, which is more tedious to do.
Load the data into a 4 by 4 array of bool''s (or ints if you want varying colour). Then, when you want to display a block, loop through each row and column in the array, and if it''s set to true, draw a quad (with an offset based on the position of the block, and the row and column).

Hope that helps,

John B
The best thing about the internet is the way people with no experience or qualifications can pretend to be completely superior to other people who have no experience or qualifications.

This topic is closed to new replies.

Advertisement