diff --git a/animation/ArcadeDemo.java b/animation/ArcadeDemo.java index c6203aa..2a1f2c9 100644 --- a/animation/ArcadeDemo.java +++ b/animation/ArcadeDemo.java @@ -120,6 +120,7 @@ protected Graphics renderFrame(Graphics g) { started = true; currentRoom++; + startMusic(); } } else { @@ -134,6 +135,8 @@ protected Graphics renderFrame(Graphics g) { waitMode = true; waitBeforeNextRoomTimer = 200; + stopMusic(); + victorySound.play(); } if(waitMode) { @@ -150,6 +153,7 @@ protected Graphics renderFrame(Graphics g) { currentRoom++; roomTime=0; + startMusic(); } else { @@ -294,13 +298,43 @@ public void initGraphics() * 3. Add a line into the initMusic() function to load the clip. * 4. Use the play(), stop() and loop() functions as needed in your code. //-----------------------------------------------------------------------*/ - AudioClip themeMusic; - AudioClip bellSound; + AudioClip song1; + AudioClip song2; + AudioClip victorySound; - public void initMusic() + + public void initMusic() { + song1 = loadClip("src/sounds/song1.wav"); + song2 = loadClip("src/sounds/song2.wav"); + victorySound = loadClip("src/sounds/victory.wav"); } - + + + // Begin playing the song for the current room + public void startMusic() + { + int songNo = rooms.get(currentRoom).getSong(); + if (songNo == 1) + song1.loop(); + else if (songNo == 2) + song2.loop(); + else + song1.loop(); + } + + + // Stop playing the current song + public void stopMusic() + { + int songNo = rooms.get(currentRoom).getSong(); + if (songNo == 1) + song1.stop(); + else if (songNo == 2) + song2.stop(); + else + song1.stop(); + } + //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ }//--end of ArcadeDemo class-- - diff --git a/gameObjects/Room.java b/gameObjects/Room.java index e4854a0..0374f85 100644 --- a/gameObjects/Room.java +++ b/gameObjects/Room.java @@ -92,6 +92,12 @@ public String getHint() { return "Click on the door"; } + + // Override this method to change which song plays in the room + public int getSong() + { + return 1; + } public void draw(Graphics g, ImageObserver io) { @@ -108,4 +114,4 @@ public Item getItemByName(String s) } return null; } -} +} \ No newline at end of file diff --git a/sounds/song1.wav b/sounds/song1.wav new file mode 100644 index 0000000..7449edf Binary files /dev/null and b/sounds/song1.wav differ diff --git a/sounds/song2.wav b/sounds/song2.wav new file mode 100644 index 0000000..fde47ff Binary files /dev/null and b/sounds/song2.wav differ diff --git a/sounds/victory.wav b/sounds/victory.wav new file mode 100644 index 0000000..e0c120f Binary files /dev/null and b/sounds/victory.wav differ