I'd like to know how you actually remove the rows. As soon as you have implemented it (or have questions), feel free to post. Because as I see it, it involves splitting pieces that contribute to the rows into two pieces, or maybe just cut one piece a little smaller, or completely remove the piece.
Unless you have just ommitted it, it doesn't seem that you are doing anything to remove the completed row. Oh wait. Is the comment - // remove row - just a placeholder for the ommitted code? That would make sense. Why don't you post that because it sounds like that is the part of the code that is failing.
EDIT: wow, I should learn to read. Apparently you already found the solution! Doh! sorry.
Quote:Original post by Fred304 I'd like to know how you actually remove the rows. As soon as you have implemented it (or have questions), feel free to post. Because as I see it, it involves splitting pieces that contribute to the rows into two pieces, or maybe just cut one piece a little smaller, or completely remove the piece.
two pieces:
XXX <-- cut hereX
one piece:
X <-- cut hereXXX
remove:
XXXX <-- cut here
How is your list of pieces sorted?
Seeing how he has a Block::Active flag, I assume he just "unflags" all blocks that belong to the removed row, and then removes all the Shapes that have all their blocks inactive. Anyway, the whole approach is slightly insane. What's the purpose of holding a list with several items, each one comprised of several blocks, which could be "active" or not? It's useless extra information. At any moment, Tetris only cares about the "soup" of blocks, not about how and by what shapes it got constructed. The logical thing to do is just have a WxH grid that fills with the correct values when a piece lands, and be done with it. BrasiLokau, I assume that you're making Tetris not just to make Tetris, but to learn. I don't think you learn much by using crazy methods like this. The design you follow does not fit the problem very good. Try to make your life simple.
Quote:Original post by Fred304 I'd like to know how you actually remove the rows. As soon as you have implemented it (or have questions), feel free to post. Because as I see it, it involves splitting pieces that contribute to the rows into two pieces, or maybe just cut one piece a little smaller, or completely remove the piece.
two pieces:
XXX <-- cut hereX
one piece:
X <-- cut hereXXX
remove:
XXXX <-- cut here
How is your list of pieces sorted?
Seeing how he has a Block::Active flag, I assume he just "unflags" all blocks that belong to the removed row, and then removes all the Shapes that have all their blocks inactive. Anyway, the whole approach is slightly insane. What's the purpose of holding a list with several items, each one comprised of several blocks, which could be "active" or not? It's useless extra information. At any moment, Tetris only cares about the "soup" of blocks, not about how and by what shapes it got constructed. The logical thing to do is just have a WxH grid that fills with the correct values when a piece lands, and be done with it. BrasiLokau, I assume that you're making Tetris not just to make Tetris, but to learn. I don't think you learn much by using crazy methods like this. The design you follow does not fit the problem very good. Try to make your life simple.
Well as i said, I created this tetris clone based on the tutorial at c-unit. I did write the code like that to learn, and because the code looks clean and it has a lot of oop elements in it. The first solution i came up with when i was plaining the game, was using a bidimensional array int area[row,col], make all the game logic based in that array(moving, detecting rows, removing) and then translating that to graphics in the screen. But since i'm getting pretty far with this the way it is, i'm going to finish it. I need to fix collision detection thats is acting weird, also when i complete more than a single row at the same time it only removes the second row after the next shape reaches the bottom(pretty weird bug), have to write score and level part, also i pretend to implement highscore, splash screen e menus, then its finished :)
and for the guy that asked how do i remove the blocks, as mike said, each block is set its Active property to true, so when i call the render method, it only renders the ones that Active are set to true.
Quote: I did write the code like that to learn, and because the code looks clean and it has a lot of oop elements in it.
Just because you use lots of classes and inheritance does not mean you have a good OO design.
Quote: and for the guy that asked how do i remove the blocks, as mike said, each block is set its Active property to true, so when i call the render method, it only renders the ones that Active are set to true.
But that does not cut the pieces into two :)
Let me make it clearer. Consider a case where an L-piece gets cut in the middle:
AB <--- cut hereCD
As I understand it you set the B block to inactive which would look something like this:
ACD
But how can you make A fall onto C? It's supposed to look like this, isn't it:
well, i must say that you 'r right... the way i'm doing its way more complicated than should be. But i really did learn alot of oop concepts with it, so it was worth writing the code that way. Because i don't expect millions of people trying out my tetris game :P, i made it for learning purposes.
I did make it work. Let me try to explain how the classes work. There is a block class, with fiels like position, if its active or not. Also there is a Shape class, which is responsible for creating an array of 4 block, the state(for rotation purposes), with methods for checkcollision, move shape, render, deactivate(loop through each block and set .active = false, so it is not draw by render method, and etc... So when i have to remove rows, i loop throw all settled shapes, and just check which ones are in the same height, as the row that has to be erased... Thats the way it works, as i said, i read a tutorial at c-unit.com about making a tetris, my code is pretty much based with the code in the website, except for changes i've made. You can go there and see if you understand. The code is not completed yet, there is a bug that if two rows are scored at the same time, it only desapear of screen after the next block hits the bottom.
[Edited by - BrasiLokau on May 19, 2006 5:33:16 PM]