home *** CD-ROM | disk | FTP | other *** search
- //----------------------------------------------------------------------------------------
- //----------------------------------------------------------------------------------------
- //
- // Filename : tetramino.cpp
- // Description : Class definition for the Tetramino class
- // Author : Marnich van Rensburg (2002)
- //
- //----------------------------------------------------------------------------------------
- //----------------------------------------------------------------------------------------
-
- #include "tetramino.h"
-
-
- // Data for Tetraminoes
- bool TetraminoData[7][4][16] =
- {
- { // I tetamino
- {0,1,0,0, 0,1,0,0, 0,1,0,0, 0,1,0,0}, //Rotation 0
- {0,0,0,0, 1,1,1,1, 0,0,0,0, 0,0,0,0}, //Rotation 1
- {0,1,0,0, 0,1,0,0, 0,1,0,0, 0,1,0,0}, //Rotation 2
- {0,0,0,0, 1,1,1,1, 0,0,0,0, 0,0,0,0}, //Rotation 3
- },
- { // J tetamino
- {0,1,0,0, 0,1,0,0, 1,1,0,0, 0,0,0,0}, //Rotation 0
- {0,0,0,0, 1,1,1,0, 0,0,1,0, 0,0,0,0}, //Rotation 1
- {0,1,1,0, 0,1,0,0, 0,1,0,0, 0,0,0,0}, //Rotation 2
- {1,0,0,0, 1,1,1,0, 0,0,0,0, 0,0,0,0}, //Rotation 3
- },
- { // L tetamino
- {0,1,0,0, 0,1,0,0, 0,1,1,0, 0,0,0,0}, //Rotation 0
- {0,0,1,0, 1,1,1,0, 0,0,0,0, 0,0,0,0}, //Rotation 1
- {1,1,0,0, 0,1,0,0, 0,1,0,0, 0,0,0,0}, //Rotation 2
- {0,0,0,0, 1,1,1,0, 1,0,0,0, 0,0,0,0}, //Rotation 3
- },
- { // O tetamino
- {0,0,0,0, 0,1,1,0, 0,1,1,0, 0,0,0,0}, //Rotation 0
- {0,0,0,0, 0,1,1,0, 0,1,1,0, 0,0,0,0}, //Rotation 1
- {0,0,0,0, 0,1,1,0, 0,1,1,0, 0,0,0,0}, //Rotation 2
- {0,0,0,0, 0,1,1,0, 0,1,1,0, 0,0,0,0}, //Rotation 3
- },
- { // S tetamino
- {0,0,0,0, 0,1,1,0, 1,1,0,0, 0,0,0,0}, //Rotation 0
- {0,1,0,0, 0,1,1,0, 0,0,1,0, 0,0,0,0}, //Rotation 1
- {0,0,0,0, 0,1,1,0, 1,1,0,0, 0,0,0,0}, //Rotation 2
- {0,1,0,0, 0,1,1,0, 0,0,1,0, 0,0,0,0}, //Rotation 3
- },
- { // T tetamino
- {0,0,0,0, 1,1,1,0, 0,1,0,0, 0,0,0,0}, //Rotation 0
- {0,1,0,0, 0,1,1,0, 0,1,0,0, 0,0,0,0}, //Rotation 1
- {0,1,0,0, 1,1,1,0, 0,0,0,0, 0,0,0,0}, //Rotation 2
- {0,1,0,0, 1,1,0,0, 0,1,0,0, 0,0,0,0} //Rotation 3
- },
- { // Z tetamino
- {0,0,0,0, 1,1,0,0, 0,1,1,0, 0,0,0,0}, //Rotation 0
- {0,1,0,0, 1,1,0,0, 1,0,0,0, 0,0,0,0}, //Rotation 1
- {0,0,0,0, 1,1,0,0, 0,1,1,0, 0,0,0,0}, //Rotation 2
- {0,1,0,0, 1,1,0,0, 1,0,0,0, 0,0,0,0}, //Rotation 3
- },
- };//TetraminoData
-
-
-
-
-
- //----------------------------------------------------------------------------------------
- // Description : Class Constructor - Initialize class data members
- //----------------------------------------------------------------------------------------
- Tetramino :: Tetramino()
- {
- Speed = 1000.0f;
- Type = 1;
- CurrentRotation = 0; // Reset Rotational state to 0
- x = TET_START_POS_X; // (x, y) positions
- y = TET_START_POS_Y;
- AssignData(Type, CurrentRotation); // Asign data for the specific tetramino
-
- }//End Tetramino
-
-
-
- //----------------------------------------------------------------------------------------
- // Description : Returns true if tetramino shoukd drop to the next row
- //----------------------------------------------------------------------------------------
-
- bool Tetramino :: DropToNextRow()
- {
- //Check if it should fall to the next row
- if(Tmr.CheckFreq(Speed))
- return true;
- else
- return false;
-
- }// DropToNextRow
-
-
- //----------------------------------------------------------------------------------------
- // Description : Assigns data for teramino cell at (x, y)
- //----------------------------------------------------------------------------------------
-
- void Tetramino :: SetMatrix(char v_x, char v_y, bool v_Data)
- {
-
- Matrix[v_x][v_y] = v_Data;
-
- }//End SetMatrix
-
-
-
- //----------------------------------------------------------------------------------------
- // Description : Returns the value of the teramino cell at (x, y)
- //----------------------------------------------------------------------------------------
-
- bool Tetramino :: GetMatrix(char v_x, char v_y)
- {
- return Matrix[v_x][v_y];
-
- }//End Tetramino
-
-
-
-
- //----------------------------------------------------------------------------------------
- // Description : Insert tetrmino data into matrix based on type and rotation passed
- //----------------------------------------------------------------------------------------
-
- void Tetramino :: AssignData(char v_Type, char v_Rotation)
- {
- char cell_n = 0; // Counter for referncing the tetramino data
-
- for (char my = 0; my != 4; my++) // loop 4 rows - Y
- {
- for (char mx = 0; mx != 4; mx++) // loop 4 cols - X
- {
- Matrix[mx][my] = TetraminoData[v_Type - 1][v_Rotation][cell_n]; // Asign Data
- cell_n++; // inc cell counter
- }//for
- }//for
-
- }//End AssignData
-
-
-
- //----------------------------------------------------------------------------------------
- // Description : Initialize a tetrmino based on the type passed
- //----------------------------------------------------------------------------------------
-
- void Tetramino :: New(char v_Type, unsigned int v_Level)
- {
- Speed = 1000.0f - ((v_Level - 1) * 100.0f);
- if(Speed < 1) Speed = 1;
-
- Type = v_Type; // Sets the type value for the tetramino
- x = TET_START_POS_X; // (x, y) positions
- y = TET_START_POS_Y;
- CurrentRotation = 0; // Have not been rotated yet
- AssignData(Type, CurrentRotation); // Asign data for the specific tetramino
-
- }//End New
-
-
-
-
- //----------------------------------------------------------------------------------------
- // Description : Moves tetramino one RIGHT
- //----------------------------------------------------------------------------------------
-
- void Tetramino :: MoveRight()
- {
- x++;
- if (x == 36) x = 0; // Wrap within the container
-
- }//End Move
-
-
-
- //----------------------------------------------------------------------------------------
- // Description : Moves tetramino one LEFT
- //----------------------------------------------------------------------------------------
-
- void Tetramino :: MoveLeft()
- {
- x--;
- if (x == -1) x = 35; // Wrap within the container
-
- }//End Move
-
-
-
-
-
- //----------------------------------------------------------------------------------------
- // Description : Moves tetramino one UP
- //----------------------------------------------------------------------------------------
-
- void Tetramino :: MoveUp()
- {
- y--;
-
- }//End Move
-
-
-
- //----------------------------------------------------------------------------------------
- // Description : Moves tetramino one DOWN
- //----------------------------------------------------------------------------------------
-
- void Tetramino :: MoveDown()
- {
- Tmr.CheckFreq(0.0f); // reset CheckFreq to prevent slip effect
- y++;
-
- }//End Move
-
-
-
-
- //----------------------------------------------------------------------------------------
- // Description : Rotates tetranino RIGHT
- //----------------------------------------------------------------------------------------
-
- void Tetramino :: RotateRight()
- {
- CurrentRotation++; //Inc current rotational state
- if (CurrentRotation == 4) CurrentRotation = 0; //Wrap if full rotation right
- AssignData(Type, CurrentRotation); //Assign new data to matrix
-
- }//End RotateRight
-
-
- //----------------------------------------------------------------------------------------
- // Description : Rotates tetranino RIGHT
- //----------------------------------------------------------------------------------------
-
- void Tetramino :: RotateLeft()
- {
- CurrentRotation--; //Decrement current rotational state
- if (CurrentRotation == -1) CurrentRotation = 3; //Wrap if full rotation left
- AssignData(Type, CurrentRotation); //Assign new data to matrix
-
- }//End RotateLeft
-
-
-