So i made this simple 2D game in processing and problem is that when i run it whole game is tilted to left a little so it have empty space on right and is cropped on left. Is there any way to fix this?
This is code:
int red = 20;
int kolona = 20;
boolean[][] grid = new boolean[red][kolona];
int playerIndexX = 10;
int playerIndexY = 10;
void setup() {
size(300, 300);
for(int i = 0; i < red; i++)
{
for(int j = 0; j < kolona; j++)
{
if(random(100) < 20 && j != 50 && i != 20)
{
grid[i][j] = true;
}
}
}
rectMode(CENTER);
}
void keyPressed()
{
if(keyCode == DOWN && playerIndexY + 1 < 20 && !grid[playerIndexX][playerIndexY+1])
{
playerIndexY++;
}
if(keyCode == UP && playerIndexY - 1 >= 0 && !grid[playerIndexX][playerIndexY- 1])
{
playerIndexY--;
}
if(keyCode == LEFT && playerIndexX - 1 >= 0 && !grid[playerIndexX-1][playerIndexY])
{
playerIndexX--;
}
if(keyCode == RIGHT && playerIndexX + 1 < 20 && !grid[playerIndexX+1][playerIndexY])
{
playerIndexX++;
}
}
void draw() {
int kockaWidth = width/red;
int kockaHeight = height/kolona;
for(int i = 0; i < red; i++)
{
for(int j = 0; j < kolona; j++)
{
if(grid[i][j])
{
fill(255,0,0);
rect(kockaWidth * i, kockaHeight *j, kockaWidth,kockaHeight);
}
else
{
stroke(1);
fill(160,160,160);
rect(kockaWidth * i, kockaHeight *j, kockaWidth,kockaHeight);
}
}
}
float playerPixelX = playerIndexX * kockaWidth;
float playerPixelY = playerIndexY * kockaHeight;
fill(0, 255, 0);
rect(playerPixelX, playerPixelY, kockaWidth, kockaHeight);
}
Grid should cover whole screen but for some reason it is tilted and i dont think this is because of code.