Need help with code! Collision is not working. I use java on processing 3.3.1

Discussion in 'Java' started by newbie73, Dec 9, 2019.

  1. newbie73

    newbie73

    Joined:
    Dec 9, 2019
    Messages:
    6
    Likes Received:
    0
    The code doesn't work, when I launch the code the balls are shown but they do not bounce of the side of the screen. I would appreciate it if someone could also help me create a code for each balls colliding with each other e.g when the balls hit each other they bounce off each other.

    float [] x={0,100,400,0,300,50,800};
    float [] y={100,200,500,50,0,30,600};
    float [] dx={(3),(4),(6),(8),(10), (2), (5)};
    float [] dy={ (5), (5), (3), (5), (1), (6), (8)};
    float [] xx={3,4,6,8,10,2,5};
    float [] yy={5,5,3,5,1,6,8};
    float ballSize;

    void setup() {
    size(1920, 1080);
    for (int i=0; i<=6; i++) {
    xx=xx*2;
    yy=yy*2;
    }
    }

    void draw() {
    noStroke();
    ballSize= 60;
    fill(0, 10);
    rect(0,0, width, height);
    fill(255);
    ellipse(x[0],y[0], ballSize, ballSize);
    ellipse(x[1],y[1], ballSize, ballSize);
    ellipse(x[2],y[2], ballSize, ballSize);
    ellipse(x[3],y[3], ballSize, ballSize);
    ellipse(x[4],y[4], ballSize, ballSize);
    ellipse(x[5],y[5], ballSize, ballSize);
    ellipse(x[6],y[6], ballSize, ballSize);


    for(int i=0; i<=6; i++) {
    x+=(dx);
    y+=(dy);
    xx+=0.0001;
    yy+=0.0001;
    }
    for (int i=0; i<=6; i++) {
    if(x>=width-50) {
    dx=(-xx);
    }
    }
    for (int i=0; i<6; i++) {
    if (y>=height-50) {
    dy=(yy);
    }
    }
    }
     
    newbie73, Dec 9, 2019
    #1
    1. Advertisements

  2. newbie73

    rogerlacante

    Joined:
    Dec 9, 2019
    Messages:
    1
    Likes Received:
    0
    float [] x={0,100,460,0,300,70,800};
    float [] y={100,200,300,50,0,80,600};
    float [] dx={(3),(4),(6),(8),(10), (2), (5)};
    float [] dy={ (5), (5), (3), (5), (1), (6), (8)};
    float [] xx={3,4,6,8,10,2,5};
    float [] yy={5,5,3,5,1,6,8};
    float ballSize;

    void setup() {
    size(1920, 1080);
    for (int i=0; i<=6; i++) {
    xx=xy*6;
    yy=xy*6;
    }
    }

    void draw() {
    noStroke();
    ballSize= 60;
    fill(0, 10);
    rect(0,0, width, height);
    fill(255);
    ellipse(x[0],y[0], ballSize, ballSize);
    ellipse(x[1],y[1], ballSize, ballSize);
    ellipse(x[2],y[2], ballSize, ballSize);
    ellipse(x[3],y[3], ballSize, ballSize);
    ellipse(x[4],y[4], ballSize, ballSize);
    ellipse(x[5],y[5], ballSize, ballSize);
    ellipse(x[6],y[6], ballSize, ballSize);


    for(int i=0; i<=6; i++) {
    x+=(dx);
    y+=(dy);
    xx+=0.0001;
    yy+=0.0001;
    }
    for (int i=0; i<=6; i++) {
    if(x>=width-50) {
    dx=(-xx);
    }
    }
    for (int i=0; i<6; i++) {
    if (y>=height-50) {
    dy=(yy);
    }
    }



    The float of the variable x was in collision with the xy intercept.

    It should be fixed now. :)
    }
     
    rogerlacante, Dec 9, 2019
    #2
    1. Advertisements

  3. newbie73

    newbie73

    Joined:
    Dec 9, 2019
    Messages:
    6
    Likes Received:
    0
    It says the variable xy doesnt exist do I create a variable named xy
     
    newbie73, Dec 9, 2019
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.