Advertisement
Guest User

Judaiism

a guest
Jan 19th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot)
  2.  
  3. public class Key extends Actor
  4. {
  5. /**
  6. * Create a new key.
  7. */
  8. private boolean isDown;
  9. private String key;
  10. private String sound;
  11.  
  12. public Key(String keyName, String soundFile)
  13. {
  14. key = keyName;
  15. sound = soundFile;
  16. }
  17.  
  18. /**
  19. * Do the action for this key.
  20. */
  21.  
  22. public void act()
  23. {
  24. if ( !isDown && Greenfoot.isKeyDown(key) ) {
  25. setImage ("white-key-down.png");
  26. isDown = true;
  27. play();
  28. }
  29. if ( isDown && !Greenfoot.isKeyDown(key) ) {
  30. setImage ("white-key.png");
  31. isDown = false;
  32. }
  33. }
  34.  
  35. public void play()
  36. {
  37. Greenfoot.playSound(sound);
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement