Help with my class code
in
Programming Questions
•
1 year ago
Hey guys.
I need some help with this code. I get the error of "cannot find anything named startX". I've substituted in floats and int, but I don't know what to do anymore...
class Missile {
float endX; // End X position
float endY; // End Y position
float endvar; // Line gradient
float startX; // Start of missile line
float startY; // Weight of the missle
color c;
Missile(float init_endX, float init_endY,
float init_endvar, float init_startX, float init_startY,
color init_c)
{
endX = init_endX;
endY = init_endY;
endvar = init_endvar;
startX = init_startX;
startY = init_startY;
c = init_c;
}
void render() {
noStroke();
fill(c);
line(startX, startY, endX, endY);
}
void update() {
startX = (float)random(300, 500);
endY = 0;
endvar = (float)random(-2.0, 2.0);
endX = startX;
endY++;
endX = endX + endvar;
}
} // class Missile
Missile randomMissile() {
return new Missile(startX, 0, random(-2.0, 2.0), random (300, 500),
random(0),
color(random(0, 256),
random(0, 256),
random(0, 256))
);
}
ArrayList<Missile> missilelist; // list in null initially
void setup() {
size(700, 500);
// creates and initially empty ArrayList of missile objects
missilelist = new ArrayList<Missile>();
}
void draw() {
background(255);
// render and update all the balls
for(Missile b : missilelist) {
b.render();
b.update();
}
}
void mousePressed() {
missilelist.add(randomMissile());
}
I need some help with this code. I get the error of "cannot find anything named startX". I've substituted in floats and int, but I don't know what to do anymore...
class Missile {
float endX; // End X position
float endY; // End Y position
float endvar; // Line gradient
float startX; // Start of missile line
float startY; // Weight of the missle
color c;
Missile(float init_endX, float init_endY,
float init_endvar, float init_startX, float init_startY,
color init_c)
{
endX = init_endX;
endY = init_endY;
endvar = init_endvar;
startX = init_startX;
startY = init_startY;
c = init_c;
}
void render() {
noStroke();
fill(c);
line(startX, startY, endX, endY);
}
void update() {
startX = (float)random(300, 500);
endY = 0;
endvar = (float)random(-2.0, 2.0);
endX = startX;
endY++;
endX = endX + endvar;
}
} // class Missile
Missile randomMissile() {
return new Missile(startX, 0, random(-2.0, 2.0), random (300, 500),
random(0),
color(random(0, 256),
random(0, 256),
random(0, 256))
);
}
ArrayList<Missile> missilelist; // list in null initially
void setup() {
size(700, 500);
// creates and initially empty ArrayList of missile objects
missilelist = new ArrayList<Missile>();
}
void draw() {
background(255);
// render and update all the balls
for(Missile b : missilelist) {
b.render();
b.update();
}
}
void mousePressed() {
missilelist.add(randomMissile());
}
1