@ -44,8 +44,8 @@ typedef enum GridSquare { EMPTY, MOVING, FULL, BLOCK, FADING } GridSquare;
/ / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/ / Global Variables Declaration
/ / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
static int screenWidth = 800 ;
static int screenHeight = 450 ;
static ">const int screenWidth = 800 ;
static ">const int screenHeight = 450 ;
static bool gameOver = false ;
static bool pause = false ;
@ -99,7 +99,7 @@ static void ResolveFallingMovement();
static bool ResolveLateralMovement ( ) ;
static bool ResolveTurnMovement ( ) ;
static void CheckDetection ( ) ;
static void CheckCompletiti on ( ) ;
static void CheckCompletion ( ) ;
static void DeleteCompleteLines ( ) ;
/ / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -116,7 +116,6 @@ int main(void)
# if defined(PLATFORM_WEB)
emscripten_set_main_loop ( UpdateDrawFrame , 0 , 1 ) ;
# else
SetTargetFPS ( 60 ) ;
/ / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -129,7 +128,6 @@ int main(void)
/ / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
}
# endif
/ / De - Initialization
/ / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
UnloadGame ( ) ; / / Unload loaded data ( textures , sounds , models . . . )
@ -239,7 +237,7 @@ void UpdateGame(void)
ResolveFallingMovement ( & detection , & pieceActive ) ;
/ / Check if we fullfilled a line and if so , erase the line and pull down the the lines above
CheckCompletiti on ( & lineToDelete ) ;
CheckCompletion ( & lineToDelete ) ;
gravityMovementCounter = 0 ;
}
@ -387,7 +385,7 @@ void DrawGame(void)
}
DrawText ( " INCOMING: " , offset . x , offset . y - 100 , 10 , GRAY ) ;
DrawText ( FormatTex t ( " LINES: %04i " , lines ) , offset . x , offset . y + 20 , 10 , GRAY ) ;
DrawText ( Text Format( " LINES: %04i " , lines ) , offset . x , offset . y + 20 , 10 , GRAY ) ;
if ( pause ) DrawText ( " GAME PAUSED " , screenWidth / 2 - MeasureText ( " GAME PAUSED " , 40 ) / 2 , screenHeight / 2 - 40 , 40 , GRAY ) ;
}
@ -450,8 +448,7 @@ static bool Createpiece()
static void GetRandompiece ( )
{
srand ( time ( NULL ) ) ;
int random = rand ( ) % 7 ;
int random = GetRandomValue ( 0 , 6 ) ;
for ( int i = 0 ; i < 4 ; i + + )
{
@ -461,15 +458,15 @@ static void GetRandompiece()
}
}
switch ( random )
switch ( random )
{
case 0 : { incomingPiece [ 1 ] [ 1 ] = MOVING ; incomingPiece [ 2 ] [ 1 ] = MOVING ; incomingPiece [ 1 ] [ 2 ] = MOVING ; incomingPiece [ 2 ] [ 2 ] = MOVING ; } break ; / / Cube
case 1 : { incomingPiece [ 1 ] [ 0 ] = MOVING ; incomingPiece [ 1 ] [ 1 ] = MOVING ; incomingPiece [ 1 ] [ 2 ] = MOVING ; incomingPiece [ 2 ] [ 2 ] = MOVING ; } break ; / / L
case 2 : { incomingPiece [ 1 ] [ 2 ] = MOVING ; incomingPiece [ 2 ] [ 0 ] = MOVING ; incomingPiece [ 2 ] [ 1 ] = MOVING ; incomingPiece [ 2 ] [ 2 ] = MOVING ; } break ; / / L inversa
case 3 : { incomingPiece [ 0 ] [ 1 ] = MOVING ; incomingPiece [ 1 ] [ 1 ] = MOVING ; incomingPiece [ 2 ] [ 1 ] = MOVING ; incomingPiece [ 3 ] [ 1 ] = MOVING ; } break ; / / Recta
case 4 : { incomingPiece [ 1 ] [ 0 ] = MOVING ; incomingPiece [ 1 ] [ 1 ] = MOVING ; incomingPiece [ 1 ] [ 2 ] = MOVING ; incomingPiece [ 2 ] [ 1 ] = MOVING ; } break ; / / Creu tallada
case 5 : { incomingPiece [ 1 ] [ 1 ] = MOVING ; incomingPiece [ 2 ] [ 1 ] = MOVING ; incomingPiece [ 2 ] [ 2 ] = MOVING ; incomingPiece [ 3 ] [ 2 ] = MOVING ; } break ; / / S
case 6 : { incomingPiece [ 1 ] [ 2 ] = MOVING ; incomingPiece [ 2 ] [ 2 ] = MOVING ; incomingPiece [ 2 ] [ 1 ] = MOVING ; incomingPiece [ 3 ] [ 1 ] = MOVING ; } break ; / / S inversa
case 0 : { incomingPiece [ 1 ] [ 1 ] = MOVING ; incomingPiece [ 2 ] [ 1 ] = MOVING ; incomingPiece [ 1 ] [ 2 ] = MOVING ; incomingPiece [ 2 ] [ 2 ] = MOVING ; } break ; / / Cube
case 1 : { incomingPiece [ 1 ] [ 0 ] = MOVING ; incomingPiece [ 1 ] [ 1 ] = MOVING ; incomingPiece [ 1 ] [ 2 ] = MOVING ; incomingPiece [ 2 ] [ 2 ] = MOVING ; } break ; / / L
case 2 : { incomingPiece [ 1 ] [ 2 ] = MOVING ; incomingPiece [ 2 ] [ 0 ] = MOVING ; incomingPiece [ 2 ] [ 1 ] = MOVING ; incomingPiece [ 2 ] [ 2 ] = MOVING ; } break ; / / L inversa
case 3 : { incomingPiece [ 0 ] [ 1 ] = MOVING ; incomingPiece [ 1 ] [ 1 ] = MOVING ; incomingPiece [ 2 ] [ 1 ] = MOVING ; incomingPiece [ 3 ] [ 1 ] = MOVING ; } break ; / / Recta
case 4 : { incomingPiece [ 1 ] [ 0 ] = MOVING ; incomingPiece [ 1 ] [ 1 ] = MOVING ; incomingPiece [ 1 ] [ 2 ] = MOVING ; incomingPiece [ 2 ] [ 1 ] = MOVING ; } break ; / / Creu tallada
case 5 : { incomingPiece [ 1 ] [ 1 ] = MOVING ; incomingPiece [ 2 ] [ 1 ] = MOVING ; incomingPiece [ 2 ] [ 2 ] = MOVING ; incomingPiece [ 3 ] [ 2 ] = MOVING ; } break ; / / S
case 6 : { incomingPiece [ 1 ] [ 2 ] = MOVING ; incomingPiece [ 2 ] [ 2 ] = MOVING ; incomingPiece [ 2 ] [ 1 ] = MOVING ; incomingPiece [ 3 ] [ 1 ] = MOVING ; } break ; / / S inversa
}
}
@ -491,8 +488,7 @@ static void ResolveFallingMovement(bool *detection, bool *pieceActive)
}
}
}
/ / We move down the piece
else
else / / We move down the piece
{
for ( int j = GRID_VERTICAL_SIZE - 2 ; j > = 0 ; j - - )
{
@ -505,6 +501,7 @@ static void ResolveFallingMovement(bool *detection, bool *pieceActive)
}
}
}
piecePositionY + + ;
}
}
@ -513,8 +510,8 @@ static bool ResolveLateralMovement()
{
bool collision = false ;
/ / Move lef t
if ( IsKeyDown ( KEY_LEFT ) )
/ / Piece movemen t
if ( IsKeyDown ( KEY_LEFT ) ) / / Move left
{
/ / Check if is possible to move to left
for ( int j = GRID_VERTICAL_SIZE - 2 ; j > = 0 ; j - - )
@ -528,6 +525,7 @@ static bool ResolveLateralMovement()
}
}
}
/ / If able , move left
if ( ! collision )
{
@ -547,9 +545,7 @@ static bool ResolveLateralMovement()
piecePositionX - - ;
}
}
/ / Move right
else if ( IsKeyDown ( KEY_RIGHT ) )
else if ( IsKeyDown ( KEY_RIGHT ) ) / / Move right
{
/ / Check if is possible to move to right
for ( int j = GRID_VERTICAL_SIZE - 2 ; j > = 0 ; j - - )
@ -567,6 +563,7 @@ static bool ResolveLateralMovement()
}
}
}
/ / If able move right
if ( ! collision )
{
@ -595,112 +592,73 @@ static bool ResolveTurnMovement()
/ / Input for turning the piece
if ( IsKeyDown ( KEY_UP ) )
{
int aux ;
int aux = 0 ;
bool checker = false ;
/ / Check all turning possibilities
if ( ( grid [ piecePositionX + 3 ] [ piecePositionY ] = = MOVING ) & &
( grid [ piecePositionX ] [ piecePositionY ] ! = EMPTY ) & &
( grid [ piecePositionX ] [ piecePositionY ] ! = MOVING ) )
{
checker = true ;
}
( grid [ piecePositionX ] [ piecePositionY ] ! = MOVING ) ) checker = true ;
if ( ( grid [ piecePositionX + 3 ] [ piecePositionY + 3 ] = = MOVING ) & &
( grid [ piecePositionX + 3 ] [ piecePositionY ] ! = EMPTY ) & &
( grid [ piecePositionX + 3 ] [ piecePositionY ] ! = MOVING ) )
{
checker = true ;
}
( grid [ piecePositionX + 3 ] [ piecePositionY ] ! = MOVING ) ) checker = true ;
if ( ( grid [ piecePositionX ] [ piecePositionY + 3 ] = = MOVING ) & &
( grid [ piecePositionX + 3 ] [ piecePositionY + 3 ] ! = EMPTY ) & &
( grid [ piecePositionX + 3 ] [ piecePositionY + 3 ] ! = MOVING ) )
{
checker = true ;
}
( grid [ piecePositionX + 3 ] [ piecePositionY + 3 ] ! = MOVING ) ) checker = true ;
if ( ( grid [ piecePositionX ] [ piecePositionY ] = = MOVING ) & &
( grid [ piecePositionX ] [ piecePositionY + 3 ] ! = EMPTY ) & &
( grid [ piecePositionX ] [ piecePositionY + 3 ] ! = MOVING ) )
{
checker = true ;
}
( grid [ piecePositionX ] [ piecePositionY + 3 ] ! = MOVING ) ) checker = true ;
if ( ( grid [ piecePositionX + 1 ] [ piecePositionY ] = = MOVING ) & &
( grid [ piecePositionX ] [ piecePositionY + 2 ] ! = EMPTY ) & &
( grid [ piecePositionX ] [ piecePositionY + 2 ] ! = MOVING ) )
{
checker = true ;
}
( grid [ piecePositionX ] [ piecePositionY + 2 ] ! = MOVING ) ) checker = true ;
if ( ( grid [ piecePositionX + 3 ] [ piecePositionY + 1 ] = = MOVING ) & &
( grid [ piecePositionX + 1 ] [ piecePositionY ] ! = EMPTY ) & &
( grid [ piecePositionX + 1 ] [ piecePositionY ] ! = MOVING ) )
{
checker = true ;
}
( grid [ piecePositionX + 1 ] [ piecePositionY ] ! = MOVING ) ) checker = true ;
if ( ( grid [ piecePositionX + 2 ] [ piecePositionY + 3 ] = = MOVING ) & &
( grid [ piecePositionX + 3 ] [ piecePositionY + 1 ] ! = EMPTY ) & &
( grid [ piecePositionX + 3 ] [ piecePositionY + 1 ] ! = MOVING ) )
{
checker = true ;
}
( grid [ piecePositionX + 3 ] [ piecePositionY + 1 ] ! = MOVING ) ) checker = true ;
if ( ( grid [ piecePositionX ] [ piecePositionY + 2 ] = = MOVING ) & &
( grid [ piecePositionX + 2 ] [ piecePositionY + 3 ] ! = EMPTY ) & &
( grid [ piecePositionX + 2 ] [ piecePositionY + 3 ] ! = MOVING ) )
{
checker = true ;
}
( grid [ piecePositionX + 2 ] [ piecePositionY + 3 ] ! = MOVING ) ) checker = true ;
if ( ( grid [ piecePositionX + 2 ] [ piecePositionY ] = = MOVING ) & &
( grid [ piecePositionX ] [ piecePositionY + 1 ] ! = EMPTY ) & &
( grid [ piecePositionX ] [ piecePositionY + 1 ] ! = MOVING ) )
{
checker = true ;
}
( grid [ piecePositionX ] [ piecePositionY + 1 ] ! = MOVING ) ) checker = true ;
if ( ( grid [ piecePositionX + 3 ] [ piecePositionY + 2 ] = = MOVING ) & &
( grid [ piecePositionX + 2 ] [ piecePositionY ] ! = EMPTY ) & &
( grid [ piecePositionX + 2 ] [ piecePositionY ] ! = MOVING ) )
{
checker = true ;
}
( grid [ piecePositionX + 2 ] [ piecePositionY ] ! = MOVING ) ) checker = true ;
if ( ( grid [ piecePositionX + 1 ] [ piecePositionY + 3 ] = = MOVING ) & &
( grid [ piecePositionX + 3 ] [ piecePositionY + 2 ] ! = EMPTY ) & &
( grid [ piecePositionX + 3 ] [ piecePositionY + 2 ] ! = MOVING ) )
{
checker = true ;
}
( grid [ piecePositionX + 3 ] [ piecePositionY + 2 ] ! = MOVING ) ) checker = true ;
if ( ( grid [ piecePositionX ] [ piecePositionY + 1 ] = = MOVING ) & &
( grid [ piecePositionX + 1 ] [ piecePositionY + 3 ] ! = EMPTY ) & &
( grid [ piecePositionX + 1 ] [ piecePositionY + 3 ] ! = MOVING ) )
{
checker = true ;
}
( grid [ piecePositionX + 1 ] [ piecePositionY + 3 ] ! = MOVING ) ) checker = true ;
if ( ( grid [ piecePositionX + 1 ] [ piecePositionY + 1 ] = = MOVING ) & &
( grid [ piecePositionX + 1 ] [ piecePositionY + 2 ] ! = EMPTY ) & &
( grid [ piecePositionX + 1 ] [ piecePositionY + 2 ] ! = MOVING ) )
{
checker = true ;
}
( grid [ piecePositionX + 1 ] [ piecePositionY + 2 ] ! = MOVING ) ) checker = true ;
if ( ( grid [ piecePositionX + 2 ] [ piecePositionY + 1 ] = = MOVING ) & &
( grid [ piecePositionX + 1 ] [ piecePositionY + 1 ] ! = EMPTY ) & &
( grid [ piecePositionX + 1 ] [ piecePositionY + 1 ] ! = MOVING ) )
{
checker = true ;
}
( grid [ piecePositionX + 1 ] [ piecePositionY + 1 ] ! = MOVING ) ) checker = true ;
if ( ( grid [ piecePositionX + 2 ] [ piecePositionY + 2 ] = = MOVING ) & &
( grid [ piecePositionX + 2 ] [ piecePositionY + 1 ] ! = EMPTY ) & &
( grid [ piecePositionX + 2 ] [ piecePositionY + 1 ] ! = MOVING ) )
{
checker = true ;
}
( grid [ piecePositionX + 2 ] [ piecePositionY + 1 ] ! = MOVING ) ) checker = true ;
if ( ( grid [ piecePositionX + 1 ] [ piecePositionY + 2 ] = = MOVING ) & &
( grid [ piecePositionX + 2 ] [ piecePositionY + 2 ] ! = EMPTY ) & &
( grid [ piecePositionX + 2 ] [ piecePositionY + 2 ] ! = MOVING ) )
{
checker = true ;
}
( grid [ piecePositionX + 2 ] [ piecePositionY + 2 ] ! = MOVING ) ) checker = true ;
if ( ! checker )
{
@ -750,6 +708,7 @@ static bool ResolveTurnMovement()
}
}
}
return true ;
}
@ -767,9 +726,9 @@ static void CheckDetection(bool *detection)
}
}
static void CheckCompletiti on ( bool * lineToDelete )
static void CheckCompletion ( bool * lineToDelete )
{
int calculator ;
int calculator = 0 ;
for ( int j = GRID_VERTICAL_SIZE - 2 ; j > = 0 ; j - - )
{
@ -801,7 +760,7 @@ static void CheckCompletition(bool *lineToDelete)
static void DeleteCompleteLines ( )
{
/ / e rase the completed line
/ / E rase the completed line
for ( int j = GRID_VERTICAL_SIZE - 2 ; j > = 0 ; j - - )
{
while ( grid [ 1 ] [ j ] = = FADING )
@ -810,6 +769,7 @@ static void DeleteCompleteLines()
{
grid [ i ] [ j ] = EMPTY ;
}
for ( int j2 = j - 1 ; j2 > = 0 ; j2 - - )
{
for ( int i2 = 1 ; i2 < GRID_HORIZONTAL_SIZE - 1 ; i2 + + )