hey guys im making a game where you drive up a road and dodge traffic like the same logic as Spy Hunter the arcade game, anyways i want to make the car actor make a crashing sound and end the game when it hits the vehicle class. So far the code I typed in doesn't do anything and the sound doesn't play, can anyone please help me? here's my code so far:
public void act()
{
backgroundMusic.playLoop();
backgroundMusic.setVolume(92);
if(Greenfoot.isKeyDown("right"))
{
moveRight();
}
if(Greenfoot.isKeyDown("left"))
{
moveLeft();
}
if (Greenfoot.isKeyDown("up"))
{
moveUp();
}
if (Greenfoot.isKeyDown("down"))
{
moveDown();
}
}
public void checkCollision()
{
Actor Car = getOneIntersectingObject(Vehicle.class);
if(Car != null)
{
Greenfoot.playSound("crash.wav");
Greenfoot.stop();
}
}
public void moveRight()
{
setLocation(getX()+3, getY());
}
public void moveLeft()
{
setLocation(getX()-3, getY());
}
public void moveUp()
{
setLocation(getX(), getY()-2);
}
public void moveDown()
{
setLocation(getX(), getY()+2);
}
}
