Jump to content
  • Advertisement
Sign in to follow this  
alx123

some tetris in SDL question

This topic is 3418 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone Im having trouble figuring where to begin coding What would be the best way to make the blocks? Tiles?? . How would I rotate the blocks? What would you reccomend after tetris? Thanks you so much

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by alx123
Hello everyone
Im having trouble figuring where to begin coding
What would be the best way to make the blocks? Tiles?? . How would I rotate the blocks?

First of all what language are you using? SDL has bindings to many languages, but for now I can assume C++.

Second of all, what have you got down already? Do you have a simple game loop set up? Can you accept input and allow the user to exit the program? You have yr methods to display images set up?

I guess we can assume that you do since you are asking about how to make the blocks. I think you should say what you have exactly completed thus far and what language you are using; it would help with answering.

EDIT: Just did a quick tetris tutorial search on the forums and found this: Link to Tetris Tutorial in C++ with SDL.

Share this post


Link to post
Share on other sites
oh sorry, well I`m using c++, and for what I have right now is only the code for setting the screen, background, but the first thing I want to do is the blocks.

Share this post


Link to post
Share on other sites
You could try the strategy that the author of the linked tutorial uses which is to create two classes: a square class and a block class. The blocks are then built up from the squares.

The squares would have data like center coordinates and color, etc. The squares could have move() and render() methods... something like that.

Then the blocks can be built from the squares. The square class could implement rotation. Also, the square class would need move() and render() methods which would synchronize the move() and render() methods of the squares so that the block would move as a cohesive whole. I guess you could also have a gravity() method which is responsible for the game physics acting on the tetrominos as they're sometimes called.

EDIT: the blocks would also need an arrangeTetromino() method to arrange the different tetrominos. Also, each tetromino could have a "leader" or "center" square that the squares rotate about when the rotate() method is called. It might simplify the logic/math of the rotate() method.

Share this post


Link to post
Share on other sites
Some straightforward answers to your questions:

Quote:
What would be the best way to make the blocks?

Well, if you've been coding for awhile you realize that data is just a matter of representation. You can do it any way you want, but realize that each "piece" is easily able to fit into a 4x4 array of int. What you might store there is either an "on/off" value or a flag for a color since each piece can look different.

Quote:
Tiles??

If you can store a piece in a 4x4 array, drawing it should be trivial if you can blit a BMP of a square or as I did it, draw it manually with some for loops and a plot pixel function.

Quote:
How would I rotate the blocks?

This is what is called a 3D array, since you already have 2D piece data that you need several pieces of.

So hopefully, it's obvious that the issue of data structures and algorithms for a video game is no different than for any program.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!