Commit 13a4fb8b authored by Yoann Bordin's avatar Yoann Bordin

bug fixes

parent 95aa3d4d
#include "tetris-struct.h"
#define SCREEN_WIDTH 1280
#define SCREEN_HEIGHT 720
#define SCREEN_WIDTH 700
#define SCREEN_HEIGHT 700
#define BORDER_GAP 20
#define SQUARE_SIZE 30
......
......@@ -46,6 +46,12 @@ int main(void){
while(rotateCollideRight(p, false)){
movePieceHztl(p, -1);
}
while(rotateCollideTop(p, false)){
movePieceVert(p, 1);
}
while(rotateCollideBottom(p, false)){
movePieceVert(p, -1);
}
while(rotateCollideGrid(grid, p, false)){
movePieceVert(p, -1);
}
......@@ -60,6 +66,12 @@ int main(void){
while(rotateCollideRight(p, true)){
movePieceHztl(p, -1);
}
while(rotateCollideTop(p, true)){
movePieceVert(p, 1);
}
while(rotateCollideBottom(p, true)){
movePieceVert(p, -1);
}
while(rotateCollideGrid(grid, p, true)){
movePieceVert(p, -1);
}
......
No preview for this file type
......@@ -221,7 +221,7 @@ bool rotateCollideRight(Piece p, bool rotation){
newPosY = refY + posX - refX;
}
if(newPosY < 0){
if(newPosY >= GRID_WIDTH){
return true;
}
}
......@@ -231,19 +231,49 @@ bool rotateCollideRight(Piece p, bool rotation){
bool rotateCollideTop(Piece p, bool rotation){
int refX = p.squares[1]->posX;
int refY = p.squares[1]->posY;
int newPosX, newPosY;
int posX, posY;
for(int i = 0; i < p.size; i++){
int posY = p.squares[i]->posY;
int newPosX;
posX = p.squares[i]->posX;
posY = p.squares[i]->posY;
if(rotation){
newPosX = refX + posY - refY;
if (rotation){
newPosX = refX - posY + refY;
newPosY = refY + posX - refX;
}
else{
newPosX = refX + posY - refY;
newPosY = refY - posX + refX;
}
if (newPosY < 0){
return true;
}
}
return false;
}
bool rotateCollideBottom(Piece p, bool rotation){
int refX = p.squares[1]->posX;
int refY = p.squares[1]->posY;
int newPosX, newPosY;
int posX, posY;
for(int i = 0; i < p.size; i++){
posX = p.squares[i]->posX;
posY = p.squares[i]->posY;
if (rotation){
newPosX = refX - posY + refY;
newPosY = refY + posX - refX;
}
else{
newPosX = refX + posY - refY;
newPosY = refY - posX + refX;
}
if(newPosX < 0){
if (newPosY >= GRID_HEIGHT){
return true;
}
}
......@@ -268,7 +298,7 @@ bool rotateCollideGrid(Grid g, Piece p, bool rotation){
newPosY = refY - posX + refX;
}
if(newPosX < 0 && newPosX >= GRID_WIDTH && g.grid[newPosX][newPosY] != NULL){
if(g.grid[newPosX][newPosY] != NULL){
return true;
}
}
......
......@@ -64,7 +64,8 @@ void movePieceHztl(Piece p, int shift);
// Bool verifications for rotating
bool rotateCollideLeft(Piece p, bool rotation);
bool rotateCollideRight(Piece p, bool rotation);
bool rotateCollideTop(Piece p, bool rotation); // To debug
bool rotateCollideTop(Piece p, bool rotation);
bool rotateCollideBottom(Piece p, bool rotation);
bool rotateCollideGrid(Grid g, Piece p, bool rotation);
// Rotating functions
......
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