Esempio n. 1
0
 /**
  * Plays the current track.
  *
  * @param loop whether or not to loop the track
  */
 public static void play(boolean loop) {
   if (trackExists()) {
     trackEnded = false;
     if (loop) player.loop();
     else player.play();
   }
 }
Esempio n. 2
0
 /** Resumes the current track. */
 public static void resume() {
   if (trackExists()) {
     pauseTime = 0f;
     player.resume();
     player.setVolume(1.0f);
   }
 }
Esempio n. 3
0
 /**
  * Plays the current track at the given position.
  *
  * @param position the track position (in ms)
  * @param loop whether or not to loop the track
  */
 public static void playAt(final int position, final boolean loop) {
   if (trackExists()) {
     setVolume(Options.getMusicVolume() * Options.getMasterVolume());
     trackEnded = false;
     pauseTime = 0f;
     if (loop) player.loop();
     else player.play();
     if (position >= 0) player.setPosition(position / 1000f);
   }
 }
Esempio n. 4
0
  @Override
  public void leave(GameContainer container, StateBasedGame game) throws SlickException {
    super.leave(container, game);
    world = null;

    // TODO: Musicクラスの利用
    music.stop();
  }
Esempio n. 5
0
 public void playMenu() {
   try {
     active = menu;
     active.loop();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Esempio n. 6
0
 public void playCredits() {
   try {
     active = credits;
     active.loop();
   } catch (Exception e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
Esempio n. 7
0
 public void playNavNormal() {
   try {
     Random r = new Random();
     active = nav_normal.get(r.nextInt(nav_normal.size()));
     activeCat = "nav_normal";
     active.play();
   } catch (Exception e) {
     // TODO: handle exception
   }
 }
Esempio n. 8
0
 public void playFight() {
   try {
     Random r = new Random();
     active = fight.get(r.nextInt(fight.size()));
     activeCat = "fight";
     active.play();
   } catch (Exception e) {
     // TODO: handle exception
   }
 }
Esempio n. 9
0
 public void playTavern() {
   try {
     Random r = new Random();
     active = tavern.get(r.nextInt(tavern.size()));
     activeCat = "tavern";
     active.play();
   } catch (Exception e) {
     // TODO: handle exception
   }
 }
Esempio n. 10
0
 public void playNavTension() {
   try {
     Random r = new Random();
     active = nav_tension.get(r.nextInt(nav_tension.size()));
     activeCat = "nav_tension";
     active.play();
   } catch (Exception e) {
     // TODO: handle exception
   }
 }
Esempio n. 11
0
  @Override
  public void enter(GameContainer container, StateBasedGame game) throws SlickException {
    super.enter(container, game);
    keyInput = new KeyInput();
    world = new World(this);
    world.init();

    // TODO: Musicクラスの利用
    music.setPosition(0);
    music.play();
    music.loop();

    // ゲーム中に動的に曲を変えたい場合
    // このBasicGameStateクラスが持つクラス
    // 今回で言えば,Battleクラスが持つWorldクラスに,
    // Battleクラスの参照を渡しておき,
    // MusicChangeメソッドなどを作成し,呼び出させるという方法がある.

    // 他にも,ShootingGameクラスなどのStateBasedGameクラスに音楽管理クラスを
    // 持たせ,そこで管理するという方法もある.
  }
Esempio n. 12
0
  /**
   * Stops and releases all sources, clears each of the specified Audio buffers, destroys the OpenAL
   * context, and resets SoundStore for future use.
   *
   * <p>Calling SoundStore.get().init() will re-initialize the OpenAL context after a call to
   * destroyOpenAL (Note: AudioLoader.getXXX calls init for you).
   *
   * @author davedes (http://slick.ninjacave.com/forum/viewtopic.php?t=3920)
   */
  private static void destroyOpenAL() {
    if (!trackExists()) return;
    stop();

    try {
      // get Music object's (private) Audio object reference
      Field sound = player.getClass().getDeclaredField("sound");
      sound.setAccessible(true);
      Audio audio = (Audio) (sound.get(player));

      // first clear the sources allocated by SoundStore
      int max = SoundStore.get().getSourceCount();
      IntBuffer buf = BufferUtils.createIntBuffer(max);
      for (int i = 0; i < max; i++) {
        int source = SoundStore.get().getSource(i);
        buf.put(source);

        // stop and detach any buffers at this source
        AL10.alSourceStop(source);
        AL10.alSourcei(source, AL10.AL_BUFFER, 0);
      }
      buf.flip();
      AL10.alDeleteSources(buf);
      int exc = AL10.alGetError();
      if (exc != AL10.AL_NO_ERROR) {
        throw new SlickException("Could not clear SoundStore sources, err: " + exc);
      }

      // delete any buffer data stored in memory, too...
      if (audio != null && audio.getBufferID() != 0) {
        buf = BufferUtils.createIntBuffer(1).put(audio.getBufferID());
        buf.flip();
        AL10.alDeleteBuffers(buf);
        exc = AL10.alGetError();
        if (exc != AL10.AL_NO_ERROR) {
          throw new SlickException(
              "Could not clear buffer " + audio.getBufferID() + ", err: " + exc);
        }
      }

      // clear OpenAL
      AL.destroy();

      // reset SoundStore so that next time we create a Sound/Music, it will reinit
      SoundStore.get().clear();

      player = null;
    } catch (Exception e) {
      ErrorHandler.error("Failed to destroy OpenAL.", e, true);
    }
  }
Esempio n. 13
0
  /** @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer) */
  public void init(GameContainer container) throws SlickException {
    SoundStore.get().setMaxSources(32);

    myContainer = container;
    sound = new Sound("testdata/restart.ogg");
    charlie = new Sound("testdata/cbrown01.wav");
    engine = new Sound("testdata/engine.wav");
    music = musica = new Music("testdata/SMB-X.XM");
    // music = musica = new Music("testdata/theme.ogg", true);
    musicb = new Music("testdata/kirby.ogg", true);
    burp = new Sound("testdata/burp.aif");

    music.play();
  }
Esempio n. 14
0
 /**
  * @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer,
  *     org.newdawn.slick.Graphics)
  */
 public void render(GameContainer container, Graphics g) {
   g.setColor(Color.white);
   g.drawString("The OGG loop is now streaming from the file, woot.", 100, 60);
   g.drawString("Press space for sound effect (OGG)", 100, 100);
   g.drawString("Press P to pause/resume music (XM)", 100, 130);
   g.drawString("Press E to pause/resume engine sound (WAV)", 100, 190);
   g.drawString("Press enter for charlie (WAV)", 100, 160);
   g.drawString("Press C to change music", 100, 210);
   g.drawString("Press B to burp (AIF)", 100, 240);
   g.drawString("Press + or - to change global volume of music", 100, 270);
   g.drawString("Press Y or X to change individual volume of music", 100, 300);
   g.drawString("Press N or M to change global volume of sound fx", 100, 330);
   g.setColor(Color.blue);
   g.drawString("Global Sound Volume Level: " + container.getSoundVolume(), 150, 390);
   g.drawString("Global Music Volume Level: " + container.getMusicVolume(), 150, 420);
   g.drawString("Current Music Volume Level: " + music.getVolume(), 150, 450);
 }
Esempio n. 15
0
  /**
   * Loads a track and plays it.
   *
   * @param file the audio file
   * @param position the track position (in ms)
   * @param loop whether or not to loop the track
   */
  private static void loadTrack(File file, int position, boolean loop) {
    try {
      player = new Music(file.getPath(), true);
      player.addListener(
          new MusicListener() {
            @Override
            public void musicEnded(Music music) {
              if (music == player) // don't fire if music swapped
              trackEnded = true;
            }

            @Override
            public void musicSwapped(Music music, Music newMusic) {}
          });
      playAt(position, loop);
    } catch (Exception e) {
      ErrorHandler.error(String.format("Could not play track '%s'.", file.getName()), e, false);
    }
  }
Esempio n. 16
0
 /**
  * Fades out the track.
  *
  * @param duration the fade time (in ms)
  */
 public static void fadeOut(int duration) {
   if (isPlaying()) player.fade(duration, 0f, true);
 }
Esempio n. 17
0
 public static void playMenuMusic() {
   if (!menuMusic.playing()) {
     menuMusic.loop();
   }
 }
Esempio n. 18
0
 public static void playBGM() {
   if (!backgroundMusic.playing()) {
     backgroundMusic.loop();
   }
 }
Esempio n. 19
0
  /** @see org.newdawn.slick.BasicGame#keyPressed(int, char) */
  public void keyPressed(int key, char c) {
    if (key == Input.KEY_ESCAPE) {
      System.exit(0);
    }
    if (key == Input.KEY_SPACE) {
      sound.play();
    }
    if (key == Input.KEY_B) {
      burp.play();
    }
    if (key == Input.KEY_A) {
      sound.playAt(-1, 0, 0);
    }
    if (key == Input.KEY_L) {
      sound.playAt(1, 0, 0);
    }
    if (key == Input.KEY_RETURN) {
      charlie.play(1.0f, 1.0f);
    }
    if (key == Input.KEY_P) {
      if (music.playing()) {
        music.pause();
      } else {
        music.resume();
      }
    }
    if (key == Input.KEY_C) {
      music.stop();
      if (music == musica) {
        music = musicb;
      } else {
        music = musica;
      }

      music.loop();
    }
    if (key == Input.KEY_E) {
      if (engine.playing()) {
        engine.stop();
      } else {
        engine.loop();
      }
    }

    if (c == '+') {
      volume += 1;
      setVolume();
    }

    if (c == '-') {
      volume -= 1;
      setVolume();
    }

    if (key == Input.KEY_Y) {
      int vol = (int) (music.getVolume() * 10);
      vol--;
      if (vol < 0) vol = 0;
      // set individual volume of music
      music.setVolume(vol / 10.0f);
    }
    if (key == Input.KEY_X) {
      int vol = (int) (music.getVolume() * 10);
      vol++;
      if (vol > 10) vol = 10;
      // set individual volume of music
      music.setVolume(vol / 10.0f);
    }
    if (key == Input.KEY_N) {
      int vol = (int) (myContainer.getSoundVolume() * 10);
      vol--;
      if (vol < 0) vol = 0;
      // set global volume of sound fx
      myContainer.setSoundVolume(vol / 10.0f);
    }
    if (key == Input.KEY_M) {
      int vol = (int) (myContainer.getSoundVolume() * 10);
      vol++;
      if (vol > 10) vol = 10;
      // set global volume of sound fx
      myContainer.setSoundVolume(vol / 10.0f);
    }
  }
Esempio n. 20
0
 public void stopMusic() {
   song.stop();
 }
Esempio n. 21
0
 /** Stops the current track. */
 public static void stop() {
   if (isPlaying()) player.stop();
   if (trackExists()) pauseTime = 0f;
 }
Esempio n. 22
0
 /** Returns true if the current track is playing. */
 public static boolean isPlaying() {
   return (trackExists() && player.playing());
 }
Esempio n. 23
0
 /** Pauses the current track. */
 public static void pause() {
   if (isPlaying()) {
     pauseTime = player.getPosition();
     player.pause();
   }
 }
Esempio n. 24
0
 /**
  * Returns the position in the current track, in milliseconds. If no track is loaded, 0 will be
  * returned.
  */
 public static int getPosition() {
   if (isPlaying()) return (int) (player.getPosition() * 1000 + Options.getMusicOffset());
   else if (isPaused()) return Math.max((int) (pauseTime * 1000 + Options.getMusicOffset()), 0);
   else return 0;
 }
Esempio n. 25
0
 /**
  * Seeks to a position in the current track.
  *
  * @param position the new track position (in ms)
  */
 public static boolean setPosition(int position) {
   return (trackExists() && position >= 0 && player.setPosition(position / 1000f));
 }
  @Override
  public void update(GameContainer container, StateBasedGame state, int delta)
      throws SlickException {
    frog.update(container, delta);
    allOtherObjects.update(container, delta);

    // Musik loopen
    if (sound_music.playing() == false) {
      if (isMusicPaused == true) sound_music.resume();
      else sound_music.loop();
    }

    // Testobjekte
    woman.update(container, delta);
    timerBar.update(container, delta);

    // Rupees einsammeln
    for (Rupee obj : allOtherObjects.getRupees()) {
      if (frog.checkCollisionWith(obj) == true) {
        if (obj.getCollected() == false) {
          obj.setCollected(true);
          obj.getSound().play();
          frog.incrRupeesInBag(obj.getWert());
          frog.getRupeeStringHover().activate(frog.getPosX(), frog.getPosY(), obj.getWert());
        }
      }
    }

    // und bei der Frau abgeben!
    /*
     * Nur wenn die Rupees bei der Frau abgegegeben werden
     * dann wird die Zeit vollends aufgefüllt
     */
    /*
     * Berechnung des Highscores:
     * Rupees * verbliebende Zeit = Highscore
     */
    if (frog.checkCollisionWith(woman) == true && frog.getRupeesInBag() != 0) {

      // Highscore Berechnung!
      highscore += (long) ((timerBar.getWidth() / 1) * frog.getRupeeaInBag());

      rupeeCounter += frog.getRupeesInBag();
      frog.setRupeesInBag(0);
      woman.setWithBag(true);
      woman.setCollisionOn(false);
      woman.setAnimation(true);
      woman.getSound().play();
      timerBar.restoreWidth();
      for (Rupee obj : allOtherObjects.getRupees()) {
        obj.randomize();
      }
    }

    // beim Tod/Gameover
    if (frog.getLifeCount() <= 0) {
      frog.getSound_gameover().play();
      sound_music.stop();

      frog.reset();
      frog.setRupeesInBag(0);
      frog.setLifeCount(2);
      timerBar.setTimerOn(false);

      state.enterState(GameStates.GameOver);
    }

    // wenn die Zeit abgelaufen wird: ein Leben nehmen!
    // außerdem die Rupees wieder neu druchwürfeln
    if (timerBar.getEvent() == true) {
      frog.reduceLifeCount();
      frog.incrLifeCount();
      timerBar.setEvent(false);
      frog.reset();
      timerBar.setTimerOn(false);

      for (Rupee obj : allOtherObjects.getRupees()) {
        obj.randomize();
      }
    }

    // Kollisionsabfrage
    // Frosch mit Autos
    for (GameObj obj : allOtherObjects.getCars()) {
      if (frog.checkCollisionWith(obj) == true) {
        frog.reset();
        timerBar.setTimerOn(false);

        for (Rupee obj2 : allOtherObjects.getRupees()) {
          obj2.randomize();
        }
      }
    }

    // mit den LOGS oder dem WASSER
    frog.setOnBoat(false);

    for (GameObj obj : allOtherObjects.getLogs()) {
      if (frog.checkCollisionWith(obj) == true) {
        frog.setOnBoat(true);
      }
    }

    for (GameObj obj : allOtherObjects.getLogs()) {
      if (frog.checkCollisionWith(obj) == true) {
        frog.setPosX(frog.getPosX() + (obj.getSpdX() * (delta / 1000.0f)));
      }
    }

    for (GameObj obj2 : allOtherObjects.getRiver()) {
      if (frog.checkCollisionWith(obj2) == true && frog.getOnBoat() == false) {
        frog.reset();
        timerBar.setTimerOn(false);

        for (Rupee obj : allOtherObjects.getRupees()) {
          obj.randomize();
        }
      }
    }

    // Falls man den Frosch wegen eines resettes nicht mehr steuern kann
    // sollen so und so viele Sekunden passieren bis man ihn wieder
    // kontrollieren kann!
    if (frog.getEingabe() == false) {
      resetTimer--;
    }
    if (resetTimer <= 0) {
      frog.setEingabe(true);
      frog.setCollisionOn(true);
      timerBar.setTimerOn(true);
      resetTimer = RESETTIMER;
      timerBar.restoreWidth();
    }

    // Der Frosch soll nicht durch die Wände können!
    for (GameObj obj : allOtherObjects.getWall()) {
      if (frog.checkCollisionWith(obj) == true) {
        // von rechts
        if (frog.getSpdX() > 0) frog.setPosX(frog.getPrevPosX());
        // von links
        else if (frog.getSpdX() < 0) frog.setPosX(frog.getPrevPosX());
        // von unten
        if (frog.getSpdY() < 0 && frog.getPosY() >= 82) frog.setPosY(frog.getPrevPosY());
      }
    }

    // Pause game
    Input input = container.getInput();
    if (input.isKeyPressed(Input.KEY_ESCAPE)) {
      sound_pause.play();
      sound_music.pause();
      isMusicPaused = true;
      state.enterState(GameStates.Paused);
    }

    /*
     * Der Guide wird nur ganz am Anfang oben als kleiner Text eingeblendet.
     * Sobald einmal die Rupees bei der Frau abgegeben worden sind,
     * verschwindet der Text bzw ein motivierender Text steht dort.
     */

    if (guideString.equals(Constants.GUIDE5) == false) {
      // erster Tipp
      guideString = Constants.GUIDE1;

      // zweiter Tipp
      if (frog.getRupeesInBag() >= 2) guideString = Constants.GUIDE2;

      // dritter Tipp
      if (rupeeCounter >= 1) guideString = Constants.GUIDE3;

      // vierter Tipp
      if (guideString.equals(Constants.GUIDE3) && frog.getRupeesInBag() >= 1)
        guideString = Constants.GUIDE4;

      // Ende
      if (guideString.equals(Constants.GUIDE4) && frog.getRupeesInBag() == 0)
        guideString = Constants.GUIDE5;
    }
  }
Esempio n. 27
0
 public void startMusic() {
   song.loop();
 }