Archived

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

Tetris clone pseudo-code.

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

Hey all. Okay, I''ve realised that the only reason I''ve not actually produced a game yet, is that I''m having problems putting the concept into perspective to actually attempt it. I''ve been so used to programming "on-the-fly", so to speak, that I''ve never had to properly design anything except complex database systems. That''s all well and good, but whilst I know I have the programming knowledge to actually produce a game like Tetris, I can''t seem to visualise the project properly, so I''m not getting anywhere. With that in mind, I''ve been knocking up some pseudo-code and wondered if someone could have a look and give me some suggestions/feedback? Hopefully, if I can get a solid design, I''ll be able to code it up relatively quickly. Here''s the pseudo-code:
--- BlockiX Pseudo-code

1. Start program.
 1a. Set game state to GAME_LOADING.
 1b. Read highscores from hard-disk into an array (or an object).

2. Initialise window.
 2a. Register window class.
 2b. Create window.

3. Start new game.
 3a. Set game state to GAME_NEW.
 3b. Initialise game grid to safe state.
 3c. Reset score.
 3d. Set game state to GAME_INPROGRESS.

4. Process game (set timer to lock game speed).
 4a. Create a tile piece (random).
 4b. Draw the piece.
 4c. If (user input) {
       Move/rotate piece.
       if (piece trying to move out of grid bounds) {
         Goto 4.
       }
       If (piece collides with another piece) {
         If (piece at bottom of grid) {
           Lock piece in place.
         }
         Goto 4.
       }
     }
     // Not sure about this bit.
     Else {
       Goto 4.
     }
 4d. If (any grid lines are complete) {
       Clear line.
       Move all affected pieces down x grid units (x being number of lines cleared).
       Increment score.
     }
 4e. If (score >= level_up required score) {
       Increment level.
       Increment game speed.
     }
 4f. If (piece collides with another piece and is at top of the grid)
       Set game state to GAME_OVER.

5. End game.
 5a. If (score > lowest highscore) {
       Prompt player to enter his/her name.
       Save new score in array (or object).
     }
 5b. Display highscores.
 5c. If (user input = File->New) {
       Set game state to GAME_NEW.
     }

6. Exit program.
 6a. Write highscores to hard-disk.
 6b. If (window closed or File->Exit) {
       Clean up resources.
       Exit.
     }
 
Thanks in advance. -hellz

Share this post


Link to post
Share on other sites
Everything seems alright except for:


If (piece collides with another piece) {
If (piece at bottom of grid) {
Lock piece in place.
}
Goto 4.
}


Shouldn''t you first check for collision between pieces, and then in another check see if there is collision between the active piece and the bottom? Something along these lines:


If (piece collides with another piece) {
Lock piece in place.
Goto 4.
}
If (piece at bottom of grid) {
Lock piece in place.
Goto 4.
}

Share this post


Link to post
Share on other sites
Thanks for the reply. Yeah, that looks right actually. I was thinking along the lines of if the piece collided with something else, and it wasn''t at the bottom of the grid, then don''t do anything with it and just wait for it to drop down another row. However, as you rightly point out, there could be two possible collisions with the piece in question.

Thanks again, I''ve made that change now.

-hellz

Share this post


Link to post
Share on other sites
Guest Anonymous Poster

If (piece collides with another piece) {
If (piece at bottom of grid) {
Lock piece in place.
}
Goto 4.
}


couldnt you also just make that one if statement like this?


if (piece collides with another piece OR
piece at bottom of grid)
{
lock piece in place
goto 4
}

correct me if im worng. i am just a simple n00b trying to learn

Share this post


Link to post
Share on other sites