We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Type "Ball" was not found
Page Index Toggle Pages: 1
Type "Ball" was not found (Read 334 times)
Type "Ball" was not found
Jan 22nd, 2008, 12:01am
 
What i've missed?

__________________________________________
Ball pilota;


void setup() {
 
 //definim tamany de finestra i color de fons
 size(400, 400);
 background(0);
 smooth();
 strokeWeight(1);
 stroke(255);
 frameRate(30);

 //especificar la situació inicial
 pilota = new Ball(30, 200, 1, 0, 10, 10);

}

void draw(){
 background(0);
 
 pilota.display();

//costat dret
//  if (x>=width-w/2){  
   pilota.bouncing(0);
 }

//costat esquerre
 if (x<=w/2){
   pilota.bouncing(PI);
 }

//sostre
 if (y<=h/2){
   pilota.bouncing(PI+HALF_PI);
 }

//terra
 if (y>=height-h/2){
   pilota.bouncing(HALF_PI);
 }
 
//movem la posició de x i y
 pilota.update;

}


class Ball {
 float x, y; // The x- and y-coordinates
 float vx, vy; // The x- and y-velocities
 float w; // width
 float h; //height
 float gravity = 0.0;
 float losses = -0.3;
 float resultant;
 float alfa;

 Ball(int xpos, int ypos, float velx, float vely, float wball, float hball) {
   x = xpos;
   y = ypos;
   vx = velx;
   vy = vely;
   w = wball;
   h = hball;
 }

 void update() {
   vy = vy + gravity;
   y += vy;
   x += vx;
 }

 void display() {
   ellipse(x, y, w, h);
 }


//rebot, introduing l'angle de la paret

 void bouncing(float tita){    
   resultant = sqrt(sq(vx) + sq(vy));
   alfa = asin(vy/vx);
   vx = resultant*cos(radians(HALF_PI-tita+alfa));
   vy = resultant*sin(radians(HALF_PI-tita+alfa));
 }
 
 void display(){
   ellipse(x, y, w, h);
 }
}

____________________________________________________
Re: Type "Ball" was not found
Reply #1 - Jan 22nd, 2008, 1:10am
 
You had an extra closing brace in your code (in the draw loop, the opening brace in an if statement is commented out), which was causing the class not found error.

You will probably want to move all the bounds-checking into your class definition, and let the ball handle it's own collisions (that way you can have a bunch of balls bouncing around and not get tangled up with boundary checking in the draw loop).

Happy coding.

PROBLEM AREA:
//costat dret
//  if (x>=width-w/2){  
   pilota.bouncing(0);
 }


UPDATED CODE:

Ball pilota;

void setup() {
 
 //definim tamany de finestra i color de fons
 size(400, 400);
 background(0);
 smooth();
 strokeWeight(1);
 stroke(255);
 frameRate(30);

 //especificar la situació inicial
 pilota = new Ball(30, 200, 1, 0, 10, 10);

}

void draw(){
 background(0);
 
 pilota.display();  
//movem la posició de x i y
 pilota.update();

}


class Ball {
 float x, y; // The x- and y-coordinates
 float vx, vy; // The x- and y-velocities
 float w; // width
 float h; //height
 float gravity = 0.5;
 float losses = -0.3;
 float resultant;
 float alfa;

 Ball(int xpos, int ypos, float velx, float vely, float wball, float hball) {
   x = xpos;
   y = ypos;
   vx = velx;
   vy = vely;
   w = wball;
   h = hball;
 }

 void update() {
   vy = vy + gravity;
   y += vy;
   x += vx;
   checkBounds();
 }
 
 void checkBounds(){
 //costat dret
 if (x>=width-w/2){  
   vx *= -1;
 }

//costat esquerre
 if (x<=w/2){
   vx *= -1;
 }

//sostre
 if (y<=h/2){
   vy *= -1;
 }

//terra
 if (y>=height-h/2){
   vy *= -1;
 }
 }

 void display() {
   ellipse(x, y, w, h);
 }  
}
Re: Type "Ball" was not found
Reply #2 - Jan 22nd, 2008, 9:52am
 
Thanks wicks!

what i've done to bounce is a little bit more complicated than *-1 in speeds because I'd like to bounce between balls too, so vx and vy will depend on the collision angle. Is there any faster way to code that?

Thanks!
Page Index Toggle Pages: 1