Ball class mover

edited June 2016 in Questions about Code

Hey guys! I'm quite new to processing, so I was wondering if you could help me. I'm trying to make a project where everytime you click on the window a new ball is launched. I already managed to do that with just one ball, but the idea is to have a new ball everytime I click. How can I do that in order to get all the balls registered on the screen? I'll send you the code that I already have.

PVector location;
PVector velocity;
PVector acceleration;
PVector gravity;
PVector lance;
float friction ;
int depth;

void setup() {
  size(800, 800, P3D);
  depth = 800;
  smooth();
  background(0);
  camera(width/2.0, height/2.0, (height/2.0) / tan(PI*30.0 / 180.0), width/2.0, height/2.0, 0, 0, 1, 0);
  gravity = new PVector(0, 0.98, 0);
  location = new PVector(width/2, height/2, -3000);
  velocity = new PVector(0, 20, -20);
  lance = new PVector(0, 0, 0);
  friction = 1.0; //0.98;
}


void draw() { 
  noStroke();
  fill(0);
  rect(0, 0, width, height);

  if (mousePressed) {
  location = new PVector(mouseX, mouseY, 200);
  lance = new PVector (0, -20, -9);
  velocity = new PVector(0, 0, 0);
}

  velocity.add(lance);
  lance = new PVector(0, 0, 0);

  if ((location.z < 30)) {
  friction = 0.76;
  gravity = new PVector(0, 0, 0);
  } else {
  friction = 1.0;
  gravity = new PVector(0, 0.98, 0);
  }
  velocity.add(gravity);
  velocity.mult(friction);
  location.add(velocity);

  println(location.z);

  noStroke();
  fill(255);
  lights();
  translate(location.x, location.y, location.z);
  sphere(35);
}

The idea is to have something like this:

postal-_3-01-2

Thanks in advanced

Sign In or Register to comment.