示例#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();
   }
 }
示例#2
0
 public void playMenu() {
   try {
     active = menu;
     active.loop();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
示例#3
0
 public void playCredits() {
   try {
     active = credits;
     active.loop();
   } catch (Exception e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
示例#4
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);
   }
 }
示例#5
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クラスに音楽管理クラスを
    // 持たせ,そこで管理するという方法もある.
  }
  @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;
    }
  }
 public static void playMenuMusic() {
   if (!menuMusic.playing()) {
     menuMusic.loop();
   }
 }
 public static void playBGM() {
   if (!backgroundMusic.playing()) {
     backgroundMusic.loop();
   }
 }
示例#9
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);
    }
  }
 public void startMusic() {
   song.loop();
 }