Commit b84b5014 authored by Yoann Bordin's avatar Yoann Bordin

added down acceleration while pressing down key

parent f38bf89a
...@@ -2,6 +2,6 @@ ...@@ -2,6 +2,6 @@
This project is based on the Tetris game invented by Alekseï Pajitnov in 1984. This project is based on the Tetris game invented by Alekseï Pajitnov in 1984.
The goal is to complete a maximum of lines in a grid with pieces (tetrominoes) that fall from the top. The goal is to complete a maximum of lines in a grid with pieces (tetrominoes) that fall from the top.
# Building # Building on Windows
This project work by compiling using Notepad++ for Raylib and adding the following files to the gcc command : This project works by compiling using Notepad++ for Raylib and adding the following files to the gcc command :
```tetris-struct.c tetris-graph.c``` ```tetris-struct.c tetris-graph.c```
\ No newline at end of file
...@@ -46,6 +46,10 @@ int main(void){ ...@@ -46,6 +46,10 @@ 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(IsKeyDown(KEY_DOWN) && canMoveDown(grid, p, 1)){
movePieceVert(p, 1);
}
if(IsKeyPressed(KEY_Q)){ // A en AZERTY if(IsKeyPressed(KEY_Q)){ // A en AZERTY
while(rotateBorderLeft(p, false)){ while(rotateBorderLeft(p, false)){
movePieceHztl(p, 1); movePieceHztl(p, 1);
......
File added
...@@ -288,6 +288,17 @@ bool canMoveHztl(Grid g, Piece p, int moveNum){ ...@@ -288,6 +288,17 @@ bool canMoveHztl(Grid g, Piece p, int moveNum){
} }
return true; return true;
} }
bool canMoveDown(Grid g, Piece p, int moveNum){
for(int i = 0; i < p.size; i++){
int x = p.squares[i]->posX;
int y = p.squares[i]->posY + moveNum;
if(y < 0 || y >= g.height || g.grid[x][y] != NULL){
return false;
}
}
return true;
}
void moveSquareHztl(Square sq, int shift){ void moveSquareHztl(Square sq, int shift){
sq->posX += shift; sq->posX += shift;
......
...@@ -59,6 +59,7 @@ void displaySquare(Square sq, int pIndex, int pListIndex); ...@@ -59,6 +59,7 @@ void displaySquare(Square sq, int pIndex, int pListIndex);
void displayPiece(Piece p, int pListIndex); void displayPiece(Piece p, int pListIndex);
void displayPieceList(Piece* pList, int size); void displayPieceList(Piece* pList, int size);
bool canMoveDown(Grid g, Piece p, int moveNum);
void moveSquareVert(Square sq, int shift); void moveSquareVert(Square sq, int shift);
void movePieceVert(Piece piece, int shift); void movePieceVert(Piece piece, int shift);
......
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