package generators;
import squaresgame.Grid;
import squaresgame.Square;
import squaresgame.SquareComponent;
import framework.component.ParentComponent;
import framework.rendering.SpriteComponent;
import framework.spacial.PositionComponent;
public abstract class SquareGenerator {
public static void generateSquares(Grid grid, ParentComponent gridParent, int spacing){
for(int i = 0; i < grid.getSquaresWidth(); i++){
for(int j = 0; j < grid.getSquaresHeight(); j++){
gridParent.addComponent(generateSquare(grid, i, j, spacing));
}
}
}
private static ParentComponent generateSquare(Grid grid, int gridX, int gridY, int spacing){
ParentComponent squareParent = new ParentComponent(getSquareLabel(gridX, gridY));
squareParent.addComponent(new SpriteComponent("res/img/Blank.png", spacing - 5, spacing - 5));
float x = gridX*spacing+10;
float y = gridY*spacing+10;
//TODO remove these weird coordinate adjustions.
squareParent.addComponent(new PositionComponent(x,y));
squareParent.addComponent(new SquareComponent(grid.getSquare(gridX, gridY)));
return squareParent;
}
public static String getSquareLabel(Square square){
return getSquareLabel(square.getX(), square.getY());
}
public static String getSquareLabel(int gridX, int gridY){
return "Square: "+gridX+" "+gridY;
}
}