• Advertisement

Archived

This topic is now archived and is closed to further replies.

Need an advice

This topic is 6059 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''m using DelphiX to make a Tetris clone. I was wondering what would be the best method of "clearing" a line of blocks when the line is full and make all the other blocks on top fall down. I''m using a sprite for each tetraminoe. Thanks in advance. Regards, Bergsteinn Einarsson

Share this post


Link to post
Share on other sites
Advertisement
i imagine in delphi you have some form of boolean variables...eh? well then its pretty obvious, that you could draw them only if their state = say true, else if state = false (DONT). so when their is a full row of blocks set their status to false, and they wont be draw. good luck ... also if you need more than 2 states, you would just define a variable state, then have different values that would act on the state.

Share this post


Link to post
Share on other sites
Camus you sure have a lot of tetris questions...

I'm not sure how your "game world" is set up, but I can only assume you have set up each piece so that it is composed of smaller square sprites. So an L for instance would actually be made up of 4 smaller square sprites. And that you track their position using a 2 dimensional array. If this is so then all you need to do is run a nested for loop to parse the array before each new piece enters the playing field and keep a boolean array of rows that need to be purged. Then simply purge them. {Purging can be done as masterg explained}

Lets take for example the original tetris which had a playing field of 10x20 squares. Here is a quick example of how you might approach determining which rows have blocks all the way across the width of the playing field.

      
var {Global Declarations}
PlayingField: Array[0..19,0..9] of Boolean;
CompleteRows: Array[0..19] of Boolean;

procedure PurgeCheck();
var
Row,Collumn: Integer;
Complete: Boolean;
begin
for Row := 0 to 19 do begin
Complete := true;
for Collumn := 0 to 9 do begin
if (PlayingField[Row,Collumn] = false) then begin
Complete := false;
end;
end;
CompleteRows[Row] := Complete;
end;
end;


Then all that is needed is to parse the CompleteRows array and handle for those rows that need to be purged. This code could obviously be optimized a bit, and it would be a good idea to actually pass in the arrays rather than use global ones like I did, but this example isn't meant to be taken verbatum. Just learn what you can from it.


P.S. Camus, whats your programming background like? (Highschool, College, Self-taught)

Edited by - Xorcist on July 18, 2001 4:00:39 AM

Share this post


Link to post
Share on other sites
Yes, I have a two-dimensional array to check if a given square in the playing field is "occupied" or not. But I don''t have a single square sprites - e.g. my L is one sprite and my T is another sprite.

But I think I know what to do know - if a line is full, I simply move all of the blocks down by one square

PS. My programming background is rather small - mostly self tought in Pascal and a little in VB and I''ve just recently become interested in Game Programming and Delphi. I used Pascal for one year in, well I don''t know if it''s High School or collage, you see I live in Iceland and here first we go to school from 6 to 16 yr and then from 16 to 20. I''m 20 now and will by starting in University this Autumn.
I''m going to study math and physic so my programming has been mostly math-related.

Thanks alot.

Regards,
Bergsteinn Einarsson

Share this post


Link to post
Share on other sites
I think you would want a simple square sprite and make the different blocks from four squares. This way, when a row is cleared you just remove that row of squares and the squares above drop one row. The problem with your approach is what happens when the middle square of a L shape gets cleared and the squares above fall down? The shape changes but you only have the one L shape sprite. Stuck. Also, another advantage to using small square sprites is that you do not need to store pre-rotated shapes. You generate the rotated shapes out of squares at run-time.

Steve ''Sly'' Williams  Code Monkey  Krome Studios

Share this post


Link to post
Share on other sites

  • Advertisement