Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot)
- public class Key extends Actor
- {
- /**
- * Create a new key.
- */
- private boolean isDown;
- private String key;
- private String sound;
- public Key(String keyName, String soundFile)
- {
- key = keyName;
- sound = soundFile;
- }
- /**
- * Do the action for this key.
- */
- public void act()
- {
- if ( !isDown && Greenfoot.isKeyDown(key) ) {
- setImage ("white-key-down.png");
- isDown = true;
- play();
- }
- if ( isDown && !Greenfoot.isKeyDown(key) ) {
- setImage ("white-key.png");
- isDown = false;
- }
- }
- public void play()
- {
- Greenfoot.playSound(sound);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement