Hello--I'm totally lost!
I am trying to add fields for the key and sound file, as well as a constructor with two parameters that initializes those fields. When I try to add a new key or add a new object, the program asks me for a ";" sign, which is already there, or doesn't allow me to shift click the object into the world. I don't know where to place my add object or new key to my code to make this work. This is what I have so far:
public class Key extends Actor
{
private boolean isDown;
private String key;
private String sound;
/**
* Create a new key linked to a given keyboard key, and
* with a given sound.
*/
public Key(String keyName, String soundFile)
{
key = keyName;
sound = soundFile;
new Key ("a", "2a.wav");
}
/**
* Do the action for this key.
*/
public void act()
{
if ( !isDown && Greenfoot.isKeyDown("a") ) {
play();
setImage ("white-key-down.png");
isDown=true;
}
if ( isDown && !Greenfoot.isKeyDown("a") ) {
setImage ("white-key.png");
isDown=false;
}
}
/**
* Play the note of this key.
*/
public void play ()
{
Greenfoot.playSound("2a.wav");
}
}