• ### What is your GameDev Story?

#### Archived

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

# Weird problem making my OGL Tetris

This topic is 5842 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 on other sites
Could you put the comments in english? Thanks

##### 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;
}

}

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 13
• 9
• 15
• 14
• 46
• ### Forum Statistics

• Total Topics
634067
• Total Posts
3015320
×