Archived

This topic is now archived and is closed to further replies.

MinNever

Weird problem making my OGL Tetris

Recommended Posts

When I put an 1 into Tablero[][] so I can put a pice in the board of my tetris game, it get doble. I mean that another place where I have put a 0 before shows like a 1 in the board. Here is some of the code where I think could be the problem. Thanks ----------------------------------------------------- #define MAX_H 12 #define MAX_V 19 #define MAX_VIDAS 3 #define TIEMPO 15 int Tablero[MAX_V][MAX_H] = {0}; bool Linea_Completa = false; void Linea() // Chequea si la linea fue completada { int x = 0; int Linea_If = 0; for ( x = 0; x<= MAX_H ; x++ ){ if ( Tablero[0][x] == 1 && Linea_If == 0) { Linea_Completa = true; } if ( Tablero[0][x] == 0 ) { Linea_Completa = false; Linea_If = 1; } } Linea_If = 0; } void Mover_Linea() { int x; int y; for ( x = 0; x <= MAX_H; x++ ) { for ( y = 0; y <= MAX_V; y++ ) { Tablero[ x ][ y ] = Tablero[ x + 1 ][ y ]; } } } void Dibujar_Tablero(int Tx, int Ty){ if (Tablero [Tx][Ty] == 0){ glColor4f(0.0f, 0.0f, 0.0f, 1.0f); glBegin(GL_QUADS); glVertex3f( 0.0f, 0.0f, 0.0f); glVertex3f( 1.0f, 0.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 0.0f); glVertex3f( 0.0f, 1.0f, 0.0f); glEnd(); } if (Tablero [Tx][Ty] == 1){ glColor4f(0.0f, 0.0f, 1.0f, 1.0f); glBegin(GL_QUADS); glVertex3f( 0.0f, 0.0f, 0.0f); glVertex3f( 1.0f, 0.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 0.0f); glVertex3f( 0.0f, 1.0f, 0.0f); glEnd(); } } void Colocar(){ // Pinta el Tablero int x; int y; for ( x = 0; x <= MAX_H; x++ ) { //Altura de la tabla for ( y = 0; y <= MAX_V; y++ ) { //Ancho de la tabla glTranslatef( 1.1f , 0.0f , 0.0f); Dibujar_Tablero(x, y); } glTranslatef( (MAX_V + 1) * (-1.1f) , 1.1f , 0.0f); } } void Poner_Pieza(int cual){ switch (cual){ case 0: Tablero[6][MAX_H - 1] = 1; Tablero[7][MAX_H - 1] = 1; Tablero[8][MAX_H - 1] = 1; Tablero[7][MAX_H] = 1; break; case 1: Tablero[6][MAX_H - 1] = 1; Tablero[7][MAX_H - 1] = 1; Tablero[6][MAX_H ] = 1; Tablero[7][MAX_H] = 1; break; } }

Share this post


Link to post
Share on other sites
#define MAX_H 12
#define MAX_V 19
#define MAX_VIDAS 3
#define TIEMPO 15

int Tablero[MAX_V][MAX_H] = {0};
bool Linea_Completa = false;

void Linea() // Check if the line is completed
{
int x = 0;
int Linea_If = 0;
for ( x = 0; x<= MAX_H ; x++ ){
if ( Tablero[0][x] == 1 && Linea_If == 0) {
Linea_Completa = true;
}
if ( Tablero[0][x] == 0 ) {
Linea_Completa = false;
Linea_If = 1;
}
}
Linea_If = 0;
}


void Mover_Linea()
{
int x;
int y;
for ( x = 0; x <= MAX_H; x++ ) {
for ( y = 0; y <= MAX_V; y++ ) {
Tablero[ x ][ y ] = Tablero[ x + 1 ][ y ];
}
}
}


void Dibujar_Tablero(int Tx, int Ty){

if (Tablero [Tx][Ty] == 0){
glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
glBegin(GL_QUADS); glVertex3f( 0.0f, 0.0f, 0.0f); glVertex3f( 1.0f, 0.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 0.0f); glVertex3f( 0.0f, 1.0f, 0.0f); glEnd();
}

if (Tablero [Tx][Ty] == 1){
glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
glBegin(GL_QUADS); glVertex3f( 0.0f, 0.0f, 0.0f); glVertex3f( 1.0f, 0.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 0.0f); glVertex3f( 0.0f, 1.0f, 0.0f); glEnd();
}
}

void Colocar(){ // Draw the board
int x;
int y;
for ( x = 0; x <= MAX_H; x++ ) { //Hight of the board
for ( y = 0; y <= MAX_V; y++ ) { //Weith of the board
glTranslatef( 1.1f , 0.0f , 0.0f);
Dibujar_Tablero(x, y);
}
glTranslatef( (MAX_V + 1) * (-1.1f) , 1.1f , 0.0f);
}
}


void Poner_Pieza(int cual){
switch (cual){
case 0:
Tablero[6][MAX_H - 1] = 1;
Tablero[7][MAX_H - 1] = 1;
Tablero[8][MAX_H - 1] = 1;
Tablero[7][MAX_H] = 1;
break;

case 1:
Tablero[6][MAX_H - 1] = 1;
Tablero[7][MAX_H - 1] = 1;
Tablero[6][MAX_H ] = 1;
Tablero[7][MAX_H] = 1;
break;
}

}

Share this post


Link to post
Share on other sites