Android Open Source - Terry-Coin Content






From Project

Back to project page Terry-Coin.

License

The source code is released under:

Apache License

If you think the Android project Terry-Coin listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.tcg.terry.managers;
//  ww  w  .  j a  v  a  2  s  .  c om
import java.util.HashMap;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.files.FileHandle;

public class Content {

  private HashMap<String, Music> music;
  private HashMap<String, Sound> sounds;
  
  public Content() {
    music = new HashMap<String, Music>();
    sounds = new HashMap<String, Sound>();
  }
  
  /*********/
  /* Music */
  /*********/
  
  public void loadMusic(String path) {
    int slashIndex = path.lastIndexOf('/');
    String key;
    if(slashIndex == -1) {
      key = path.substring(0, path.lastIndexOf('.'));
    }
    else {
      key = path.substring(slashIndex + 1, path.lastIndexOf('.'));
    }
    loadMusic(path, key);
  }
  public void loadMusic(String path, String key) {
    Music m = Gdx.audio.newMusic(Gdx.files.internal(path));
    music.put(key, m);
  }
  public void loadMusic(FileHandle path, String key) {
    Music m = Gdx.audio.newMusic(path);
    music.put(key, m);
  }
  public Music getMusic(String key) {
    return music.get(key);
  }
  public void removeMusic(String key) {
    Music m = music.get(key);
    if(m != null) {
      music.remove(key);
      m.dispose();
    }
  }
  
  /*******/
  /* SFX */
  /*******/
  
  public void loadSound(String path) {
    int slashIndex = path.lastIndexOf('/');
    String key;
    if(slashIndex == -1) {
      key = path.substring(0, path.lastIndexOf('.'));
    }
    else {
      key = path.substring(slashIndex + 1, path.lastIndexOf('.'));
    }
    loadSound(path, key);
  }
  public void loadSound(String path, String key) {
    Sound sound = Gdx.audio.newSound(Gdx.files.internal(path));
    sounds.put(key, sound);
  }
  public Sound getSound(String key) {
    return sounds.get(key);
  }
  public void removeSound(String key) {
    Sound sound = sounds.get(key);
    if(sound != null) {
      sounds.remove(key);
      sound.dispose();
    }
  }
  
  /*********/
  /* other */
  /*********/
  
  public void removeAll() {
    for(Object o : music.values()) {
      Music music = (Music) o;
      music.dispose();
    }
    music.clear();
    for(Object o : sounds.values()) {
      Sound sound = (Sound) o;
      sound.dispose();
    }
    sounds.clear();
  }
  
  public void stopAllSound() {
    for(Object o : music.values()) {
      Music music = (Music) o;
      music.stop();
    }
    for(Object o : sounds.values()) {
      Sound sound = (Sound) o;
      sound.stop();
    }
  }
  
}




Java Source Code List

com.tcg.terry.MainActivity.java
com.tcg.terry.Main.java
com.tcg.terry.entities.Button.java
com.tcg.terry.entities.Cloud.java
com.tcg.terry.entities.Coin.java
com.tcg.terry.entities.Cursor.java
com.tcg.terry.entities.Flower.java
com.tcg.terry.entities.Ground.java
com.tcg.terry.entities.JumpButton.java
com.tcg.terry.entities.MenuButton.java
com.tcg.terry.entities.Player.java
com.tcg.terry.entities.SprintButton.java
com.tcg.terry.gamestates.ControlsState.java
com.tcg.terry.gamestates.GameOverState.java
com.tcg.terry.gamestates.GameState.java
com.tcg.terry.gamestates.MenuState.java
com.tcg.terry.gamestates.PlayState.java
com.tcg.terry.gamestates.SplashState.java
com.tcg.terry.main.Game.java
com.tcg.terry.managers.Content.java
com.tcg.terry.managers.GameStateManager.java
com.tcg.terry.managers.Timer.java