Hello guys. I am currently working on sounds on my car. I want it to play a sound when it's idle. And another when it's driving. And another when it's in reverse. And finally a sound for "turbomode". but it does not work everytime i drive, reverse & ect. here is my code:
import greenfoot.*;
//*
public class Køremand extends SmoothMover
{
int speed = 0;
int drive1 =2;
int turbo1 =5;
int reverse1 =-1;
int idle1 =0;
private KøremandPoint køremandPoint;
GreenfootSound drive = new GreenfootSound("drive.wav");
GreenfootSound turbo = new GreenfootSound("turbo.wav");
GreenfootSound idle = new GreenfootSound("idle.wav");
GreenfootSound reverse = new GreenfootSound("reverse.wav");
GreenfootSound hit = new GreenfootSound("Hit.wav");
public Køremand(KøremandPoint køremandpoint)
{
køremandPoint = køremandpoint;
}
public void act()
{
moving();
checkCollision();
}
private void moving()
{
int change = 0;
if (Greenfoot.isKeyDown("6")) change++;
if (Greenfoot.isKeyDown("4")) change--;
turn(change); //turn(amount) is basically setRotation(getRotation()+amount)
int change1=0;
if (Greenfoot.isKeyDown("8")) change1 = drive1;
if (Greenfoot.isKeyDown("5")) change1 = reverse1;
if (Greenfoot.isKeyDown("backspace")) change1 = turbo1;
move(change1);
if (change1 != speed)
{
if (speed == idle1 && idle.isPlaying()) idle.stop();
if (speed == drive1 && drive.isPlaying()) drive.stop();
if (speed == turbo1 && turbo.isPlaying()) turbo.stop();
if (speed == reverse1 && reverse.isPlaying()) reverse.stop();
speed = change1;
if (speed == idle1) idle.playLoop();
if (speed == drive1) drive.playLoop();
if (speed == turbo1) turbo.playLoop();
if (speed == reverse1) reverse.playLoop();
}
}
private void checkCollision()
{
Actor zombie = getOneIntersectingObject(Zombie.class);
if (zombie != null)
{
getWorld().removeObject(zombie);
getWorld().addObject (new Splat(), getX(), getY());
hit.play();
køremandPoint.setValue(køremandPoint.getValue() + 1);
}
}
}

