2d array movement help

Hello guys,

I’m trying to create a game using an 2d array to create a grid of (invisible) squares to put items in them. I’m having trouble moving the grid of squares down because I don’t want them to fit the screen.

Let’s say if my window size is 800,600 how would I let the grid of squares start at 200 (Y)? Thank you so much for your help!! And how would I evenly distribute them over the width of the screen?

I also want to randomize squares with bombs and life points, but they can’t spawn & be too close to eachother, what would be the best option to do this?

int [][]field = new int[30][20];
 int space = 5;

for (int x = 0; x < field.length; x++) {
 for (int y = 0; y < field[x].length; y++){
 rect(2xspace, 2yspace, space, space);

Here you calculate the position of the cell

you can say x*space and add 200 to it

Thank you so much, didn’t know it’d be that easy!

1 Like

And welcome to the forum!

Great to have you here!!!

That be a bit tricky

In setup or before your current for-loops have a separate nested for-loop where you define the cells based on a random() number. See reference.

Where this color means bomb for example

1 Like