public void playMusic() {
   music.setVolume(1);
   music.setLooping(true);
   if (music != null && !music.isPlaying()) {
     music.play();
   }
 }
Exemple #2
0
  @Override
  public void present(float deltaTime) {
    GLCommon gl = Gdx.gl;
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    camera.update();

    worldRender.render(deltaTime);
    if (isTreasure) {
      batcher.begin();
      renderTreasure(treasureType);
      if (isTreasureSound) {
        Assets.playSound(Assets.treasureSound, game.soundState);
        isTreasureSound = false;
      }
      batcher.end();
    } else if (isFinal) {
      batcher.begin();
      renderFinal();
      batcher.end();
    } else {
      if (isPause && !isDialog) {
        batcher.begin();
        renderGamePause();
        batcher.end();
      }
    }
    if ((isPause || !game.soundState) && bgMusic.isPlaying()) {
      bgMusic.pause();
    } else if (!isPause && !bgMusic.isPlaying() && game.soundState) {
      Assets.playMusic(bgMusic, game.soundState);
    }
  }
 // Metodo que devuelve una textura de un Arraylist cada X tiempo (intervalTime).
 private Texture SwapTextureFromArray(
     ArrayList<Texture> list, int startIndex, long startTime, float intervalTime) {
   Texture img = null;
   if (startIndex < list.size()) {
     Music sound = soundsList.get(startIndex);
     if (TimeUtils.timeSinceMillis(startTime) < intervalTime * 1000) {
       img = list.get(startIndex);
       if (startIndex < titlesList.size()) {
         imageTitle.ChangeFontText(titlesList.get(startIndex));
       }
       if (!soundPlayed) {
         System.out.println("Playing music");
         sound.play();
         soundPlayed = true;
       }
     } else {
       if (!sound.isPlaying()) {
         actualImgIndex++;
         beginTime = TimeUtils.millis();
         img = list.get(startIndex);
         imageTitle.ChangeFontText(titlesList.get(startIndex));
         System.out.println("Music finished");
         soundPlayed = false;
       }
     }
   } else {
     img = list.get(texturesList.size() - 1);
   }
   return img;
 }
 public void dispose() {
   m_BorderTexture.dispose();
   m_BackgroundMusic.stop();
   m_BackgroundMusic.dispose();
   m_RayHandler.dispose();
   m_PhysicsWorld.dispose();
 }
  private GameScreen() {
    this.superflu = SuperFlu.getInstance();
    stage = new Stage(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false);
    groupZones = new Group();
    groupVilles = new GroupVilles();
    groupTransferts = new Group();

    Texture backgroundTexture = superflu.manager.get("images/fond_carte.png", Texture.class);
    TextureRegion backgroundTextureRegion =
        new TextureRegion(backgroundTexture, VIRTUAL_WIDTH, VIRTUAL_HEIGHT);
    Image imgBackground = new Image(backgroundTextureRegion);
    imgBackground.touchable = false;
    stage.addActor(imgBackground);

    Texture carteTexture = superflu.manager.get("images/carte.png", Texture.class);
    TextureRegion carteTextureRegion =
        new TextureRegion(carteTexture, VIRTUAL_WIDTH, VIRTUAL_HEIGHT);
    Image carte = new Image(carteTextureRegion);
    carte.touchable = false;
    stage.addActor(carte);

    stage.addActor(groupZones);
    stage.addActor(groupVilles);
    stage.addActor(groupTransferts);

    stage.addActor(TransfertCreator.getInstance());

    Music softMusic = superflu.manager.get("music/soft.mp3", Music.class);
    softMusic.play();

    createEntities();
    Gdx.input.setInputProcessor(stage);

    stage.addActor(new GlobalStatsActor(gameLogic));
  }
Exemple #6
0
  private void randomizeMusic() {
    int random;
    // If its not the first time randomizing
    if (currentMusic != -1) {
      random = rand.nextInt(musicFileNames.length - 1);

      // To make sure the same music dosen't play twice
      if (currentMusic <= random) {
        random++;
      }
    } else {
      random = rand.nextInt(musicFileNames.length);
    }

    if (music != null) {
      music.stop();
      music.dispose();
    }

    currentMusic = random;
    music = Gdx.audio.newMusic(Gdx.files.internal("audio/" + musicFileNames[random]));
    music.play();
    music.setVolume(1);

    music.setOnCompletionListener(
        new OnCompletionListener() {
          @Override
          public void onCompletion(Music music) {
            randomizeMusic();
            music.dispose();
          }
        });
  }
Exemple #7
0
  /** Stops and disposes the current music being played, if any. */
  public void stop() {
    if (musicBeingPlayed != null) {

      musicBeingPlayed.stop();
      musicBeingPlayed.dispose();
    }
  }
Exemple #8
0
  @Override
  public void create() {
    // load the images for the droplet and the bucket, 48x48 pixels each
    dropImage = new Texture(Gdx.files.internal("data/droplet.png"));
    bucketImage = new Texture(Gdx.files.internal("data/bucket.png"));

    // load the drop sound effect and the rain background "music"
    dropSound = Gdx.audio.newSound(Gdx.files.internal("data/drop.wav"));
    rainMusic = Gdx.audio.newMusic(Gdx.files.internal("data/rain.mp3"));

    // start the playback of the background music immediately
    rainMusic.setLooping(true);
    rainMusic.play();

    // create the camera and the SpriteBatch
    camera = new OrthographicCamera();
    camera.setToOrtho(false, 800, 480);
    batch = new SpriteBatch();

    // create a Rectangle to logically represent the bucket
    bucket = new Rectangle();
    bucket.x = 800 / 2 - 48 / 2; // center the bucket horizontally
    bucket.y = 20; // bottom left corner of the bucket is 20 pixels above the bottom screen edge
    bucket.width = 48;
    bucket.height = 48;

    // create the raindrops array and spawn the first raindrop
    raindrops = new Array<Rectangle>();
    spawnRaindrop();
  }
  @Override
  public void create() {
    music = Gdx.audio.newMusic(Gdx.files.internal("res/racerx.mp3"));
    music.setLooping(true);
    music.play();

    splashScreen = new SplashScreen(this);
    setScreen(splashScreen);
  }
 @Override
 public void dispose() {
   stage.dispose();
   for (Texture t : texturesList) {
     t.dispose();
   }
   for (Music m : soundsList) {
     m.dispose();
   }
 }
Exemple #11
0
 public static void play(String newKey) {
   if (!enabled) return;
   if (music != null) {
     music.stop();
   }
   key = newKey;
   music = musics.get(key);
   music.setLooping(true);
   music.play();
 }
Exemple #12
0
  private void initMusic() {
    music = AssetsLoader.getMusic();

    boolean musicOn = preferences.getBoolean("musicOn", true);
    float musicVolume = preferences.getFloat("musicVolume", 1);
    music.setLooping(true);
    if (musicOn) {
      music.play();
    }
    music.setVolume(musicVolume);
  }
 public static void reloadMusic() {
   if (MiningAdventure.PREF_AUDIO) {
     aud.stop();
     aud.dispose();
     aud = null;
     if (!MiningAdventure.sanic) {
       aud = Gdx.audio.newMusic(Gdx.files.internal("music/Game.mp3"));
     } else {
       aud = Gdx.audio.newMusic(Gdx.files.internal("music/SANIC.mp3"));
     }
     aud.play();
     aud.setLooping(true);
   }
 }
 // Other
 public void removeAll() {
   for (Object o : music.values()) {
     Music m = (Music) o;
     m.dispose();
   }
   for (Object o : sound.values()) {
     Sound s = (Sound) o;
     s.dispose();
   }
   for (Object o : font.values()) {
     BitmapFont bmf = (BitmapFont) o;
     bmf.dispose();
   }
 }
Exemple #15
0
  /**
   * Plays the given music (starts the streaming).
   *
   * <p>If there is already a music being played it is stopped automatically.
   */
  public void play(Music music) {
    // check if the music is enabled
    if (!enabled) return;

    // stop any music being played

    //        stop(); // removing this solves the restart problem (if menu-music is added, maybe
    // it's needed again)

    // start streaming the new music
    musicBeingPlayed = music;
    musicBeingPlayed.setVolume(volume);
    musicBeingPlayed.setLooping(true);
    musicBeingPlayed.play();
  }
Exemple #16
0
  @Override
  public void hide() {
    super.hide();
    if (music != null) {
      music.stop();
      music.dispose();
    }
    music = null;

    if (!gameMode.isGameOver()) {
      saveStats();
    }

    setPaused(false);
  }
 @Override
 public void dispose() {
   music.dispose();
   //			raceScreen.dispose();
   //			splashScreen.dispose();
   getScreen().dispose();
 }
Exemple #18
0
 public static void dispose() {
   player.dispose();
   boundary.dispose();
   jumpSound.dispose();
   slideSound.dispose();
   backgroundMusic.dispose();
 }
  public GameScreen(final Drop gam) {
    this.game = gam;

    // load the images for the droplet and the bucket, 64x64 pixels each
    dropImage = new Texture(Gdx.files.internal("droplet.png"));
    bucketImage = new Texture(Gdx.files.internal("bucket.png"));

    // load the drop sound effect and the rain background "music"
    dropSound = Gdx.audio.newSound(Gdx.files.internal("drop.wav"));
    rainMusic = Gdx.audio.newMusic(Gdx.files.internal("rain.mp3"));
    rainMusic.setLooping(true);

    // create the camera and the SpriteBatch
    camera = new OrthographicCamera();
    camera.setToOrtho(false, 800, 480);

    // create a Rectangle to logically represent the bucket
    bucket = new Rectangle();
    bucket.x = 800 / 2 - 64 / 2; // center the bucket horizontally
    bucket.y = 20; // bottom left corner of the bucket is 20 pixels above
    // the bottom screen edge
    bucket.width = 64;
    bucket.height = 64;

    // create the raindrops array and spawn the first raindrop
    raindrops = new Array<Rectangle>();
    spawnRaindrop();
  }
  public void update(float delta) {
    // We draw the elements in order: from top to bottom.
    // so we need to order the array list
    for (SceneLayer layer : layers) layer.update();

    // music delay update
    if (music != null && !music.isPlaying()) {
      boolean initialTime = false;

      if (currentMusicDelay <= initialMusicDelay) initialTime = true;

      currentMusicDelay += delta;

      if (initialTime) {
        if (currentMusicDelay > initialMusicDelay) playMusic();
      } else {
        if (repeatMusicDelay >= 0 && currentMusicDelay > repeatMusicDelay + initialMusicDelay) {
          currentMusicDelay = initialMusicDelay;
          playMusic();
        }
      }
    }

    for (BaseActor a : actors.values()) {
      a.update(delta);
    }

    camera.update(delta);

    if (followActor != null) {
      camera.updatePos(followActor);
    }
  }
 @Override
 public void dispose() {
   dropImage.dispose();
   bucketImage.dispose();
   dropSound.dispose();
   rainMusic.dispose();
 }
  @Override
  public void create() {
    shapeRenderer = new ShapeRenderer();
    batch = new SpriteBatch();
    camera = new OrthographicCamera();
    camera.setToOrtho(false, 800, 480);
    uiCamera = new OrthographicCamera();
    uiCamera.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    uiCamera.update();

    font = new BitmapFont(Gdx.files.internal("arial.fnt"));

    background = new Texture("background.png");
    ground = new TextureRegion(new Texture("ground.png"));
    ceiling = new TextureRegion(ground);
    ceiling.flip(true, true);

    rock = new TextureRegion(new Texture("rock.png"));
    rockDown = new TextureRegion(rock);
    rockDown.flip(false, true);

    Texture frame1 = new Texture("plane1.png");
    frame1.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    Texture frame2 = new Texture("plane2.png");
    Texture frame3 = new Texture("plane3.png");

    ready = new TextureRegion(new Texture("ready.png"));
    gameOver = new TextureRegion(new Texture("gameover.png"));

    plane =
        new Animation(
            0.05f,
            new TextureRegion(frame1),
            new TextureRegion(frame2),
            new TextureRegion(frame3),
            new TextureRegion(frame2));
    plane.setPlayMode(PlayMode.LOOP);

    music = Gdx.audio.newMusic(Gdx.files.internal("music.mp3"));
    music.setLooping(true);
    music.play();

    explode = Gdx.audio.newSound(Gdx.files.internal("explode.wav"));

    resetWorld();
  }
Exemple #23
0
 @Override
 public void dispose() {
   // dispose of all the native resources
   dropImage.dispose();
   bucketImage.dispose();
   dropSound.dispose();
   rainMusic.dispose();
   batch.dispose();
 }
  private void startLevel(String filename) {
    level = Level.loadLevel(filename);
    nextFootstep = 0;
    music = Gdx.audio.newMusic(Gdx.files.internal(level.getMusicFiles().poll()));
    music.play();
    final GameScreen thisGameScreen = this;
    music.setOnCompletionListener(
        new OnCompletionListener() {

          @Override
          public void onCompletion(Music music) {
            music.dispose();
            level.incrementCurrentSection();

            String nextMusicName = level.getMusicFiles().poll();
            if (!endingLevel) {
              if (nextMusicName != null) {
                Music nextMusic = Gdx.audio.newMusic(Gdx.files.internal(nextMusicName));
                nextMusic.play();
                nextMusic.setOnCompletionListener(this);
                thisGameScreen.music = nextMusic;
              } else {
                // End of level!
                // Play end of level sound
                // After it ends, load level 2
                Music endSound = Gdx.audio.newMusic(Gdx.files.internal("endOfLevel.ogg"));
                endSound.play();
                // final OnCompletionListener thisCompletionListener =
                // this;
                // this;
                endSound.setOnCompletionListener(
                    new OnCompletionListener() {

                      @Override
                      public void onCompletion(Music music) {
                        music.dispose();
                        startLevel("theme2.txt");
                      }
                    });
              }
            }
          }
        });
  }
Exemple #25
0
  /*
   *  The create() method initializes our all of our resources and loads them into memory before the rest of the game is run
   *  This method is the first called after the entry point(based on platform) and is only called once.
   *  This is also a convenient place to put boiler plate code for the rest of the game that we only want ran once on startup.
   *
   *  NOTE: Gdx.files.internal() defaults to the assets put into the Android project folder and takes String "filename.filetype" as a parameter.
   */
  @Override
  public void create() {
    dropImage = new Texture(Gdx.files.internal("droplet.png"));
    bucketImage = new Texture(Gdx.files.internal("bucket.png"));

    dropSound = Gdx.audio.newSound(Gdx.files.internal("droplet.mp3"));
    rainMusic = Gdx.audio.newMusic(Gdx.files.internal("rain.mp3"));

    rainMusic.setLooping(true); // set rainMusic (rain.mp3) to play over and over again
    rainMusic.play(); // starts the rainMusic audio

    camera = new OrthographicCamera(); // initialize camera, part of opengl/opengl-es.

    /*
     * sets the camera to 2 dimensional plane. Seems redundant since we are using OrthographicCamera() object.
     * Note: investigate camera settings
     */
    camera.setToOrtho(false, 800, 400);

    batch = new SpriteBatch(); // new sprite batch used in render() ie.Draws images.

    /*
     * set bucket properties. Use Rectangle object to represent bucket, track position and set size
     * used for collision detection with raindrop objects
     *
     */
    bucket = new Rectangle();
    bucket.x = 800 / 2 - 64 / 2;
    bucket.y = 20;
    bucket.width = 64;
    bucket.height = 64;

    /*
     * initializes Libgdx Array.
     * Note: Investigate how  Libgdx Array is different than regular Java Array.
     */
    raindrops = new Array<Rectangle>();

    /*
     * creates new raindrops to be drawn for our game. This method is called here to
     * start the first raindrop.
     */
    spawnRaindrop();
  }
Exemple #26
0
  public void removeAll() {
    for (Object o : textures.values()) {
      Texture tex = (Texture) o;
      tex.dispose();
    }
    textures.clear();

    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();
  }
Exemple #27
0
  @Override
  public void dispose() {
    super.dispose();
    music.dispose();

    for (Entity ent : entities) ent.dispose();

    enemies.clear();
    powerups.clear();
    bullets.clear();
  }
  public BaseLevel(GameScreen gameScreen) {
    m_GameScreen = gameScreen;
    m_Entities = new ArrayList<IEntity>();

    m_BackgroundMusic = Gdx.audio.newMusic(Gdx.files.internal("music/background.mp3"));
    m_BackgroundMusic.setVolume(gameScreen.m_Settings.m_BackgroundMusicVolume * 0.75f);
    m_BackgroundMusic.setLooping(true);
    m_BackgroundMusic.play();

    m_ClockTick = Gdx.audio.newSound(Gdx.files.internal("music/tick.mp3"));
    m_Powerup = Gdx.audio.newSound(Gdx.files.internal("music/powerup.wav"));
    m_Crash = Gdx.audio.newSound(Gdx.files.internal("music/crash.mp3"));
    m_Wind = Gdx.audio.newSound(Gdx.files.internal("music/wind.mp3"));

    // title
    m_BorderTexture = new Texture(Gdx.files.internal("map/border.png"));
    m_BorderTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    TextureRegion borderRegion = new TextureRegion(m_BorderTexture, 0, 0, 800, 600);
    m_BorderSprite = new Sprite(borderRegion);
    m_BorderSprite.setColor(1, 1, 1, 0.5f);
  }
  @Override
  public void show() {
    buttonRenderer = new SpriteBatch();

    if (aud != null && !MiningAdventure.PREF_AUDIO) {
      aud.stop();
      aud.dispose();
      aud = null;
    }

    if (aud == null && MiningAdventure.PREF_AUDIO) {
      if (!MiningAdventure.sanic) {
        aud = Gdx.audio.newMusic(Gdx.files.internal("music/Game.mp3"));
      } else {
        aud = Gdx.audio.newMusic(Gdx.files.internal("music/SANIC.mp3"));
      }
      aud.play();
      aud.setLooping(true);
    }

    Gdx.input.setInputProcessor(this);
  }
  @Override
  public void write(Json json) {
    json.writeValue("layers", layers);
    json.writeValue("id", id);
    json.writeValue("state", state, state == null ? null : state.getClass());
    json.writeValue("verbs", verbManager);

    json.writeValue("actors", actors);
    json.writeValue("player", player);

    json.writeValue("backgroundAtlas", backgroundAtlas);
    json.writeValue("backgroundRegionId", backgroundRegionId);

    json.writeValue("lightMapAtlas", lightMapAtlas);

    json.writeValue("lightMapRegionId", lightMapRegionId);

    json.writeValue("musicFilename", musicFilename);
    json.writeValue("loopMusic", loopMusic);
    json.writeValue("initialMusicDelay", initialMusicDelay);
    json.writeValue("repeatMusicDelay", repeatMusicDelay);

    json.writeValue("isPlaying", music != null && music.isPlaying());
    json.writeValue("musicPos", music != null && music.isPlaying() ? music.getPosition() : 0f);

    json.writeValue("camera", camera);

    json.writeValue(
        "followActor",
        followActor == null ? null : followActor.getId(),
        followActor == null ? null : String.class);

    json.writeValue("depthVector", depthVector);

    json.writeValue(
        "polygonalNavGraph",
        polygonalNavGraph,
        polygonalNavGraph == null ? null : PolygonalNavGraph.class);
  }