Greenfoot play sound if an object of class type is getting closer with a distance to another class object

240 Views Asked by At

I am working on a simple car game on greenfoot and I wanna add an alert sound if my car is getting closer to a truck

This was my trial in the truck class's act method but it keeps on showing an exception:

if(!getObjectsInRange(60, Car1.class).isEmpty()) 
{
   Greenfoot.playSound("alert.wav");
}

please advise. Thank you.

0

There are 0 best solutions below