Hello guys. In my game i have a car that is supposed to make different sounds. the sounds i want is the following:
When the car is idle
When the car is driving
When the car is doing turbo
When the car is reversing
Here's my code for my car so far
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Skydemand here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class nyKøremand extends SmoothMover
{
int change = 0;
int change1 =0;
int kør =2;
int speed =5;
GreenfootSound driving = new GreenfootSound("drive.wav");
GreenfootSound turbo = new GreenfootSound("turbo.wav");
GreenfootSound idle = new GreenfootSound("idle.wav");
GreenfootSound reverse = new GreenfootSound("reverse.wav");
String key = Greenfoot.getKey(); // saves the key returned
/**
* Act - do whatever the Skydemand wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
if (Greenfoot.isKeyDown("6")) change++ ;
if (Greenfoot.isKeyDown("4")) change-- ;
setRotation(change);
change1=0;
if (Greenfoot.isKeyDown("8")) change1=change1+kør ;
if (Greenfoot.isKeyDown("5")) change1-- ;
if(Greenfoot.isKeyDown("backspace")) change1=change1+speed ;
move(change1);
if (change1 ==0) idle.playLoop();
else idle.stop();
if (change1 ==1) driving.playLoop();
else driving.stop();
if (change1 ==-1) reverse.playLoop();
else reverse.stop();
if (change1 ==5) turbo.playLoop();
else turbo.stop();
}
}
