Boolean paramater has unexpected token error
in
Programming Questions
•
8 months ago
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);
}
}
void draw() {
background(255);
fill(0);
text("Score: " + score, 10, height - 10);
lanes();
for(int i = 0; i < cars.length; i++) {
cars[i].displayTheCarMove();
if(cars[i].checkFrogDead(frog))
frog.initialiseFrog();
}
frog.display();
}
void keyPressed() {
frog.move();
}
class Car {
float cWidth, cHeight;
float centerX, centerY;
float speed;
int shade;
Car(float cL, float cH, float lane) {
cWidth = cL;
cHeight = cH;
centerX = random(cWidth/2, width - cWidth/2);
for(int i = 0; i < cars.length; i++){
centerY = 15 + i*30;
}
speed = DIFFICULTY*random(0.5,3.0);
if (random(101)<50)
speed *= -1.0;
shade = (int)random(201);
}
void displayTheCarMove() {
display();
carMove();
}
void carMove() {
centerX += speed;
if((centerX <= cWidth/2) || (centerX >= width - cWidth / 2)) {
speed *= -1;
}
}
void display() {
rectMode(CENTER);
noStroke();
fill(shade);
rect(centerX, centerY, cWidth, cHeight);
}
boolean checkFrogDead(f){
if (centerY != f.centerY)
return false;
if (centerX < f.centerX) {
if (f.centerX - centerX <= 12.0 + cWidth/2) {
return true;
}
return false;
}
if (centerX > f.centerX) {
if(centerX - f.centerX <= 12.0 + cWidth/2) {
return true;
}
return false;
}
return false;
}
}
class Frog {
float centerX, centerY;
Frog() {
initialiseFrog();
}
void initialiseFrog () {
centerX = width*0.475;
centerY = height - 15;
}
void display() {
noStroke();
rectMode(CENTER);
fill(0,255,0);
rect(centerX, centerY,FROG_SIZE, FROG_SIZE);
}
void move() {
if(key == CODED) {
if(keyCode == UP) {
crossTheRoad();
}
if(keyCode == DOWN) {
centerY = constrain(centerY += 30, 0, height - 15);
}
if(keyCode == LEFT) {
centerX = constrain(centerX -= 30, 15 , width - 15);
}
if(keyCode == RIGHT) {
centerX = constrain(centerX += 30, 15 , width - 15);
}
}
}
void crossTheRoad() {
centerY -= 30;
if (centerY < 15) {
score += 1;
initialiseFrog();
}
}
}
void lanes() {
stroke(255,0,0);
for (int i = 0; i <= (6 + DIFFICULTY); i++) {
for (int j = 0; j < width; j += 20)
line(j,i*LANE_HEIGHT,j+10,i*LANE_HEIGHT);
}
}
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);
fill(0);
text("Score: " + score, 10, height - 10);
lanes();
for(int i = 0; i < cars.length; i++) {
cars[i].displayTheCarMove();
if(cars[i].checkFrogDead(frog))
frog.initialiseFrog();
}
frog.display();
}
void keyPressed() {
frog.move();
}
class Car {
float cWidth, cHeight;
float centerX, centerY;
float speed;
int shade;
Car(float cL, float cH, float lane) {
cWidth = cL;
cHeight = cH;
centerX = random(cWidth/2, width - cWidth/2);
for(int i = 0; i < cars.length; i++){
centerY = 15 + i*30;
}
speed = DIFFICULTY*random(0.5,3.0);
if (random(101)<50)
speed *= -1.0;
shade = (int)random(201);
}
void displayTheCarMove() {
display();
carMove();
}
void carMove() {
centerX += speed;
if((centerX <= cWidth/2) || (centerX >= width - cWidth / 2)) {
speed *= -1;
}
}
void display() {
rectMode(CENTER);
noStroke();
fill(shade);
rect(centerX, centerY, cWidth, cHeight);
}
boolean checkFrogDead(f){
if (centerY != f.centerY)
return false;
if (centerX < f.centerX) {
if (f.centerX - centerX <= 12.0 + cWidth/2) {
return true;
}
return false;
}
if (centerX > f.centerX) {
if(centerX - f.centerX <= 12.0 + cWidth/2) {
return true;
}
return false;
}
return false;
}
}
class Frog {
float centerX, centerY;
Frog() {
initialiseFrog();
}
void initialiseFrog () {
centerX = width*0.475;
centerY = height - 15;
}
void display() {
noStroke();
rectMode(CENTER);
fill(0,255,0);
rect(centerX, centerY,FROG_SIZE, FROG_SIZE);
}
void move() {
if(key == CODED) {
if(keyCode == UP) {
crossTheRoad();
}
if(keyCode == DOWN) {
centerY = constrain(centerY += 30, 0, height - 15);
}
if(keyCode == LEFT) {
centerX = constrain(centerX -= 30, 15 , width - 15);
}
if(keyCode == RIGHT) {
centerX = constrain(centerX += 30, 15 , width - 15);
}
}
}
void crossTheRoad() {
centerY -= 30;
if (centerY < 15) {
score += 1;
initialiseFrog();
}
}
}
void lanes() {
stroke(255,0,0);
for (int i = 0; i <= (6 + DIFFICULTY); i++) {
for (int j = 0; j < width; j += 20)
line(j,i*LANE_HEIGHT,j+10,i*LANE_HEIGHT);
}
}
1