Bubble popping animation

This is a test we did yesterday without any switch states…
its to sets out gravity and also a way to “switch state” with if.
When I click the mouse I change the size of the “ball” to zero with a variable and create a new “ball” with the size of 1 in the same spot. Also I stop the movement with “gravity” and the small new “ball” falls to the ground.

I tried adding “switch” to this code right now with no success :frowning:
Could you modify my code to work with switch?

Also… In this code… We tried really hard to re-spawn a new “ball” when the dead dropping ball exits the screen… Couldn’t make that happen either.

//Gravity test by Teljemo and son...
//Click anywhere to pop the ball and see the reaminting matter fall to the ground.
//To do: 
//Respawn ball when matter exits window.
//Change to states.


float gravity;      //Gravity variable
float x;            //Startpoint for ball in X
float upspeed;      //The speed of the ball rising.
float riseStart;    //Start point of the ball and position of ball (follows the ball)
boolean click = false;      //For mousepress (tried this way instead of a void mousePressed)
float bsize1;      //original size of ball
float bsize2;      //Size of dropping small ball

void setup() {
  size(640, 360);
  x = width/2;    //Ball rise from middle of window
  riseStart = height+bsize2;      //Ball starts from its own size below window
  bsize1 = 20;
  bsize2 = 1;
  upspeed = 5;
  gravity = 0.5;
}

void draw() {


  background(0);
  noFill();
  stroke(255);
  ellipse(x, riseStart, bsize1, bsize1);  //Ball with size1 as 20


  println("rS", riseStart);

  riseStart = riseStart - upspeed;
  if (mousePressed) {
    click = true;
  }

  if (click) {
    upspeed = upspeed - gravity;
    ellipse(x, riseStart, bsize2, bsize2); // new small ball created
    bsize1 = 0;    //The original ball size changet to 0 = invisible. Still follows "riseStart"
  }

//Tried to reset riseStart when the small ball exits the window to spawn a new ball.
  if (riseStart > height+bsize2) {
    riseStart = height+bsize2;
  }
}//draw
1 Like