Permalink
Browse files

Add mute button (which currently does nothing)

  • Loading branch information...
aardvarrk committed Jan 24, 2013
1 parent 0f2f759 commit 7ffbe83a01f735f30899550f294c957b8fa3d67d
Showing with 532 additions and 474 deletions.
  1. +5 −2 FloodWorld.java
  2. +40 −0 MuteButton.java
  3. +487 −472 project.greenfoot
View
@@ -6,14 +6,15 @@
private Player player;
private Coins coinCounter;
private Overlay overlay;
+ private MuteButton muteButton;
GreenfootSound backgroundMusic = new GreenfootSound("zeerstoer.mp3");
public FloodWorld(Player.PlayerType playerType) {
super(80, 80, 10);
backgroundMusic.playLoop();
- setPaintOrder(Overlay.class, Counter.class, Coins.class, MenuBar.class, Player.class, Bag.class, Coin.class, Water.class, Floodbank.class);
+ setPaintOrder(MuteButton.class, Overlay.class, Counter.class, Coins.class, MenuBar.class, Player.class, Bag.class, Coin.class, Water.class, Floodbank.class);
for(int i=0; i<=80; i++) {
for(int j=0; j<=30; j++) {
@@ -45,6 +46,8 @@ public FloodWorld(Player.PlayerType playerType) {
coinCounter = new Coins("Coins: ");
addObject(coinCounter, 6, 76);
+
+ addObject(muteButton = new MuteButton(), 30, 30);
}
public void act(){
@@ -73,7 +76,7 @@ public void setOverlayLocation(int x, int y) {
}
overlay.setLocation(x, y);
}
-
+
public void gameOver() {
Greenfoot.setWorld(new GameOverWorld(Game.SANDBAG_GAME, scoreCounter.getValue()));
}
View
@@ -0,0 +1,40 @@
+import greenfoot.*;
+
+public class MuteButton extends Actor {
+ private static GreenfootImage mutedImage;
+ private static GreenfootImage unmutedImage;
+
+ private boolean muted;
+
+ public MuteButton() {
+ mute();
+ }
+
+ @Override
+ public void act() {
+ if (Greenfoot.mouseClicked(this)) toggleMute();
+ }
+
+ public boolean isMuted() {
+ return muted;
+ }
+
+ private void toggleMute() {
+ if (muted) unmute(); else mute();
+ }
+
+ private void mute() {
+ if (mutedImage == null) mutedImage = new GreenfootImage("images/volumeknop_uit.png");
+
+ muted = true;
+ setImage(mutedImage);
+ }
+
+ private void unmute() {
+ if (unmutedImage == null) unmutedImage = new GreenfootImage("images/volumeknop_aan.png");
+
+ muted = false;
+ setImage(unmutedImage);
+ }
+}
+
Oops, something went wrong.

0 comments on commit 7ffbe83

Please sign in to comment.