Array Collision
in
Programming Questions
•
1 year ago
I am try to make this collision with multiple balls work,but I am not understanding how to get it.
Is there anyone who has a suggestion for me?
I would be so helpful
This is my code.
Thanks! :)
- float [] ballFallX = new float [0];
- float [] ballFallY = new float [0];
- float circleX, circleY;
- int x=50;
- float ballspeed;
- int i=1;
- int triangleX=500;
- int triangleY=300;
- boolean alp=true;
- float[] xnew=new float[5];
- float[] y=new float[5];
- float[] speed= new float[5];
- void setup() {
- size(700, 700);
- ballspeed=5;
- frameRate(40);
- for (int i=0; i <5; i++){
- xnew[i]=random(width); //random position between 0 and the width
- y[i]=random(height);//random position between 0 and the heigth
- speed[i]=random(1,5); //the star will have a random speed
- }
- }
- void draw() {
- background(0);
- for (int i=0; i <5; i++){
- ellipse(xnew[i],y[i],40,40);
- y[i]=y[i]+speed[i]; //here I am going to move the star on y
- if(y[i]>700){ //here we say that if it goes out of the screen it has to jump back
- y[i]=0;
- }
- circleFunc();
- triangleX= x;
- triangleY=600;
- fill(0, 10, 200);
- triangle(x+20, 675, triangleX, triangleY, x-20, 675);
- }
- }
- void keyPressed() {
- if (key == CODED) {
- if (keyCode == RIGHT) {
- x+=20;
- }
- else if (keyCode == LEFT) {
- x-=20;
- }
- else if (keyCode == UP) {
- ballFallX = append(ballFallX, triangleX);
- ballFallY = append(ballFallY, triangleY);
- }
- }
- }
- void circleFunc() {
- for (int i=0; i<ballFallX.length; i++)
- {
- fill (200, 0, 111);
- ellipse(ballFallX[i], ballFallY[i], 10, 10);
- println(i + " THis is the number of ball in the array");
- /*
- if (abs(circleX-triangleX)<50 && abs(circleY-triangleY)<50)
- {
- alp=false;
- println(alp+" after test");
- }
- if (alp ==false)
- {
- ballFallX[i]=100;
- ballFallY[i]=100;
- alp=true;
- fill(0,0);
- println(alp + " in function ");
- }
- */
- circleX=ballFallX[i];
- circleY=ballFallY[i];
- // println ("Here is the X array " +ballFallX[i]);
- ballFallY[i]-=ballspeed;
- }
- }
1