I am pretty new to LibGDX and game developing in general and i am currently writing my first game (a breakout clone) with LibGDX.
I have tried to store the Leveldata (positions of Blocks) in a 2-dimensional array like this:
// 1 = block, 0 = empty
levelArray = new int[][] {
{0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0},
{1,1,1,1,1,1,1,1,1,1,1,1},
{0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0}
};
Currently there are only normal blocks, that can be destroyed by the ball. In the future i will implement unbreakable blocks and blocks that drop upgrades like more balls or balls that break through blocks.
When a new game (or level) is created i iterate over the Array and create the blocks like this:
brickStorage = BrickStorage.getInstance();
for(int y = 0; y < levelArray.length; y++) {
for(int x = 1; x < levelArray[y].length; x++) {
if(levelArray[y][x] == 1)
brickStorage.add(
new Brick((x*BRICK_WIDTH+MAP_EDGE)/PIXEL_TO_METER,(y*BRICK_HEIGHT-MAP_EDGE)/PIXEL_TO_METER));
}
}
My question now is, if i want to create a new level i have to write another array. Is there a better way to store Block positions and types when loading a new level?
If further code is needed i will of course edit it here