You're browsing the old v2.x documentation. This version is no longer maintained. Click here to go the v3.x documentation.

Step 3.3: Coding the loops

If you remember the flow chart from Step 2.4, there we designed the program flow in several loops that are nested into one another.

  • The inner loop, reponsive for moving the current piece in the playfield, let's call it the update loop. One iteration in this loop is one downward movement of a piece.
  • The middle loop, or the game loop, which is looping during the gameplay. It is responsive for “sending” the pieces after one another. One iteration within this loop is one piece falling down.
  • The outer loop, the program loop. One iteration within this loop is a game.

Here is how the three loops are nested (in pseudo code):

REM program loop
WHILE <true>
  <player presses fire>
  <initialize game variables>
  REM game loop
    <put new piece at top>
    REM update loop
      <move piece>
    UNTIL <piece hits bottom>
    <clear rows>
    <update score>
  UNTIL <game over>
  <update hiscore>

The actual code will follow the idea of the above pseudo-code.

I suggest we start with the update loop on the next page.