mirror of https://github.com/raysan5/raylib
Replaced tabs by spaces
This commit is contained in:
parent
fffbf48dec
commit
dcbf2a0e0c
454
games/tetris.c
454
games/tetris.c
|
@ -179,22 +179,22 @@ void InitGame(void)
|
||||||
|
|
||||||
// Initialize grid matrices
|
// Initialize grid matrices
|
||||||
for (int i = 0; i < GRID_HORIZONTAL_SIZE; i++)
|
for (int i = 0; i < GRID_HORIZONTAL_SIZE; i++)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < GRID_VERTICAL_SIZE; j++)
|
for (int j = 0; j < GRID_VERTICAL_SIZE; j++)
|
||||||
{
|
{
|
||||||
if ((j == GRID_VERTICAL_SIZE - 1) || (i == 0) || (i == GRID_HORIZONTAL_SIZE - 1)) grid[i][j] = BLOCK;
|
if ((j == GRID_VERTICAL_SIZE - 1) || (i == 0) || (i == GRID_HORIZONTAL_SIZE - 1)) grid[i][j] = BLOCK;
|
||||||
else grid[i][j] = EMPTY;
|
else grid[i][j] = EMPTY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize incoming piece matrices
|
// Initialize incoming piece matrices
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
for (int j = 0; j< 4; j++)
|
for (int j = 0; j< 4; j++)
|
||||||
{
|
{
|
||||||
incomingPiece[i][j] = EMPTY;
|
incomingPiece[i][j] = EMPTY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update game (one frame)
|
// Update game (one frame)
|
||||||
|
@ -423,34 +423,34 @@ static bool Createpiece()
|
||||||
piecePositionY = 0;
|
piecePositionY = 0;
|
||||||
|
|
||||||
// If the game is starting and you are going to create the first piece, we create an extra one
|
// If the game is starting and you are going to create the first piece, we create an extra one
|
||||||
if (beginPlay)
|
if (beginPlay)
|
||||||
{
|
{
|
||||||
GetRandompiece();
|
GetRandompiece();
|
||||||
beginPlay = false;
|
beginPlay = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We assign the incoming piece to the actual piece
|
// We assign the incoming piece to the actual piece
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
for (int j = 0; j< 4; j++)
|
for (int j = 0; j< 4; j++)
|
||||||
{
|
{
|
||||||
piece[i][j] = incomingPiece[i][j];
|
piece[i][j] = incomingPiece[i][j];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// We assign a random piece to the incoming one
|
// We assign a random piece to the incoming one
|
||||||
GetRandompiece();
|
GetRandompiece();
|
||||||
|
|
||||||
// Assign the piece to the grid
|
// Assign the piece to the grid
|
||||||
for (int i = piecePositionX; i < piecePositionX + 4; i++)
|
for (int i = piecePositionX; i < piecePositionX + 4; i++)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < 4; j++)
|
for (int j = 0; j < 4; j++)
|
||||||
{
|
{
|
||||||
if (piece[i - (int)piecePositionX][j] == MOVING) grid[i][j] = MOVING;
|
if (piece[i - (int)piecePositionX][j] == MOVING) grid[i][j] = MOVING;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void GetRandompiece()
|
static void GetRandompiece()
|
||||||
|
@ -459,22 +459,22 @@ static void GetRandompiece()
|
||||||
int random = rand() % 7;
|
int random = rand() % 7;
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < 4; j++)
|
for (int j = 0; j < 4; j++)
|
||||||
{
|
{
|
||||||
incomingPiece[i][j] = EMPTY;
|
incomingPiece[i][j] = EMPTY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 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 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 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 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 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 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 6: { incomingPiece[1][2] = MOVING; incomingPiece[2][2] = MOVING; incomingPiece[2][1] = MOVING; incomingPiece[3][1] = MOVING; } break; //S inversa
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -482,34 +482,34 @@ static void ResolveFallingMovement(bool *detection, bool *pieceActive)
|
||||||
{
|
{
|
||||||
// If we finished moving this piece, we stop it
|
// If we finished moving this piece, we stop it
|
||||||
if (*detection)
|
if (*detection)
|
||||||
{
|
{
|
||||||
for (int j = GRID_VERTICAL_SIZE - 2; j >= 0; j--)
|
for (int j = GRID_VERTICAL_SIZE - 2; j >= 0; j--)
|
||||||
{
|
{
|
||||||
for (int i = 1; i < GRID_HORIZONTAL_SIZE - 1; i++)
|
for (int i = 1; i < GRID_HORIZONTAL_SIZE - 1; i++)
|
||||||
{
|
{
|
||||||
if (grid[i][j] == MOVING)
|
if (grid[i][j] == MOVING)
|
||||||
{
|
{
|
||||||
grid[i][j] = FULL;
|
grid[i][j] = FULL;
|
||||||
*detection = false;
|
*detection = false;
|
||||||
*pieceActive = false;
|
*pieceActive = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// We move down the piece
|
// We move down the piece
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (int j = GRID_VERTICAL_SIZE - 2; j >= 0; j--)
|
for (int j = GRID_VERTICAL_SIZE - 2; j >= 0; j--)
|
||||||
{
|
{
|
||||||
for (int i = 1; i < GRID_HORIZONTAL_SIZE - 1; i++)
|
for (int i = 1; i < GRID_HORIZONTAL_SIZE - 1; i++)
|
||||||
{
|
{
|
||||||
if (grid[i][j] == MOVING)
|
if (grid[i][j] == MOVING)
|
||||||
{
|
{
|
||||||
grid[i][j+1] = MOVING;
|
grid[i][j+1] = MOVING;
|
||||||
grid[i][j] = EMPTY;
|
grid[i][j] = EMPTY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
piecePositionY++;
|
piecePositionY++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -519,78 +519,78 @@ static bool ResolveLateralMovement()
|
||||||
bool collision = false;
|
bool collision = false;
|
||||||
|
|
||||||
// Move left
|
// Move left
|
||||||
if (IsKeyDown(KEY_LEFT))
|
if (IsKeyDown(KEY_LEFT))
|
||||||
{
|
{
|
||||||
// Check if is possible to move to left
|
// Check if is possible to move to left
|
||||||
for (int j = GRID_VERTICAL_SIZE - 2; j >= 0; j--)
|
for (int j = GRID_VERTICAL_SIZE - 2; j >= 0; j--)
|
||||||
{
|
{
|
||||||
for (int i = 1; i < GRID_HORIZONTAL_SIZE - 1; i++)
|
for (int i = 1; i < GRID_HORIZONTAL_SIZE - 1; i++)
|
||||||
{
|
{
|
||||||
if (grid[i][j] == MOVING)
|
if (grid[i][j] == MOVING)
|
||||||
{
|
{
|
||||||
// Check if we are touching the left wall or we have a full square at the left
|
// Check if we are touching the left wall or we have a full square at the left
|
||||||
if ((i-1 == 0) || (grid[i-1][j] == FULL)) collision = true;
|
if ((i-1 == 0) || (grid[i-1][j] == FULL)) collision = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If able, move left
|
// If able, move left
|
||||||
if (!collision)
|
if (!collision)
|
||||||
{
|
{
|
||||||
for (int j = GRID_VERTICAL_SIZE - 2; j >= 0; j--)
|
for (int j = GRID_VERTICAL_SIZE - 2; j >= 0; j--)
|
||||||
{
|
{
|
||||||
for (int i = 1; i < GRID_HORIZONTAL_SIZE - 1; i++) // We check the matrix from left to right
|
for (int i = 1; i < GRID_HORIZONTAL_SIZE - 1; i++) // We check the matrix from left to right
|
||||||
{
|
{
|
||||||
// Move everything to the left
|
// Move everything to the left
|
||||||
if (grid[i][j] == MOVING)
|
if (grid[i][j] == MOVING)
|
||||||
{
|
{
|
||||||
grid[i-1][j] = MOVING;
|
grid[i-1][j] = MOVING;
|
||||||
grid[i][j] = EMPTY;
|
grid[i][j] = EMPTY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
piecePositionX--;
|
piecePositionX--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move right
|
// Move right
|
||||||
else if (IsKeyDown(KEY_RIGHT))
|
else if (IsKeyDown(KEY_RIGHT))
|
||||||
{
|
{
|
||||||
// Check if is possible to move to right
|
// Check if is possible to move to right
|
||||||
for (int j = GRID_VERTICAL_SIZE - 2; j >= 0; j--)
|
for (int j = GRID_VERTICAL_SIZE - 2; j >= 0; j--)
|
||||||
{
|
{
|
||||||
for (int i = 1; i < GRID_HORIZONTAL_SIZE - 1; i++)
|
for (int i = 1; i < GRID_HORIZONTAL_SIZE - 1; i++)
|
||||||
{
|
{
|
||||||
if (grid[i][j] == MOVING)
|
if (grid[i][j] == MOVING)
|
||||||
{
|
{
|
||||||
// Check if we are touching the right wall or we have a full square at the right
|
// Check if we are touching the right wall or we have a full square at the right
|
||||||
if ((i+1 == GRID_HORIZONTAL_SIZE - 1) || (grid[i+1][j] == FULL))
|
if ((i+1 == GRID_HORIZONTAL_SIZE - 1) || (grid[i+1][j] == FULL))
|
||||||
{
|
{
|
||||||
collision = true;
|
collision = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If able move right
|
// If able move right
|
||||||
if (!collision)
|
if (!collision)
|
||||||
{
|
{
|
||||||
for (int j = GRID_VERTICAL_SIZE - 2; j >= 0; j--)
|
for (int j = GRID_VERTICAL_SIZE - 2; j >= 0; j--)
|
||||||
{
|
{
|
||||||
for (int i = GRID_HORIZONTAL_SIZE - 1; i >= 1; i--) // We check the matrix from right to left
|
for (int i = GRID_HORIZONTAL_SIZE - 1; i >= 1; i--) // We check the matrix from right to left
|
||||||
{
|
{
|
||||||
// Move everything to the right
|
// Move everything to the right
|
||||||
if (grid[i][j] == MOVING)
|
if (grid[i][j] == MOVING)
|
||||||
{
|
{
|
||||||
grid[i+1][j] = MOVING;
|
grid[i+1][j] = MOVING;
|
||||||
grid[i][j] = EMPTY;
|
grid[i][j] = EMPTY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
piecePositionX++;
|
piecePositionX++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return collision;
|
return collision;
|
||||||
}
|
}
|
||||||
|
@ -599,164 +599,164 @@ static bool ResolveTurnMovement()
|
||||||
{
|
{
|
||||||
// Input for turning the piece
|
// Input for turning the piece
|
||||||
if (IsKeyDown(KEY_UP))
|
if (IsKeyDown(KEY_UP))
|
||||||
{
|
{
|
||||||
int aux;
|
int aux;
|
||||||
bool checker = false;
|
bool checker = false;
|
||||||
|
|
||||||
// Check all turning possibilities
|
// Check all turning possibilities
|
||||||
if ((grid[piecePositionX + 3][piecePositionY] == MOVING) &&
|
if ((grid[piecePositionX + 3][piecePositionY] == MOVING) &&
|
||||||
(grid[piecePositionX][piecePositionY] != EMPTY) &&
|
(grid[piecePositionX][piecePositionY] != EMPTY) &&
|
||||||
(grid[piecePositionX][piecePositionY] != MOVING))
|
(grid[piecePositionX][piecePositionY] != MOVING))
|
||||||
{
|
{
|
||||||
checker = true;
|
checker = true;
|
||||||
}
|
}
|
||||||
if ((grid[piecePositionX + 3][piecePositionY + 3] == MOVING) &&
|
if ((grid[piecePositionX + 3][piecePositionY + 3] == MOVING) &&
|
||||||
(grid[piecePositionX + 3][piecePositionY] != EMPTY) &&
|
(grid[piecePositionX + 3][piecePositionY] != EMPTY) &&
|
||||||
(grid[piecePositionX + 3][piecePositionY] != MOVING))
|
(grid[piecePositionX + 3][piecePositionY] != MOVING))
|
||||||
{
|
{
|
||||||
checker = true;
|
checker = true;
|
||||||
}
|
}
|
||||||
if ((grid[piecePositionX][piecePositionY + 3] == MOVING) &&
|
if ((grid[piecePositionX][piecePositionY + 3] == MOVING) &&
|
||||||
(grid[piecePositionX + 3][piecePositionY + 3] != EMPTY) &&
|
(grid[piecePositionX + 3][piecePositionY + 3] != EMPTY) &&
|
||||||
(grid[piecePositionX + 3][piecePositionY + 3] != MOVING))
|
(grid[piecePositionX + 3][piecePositionY + 3] != MOVING))
|
||||||
{
|
{
|
||||||
checker = true;
|
checker = true;
|
||||||
}
|
}
|
||||||
if ((grid[piecePositionX][piecePositionY] == MOVING) &&
|
if ((grid[piecePositionX][piecePositionY] == MOVING) &&
|
||||||
(grid[piecePositionX][piecePositionY + 3] != EMPTY) &&
|
(grid[piecePositionX][piecePositionY + 3] != EMPTY) &&
|
||||||
(grid[piecePositionX][piecePositionY + 3] != MOVING))
|
(grid[piecePositionX][piecePositionY + 3] != MOVING))
|
||||||
{
|
{
|
||||||
checker = true;
|
checker = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ((grid[piecePositionX + 1][piecePositionY] == MOVING) &&
|
if ((grid[piecePositionX + 1][piecePositionY] == MOVING) &&
|
||||||
(grid[piecePositionX][piecePositionY + 2] != EMPTY) &&
|
(grid[piecePositionX][piecePositionY + 2] != EMPTY) &&
|
||||||
(grid[piecePositionX][piecePositionY + 2] != MOVING))
|
(grid[piecePositionX][piecePositionY + 2] != MOVING))
|
||||||
{
|
{
|
||||||
checker = true;
|
checker = true;
|
||||||
}
|
}
|
||||||
if ((grid[piecePositionX + 3][piecePositionY + 1] == MOVING) &&
|
if ((grid[piecePositionX + 3][piecePositionY + 1] == MOVING) &&
|
||||||
(grid[piecePositionX + 1][piecePositionY] != EMPTY) &&
|
(grid[piecePositionX + 1][piecePositionY] != EMPTY) &&
|
||||||
(grid[piecePositionX + 1][piecePositionY] != MOVING))
|
(grid[piecePositionX + 1][piecePositionY] != MOVING))
|
||||||
{
|
{
|
||||||
checker = true;
|
checker = true;
|
||||||
}
|
}
|
||||||
if ((grid[piecePositionX + 2][piecePositionY + 3] == MOVING) &&
|
if ((grid[piecePositionX + 2][piecePositionY + 3] == MOVING) &&
|
||||||
(grid[piecePositionX + 3][piecePositionY + 1] != EMPTY) &&
|
(grid[piecePositionX + 3][piecePositionY + 1] != EMPTY) &&
|
||||||
(grid[piecePositionX + 3][piecePositionY + 1] != MOVING))
|
(grid[piecePositionX + 3][piecePositionY + 1] != MOVING))
|
||||||
{
|
{
|
||||||
checker = true;
|
checker = true;
|
||||||
}
|
}
|
||||||
if ((grid[piecePositionX][piecePositionY + 2] == MOVING) &&
|
if ((grid[piecePositionX][piecePositionY + 2] == MOVING) &&
|
||||||
(grid[piecePositionX + 2][piecePositionY + 3] != EMPTY) &&
|
(grid[piecePositionX + 2][piecePositionY + 3] != EMPTY) &&
|
||||||
(grid[piecePositionX + 2][piecePositionY + 3] != MOVING))
|
(grid[piecePositionX + 2][piecePositionY + 3] != MOVING))
|
||||||
{
|
{
|
||||||
checker = true;
|
checker = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ((grid[piecePositionX + 2][piecePositionY] == MOVING) &&
|
if ((grid[piecePositionX + 2][piecePositionY] == MOVING) &&
|
||||||
(grid[piecePositionX][piecePositionY + 1] != EMPTY) &&
|
(grid[piecePositionX][piecePositionY + 1] != EMPTY) &&
|
||||||
(grid[piecePositionX][piecePositionY + 1] != MOVING))
|
(grid[piecePositionX][piecePositionY + 1] != MOVING))
|
||||||
{
|
{
|
||||||
checker = true;
|
checker = true;
|
||||||
}
|
}
|
||||||
if ((grid[piecePositionX + 3][piecePositionY + 2] == MOVING) &&
|
if ((grid[piecePositionX + 3][piecePositionY + 2] == MOVING) &&
|
||||||
(grid[piecePositionX + 2][piecePositionY] != EMPTY) &&
|
(grid[piecePositionX + 2][piecePositionY] != EMPTY) &&
|
||||||
(grid[piecePositionX + 2][piecePositionY] != MOVING))
|
(grid[piecePositionX + 2][piecePositionY] != MOVING))
|
||||||
{
|
{
|
||||||
checker = true;
|
checker = true;
|
||||||
}
|
}
|
||||||
if ((grid[piecePositionX + 1][piecePositionY + 3] == MOVING) &&
|
if ((grid[piecePositionX + 1][piecePositionY + 3] == MOVING) &&
|
||||||
(grid[piecePositionX + 3][piecePositionY + 2] != EMPTY) &&
|
(grid[piecePositionX + 3][piecePositionY + 2] != EMPTY) &&
|
||||||
(grid[piecePositionX + 3][piecePositionY + 2] != MOVING))
|
(grid[piecePositionX + 3][piecePositionY + 2] != MOVING))
|
||||||
{
|
{
|
||||||
checker = true;
|
checker = true;
|
||||||
}
|
}
|
||||||
if ((grid[piecePositionX][piecePositionY + 1] == MOVING) &&
|
if ((grid[piecePositionX][piecePositionY + 1] == MOVING) &&
|
||||||
(grid[piecePositionX + 1][piecePositionY + 3] != EMPTY) &&
|
(grid[piecePositionX + 1][piecePositionY + 3] != EMPTY) &&
|
||||||
(grid[piecePositionX + 1][piecePositionY + 3] != MOVING))
|
(grid[piecePositionX + 1][piecePositionY + 3] != MOVING))
|
||||||
{
|
{
|
||||||
checker = true;
|
checker = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((grid[piecePositionX + 1][piecePositionY + 1] == MOVING) &&
|
if ((grid[piecePositionX + 1][piecePositionY + 1] == MOVING) &&
|
||||||
(grid[piecePositionX + 1][piecePositionY + 2] != EMPTY) &&
|
(grid[piecePositionX + 1][piecePositionY + 2] != EMPTY) &&
|
||||||
(grid[piecePositionX + 1][piecePositionY + 2] != MOVING))
|
(grid[piecePositionX + 1][piecePositionY + 2] != MOVING))
|
||||||
{
|
{
|
||||||
checker = true;
|
checker = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((grid[piecePositionX + 2][piecePositionY + 1] == MOVING) &&
|
if ((grid[piecePositionX + 2][piecePositionY + 1] == MOVING) &&
|
||||||
(grid[piecePositionX + 1][piecePositionY + 1] != EMPTY) &&
|
(grid[piecePositionX + 1][piecePositionY + 1] != EMPTY) &&
|
||||||
(grid[piecePositionX + 1][piecePositionY + 1] != MOVING))
|
(grid[piecePositionX + 1][piecePositionY + 1] != MOVING))
|
||||||
{
|
{
|
||||||
checker = true;
|
checker = true;
|
||||||
}
|
}
|
||||||
if ((grid[piecePositionX + 2][piecePositionY + 2] == MOVING) &&
|
if ((grid[piecePositionX + 2][piecePositionY + 2] == MOVING) &&
|
||||||
(grid[piecePositionX + 2][piecePositionY + 1] != EMPTY) &&
|
(grid[piecePositionX + 2][piecePositionY + 1] != EMPTY) &&
|
||||||
(grid[piecePositionX + 2][piecePositionY + 1] != MOVING))
|
(grid[piecePositionX + 2][piecePositionY + 1] != MOVING))
|
||||||
{
|
{
|
||||||
checker = true;
|
checker = true;
|
||||||
}
|
}
|
||||||
if ((grid[piecePositionX + 1][piecePositionY + 2] == MOVING) &&
|
if ((grid[piecePositionX + 1][piecePositionY + 2] == MOVING) &&
|
||||||
(grid[piecePositionX + 2][piecePositionY + 2] != EMPTY) &&
|
(grid[piecePositionX + 2][piecePositionY + 2] != EMPTY) &&
|
||||||
(grid[piecePositionX + 2][piecePositionY + 2] != MOVING))
|
(grid[piecePositionX + 2][piecePositionY + 2] != MOVING))
|
||||||
{
|
{
|
||||||
checker = true;
|
checker = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!checker)
|
if (!checker)
|
||||||
{
|
{
|
||||||
aux = piece[0][0];
|
aux = piece[0][0];
|
||||||
piece[0][0] = piece[3][0];
|
piece[0][0] = piece[3][0];
|
||||||
piece[3][0] = piece[3][3];
|
piece[3][0] = piece[3][3];
|
||||||
piece[3][3] = piece[0][3];
|
piece[3][3] = piece[0][3];
|
||||||
piece[0][3] = aux;
|
piece[0][3] = aux;
|
||||||
|
|
||||||
aux = piece[1][0];
|
aux = piece[1][0];
|
||||||
piece[1][0] = piece[3][1];
|
piece[1][0] = piece[3][1];
|
||||||
piece[3][1] = piece[2][3];
|
piece[3][1] = piece[2][3];
|
||||||
piece[2][3] = piece[0][2];
|
piece[2][3] = piece[0][2];
|
||||||
piece[0][2] = aux;
|
piece[0][2] = aux;
|
||||||
|
|
||||||
aux = piece[2][0];
|
aux = piece[2][0];
|
||||||
piece[2][0] = piece[3][2];
|
piece[2][0] = piece[3][2];
|
||||||
piece[3][2] = piece[1][3];
|
piece[3][2] = piece[1][3];
|
||||||
piece[1][3] = piece[0][1];
|
piece[1][3] = piece[0][1];
|
||||||
piece[0][1] = aux;
|
piece[0][1] = aux;
|
||||||
|
|
||||||
aux = piece[1][1];
|
aux = piece[1][1];
|
||||||
piece[1][1] = piece[2][1];
|
piece[1][1] = piece[2][1];
|
||||||
piece[2][1] = piece[2][2];
|
piece[2][1] = piece[2][2];
|
||||||
piece[2][2] = piece[1][2];
|
piece[2][2] = piece[1][2];
|
||||||
piece[1][2] = aux;
|
piece[1][2] = aux;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int j = GRID_VERTICAL_SIZE - 2; j >= 0; j--)
|
for (int j = GRID_VERTICAL_SIZE - 2; j >= 0; j--)
|
||||||
{
|
{
|
||||||
for (int i = 1; i < GRID_HORIZONTAL_SIZE - 1; i++)
|
for (int i = 1; i < GRID_HORIZONTAL_SIZE - 1; i++)
|
||||||
{
|
{
|
||||||
if (grid[i][j] == MOVING)
|
if (grid[i][j] == MOVING)
|
||||||
{
|
{
|
||||||
grid[i][j] = EMPTY;
|
grid[i][j] = EMPTY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = piecePositionX; i < piecePositionX + 4; i++)
|
for (int i = piecePositionX; i < piecePositionX + 4; i++)
|
||||||
{
|
{
|
||||||
for (int j = piecePositionY; j < piecePositionY + 4; j++)
|
for (int j = piecePositionY; j < piecePositionY + 4; j++)
|
||||||
{
|
{
|
||||||
if (piece[i - piecePositionX][j - piecePositionY] == MOVING)
|
if (piece[i - piecePositionX][j - piecePositionY] == MOVING)
|
||||||
{
|
{
|
||||||
grid[i][j] = MOVING;
|
grid[i][j] = MOVING;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -764,44 +764,44 @@ static bool ResolveTurnMovement()
|
||||||
static void CheckDetection(bool *detection)
|
static void CheckDetection(bool *detection)
|
||||||
{
|
{
|
||||||
for (int j = GRID_VERTICAL_SIZE - 2; j >= 0; j--)
|
for (int j = GRID_VERTICAL_SIZE - 2; j >= 0; j--)
|
||||||
{
|
{
|
||||||
for (int i = 1; i < GRID_HORIZONTAL_SIZE - 1; i++)
|
for (int i = 1; i < GRID_HORIZONTAL_SIZE - 1; i++)
|
||||||
{
|
{
|
||||||
if ((grid[i][j] == MOVING) && ((grid[i][j+1] == FULL) || (grid[i][j+1] == BLOCK))) *detection = true;
|
if ((grid[i][j] == MOVING) && ((grid[i][j+1] == FULL) || (grid[i][j+1] == BLOCK))) *detection = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void CheckCompletition(bool *lineToDelete)
|
static void CheckCompletition(bool *lineToDelete)
|
||||||
{
|
{
|
||||||
int calculator;
|
int calculator;
|
||||||
|
|
||||||
for (int j = GRID_VERTICAL_SIZE - 2; j >= 0; j--)
|
for (int j = GRID_VERTICAL_SIZE - 2; j >= 0; j--)
|
||||||
{
|
{
|
||||||
calculator = 0;
|
calculator = 0;
|
||||||
for (int i = 1; i < GRID_HORIZONTAL_SIZE - 1; i++)
|
for (int i = 1; i < GRID_HORIZONTAL_SIZE - 1; i++)
|
||||||
{
|
{
|
||||||
// Count each square of the line
|
// Count each square of the line
|
||||||
if (grid[i][j] == FULL)
|
if (grid[i][j] == FULL)
|
||||||
{
|
{
|
||||||
calculator++;
|
calculator++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if we completed the whole line
|
// Check if we completed the whole line
|
||||||
if (calculator == GRID_HORIZONTAL_SIZE - 2)
|
if (calculator == GRID_HORIZONTAL_SIZE - 2)
|
||||||
{
|
{
|
||||||
*lineToDelete = true;
|
*lineToDelete = true;
|
||||||
calculator = 0;
|
calculator = 0;
|
||||||
// points++;
|
// points++;
|
||||||
|
|
||||||
// Mark the completed line
|
// Mark the completed line
|
||||||
for (int z = 1; z < GRID_HORIZONTAL_SIZE - 1; z++)
|
for (int z = 1; z < GRID_HORIZONTAL_SIZE - 1; z++)
|
||||||
{
|
{
|
||||||
grid[z][j] = FADING;
|
grid[z][j] = FADING;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DeleteCompleteLines()
|
static void DeleteCompleteLines()
|
||||||
|
|
12
src/core.c
12
src/core.c
|
@ -1752,8 +1752,8 @@ static void MouseButtonCallback(GLFWwindow *window, int button, int action, int
|
||||||
// Normalize gestureEvent.position[0] for screenWidth and screenHeight
|
// Normalize gestureEvent.position[0] for screenWidth and screenHeight
|
||||||
gestureEvent.position[0].x /= (float)GetScreenWidth();
|
gestureEvent.position[0].x /= (float)GetScreenWidth();
|
||||||
gestureEvent.position[0].y /= (float)GetScreenHeight();
|
gestureEvent.position[0].y /= (float)GetScreenHeight();
|
||||||
|
|
||||||
// Gesture data is sent to gestures system for processing
|
// Gesture data is sent to gestures system for processing
|
||||||
ProcessGestureEvent(gestureEvent);
|
ProcessGestureEvent(gestureEvent);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -1890,7 +1890,7 @@ static void AndroidCommandCallback(struct android_app *app, int32_t cmd)
|
||||||
|
|
||||||
// TODO: GPU assets reload in case of lost focus (lost context)
|
// TODO: GPU assets reload in case of lost focus (lost context)
|
||||||
// NOTE: This problem has been solved just unbinding and rebinding context from display
|
// NOTE: This problem has been solved just unbinding and rebinding context from display
|
||||||
/*
|
/*
|
||||||
if (assetsReloadRequired)
|
if (assetsReloadRequired)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < assetsCount; i++)
|
for (int i = 0; i < assetsCount; i++)
|
||||||
|
@ -2471,9 +2471,9 @@ static void *GamepadThread(void *arg)
|
||||||
const int joystickAxisY = 1;
|
const int joystickAxisY = 1;
|
||||||
|
|
||||||
// Read gamepad event
|
// Read gamepad event
|
||||||
struct js_event gamepadEvent;
|
struct js_event gamepadEvent;
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
if (read(gamepadStream, &gamepadEvent, sizeof(struct js_event)) == (int)sizeof(struct js_event))
|
if (read(gamepadStream, &gamepadEvent, sizeof(struct js_event)) == (int)sizeof(struct js_event))
|
||||||
{
|
{
|
||||||
|
@ -2507,7 +2507,7 @@ static void *GamepadThread(void *arg)
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -385,7 +385,7 @@ typedef struct Model {
|
||||||
Matrix transform;
|
Matrix transform;
|
||||||
Texture2D texture; // Only for OpenGL 1.1, on newer versions this should be in the shader
|
Texture2D texture; // Only for OpenGL 1.1, on newer versions this should be in the shader
|
||||||
Shader shader;
|
Shader shader;
|
||||||
//Material material;
|
//Material material;
|
||||||
} Model;
|
} Model;
|
||||||
|
|
||||||
// Ray type (useful for raycast)
|
// Ray type (useful for raycast)
|
||||||
|
|
Loading…
Reference in New Issue