Hey guys,
How do you play Arrays?
Here is the code:
I'm probably missing something that will make me feel stupid.
-GhostTheToast
public class Key extends Actor
{
private boolean isDown;
private String key;
private String sound;
private String upImage;
private String downImage;
private String [] lower =
{"2c", "2d", "2e", "2f", "2g", "2a", "2b", "3c", "3d", "3e", "3g"};
/**
* Create a new key linked to a given keyboard key, and
* with a given sound.
*/
public Key(String keyName, String soundFile, String img1, String img2)
{
sound = soundFile;
key = keyName;
upImage = img1;
downImage = img2;
setImage(upImage);
isDown = false;
}
/**
* Do the action for this key.
*/
public void act()
{
if (!isDown && Greenfoot.isKeyDown(key)) {
play();
setImage(downImage);
isDown = true;
}
if (isDown && !Greenfoot.isKeyDown(key)) {
setImage(upImage);
isDown = false;
}
if (Greenfoot.isKeyDown("SPACE") && Greenfoot.isKeyDown(key)) {
Greenfoot.playSound (lower+".wav");
}
}
/**
* Play the note of this key.
*/
public void play()
{
if (Greenfoot.isKeyDown("SPACE") && Greenfoot.isKeyDown(key)) {
Greenfoot.playSound (lower+".wav");
}
Greenfoot.playSound(sound);
}
}


