# I'm trying to use arrarys to make circles fall

**URL:** <https://discourse.processing.org/t/im-trying-to-use-arrarys-to-make-circles-fall/7371>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [January 9, 2019, 8:47pm UTC](https://discourse.processing.org/t/im-trying-to-use-arrarys-to-make-circles-fall/7371 "2019-01-09T20:47:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![squirrel1969](https://avatars.discourse-cdn.com/v4/letter/s/47e85d/32.png) [@squirrel1969](https://discourse.processing.org/u/squirrel1969)\
**Post date:** [January 9, 2019, 8:47pm UTC](https://discourse.processing.org/t/im-trying-to-use-arrarys-to-make-circles-fall/7371/1 "2019-01-09T20:47:16Z")

</div>

Hello!  
I’m new to processing and coding in general and for our final project I want to make a game where circles move across the screen horizontally and you have to avoid them. We didn’t learn how to use arrays, but I want to use them to do this.

I managed to get them coming from different y-coordinates but am not sure how to make a new array to get them to be at different x coordinates, I’m currently just using a variable for the x coordinates. Right now the next batch of circles only comes when all the circles cross the window, but I want to have the circles come from random x-coordinates and only reset individual circles when it crosses the window

Sorry for wording this so badly lol

This is what I have so far:

```auto
int [] num=new int [5];

int x=int(random(-200, -100));

int ballx=mouseX;

int bally=mouseY;

void setup() {

  size(400, 400);

}

void draw() {

  background(255);

  for (int i=0; i<5; i++) //makes the circle

  {

  ellipse(x, num[i], 40, 40);

    x++;

 

    ellipse(mouseX, mouseY, 20, 20);

    if (dist(mouseX, mouseY, x, num[i])<=40)

      println("you lose");

       if (x>t;=width)

  {     

    x=int(random(-200, -100));

    for ( i=0; i<;5; i++) //makes the location of the circles different

      num[i]=int(random(height));

  }

  }

}

```

---

<div class="post-metadata">

**Author:** ![Sky](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sky/32/3013_2.png) [@Sky](https://discourse.processing.org/u/Sky)\
**Post date:** [January 9, 2019, 9:00pm UTC](https://discourse.processing.org/t/im-trying-to-use-arrarys-to-make-circles-fall/7371/2 "2019-01-09T21:00:48Z")

</div>

Try using [PVector()](https://processing.org/reference/PVector.html)

---

<div class="post-metadata">

**Author:** ![Sky](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sky/32/3013_2.png) [@Sky](https://discourse.processing.org/u/Sky)\
**Post date:** [January 9, 2019, 9:29pm UTC](https://discourse.processing.org/t/im-trying-to-use-arrarys-to-make-circles-fall/7371/4 "2019-01-09T21:29:16Z")

</div>

```auto
PVector[] ellX = new PVector[5];// circles that move in X
PVector[] ellY = new PVector[5];// circles that move in y
void setup() {
  size(400, 400);
  for (int i = 0; i < 5; i++) {
    ellX[i] = new PVector(random(-200, -100), random(0, height));
    ellY[i] = new PVector(random(0, width), random(-200, -100));
  }
}

void draw() {
  background(255);
  //draw cirles
  for (int i = 0; i < 5; i++) {
    ellipse(ellX[i].x, ellX[i].y, 20, 20);
    ellipse(ellY[i].x, ellY[i].y, 20, 20);
  }
  //move them
  for (int i = 0; i < 5; i++) {
    ellX[i].x++;
    ellY[i].y++;
    float dist1 = dist(ellX[i].x, ellX[i].y, mouseX, mouseY);
    float dist2 = dist(ellY[i].x, ellY[i].y, mouseX, mouseY);
    if (dist1 <= 20 || dist2 <= 20) {
      println("YOU LOSE");
    }
  }
  //reset circle if it reeached the end
  for (int i = 0; i < 5; i++) {
    if(ellX[i].x >= width){
      ellX[i] = new PVector(random(-200, -100), random(0, height));
    }
   if(ellY[i].y >= height){
      ellY[i] = new PVector(random(0, width), random(-200, -100));
    }
  }
}

```

This works, I hope you understand something

---

<div class="post-metadata">

**Author:** ![squirrel1969](https://avatars.discourse-cdn.com/v4/letter/s/47e85d/32.png) [@squirrel1969](https://discourse.processing.org/u/squirrel1969)\
**Post date:** [January 9, 2019, 9:41pm UTC](https://discourse.processing.org/t/im-trying-to-use-arrarys-to-make-circles-fall/7371/5 "2019-01-09T21:41:34Z")

</div>

Thank you!  
This is what I’m trying to do, but is there a way to do this without pvector? I haven’t learned how to use that

---

<div class="post-metadata">

**Author:** ![Sky](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sky/32/3013_2.png) [@Sky](https://discourse.processing.org/u/Sky)\
**Post date:** [January 9, 2019, 9:49pm UTC](https://discourse.processing.org/t/im-trying-to-use-arrarys-to-make-circles-fall/7371/6 "2019-01-09T21:49:46Z")

</div>

So, PVector() is something that exist in Processing.  
you have two ways  
1 ) Create a class with float x and y,(this is what a PVector is), but if you have never used arrays, I think you dont know what classes are  
2 ) ellXx store ellipse that move on X x coordinate  
ellXy store ellipse that move on X y coordinate  
ellYx …  
ellYy…  
you get the idea right? 2 arrays that stores X and Y of circles that move on X and the same for circles that move on Y

---

<div class="post-metadata">

**Author:** ![Sky](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sky/32/3013_2.png) [@Sky](https://discourse.processing.org/u/Sky)\
**Post date:** [January 9, 2019, 9:53pm UTC](https://discourse.processing.org/t/im-trying-to-use-arrarys-to-make-circles-fall/7371/7 "2019-01-09T21:53:51Z")

</div>

and if the player gets hit, you can use[text(YOU LOSEx,y)](https://processing.org/reference/text_.html) [delay()](https://processing.org/reference/delay_.html) and [exit()](https://processing.org/reference/exit_.html)
