Getting a "Constructor is undefined" error in my Billiards game
in
Programming Questions
•
6 months ago
I'm working on a project for one of the classes at my university and I'm getting an error that the constructor for the Ball class is undefined. I thought the way I set it up was correct and I'm not exactly sure what I'm doing wrong with the constructor. Your advice on fixing it is appreciated. :)
///////Beginning of code////////
//Billiard
//by D. Witt
int ballPlaced = 0;
float centerX1, centerY1, centerX2, centerY2;
float rise, run;
boolean isLaunched;
Ball cueBall, targetBall;
float currentDist;
void setup()
{
size(800, 400);
background(0,100,0);
rise = 0;
run = 0;
cueBall = new Ball(centerX1, centerY1, color(255,255,255));
targetBall = new Ball(centerX2, centerY2, color(255,255,0));
isLaunched = false;
}
void draw()
{
background(0,100,0);
if (ballPlaced > 0)
{
cueBall.display();
}
if (ballPlaced > 1)
{
targetBall.display();
}
if (isLaunched)
{
currentDist = dist(centerX2, centerY2, centerX1, centerY1);
while(currentDist > 100){
cueBall.launch();
}
if(currentDist <= 100){
targetBall.launch();
}
}
}
void mouseClicked()
{
if (ballPlaced == 0)
{
centerX1 = mouseX;
centerY1 = mouseY;
ballPlaced += 1;
}
else if (ballPlaced == 1)
{
centerX2 = mouseX;
centerY2 = mouseY;
ballPlaced += 1;
}
else if ((ballPlaced == 2) && (isLaunched == false))
{
isLaunched = true;
rise = centerY2 - centerY1;
run = centerX2 - centerX1;
float distance = dist(centerX2, centerY2, centerX1, centerY1);
rise = rise / distance;
run = run / distance;
}
}
void keyPressed()
{
if (key == 'c')
{
ballPlaced = 0;
isLaunched = false;
}
}
class Ball{
float currentX;
float currentY;
color c;
Car(){
xpos = 10;
ypos = 10;
currentColor = color(255,255,255);
}
void display(){
ellipse(currentX, currentY, 50, 50);
}
void launch(){
centerX1 += run*2.0;
centerY1 += rise*2.0;
}
}
1