When your y values exceed 49 (MAP_HEIGHT - 1
) you are overflowing your array. If in your draw loop you calculate y=a*x+b
and print Z instead of X you'll see the first line is X's and the overflowed errors are all Z's
for(int x=0;x<MAP_LENGTH;x++)
{
int y = a*x+b;
if(y<MAP_HEIGHT) {
piano.griglia[x][y]='X';
} else {
piano.griglia[x][y]='Z';
}
}
This is due to the way memory for the arrays is stored in C++, it just happens writing outside one array here causes you to write into the next one. In general doing this will crash your program.
Also note that here the x loop should be over MAP_LENGTH
.
I would also strongly advise getting a proper graphics library