Beispiel #1
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();
          }
        });
  }
Beispiel #2
0
  /** Stops and disposes the current music being played, if any. */
  public void stop() {
    if (musicBeingPlayed != null) {

      musicBeingPlayed.stop();
      musicBeingPlayed.dispose();
    }
  }
 public void dispose() {
   m_BorderTexture.dispose();
   m_BackgroundMusic.stop();
   m_BackgroundMusic.dispose();
   m_RayHandler.dispose();
   m_PhysicsWorld.dispose();
 }
Beispiel #4
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();
 }
 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);
   }
 }
Beispiel #6
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 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);
  }
  public static void unLoadAll() {
    Set<String> st = musicCache.keySet();
    for (String string : st) {
      Music music = musicCache.get(string);
      music.stop();
      music.dispose();
    }
    musicCache.clear();

    st = textureCache.keySet();
    for (String string : st) {
      Texture t = textureCache.get(string);
      t.dispose();
    }
    textureCache.clear();

    st = soundCache.keySet();
    for (String string : st) {
      Sound s = soundCache.get(string);
      s.dispose();
    }
    soundCache.clear();
  }
  @Override
  public void render(float delta) {
    super.render();

    totalGameTimer += delta;
    // if ((totalGameTimer >= 5) && (levelStarted == false)) {
    // startLevel("theme1.txt");
    // levelStarted = true;
    // return;
    // }

    Gdx.gl.glClearColor(0, 0, 0.2f, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    batch.begin();
    {
      // batch.draw(rightFootprintTexture, WIDTH / 2 + footSpacing - 50,
      // 0);
      // batch.draw(leftFootprintTexture, WIDTH / 2 - footSpacing - 50,
      // 0);
      // batch.draw(rightWall, 0, 0, WIDTH, HEIGHT);
      // batch.draw(leftWall, 0, 0, WIDTH, HEIGHT);
      // batch.draw(perspectiveTexture, 0, 0, WIDTH, HEIGHT);

    }
    batch.end();

    batch.begin();
    // sprite.draw(batch);
    elapsedTime += Gdx.graphics.getDeltaTime();
    // batch.draw(), x, y, originX, originY, width, height, scaleX, scaleY,
    // rotation);
    batch.draw(smokeTexture, 0, 0, WIDTH, HEIGHT);

    // System.out.println(level.getSkipped());
    int damage = (level.getSkipped() + level.getMisses()) / 3;

    // System.out.println(damage);

    if (damage == 5) {
      leftWallAnimation = new Animation(1 / 45f, leftWallTextureAtlas.getRegions());
      rightWallAnimation = new Animation(1 / 45f, rightWallTextureAtlas.getRegions());
    }

    if (damage >= 6) {
      deathCounter++;
      ScreenManager.getInstance().show(ScreenManager.Screens.TITLE);
      endingLevel = true;
      music.stop();
      music.dispose();
    } else {
      batch.draw(
          pentagramAtlas.findRegion("000" + Integer.toString((damage % 7) + 1)),
          WIDTH / 2 - (72 / 2),
          HEIGHT - 72,
          72,
          72);
    }
    // batch.draw(stairTexture, 0, (float) -(level.getCurrPos() * 10),
    // WIDTH, HEIGHT);
    batch.draw(
        stairsAnimation.getKeyFrame(level.getFootstepsBetween(-level.getCurrPos(), 0).size(), true),
        (float) 0,
        0,
        WIDTH,
        HEIGHT / 2);
    batch.draw(leftWallAnimation.getKeyFrame(elapsedTime, true), 0, 0, 225, HEIGHT);
    batch.draw(rightWallAnimation.getKeyFrame(elapsedTime, true), WIDTH - 225, 0, 225, HEIGHT);
    batch.end();

    // Advance in level
    // level.addCurrPos(delta);
    // TODO:
    level.syncWithMusic(music);

    // // Announce next footstep, if one has been passed
    // if (level.getFootsteps().get(nextFootstep).getTime() <
    // level.getCurrPos()) {
    // // "Next" footstep is in the past
    // nextFootstep++;
    //
    // // Announce
    // System.out.println("Next footstep is now: " +
    // level.getFootsteps().get(nextFootstep).toString());
    // }

    // TODO: Look for input
    boolean leftPressed = Gdx.input.isKeyJustPressed(Input.Keys.SHIFT_LEFT);
    boolean rightPressed = Gdx.input.isKeyJustPressed(Input.Keys.SHIFT_RIGHT);
    if (leftPressed || rightPressed) {
      // TODO: If pressed BEFORE a footstep, miss the next footstep

      // If pressed DURING a footstep, mark footstep as hit if it is left.
      // Otherwise miss.
      for (Footstep f : level.getActiveFootsteps(HIT_THRESHOLD)) {
        if (f != null) {
          Footstep active = f;
          if ((!active.isDidHit()) && (!active.isDidMiss())) {
            if (((active.getType() == FootstepType.LEFT) && leftPressed)
                || ((active.getType() == FootstepType.RIGHT) && rightPressed)) {
              // HIT!
              active.setDidHit(true);
              // System.out.println("HIT FOOTSTEP: " +
              // active.toString());
            } else {
              // Miss.
              active.setDidMiss(true);
              // System.out.println("MISSED FOOTSTEP: " +
              // active.toString());
            }
          }
        }
      }
    }

    // Render visible footsteps
    batch.begin();
    {
      double startTime = -2;
      double farthestTime = 5.0f;
      for (Footstep f : level.getFootstepsBetween(startTime, farthestTime)) {
        float distanceOnRoad =
            (float) ((f.getTime() - level.getCurrPos()) / (farthestTime - startTime));
        distanceOnRoad -= 1;
        distanceOnRoad = -(-Math.abs(distanceOnRoad * distanceOnRoad * distanceOnRoad) - 1);
        distanceOnRoad = 2 - (distanceOnRoad);
        Sprite sprite = new Sprite(rightFootprintTexture);
        // Flip for left foot
        sprite.flip(f.getType() == FootstepType.LEFT, false);
        // Add alpha
        if (distanceOnRoad > 0) {
          sprite.setAlpha((1f - distanceOnRoad) * 0.9f + 0.1f);
        }
        // Add scaling
        sprite.setScale((1f - distanceOnRoad) * 0.6f);
        // Light footsteps that are "active"
        double distanceTo = f.getTime() - level.getCurrPos();
        if (Math.abs(distanceTo) < LIT_THRESHOLD) {
          sprite.setColor(Color.BLUE);
        }
        if (-distanceTo > LIT_THRESHOLD && (!(f.isDidHit() || f.isDidMiss()))) {
          sprite.setRotation((int) (level.getCurrPos() * 2000));
          sprite.setColor(Color.FIREBRICK);
        }

        // Mark hits or misses
        if (f.isDidHit()) {
          sprite.setColor(Color.GREEN);
        } else if (f.isDidMiss()) {
          sprite.setColor(Color.RED);
        }

        float leftFactor = 1;
        if (f.getType() == FootstepType.LEFT) {
          leftFactor = -1;
        }
        float x = WIDTH / 2 + (leftFactor * (WIDTH / 11) * (1 - distanceOnRoad));
        float y = (distanceOnRoad * (HEIGHT / 2 + 50 - FOOTSTEP_LINE)) + FOOTSTEP_LINE;

        // Celebrate hits!
        if (f.isDidHit()) {
          y += -distanceTo * 100;
        }

        sprite.setCenter(x, y);
        sprite.draw(batch);
      }
    }
    batch.end();
  }
Beispiel #10
0
 private static void dispose() {
   if (music1.isPlaying()) music1.stop();
   music1.dispose();
   if (music2.isPlaying()) music2.stop();
   music2.dispose();
 }
 public void stopMusic() {
   if (music != null && music.isPlaying()) {
     music.stop();
   }
 }
 public synchronized void stopSong() {
   if (_music == null) {
     return;
   }
   _music.stop();
 }
 public void stopMusic() {
   if (music != null) music.stop();
 }
 public void stopMusic() {
   for (Object o : music.values()) {
     Music m = (Music) o;
     m.stop();
   }
 }
Beispiel #15
0
 @Override
 public void dispose() {
   bgMusic.stop();
   Assets.treasureSound.stop();
 }
Beispiel #16
0
 public void stopMusic() {
   if (musicBeingPlayed != null) {
     musicBeingPlayed.stop();
   }
 }