Beispiel #1
0
 /**
  * This function converts .mp3 song to .WAV song
  *
  * @param filepathToConvert - the source file path (mp3)
  * @param convertedFilepath - the destination file path (wave)
  */
 public void convertMP3ToWav(String filepathToConvert, String convertedFilepath) {
   try {
     converter.convert(filepathToConvert, convertedFilepath);
   } catch (JavaLayerException e) {
     e.printStackTrace();
   }
 }
Beispiel #2
0
 /**
  * Starts this applet. An input stream and audio device are created and passed to the play()
  * method.
  */
 public void start() {
   String name = getAudioFileName();
   try {
     InputStream in = getAudioStream();
     AudioDevice dev = getAudioDevice();
     play(in, dev);
   } catch (JavaLayerException ex) {
     synchronized (System.err) {
       System.err.println("Unable to play " + name);
       ex.printStackTrace(System.err);
     }
   }
 }
Beispiel #3
0
  public void songManager() {
    UI ui = new UI();
    int choice = ui.getChoice();
    Play p = new Play(this);

    while (choice != 5) {
      switch (choice) {
        case 1:
          sortByArtist();
          print();
          break;
        case 2:
          sortByTitle();
          print();
          break;
        case 3:
          Scanner sc = new Scanner(new InputStreamReader(System.in));
          int songChoice = 0;
          while (songChoice < 1 || songChoice > size()) {
            System.out.println("Enter Song Choice: ");
            sortByArtist();
            print();
            songChoice = sc.nextInt();
          }
          try {
            p.playSong(songChoice, this);
          } catch (JavaLayerException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
          break;
        case 4:
          if (player != null) {
            player.close();
          }
          break;
        default:
          break;
      }
      choice = ui.getChoice();
      if (choice == 5) break;
    }
  }
Beispiel #4
0
 public static void play(final String audioFilePath) {
   if (isEnabled) {
     try {
       final AdvancedPlayer p = new AdvancedPlayer(new FileInputStream(new File(audioFilePath)));
       Thread t =
           new Thread() {
             @Override
             public void run() {
               try {
                 p.play();
               } catch (JavaLayerException e) {
                 e.printStackTrace();
               }
             }
           };
       t.setPriority(Thread.MIN_PRIORITY);
       t.start();
     } catch (FileNotFoundException e) {
       e.printStackTrace();
     } catch (JavaLayerException e) {
       e.printStackTrace();
     }
   }
 }
  @Override
  public void init(GameContainer gc) {

    try {
      Scanner test = ResourceLoader.openFile("Test");
    } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    try {
      ResourceLoader.createTextbox("test");
    } catch (TextboxException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }
    try {
      theTileMap = new BasicTileMap("res/testMap.tmx");
      // ((BasicTileMap)(theTileMap)).setPathing(tileMapPathing);
      theTileMap.useDefaultCamera();
      System.out.println(
          "LEFT: "
              + theTileMap.getLeftBound()
              + " RIGHT: "
              + theTileMap.getRightBound()
              + " UPPER: "
              + theTileMap.getUpperBound()
              + " LOWER: "
              + theTileMap.getLowerBound());
      theTileMap.setViewCollision(true);
      Game.setGameMap(theTileMap);
    } catch (SlickException e) {
      e.printStackTrace();
    }
    player1 = new TestPlayer(100, 200, 50, 50);
    player1.setSpeed(5f);
    player1.setShape("Rectangle");
    player1.setMovableCollision(true);
    player1.setViewCollision(false);
    pawnCamera = new Camera(player1, 100, 50);
    player1.attachCamera(pawnCamera);

    player2 = new Pawn(300, 400, 50, 50);
    player2.setShape("Rectangle");
    player2.setMovableCollision(false);
    player2.useDefaultCamera();

    // player3 = new Player(350, 600, 100, 100);
    // player3.useDefaultCamera();
    Game.setGameCamera(player1.getCamera());
    testBox2 = new BasicDialogbox(150, 100, 300, 300);
    testBox2.load("testDialog.txt");
    testBox2.setUseCameraCoordinates(true);
    testBox2.addTextboxListener(
        new TextboxListener() {

          @Override
          public void textboxStopped(TextboxEvent e) {
            testBox.stop();
          }
        });

    // pathFinder.run
    testBox = new Confirmbox(75, 300, 500, 200);
    testBox.load("testConfirmDialog.txt");
    testBox.setColumns(2);
    testBox.drawColumnLines(true);
    Textbox.setTextboxScrollUpKey(Input.KEY_W);
    Textbox.setTextboxScrollDownKey(Input.KEY_S);
    Textbox.setTextboxScrollLeftKey(Input.KEY_A);
    Textbox.setTextboxScrolRightKey(Input.KEY_D);
    testBox.pack();
    testBox.setUseCameraCoordinates(true);
    Textbox.setTextboxActionKey(Input.KEY_SPACE);
    testBox.addConfirmboxListener(
        new ConfirmboxListener() {

          @Override
          public void textboxStopped(TextboxEvent e) {}

          @Override
          public void selectionCommandPerformed(ConfirmboxEvent e) {
            System.out.println(e.getSelectionCommand());
            Textbox.setTextboxActionKey(Input.KEY_ENTER);
            testBox.pause();
            testBox.setSelectionBoxActive(false);
            testBox.setFocused(false);
            testBox2.setFocused(true);
            if (!testBox2.hasStarted()) testBox2.start();
            else {
              testBox2.resume();
              testBox2.show();
            }
          }

          public void scrollCommandPerformed(ConfirmboxEvent e) {
            System.out.println(e.getScrollCommand());
            System.out.println(e.getSelectionCommand());
          }
        });

    gameTimer = new GameTimer(300, 300);
    // gameTimer.setUseCameraCoordinates(false);
    gameTimer.setTime(5, FPS);
    gameTimer.setRecurring(true);
    // gameTimer.setFormat("%2d:%02d:%-2d");
    gameTimer.addTimerListener(
        new TimerListener() {
          public void timerReachedZero(TimerEvent e) {
            System.out.println("Game Timer Reached Zero");
          }
        });
    // gameTimer.start();

    realTimer = new RealTimer(300, 300);
    realTimer.addTimerListener(
        new TimerListener() {

          @Override
          public void timerReachedZero(TimerEvent e) {
            System.out.println("Real Timer reached Zero");
          }
        });
    realTimer.setTime(20, FPS);
    realTimer.setRecurring(true);
    realTimer.start();
    // realTimer.pause();

    gameEntities.add(theTileMap);
    gameEntities.add(player1);
    gameEntities.add(player2);
    // gameEntities.add(player3);
    gameEntities.add(testBox);
    gameEntities.add(testBox2);
    // gameEntities.add(gameTimer);
    gameEntities.add(realTimer);

    KeyInput.addInputCommand("Move+X", Input.KEY_RIGHT, 0);
    KeyInput.addInputCommand("Move-X", Input.KEY_LEFT, 0);
    KeyInput.addInputCommand("Move+Y", Input.KEY_DOWN, 0);
    KeyInput.addInputCommand("Move-Y", Input.KEY_UP, 0);
    KeyInput.addInputCommand("PauseTextbox", Input.KEY_P, 0);
    KeyInput.addInputCommand("ResumeTextbox", Input.KEY_R, 0);
    KeyInput.addInputCommand("StopTextbox", Input.KEY_ESCAPE, 0);
    KeyInput.addInputCommand("Start Dialog", Input.KEY_ENTER, 0);

    MouseInput.addMouseInputCommand("Attack", Input.MOUSE_LEFT_BUTTON, 0);

    // BackgroundMusic.addSongToQueue("01.-title.mp3");
    BackgroundMusic.addSongToQueue("08.-bonus-level.mp3");

    try {
      BackgroundMusic.playAllInQueue();
    } catch (JavaLayerException e) {
      e.printStackTrace();
    }
  }
 public void printStackTrace() {
   printStackTrace(System.err);
 }