17.2.1 Add Squares

Before you start with the create and draw methods, create some ’helper’ functions to make it easier on yourself. These methods are in the class block, but they are private. The first function is makeSBlock. Which looks like this:

 
void makeSBlock() 
{ 
  //    [0][1] 
  // [3][2] 
5 
  squares.New().create(VecI2(pos.x    , pos.y    ), BT_S); 
  squares.New().create(VecI2(pos.x + 1, pos.y    ), BT_S); 
  squares.New().create(VecI2(pos.x    , pos.y - 1), BT_S); 
  squares.New().create(VecI2(pos.x - 1, pos.y - 1), BT_S); 
10}  

Each block consists of 4 squares. The first square will have the same position as the block. This is important to properly rotate the block later. The other squares should get a position that is derived from the first position. You can look at the diagram in the comments to get a better picture of the positions. The second argument (BT_S) indicates the type of the block. It is important for drawing the square in the right color. You can now create your own functions for the other blocks. Below are the declarations with a diagram for each block.

 
void makeSquareBlock() 
{ 
  // [0][2] 
  // [1][3] 
5} 
 
void makeTBlock() 
{ 
  //    [1] 
10  // [2][0][3] 
} 
 
void makeLBlock() 
{ 
15  // [2] 
  // [1] 
  // [0][3] 
} 
 
20void makeBackwardsLBlock() 
{ 
  //    [2] 
  //    [1] 
  // [3][0] 
25} 
 
void makeStraightBlock() 
{ 
  // [2] 
30  // [1] 
  // [0] 
  // [3] 
} 
 
35void makeBackwardsSBlock() 
{ 
  // [1][0] 
  //    [2][3] 
}  
40

We now create an additional private function setupSquares(). In it, you first empty the container squares. Next, depending on the  eeFunc BLOCK_type, you call the appropriate function. You can start from this example and complete it yourself.

 
void setupSquares() 
{ 
   squares.clear(); 
 
5   switch(type) 
 { 
      case BT_SQUARE: makeSquareBlock(); break
      // create the remaining code your self 
 } 
10}