# 2d array movement help

**URL:** <https://discourse.processing.org/t/2d-array-movement-help/24851>\
**Category:** Coding Questions\
**Created:** [October 23, 2020, 2:19pm UTC](https://discourse.processing.org/t/2d-array-movement-help/24851 "2020-10-23T14:19:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lilith](https://avatars.discourse-cdn.com/v4/letter/l/e36b37/32.png) [@Lilith](https://discourse.processing.org/u/Lilith)\
**Post date:** [October 23, 2020, 2:19pm UTC](https://discourse.processing.org/t/2d-array-movement-help/24851/1 "2020-10-23T14:19:55Z")

</div>

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?

```auto

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++){
 fill(speelveld[x][y]);
 rect(2xspace, 2yspace, space, space);
 } 
} 
}

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [October 23, 2020, 2:54pm UTC](https://discourse.processing.org/t/2d-array-movement-help/24851/2 "2020-10-23T14:54:46Z")

</div>

> [@Lilith](#):
>
> `rect(2xspace, 2yspace`

Here you calculate the position of the cell

you can say `x*space` and add 200 to it

---

<div class="post-metadata">

**Author:** ![Lilith](https://avatars.discourse-cdn.com/v4/letter/l/e36b37/32.png) [@Lilith](https://discourse.processing.org/u/Lilith)\
**Post date:** [October 23, 2020, 8:53pm UTC](https://discourse.processing.org/t/2d-array-movement-help/24851/3 "2020-10-23T20:53:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [October 23, 2020, 10:12pm UTC](https://discourse.processing.org/t/2d-array-movement-help/24851/4 "2020-10-23T22:12:25Z")

</div>

And welcome to the forum!

Great to have you here!!!

> [@Lilith](#):
>
> want to randomize squares with bombs and life points, but they can’t spawn & be too close to eachother

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.

> [@Lilith](#):
>
> `speelveld[x][y] = color(255,0,0);`

Where this color means bomb for example

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [October 24, 2020, 8:36am UTC](https://discourse.processing.org/t/2d-array-movement-help/24851/5 "2020-10-24T08:36:03Z")

</div>

> **[r/processing - 2d array movement help](https://www.reddit.com/r/processing/comments/jgnx0w/2d_array_movement_help/)**
>
> 3 votes and 1 comment so far on Reddit
