I don't understand why i am getting an error the parameter of a boolean. Because I am using variables with the same names for different classes I thought you would need to specify which objects the variables were for, and therefore distinguish them using the frog class.
final int DASH_LENGTH = 10;
final int LANE_HEIGHT = 30;
final int GAP = 3;
final int DIFFICULTY = (int)random(1,6); //keep between 1 and 5
final int N_CARS = 6 + DIFFICULTY;
final int CAR_HEIGHT = 24;
final int FROG_SIZE = 24;
int score = 0;
Car[] cars;
Frog frog;
void setup() {
size(600,480);
background(255);
frog = new Frog();
cars = new Car[6 + DIFFICULTY];
for (int i=0; i<cars.length; i++) {
int carLength = (int)random(40,101);
cars[i] = new Car(carLength, CAR_HEIGHT, 15 + i*30);
}
}
I keep getting this error on my array however i don't think it is out of bounds because i have specified its length. the error will give me a number but for my program they aren't out of bounds.
final int DASH_LENGTH = 10;
final int LANE_HEIGHT = 30;
final int GAP = 3;
final int DIFFICULTY = (int)random(1,6); //keep between 1 and 5
final int N_CARS = 6 + DIFFICULTY;
final int CAR_HEIGHT = 24;
final int FROG_SIZE = 24;
int score = 0;
Car[] cars;
Frog frog;
void setup() {
size(600,480);
background(255);
frog = new Frog();
cars = new Car[6 + DIFFICULTY];
for (int i=0; i<cars.length; i++) {
int carLength = (int)random(40,101);
cars[i] = new Car(carLength, CAR_HEIGHT, 15 + i*30);
}
}
void draw() {
background(255);
lanes();
for(int i = 0; i <= cars.length; i++) {
cars[i].displayTheCarMove(); /*THIS IS WHERE I GET THE ERROR. BUT ABOVE THERE IS A SIMILAR LINE OF CODE AND THAT WORKED FINE. */
}
frog.display();
}
void keyPressed() {
frog.move();
}
class Car {
float cWidth, cHeight;
float centerX, centerY;
float speed;
int shade;
Hey, Im currently doing a class exercise on classes and objects and so my program is very basic, however, i am getting the error message the constructor xx(string, int, float) is undefined.
Here is my code, please help me work out why there is an error.
I am having trouble getting a shape to change colour as it falls to the bottom of the screen. At the moment, using the code below my shape doesn't change colour until it is at the bottom of the screen, whereupon it changes and then changes back instantly. Could someone please tell me why my code does this? I need the shape to gradually change from yellow to red.