Commit 69fbf0f9 authored by Yoann Bordin's avatar Yoann Bordin

Line removing implementation

parent 24e6e5ff
...@@ -35,18 +35,24 @@ int main(void){ ...@@ -35,18 +35,24 @@ int main(void){
movePieceHztl(p, 3); movePieceHztl(p, 3);
isFixed = false; isFixed = false;
} }
// Déplacements saisis au clavier
if(IsKeyPressed(KEY_LEFT)) movePieceHztl(p, -1);
if(IsKeyPressed(KEY_RIGHT)) movePieceHztl(p, 1);
if(IsKeyPressed(KEY_A)) rotatePiece(p, false);
if(IsKeyPressed(KEY_Z)) rotatePiece(p, true);
// Déplacer pièce toutes les 2s // Déplacer pièce toutes les 1s
if(frameCounter%10 == 0){ if(frameCounter%20 == 0){
if(canMove(p, grid)){ if(canMove(p, grid)){
movePieceVert(p, 1); movePieceVert(p, 1);
} }
else{ else{
addPieceToGrid(p, grid); addPieceToGrid(p, grid);
isFixed = true; isFixed = true;
removeLinesIfCompleted(grid);
} }
} }
drawPiece(p); drawPiece(p);
......
No preview for this file type
...@@ -108,19 +108,16 @@ void rotateSquare(Square sq, Square ref, bool rotation){ ...@@ -108,19 +108,16 @@ void rotateSquare(Square sq, Square ref, bool rotation){
int posY = sq->posY; int posY = sq->posY;
if(rotation){ if(rotation){
sq->posX = refX - posY; sq->posX = refX - posY + refY;
sq->posY = refY + posX; sq->posY = refY + posX - refX;
} }
else{ else{
sq->posX = refX + posY; sq->posX = refX + posY - refY;
sq->posY = refY - posX; sq->posY = refY - posX + refX;
} }
} }
void rotatePiece(Piece p, bool rotation){ void rotatePiece(Piece p, bool rotation){
//const int width = GRID_WIDTH;
//const int height = GRID_HEIGHT;
for(int i = 0; i < p.size; i++){ for(int i = 0; i < p.size; i++){
if(i != 1){ if(i != 1){
rotateSquare(p.squares[i], p.squares[1], rotation); rotateSquare(p.squares[i], p.squares[1], rotation);
...@@ -290,4 +287,31 @@ void movePieceHztl(Piece p, int shift){ ...@@ -290,4 +287,31 @@ void movePieceHztl(Piece p, int shift){
for(int i = 0; i < p.size; i++){ for(int i = 0; i < p.size; i++){
moveSquareHztl(p.squares[i], shift); moveSquareHztl(p.squares[i], shift);
} }
}
void removeLine(Grid g, int lineIndex){
int i = lineIndex;
while(i > 0){
i--;
for(int j = 0; j < g.width; j++){
g.grid[j][i+1] = g.grid[j][i];
}
for(int k = 0; k < g.width; k++){
g.grid[k][0] = NULL;
}
}
}
void removeLinesIfCompleted(Grid grid){
for(int k = 0; k < grid.height; k++){
int j = 0;
while(j < grid.width && grid.grid[j][k] != NULL){
j++;
}
if (j == grid.width){
removeLine(grid, k);
}
}
} }
\ No newline at end of file
...@@ -5,9 +5,9 @@ ...@@ -5,9 +5,9 @@
#include "raylib.h" #include "raylib.h"
#define PIECE_SIZE 4; #define PIECE_SIZE 4
#define GRID_WIDTH 10; #define GRID_WIDTH 10
#define GRID_HEIGHT 20; #define GRID_HEIGHT 20
typedef struct square_s{ typedef struct square_s{
int posX; int posX;
...@@ -62,4 +62,7 @@ void displayPieceList(Piece* pList, int size); ...@@ -62,4 +62,7 @@ void displayPieceList(Piece* pList, int size);
void moveSquareVert(Square sq, int shift); void moveSquareVert(Square sq, int shift);
void movePieceVert(Piece piece, int shift); void movePieceVert(Piece piece, int shift);
void moveSquareHztl(Square sq, int shift); void moveSquareHztl(Square sq, int shift);
void movePieceHztl(Piece p, int shift); void movePieceHztl(Piece p, int shift);
\ No newline at end of file
void removeLine(Grid g, int lineIndex);
void removeLinesIfCompleted(Grid grid);
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment