I'm looking for help on how to compare variables which are random and changing inside arrays in two different classes. Not sure if I'm making sense with that so please see below:
I'd like it so that if the xLoc variables below on both the Deer and Car classes are the same, that the Deer's array subtracts by 1. I created a void called "crash", directly following the "void draw", which is hidden out below as an example of what I was trying, but I keep geeting the error " Cannot make a static reference to the non-static field Deer.xLoc". Which makes sense as these floats are constantly changing.
In otherwords if the Deer hits the Car a deer is deleted. - I'm just starting out so not sure how to make this work and any help is appreciated. - Cheers!!
void setup() {
size(800,800);
for (int loop = 0; loop < newDeer.length; loop++){
newDeer [loop] = new Deer(random(0,800),0,20,20,random(1,6));
}
for (int loop = 0; loop < newCar.length; loop++){
newCar [loop] = new Car(0,random(0,800),20,20,random(1,25));
}
}
/* ERROR AND MESSAGE
void crash(){
if (Deer.xLoc == Car.xLoc) {
numberOfDeer = numberofDeer - 1;
}
}
Cannot make a static reference to the non-static field Deer.xLoc
*/
int numberOfDeer = 3;
Deer newDeer[] = new Deer[numberOfDeer];