Commit 4b057466 authored by Yoann Bordin's avatar Yoann Bordin

Merge branch 'testing' into dev

parents cc8a756c 24515210
File added
...@@ -38,11 +38,15 @@ void drawGrid(Grid g){ ...@@ -38,11 +38,15 @@ void drawGrid(Grid g){
if(g.grid[x][y] != NULL){ if(g.grid[x][y] != NULL){
drawSquare(x, y, g.grid[x][y]->color); drawSquare(x, y, g.grid[x][y]->color);
} }
//drawSquare(g.grid[x][y]);
} }
} }
} }
void displayScore(int score){
DrawText("score", 400, 50, 20, RAYWHITE);
DrawText(TextFormat("%4i", score), 430, 80, 20, RAYWHITE);
}
void gameInstructions(Grid grid, Piece* pList){ void gameInstructions(Grid grid, Piece* pList){
Piece piece = generePiece(pList); Piece piece = generePiece(pList);
......
...@@ -16,4 +16,6 @@ void drawSquare(int x, int y, Color color); ...@@ -16,4 +16,6 @@ void drawSquare(int x, int y, Color color);
void drawPiece(Piece p); void drawPiece(Piece p);
void drawGrid(Grid g); void drawGrid(Grid g);
void displayScore(int score);
void gameInstructions(Grid grid, Piece* pList); void gameInstructions(Grid grid, Piece* pList);
\ No newline at end of file
...@@ -9,12 +9,15 @@ int main(void){ ...@@ -9,12 +9,15 @@ int main(void){
Piece p = pieceInit(); Piece p = pieceInit();
bool isFixed = true; bool isFixed = true;
int score = 0;
int frameCounter = 0; int frameCounter = 0;
while(!WindowShouldClose() && !gameOver(grid)){ while(!WindowShouldClose() && !gameOver(grid)){
BeginDrawing(); BeginDrawing();
InitDisplay(); InitDisplay();
displayScore(score);
// Testing // Testing
char text1[10]; char text1[10];
...@@ -43,8 +46,32 @@ int main(void){ ...@@ -43,8 +46,32 @@ int main(void){
if(IsKeyPressed(KEY_RIGHT) && canMoveHztl(grid, p, 1)){ if(IsKeyPressed(KEY_RIGHT) && canMoveHztl(grid, p, 1)){
movePieceHztl(p, 1); movePieceHztl(p, 1);
} }
if(IsKeyPressed(KEY_A)) rotatePiece(p, false); if(IsKeyPressed(KEY_Q)){ // A en AZERTY
if(IsKeyPressed(KEY_Z)) rotatePiece(p, true); while(rotateBorderLeft(p, false)){
movePieceHztl(p, 1);
}
while(rotateBorderRight(p, false)){
movePieceHztl(p, -1);
}
while(rotateCollideGrid(grid, p, false)){
movePieceVert(p, -1);
}
rotatePiece(grid, p, false);
}
if(IsKeyPressed(KEY_W)){ // Z en AZERTY
while(rotateBorderLeft(p, true)){
movePieceHztl(p, 1);
}
while(rotateBorderRight(p, true)){
movePieceHztl(p, -1);
}
while(rotateCollideGrid(grid, p, true)){
movePieceVert(p, -1);
}
rotatePiece(grid, p, true);
}
// Déplacer pièce toutes les 1s // Déplacer pièce toutes les 1s
if(frameCounter%20 == 0){ if(frameCounter%20 == 0){
...@@ -55,7 +82,7 @@ int main(void){ ...@@ -55,7 +82,7 @@ int main(void){
addPieceToGrid(p, grid); addPieceToGrid(p, grid);
isFixed = true; isFixed = true;
removeLinesIfCompleted(grid); score += removeLinesIfCompleted(grid);
} }
} }
......
...@@ -117,14 +117,12 @@ void rotateSquare(Square sq, Square ref, bool rotation){ ...@@ -117,14 +117,12 @@ void rotateSquare(Square sq, Square ref, bool rotation){
} }
} }
void rotatePiece(Piece p, bool rotation){ void rotatePiece(Grid g, Piece p, bool rotation){
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);
} }
} }
} }
void addPieceToGrid(Piece piece, Grid grid){ void addPieceToGrid(Piece piece, Grid grid){
...@@ -301,7 +299,8 @@ void movePieceHztl(Piece p, int shift){ ...@@ -301,7 +299,8 @@ void movePieceHztl(Piece p, int shift){
} }
} }
void removeLinesIfCompleted(Grid grid){ int removeLinesIfCompleted(Grid grid){
int nbLinesRemoved = 0;
bool isLineCompleted; bool isLineCompleted;
int y = 0; int y = 0;
...@@ -314,6 +313,7 @@ void removeLinesIfCompleted(Grid grid){ ...@@ -314,6 +313,7 @@ void removeLinesIfCompleted(Grid grid){
} }
if(isLineCompleted){ if(isLineCompleted){
nbLinesRemoved++;
int lineToRemove = y; int lineToRemove = y;
//free //free
...@@ -336,6 +336,7 @@ void removeLinesIfCompleted(Grid grid){ ...@@ -336,6 +336,7 @@ void removeLinesIfCompleted(Grid grid){
y++; y++;
} }
} }
return nbLinesRemoved;
} }
void displayColumn(Square* line, int index, int height){ void displayColumn(Square* line, int index, int height){
...@@ -351,3 +352,78 @@ void displayGrid(Grid g){ ...@@ -351,3 +352,78 @@ void displayGrid(Grid g){
displayColumn(g.grid[x], x, g.height); displayColumn(g.grid[x], x, g.height);
} }
} }
bool rotateBorderLeft(Piece p, bool rotation){
int refX = p.squares[1]->posX;
int refY = p.squares[1]->posY;
for(int i = 0; i < p.size; i++){
int posX = p.squares[i]->posX;
int posY = p.squares[i]->posY;
int newPosX, newPosY;
if(rotation){
newPosX = refX - posY + refY;
newPosY = refY + posX - refX;
}
else{
newPosX = refX + posY - refY;
newPosY = refY - posX + refX;
}
if(newPosX < 0){
return true;
}
}
return false;
}
bool rotateBorderRight(Piece p, bool rotation){
int refX = p.squares[1]->posX;
int refY = p.squares[1]->posY;
for(int i = 0; i < p.size; i++){
int posX = p.squares[i]->posX;
int posY = p.squares[i]->posY;
int newPosX, newPosY;
if(rotation){
newPosX = refX - posY + refY;
newPosY = refY + posX - refX;
}
else{
newPosX = refX + posY - refY;
newPosY = refY - posX + refX;
}
if(newPosX >= GRID_WIDTH){
return true;
}
}
return false;
}
bool rotateCollideGrid(Grid g, Piece p, bool rotation){
int refX = p.squares[1]->posX;
int refY = p.squares[1]->posY;
for(int i = 0; i < p.size; i++){
int posX = p.squares[i]->posX;
int posY = p.squares[i]->posY;
int newPosX, newPosY;
if(rotation){
newPosX = refX - posY + refY;
newPosY = refY + posX - refX;
}
else{
newPosX = refX + posY - refY;
newPosY = refY - posX + refX;
}
if(newPosX < 0 && newPosX >= GRID_WIDTH && g.grid[newPosX][newPosY] != NULL){
return true;
}
}
return false;
}
\ No newline at end of file
...@@ -44,7 +44,7 @@ bool canMove(Piece piece, Grid grid); ...@@ -44,7 +44,7 @@ bool canMove(Piece piece, Grid grid);
bool canMoveSquare(Square sq, Grid g); bool canMoveSquare(Square sq, Grid g);
void rotateSquare(Square sq, Square ref, bool rotation); void rotateSquare(Square sq, Square ref, bool rotation);
void rotatePiece(Piece p, bool rotation); // False makes a counterclockwise rotation and true makes a clockwise rotation void rotatePiece(Grid g, Piece p, bool rotation); // False makes a counterclockwise rotation and true makes a clockwise rotation
void addPieceToGrid(Piece piece, Grid grid); void addPieceToGrid(Piece piece, Grid grid);
void addSquareToGrid(Square sq, Grid g); void addSquareToGrid(Square sq, Grid g);
...@@ -66,7 +66,11 @@ bool canMoveHztl(Grid g, Piece p, int moveNum); ...@@ -66,7 +66,11 @@ bool canMoveHztl(Grid g, Piece p, int moveNum);
void moveSquareHztl(Square sq, int shift); void moveSquareHztl(Square sq, int shift);
void movePieceHztl(Piece p, int shift); void movePieceHztl(Piece p, int shift);
void removeLinesIfCompleted(Grid grid); int removeLinesIfCompleted(Grid grid);
void displayColumn(Square* line, int index, int height); void displayColumn(Square* line, int index, int height);
void displayGrid(Grid g); void displayGrid(Grid g);
bool rotateBorderLeft(Piece p, bool rotation);
bool rotateBorderRight(Piece p, bool rotation);
bool rotateCollideGrid(Grid g, Piece p, bool rotation);
\ No newline at end of file
...@@ -5,4 +5,4 @@ ...@@ -5,4 +5,4 @@
(0,0)(1,0)(2,0)(0,1) (0,0)(1,0)(2,0)(0,1)
(0,0)(1,0)(2,0)(2,1) (0,0)(1,0)(2,0)(2,1)
(0,0)(1,0)(1,1)(2,1) (0,0)(1,0)(1,1)(2,1)
(1,0)(2,0)(0,1)(1,1) (2,0)(1,0)(0,1)(1,1)
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