Java tutorial
/* Copyright [2014] [James Thomas Hayes] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package com.codefiddler.libgdx.spinit.assets; import java.util.ArrayList; import java.util.List; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.audio.Sound; public class SoundEffects { private int state = 0; private Sound d; private Sound cS; private Sound c; private Sound buzzer; private Sound intro; private Sound winner; private List<Sound> effects; private Sound endWinnerSound; public SoundEffects() { c = Gdx.audio.newSound(Gdx.files.internal("data/sounds/c.mp3")); cS = Gdx.audio.newSound(Gdx.files.internal("data/sounds/cS.mp3")); d = Gdx.audio.newSound(Gdx.files.internal("data/sounds/d.mp3")); buzzer = Gdx.audio.newSound(Gdx.files.internal("data/sounds/buzzer.mp3")); intro = Gdx.audio.newSound(Gdx.files.internal("data/sounds/intro.mp3")); winner = Gdx.audio.newSound(Gdx.files.internal("data/sounds/winner.mp3")); endWinnerSound = Gdx.audio.newSound(Gdx.files.internal("data/sounds/endWinner.mp3")); effects = new ArrayList<Sound>(); for (int i = 1; i <= 16; i++) { effects.add(Gdx.audio.newSound(Gdx.files.internal("data/sounds/effects/" + i + ".mp3"))); } } public void play() { switch (state) { case 0: c.play(3f); break; case 1: cS.play(3f); break; case 2: d.play(3f); break; case 3: cS.play(3f); break; default: break; } state = (state + 1) % 4; } public void dispose() { d.dispose(); cS.dispose(); d.dispose(); buzzer.dispose(); for (Sound sound : effects) { sound.dispose(); } } public Sound getWinnerSound() { return winner; } public Sound getSound(int index) { int effectsIndex = index % effects.size(); return effects.get(effectsIndex); } public Sound getOpps(int i) { return buzzer; } public void playIntro() { intro.play(); } public Sound getEndWinnerSound() { return endWinnerSound; } }