Cannot find Class
in
Programming Questions
•
2 years ago
It says it cannot find my class- its there so I don't know what to do. And also, I removed that problem to see if the rest would run and it also said it HorizontalCar was undefined.
Please help! and thanks in advance
Timer_Car timer_Car;
HorizontalCar[] horizontalCar;
VerticalCar[] verticalCar;
int totalHorizontalCar = 0;
int totalVerticalCar = 0;
void setup() {
size(600, 600);
smooth();
//horizontalCar = new HoriztonalCar[200];
//verticalCar = new VerticalCar[100];
timer_Car = new Timer_Car(200);
timer_Car.start();
for(int i = 0; i < horizontalCar.length; i ++){
horizontalCar[i] = new HorizontalCar(color(random(255), random(255), random(255)), 0, i*2, i/20);
}
for(int j = 0; j < verticalCar.length; j ++){
verticalCar[j] = new verticalCar(color(random(255), random(255), random(255)),j*2, 0, j/20);
}
}
void draw() {
background(255);
if(timer_Car.isFinished()){
horizontalCar[totalHorizontalCar] = new HorizontalCar();
totalHorizontalCar ++;
verticalCar[totalVerticalCar] = new VerticalCar();
totalVerticalCar ++;
if(totalHorizontalCar >= horizontalCar.length){
totalHorizontalCar = 0;
}
if(totalVerticalCar >= verticalCar.length){
totalVerticalCar = 0;
}
timer_Car.start();
}
for (int i = 0; i < horizontalcar.length; i ++ ) {
horizontalcar[i].move();
horizontalcar[i].display();
}
for (int j = 0; j < verticalcar.length; j ++ ) {
verticalcar[j].move();
verticalcar[j].display();
}
}
class HorizontalCar {
color c;
float xpos;
float ypos;
float xspeed;
HorizontalCar(color c_, float xpos_, float ypos_, float xspeed_) {
c = c_;
xpos = xpos_;
ypos = ypos_;
xspeed = xspeed_;
}
void display() {
rectMode(CENTER);
stroke(0);
fill(c);
rect(xpos,ypos,20,10);
}
void move() {
xpos = xpos + xspeed;
if (xpos > width) {
xpos = 0;
}
}
}
class VerticalCar {
color c;
float xpos;
float ypos;
float yspeed;
VerticalCar(color c_, float xpos_, float ypos_, float yspeed_) {
c = c_;
xpos = xpos_;
ypos = ypos_;
yspeed = yspeed_;
}
void display() {
rectMode(CENTER);
stroke(0);
fill(c);
rect(xpos,ypos,20,10);
}
void move() {
ypos = ypos + yspeed*-1;
if (ypos > height) {
ypos = 0;
}
}
}
class Timer_Car {
int savedTime; // When Timer started
int totalTime; // How long Timer should last
Timer_Car(int tempTotalTime) {
totalTime = tempTotalTime;
}
// Starting the timer
void start() {
// When the timer starts it stores the current time in milliseconds.
savedTime = millis();
}
// The function isFinished() returns true if "totalTime" has passed.
// The work of the timer is farmed out to this method.
boolean isFinished() {
// Check how much time has passed
int passedTime = millis()- savedTime;
if (passedTime > totalTime) {
return true;
} else {
return false;
}
}
void restart(){
for (int i = 0; i < totalHorizontalCar; i++ ) {
}
for (int i = 0; i < totalVerticalCar; i++ ) {
}
}
}
1
