How can i move a circle that is going across to move diagonally once its reached a certain point??!!

Hi im in dire straights can anyone tell me how i could move a circle that is going across the screen to move diagonally upwards and then downwards once its reached a certain point in the screen this is for an assignment i have for college i really need help. heres the code i have so far its just a mish mash of code ive gotten from tutorials etc so forgive me if its messy and irrelevant. PLEASE HELP thank you

Tagged:

Answers

  • int moveY, moveX;

    void setup (){ moveY = 0; moveX = 0; size (600, 600);

    }

    void draw (){ background (252); fill (300,0,0); rect(200,15,150,550); fill (0,10,200); rect(350,15,150,550); fill (0,630,10); ellipse (moveX,300,50,50); moveY++; moveX++; if (moveY >=height) { moveY=0; if (moveX >= width) { moveX=0; if (moveX >200,

    }
    }
    

    }

  • so all im getting is the circle moving across...

  • edited March 2016
    int ballX, ballY;
    
    void setup () { 
      size (600, 600);
      ballX = 0;
      ballY = 300;
    }
    
    void draw () { 
      background(252);
      ball_simulate();
      ball_render();
    }
    
    void ball_simulate() {
      ballX++;
      ballX%=width;
      if (ballX>200 && ballX<=350) {
        ballY--;
      }
      if (ballX>350 && ballX < 500) {
        ballY++;
      }
    }
    
    void ball_render() {
      fill(300, 0, 0); 
      rect(200, 15, 150, 550); 
      fill(0, 10, 200); 
      rect(350, 15, 150, 550); 
      fill(0, 630, 10); 
      ellipse(ballX, ballY, 50, 50);
    }
    
Sign In or Register to comment.