Skip to content

Commit

Permalink
new sounds
Browse files Browse the repository at this point in the history
  • Loading branch information
undermink committed Oct 7, 2012
1 parent 285d84c commit e6f7def
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 10 deletions.
2 changes: 1 addition & 1 deletion defend/src/com/cdm/defend/DefendGame.java
Expand Up @@ -43,7 +43,7 @@ public void create() {
demoScreen = new LevelScreen(demoGame, demoCampaign, true);

optionsScreen = new SoundScreen(this);
SoundScreen.playSong(1);
SoundScreen.playSong(0);
setScreen(menuScreen = new MenuScreen(this, demoScreen));
highscoreScreen = new HighScoreScreen(this);
inputScreen = new InputScreen(this, c);
Expand Down
11 changes: 8 additions & 3 deletions defend/src/com/cdm/gui/effects/SoundFX.java
Expand Up @@ -11,7 +11,7 @@
public class SoundFX {

public enum Type {
KLICK, SHOT, SHOT2, HIT, HIT2, HURT, STUNRAY, LOOSE, WIN
KLICK, SHOT, SHOT2, HIT, HIT2, HURT, STUNRAY, LOOSE, WIN, WIN2, LEVEL1, LEVEL2
};

private static Map<Type, Sound> sounds = new TreeMap<Type, Sound>();
Expand All @@ -31,11 +31,16 @@ public static void Initialize() {
Gdx.audio.newSound(Gdx.files.internal("data/punch.ogg")));
sounds.put(Type.STUNRAY,
Gdx.audio.newSound(Gdx.files.internal("data/stunray01.ogg")));

sounds.put(Type.LEVEL1,
Gdx.audio.newSound(Gdx.files.internal("data/level_completed.ogg")));
sounds.put(Type.LEVEL2,
Gdx.audio.newSound(Gdx.files.internal("data/next_level.ogg")));
sounds.put(Type.LOOSE,
Gdx.audio.newSound(Gdx.files.internal("data/loose.ogg")));
sounds.put(Type.WIN,
Gdx.audio.newSound(Gdx.files.internal("data/bonus.ogg")));
sounds.put(Type.WIN2,
Gdx.audio.newSound(Gdx.files.internal("data/win02.ogg")));

}

Expand All @@ -46,7 +51,7 @@ public static void dispose() {
sounds.clear();
}

public void play(Type type) {
public static void play(Type type) {
Sound s = sounds.get(type);
if (s != null)
s.play(SoundScreen.FXvol);
Expand Down
3 changes: 3 additions & 0 deletions defend/src/com/cdm/view/Campaign.java
Expand Up @@ -4,6 +4,8 @@
import java.util.List;

import com.cdm.Game;
import com.cdm.gui.effects.SoundFX;
import com.cdm.gui.effects.SoundFX.Type;
import com.cdm.view.elements.Grid;
import com.cdm.view.elements.Level;
import com.cdm.view.elements.PlayerState;
Expand All @@ -29,6 +31,7 @@ public Level getNextLevel(Game game, LevelScreen screen) {
level = new Level(game, new Grid(levels.get(plevel)), screen,
playerState);
levelNo += 1;
SoundFX.play(Type.LEVEL2);
if (levelNo >= 11)
levelNo = 0;
level.setLevelNo(levelNo);
Expand Down
6 changes: 5 additions & 1 deletion defend/src/com/cdm/view/LevelScreen.java
Expand Up @@ -10,6 +10,8 @@
import com.cdm.gui.IUnitTypeSelected;
import com.cdm.gui.UnitTypeButton;
import com.cdm.gui.WidgetContainer;
import com.cdm.gui.effects.SoundFX;
import com.cdm.gui.effects.SoundFX.Type;
import com.cdm.view.elements.Elements;
import com.cdm.view.elements.Level;
import com.cdm.view.elements.LevelFinishedListener;
Expand Down Expand Up @@ -315,10 +317,12 @@ public void buttonPressed(String buttonName) {
// FIXME move this function in a "Campaign" or game-control class, maybe
// "towergame"
public void restart() {
if (campaign.playerState.getPoints() >= 100) {
if (campaign.playerState.getPoints() >= 1000) {
SoundScreen.playSong(0);
game.setScreen(Screen.INPUT_SCREEN);
} else {
game.setScreen(Screen.HIGHSCORE_SCREEN);
SoundScreen.playSong(0);
campaign.restart(game);
setLevel(campaign.getNextLevel(game, this));
}
Expand Down
16 changes: 12 additions & 4 deletions defend/src/com/cdm/view/SoundScreen.java
Expand Up @@ -16,7 +16,7 @@ public class SoundScreen extends Screen implements IButtonPressed {
private WidgetContainer gui = new WidgetContainer();
private Renderer renderer = new Renderer();
private Game game;
private static Music music, music0, music1, music2;
private static Music music, music0, music1, music2, music3;
private static int song = 2;
private static boolean stop = false;
private Color white = new Color(1, 1, 1, 1);
Expand All @@ -29,7 +29,8 @@ public SoundScreen(Game pgame) {
music0 = Gdx.audio.newMusic(Gdx.files.internal("data/level01.ogg"));
music1 = Gdx.audio.newMusic(Gdx.files.internal("data/level02.ogg"));
music2 = Gdx.audio.newMusic(Gdx.files.internal("data/level03.ogg"));
music = music1;
music3 = Gdx.audio.newMusic(Gdx.files.internal("data/intro.ogg"));
music = music3;
music.setLooping(true);
game = pgame;
gui.add(new BigButton(Gdx.graphics.getWidth() / 3 + 50, 300,
Expand Down Expand Up @@ -96,7 +97,7 @@ else if (buttonName.equals("up")) {
stop=true;
if (music.isPlaying())
music.stop();
if (song <= 2) {
if (song <= 3) {
song += 1;
} else
song = 1;
Expand All @@ -106,6 +107,10 @@ else if (buttonName.equals("up")) {
music = music1;
if (song == 3)
music = music2;
if (song == 4)
music = music3;



} else if (buttonName.equals("FXup")) {
if (music != null) {
Expand Down Expand Up @@ -146,13 +151,16 @@ public static void playSong(int id) {
return;
if(music!=null)
music.stop();
song=(id%3)+1;
song=(id%3);
if (song == 1)
music = music0;
if (song == 2)
music = music1;
if (song == 3)
music = music2;
if (song == 4)
music = music3;

music.setVolume(vol);
music.setLooping(true);
music.play();
Expand Down
6 changes: 5 additions & 1 deletion defend/src/com/cdm/view/enemy/EnemyPlayer.java
Expand Up @@ -5,6 +5,8 @@
import java.util.SortedSet;
import java.util.TreeSet;

import com.cdm.gui.effects.SoundFX;
import com.cdm.gui.effects.SoundFX.Type;
import com.cdm.view.Position;
import com.cdm.view.elements.EnemyUnits;
import com.cdm.view.elements.Level;
Expand Down Expand Up @@ -87,8 +89,10 @@ public void addTime(float t) {

private void startWait() {
waveNo += 1;
if (waveNo >= maxLevel)
if (waveNo >= maxLevel) {
SoundFX.play(Type.LEVEL2);
levelFinishedListener.levelFinished();
}
mode = Mode.WAIT;
timeToNextWave = WAITING_TIME;
}
Expand Down

0 comments on commit e6f7def

Please sign in to comment.