Jump to content
  • Advertisement
Sign in to follow this  
cwl157

dark gdk and tetris

This topic is 3657 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

I have been programming in java and c++ for a couple years but have always had a hard time with graphics. Creating tetris is something i have wanted to do for a while now and i tried once using sdl and c++ but did not get very far. Now i found out that dark gdk is free with visual c++ so i downloaded it and went through a tutorial that came with it. I think making tetris using visual c++ and dark gdk will not be too hard with all the built in sprite handling functions that dark gdk comes with. One thought i have come across while thinking up the design for it is how does collision detection work. If i am correct dark gdk comes with a function that detects if one sprite is hitting another but the sprites are rectangles. Not all forms of all tetris peices are rectangles so how do i make the collision detection so the peices will line up flush with each other?

Share this post


Link to post
Share on other sites
Advertisement
What do you mean by not all the pieces of Tetris are rectangles?

Think of it this way: every piece in the game is composed of four rectangles.

Share this post


Link to post
Share on other sites
You may need to consider implementing a higher level 'piece' object that understands how to do collision detection between two 'piece' objects by testing the subrectangles that make up those pieces for collision.

Share this post


Link to post
Share on other sites
right but i was thinking of it as each peice would be a sprite not all rectangles that make up each peice but each tetrad i think they are called would be a sprite. So if thats the case then the rectangle around each tetrad sprite would not necessarily be the outside edge of the tetris peice.

Share this post


Link to post
Share on other sites
Oh ok so if each tetris tetrad is going to be made up of a different colored rectangle, i could have each colored recangle be seperate. Then when the rectangle collides with another rectangle the tetris tetrad sprite would stop moving? Does that sound like it would work?

Share this post


Link to post
Share on other sites
Or I have heard people say that because the tetrads are easy to draw that using sprites in tetris is not necessary. And if that is the case can someone explain to me then in c++ or java how you would draw a tetris tetrad. I can see how it would be like a 2d array and i have done extensive work with 2d arrays and can not at all picture how i would draw a tetrad. I can also see how the board itself is like a 2d array but can not figure out how that would relate to the whole graphics thing and stuff. Because if the whole window was a 2d array then you could check to delete lines too. You would just check each row in the 2d array and see if there is a rectangle in each column and if there is then delete the row. Each tetrad could be a 2d array and you would only draw the rectangles specific to that peice, the rest would be blank space. So how do i take the logic used in console / text based 2d arrays and apply it to graphics. I guess that might be my real question. Again, i dont care what language at this point c++ or java maybe java because objects are easier.

Share this post


Link to post
Share on other sites
In my Tetris game I'm working on. I use a 2D array for the pit/well and a 2d array for the pieces.

Each cell of the array is a block. Therefore

xxxx
xRRx
xRRx
xxxx

would be a square piece.

Use a 4 x 4 for your piece and a 10 x 20 or whatever dimiensions you wish to choose for your pit/well.

Then you can check for collision using the arrays.

Now when it comes to graphics. You just read the array and print the blocks as you read through the array. Each cell will be "mapped" to a section of the screen.

something like

print block at coordinates [16*x][16*y] I don't have my code in front of me but it's something similar to this if your blocks are 16 x 16.

Share this post


Link to post
Share on other sites
o ok so you say print them at 16*x and 16*y because each of your rectangles is 16 pixels by 16 pixels. And your playing space then is 10 rows by 20 columns so if you want to place a peice at row 3 col 6 you say 16*3 16*6 and this will space over the amount of pixels necessary to place a peice at row 3 col 6

Share this post


Link to post
Share on other sites
ok so lets say i wanted to switch this to java and following what you have told me this is how i would do it. I would have a peice class that would have 1 rectangle size and color and then inheriting from that i would have a class representing each tetris tetrad peice. They would start as a 4 x 4 char array like murdock has in his post. From there i would loop through the 4 x 4 array and draw a rectangle everywhere there is supposed to be one. And each rectangle would get drawn at the row * size of rec and col * size of rect. Does that sounda about right for drawing the tetris tetrads?

Share this post


Link to post
Share on other sites
You shouldn't think of collision detection in termes of visible sprites. Your tetris game should be playable even without seeing anything (for example, a bot could play it). Think about how to represent your game board and your pieces so that you can ask the game board "does this piece fit?".

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!