Example #1
0
 public void stop() {
   if (drivingClip != null) {
     drivingClip.stop();
   }
   if (turningClip != null) {
     turningClip.stop();
   }
 }
Example #2
0
  /*
   * Joue un son lors de la fin de la partie
   */
  public void playSoundFin() {
    if (this._myControler.isSound()) {
      AudioClip clip;

      clip = Applet.newAudioClip(getClass().getResource("/resources/sons/applaudissements.wav"));
      clip.play();
    }
  }
Example #3
0
  /*
   * Joue un son lors du lancer
   */
  public void playSoundDe() {
    if (this._myControler.isSound()) {
      AudioClip clip;

      clip = Applet.newAudioClip(getClass().getResource("/resources/sons/dé_roulant.wav"));
      clip.play();
    }
  }
Example #4
0
  public static AudioClip reproducirSonido(AudioClip sonido, boolean loop) {
    if (loop) {
      sonido.loop();
    }

    sonido.play();

    return sonido;
  }
Example #5
0
    public void playDestroyRows(int rows) {
      int soundid = rows - 1;
      if (0 > soundid || soundid >= destroyRowSounds.length || destroyRowSounds[soundid] == null)
        return;

      soundTrack.stop();
      destroyRowSounds[soundid].play();
      soundTrack.stop();
      destroyRowSounds[soundid].play();
      soundTrack.stop();
      destroyRowSounds[soundid].play();
      soundTrack.play();
    }
 /**
  * Plays an audio file (in .wav, .mid, or .au format) in a loop in a background thread.
  *
  * @param filename the name of the audio file
  */
 public void loop(String filename) {
   URL url = null;
   try {
     File file = new File(filename);
     if (file.canRead()) url = file.toURI().toURL();
   } catch (MalformedURLException e) {
     e.printStackTrace();
   }
   // URL url = StdAudio.class.getResource(filename);
   if (url == null) throw new RuntimeException("audio " + filename + " not found");
   AudioClip clip = Applet.newAudioClip(url);
   clip.loop();
 }
Example #7
0
  public void win() {
    timer.stop();

    backgroundMusic.stop();
    winMusic = Applet.newAudioClip(getCompleteURL("Victory Fanfare.wav"));
    winMusic.play();
    JOptionPane.showMessageDialog(
        panel,
        "You have successfully marked all of Fabear's possible hiding spots!\n"
            + "He is now being sent to the lab for further analysis.\n"
            + "Hopefully our hero will once again be himself.",
        "Game Over",
        JOptionPane.INFORMATION_MESSAGE);
    System.exit(0);
  }
Example #8
0
 private GObject checkCorner(double x, double y) {
   GObject obj = getElementAt(x, y); // check the corner for GObject
   if (obj == paddle) {
     vy = -Math.abs(vy);
     PrecisionPaddle();
   } else if (obj != null && obj != lifeCount) { // check if the ball hits a brick
     remove(obj);
     vy = -1.05 * vy;
     vx = 1.05 * vx;
     brickCount--;
     AudioClip bounceClip = MediaTools.loadAudioClip("bounce.au");
     bounceClip.play();
   }
   return obj;
 }
 public void checkEnemyCollision() {
   for (Enemy e : enemyList) {
     if (e.getOnScreen()) { // can be removed later on
       // goes through all the enemies and checks if they collide
       if (e.checkCollision(e.getPics().get(e.getCounter()), player1)) {
         if (player1.getInvi() == false) {
           // If the player is not invisble then you get spiked.
           if (player1.getVelocity() > 0) { // if the player hits it from the bottom
             player1.setSpikeVelo();
             loseCoins();
           } else {
             player1.setVelo(
                 50); // if the player is on top instead the player bounces off the enemy
             if (musicOn) {
               bounce.play();
             }
           }
         }
         eRemove.add(e); // once we hit, we remove the enemy
       }
     } else {
       eRemove.add(e); // if the enemy goes of the screen, we remove
     }
   }
   for (Enemy e : eRemove) {
     poofList.add(new Poof(e.getX(), e.getY(), 1)); // removes all the enemies
     enemyList.remove(e);
   }
   eRemove = new ArrayList<Enemy>();
 }
Example #10
0
  /**
   * Méthode qui joue un son aléatoirement dans le style 'manger' ou 'jouer'.
   *
   * @param n, un entier représentant 'jouer' ou 'manger'.
   */
  private void jouerSons(int n) {

    Random rnd = new Random(); // On créer un random
    int index = 0; // On initialise l'index à 0

    switch (n) {

        // Pour le cas ou le tamagoshi joue
      case 1:
        index =
            rnd.nextInt(
                this.hmManger
                    .size()); // On génère un nombre aléatoire pour prendre un son au hasard dans la
                              // hashmap
        this.clip = Applet.newAudioClip(getClass().getResource(this.hmManger.get(index)));
        break;

        // Pour le cas ou le tamagoshi mange
      case 2:
        index =
            rnd.nextInt(
                this.hmJouer
                    .size()); // On génère un nombre aléatoire pour prendre un son au hasard dans la
                              // hashmap
        this.clip = Applet.newAudioClip(getClass().getResource(this.hmJouer.get(index)));
        break;

      default:
        break;
    }

    clip.play(); // On lance l'audio
  }
 public void checkStarCollision() {
   for (Star s : starList) {
     if (s.getOnScreen()) { // if the star is on the screen we need to check if player collides
       if (s.checkCollision(
           s.getPics().get(s.getCounter()),
           player1)) { // if the player collides with the star we remove it then change the
         // velosity to the distance that the star provides
         sRemove.add(s); // remove star once you collide with it
         player1.setVelo(s.getDist()); // changes the velocity
         player1.setInvi(true); // sets the player invisble for a few seconds
         score += s.getPoints(); // points increase by the star type
         if (musicOn) {
           starSound.play(); // playthe star sound
         }
       }
     } else {
       sRemove.add(s); // remove the star if its not on the screen
     }
   }
   for (Star s : sRemove) {
     poofList.add(new Poof(s.getX(), s.getY(), s.getNum() + 3)); // make the poof effect
     starList.remove(s);
   }
   sRemove = new ArrayList<Star>();
 }
Example #12
0
  public Janela(int width, int height, GLCanvas canvas) throws IOException {
    animator = new FPSAnimator(canvas, 240);
    setSize(new Dimension(width, height));
    setLocationRelativeTo(null);
    setMinimumSize(getSize());
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    panel.add(canvas, BorderLayout.CENTER);
    getContentPane().add(panel);
    canvas.addGLEventListener(new GLWindow(panel, canvas));
    addWindowListener(
        new WindowAdapter() {

          @Override
          public void windowClosing(WindowEvent e) {
            super.windowClosing(
                e); // To change body of generated methods, choose Tools | Templates.
            animator.stop();
            System.out.println("Animação parou!");
          }
        });
    setExtendedState(JFrame.MAXIMIZED_BOTH);
    setVisible(true);
    JDInfo info = new JDInfo(this, true);
    info.setVisible(true);
    animator.start();
    clip = Applet.newAudioClip(new File("./resources/Cabin.wav").toURL());
    clip.loop();
  }
Example #13
0
  /* -------------------------------------------------------------*/
  private void objectCollision(ArrayList movingObjects) {
    for (int i = 0; i < movingObjects.size(); i++) {
      // make sure not testing if collided with yourself :P
      if (((SpaceObject) movingObjects.get(i)).getObjCount() != objectNum) {
        SpaceObject object = (SpaceObject) movingObjects.get(i);

        // find distance vector between two objects
        int x = pos_x - object.getXPos();
        int y = pos_y - object.getYPos();

        double distance = Math.sqrt(x * x + y * y);

        // has it collided with the object?
        if (distance < (radius + object.getRadius())) {
          // has it collided with a BULLET (or MISSILE)?
          if (object.isBullet()) {
            // do nothing
          }
          // is it another SPACESHIP? (INSTANT DEATH)
          else if (object.isSpaceShip()) {
            // do nothing
          }
          // collided with anything else (e.g PLANET): (INSTANT DEATH)
          else {
            collision.play();
            kill(movingObjects); // object has died
          }
        }
      }
    } // end for loop
  }
  private void playSound() {

    try {

      if (System.getProperty("os.name").contains("Mac")) {
        tester = new URL("file:///Users/DavidMac/Desktop/School/Pong1.1/pong.wav");
      } else {
        tester = new URL("file:///C:/Users/David/workspace/Pong/pong.wav");
      }
      AudioClip clip = Applet.newAudioClip(tester);

      clip.play();
    } catch (MalformedURLException murle) {
      System.out.println(murle);
    }
  }
Example #15
0
 /** Loop a sound file (in .wav or .au format) in a background thread. */
 public static void loop(String filename) {
   if (muted) {
     return;
   }
   URL url = null;
   try {
     File file = new File(filename);
     if (file.canRead()) url = file.toURI().toURL();
   } catch (MalformedURLException e) {
     e.printStackTrace();
   }
   // URL url = StdAudio.class.getResource(filename);
   if (url == null) throw new RuntimeException("audio " + filename + " not found");
   AudioClip clip = Applet.newAudioClip(url);
   clip.loop();
   notifyListeners(new AudioEvent(AudioEvent.Type.LOOP));
 }
 public static void playSound(String identifier) {
   /* to Play sound from identifier */
   switch (identifier) {
     case "menu":
       menuSong.play();
       break;
     case "shot":
       gunShot.play();
       break;
     case "reload":
       reload.play();
       break;
     case "kill":
       killSound.play();
       break;
     case "win":
       winSound.play();
       break;
     case "lose":
       enemy_winSound.play();
       break;
     case "game":
       gameSong.play();
       break;
     default:
       break;
   }
 }
  private void checkForCollision() {
    // check if ball has hit floor. If so, bounce it upwards.
    if (ball.getY() > getHeight() - DIAM_BALL) {
      bounceClip.play();
      yVel = -yVel * BOUNCE_REDUCE; // bounces back almost to BOUNCE_REDUCE * starting height

      // moves ball back above the floor the same distance it would have dropped below the floor in
      // same time
      double diff = ball.getY() - (getHeight() - DIAM_BALL);
      ball.move(0, -2 * diff);
    }
  }
Example #18
0
 public void onMousePress(Location point) {
   if (button.contains(point)) {
     startGame();
     munch.play();
   }
   if (yellow.contains(point)) {
     fishPic = yellowFishPic;
     munch.play();
   }
   if (pink.contains(point)) {
     fishPic = pinkFishPic;
     munch.play();
   }
   if (purple.contains(point)) {
     fishPic = purpleFishPic;
     munch.play();
   }
   if (green.contains(point)) {
     fishPic = greenFishPic;
     munch.play();
   }
   if (grey.contains(point)) {
     fishPic = greyFishPic;
     munch.play();
   }
 }
 public void keyPressed(KeyEvent k) {
   int keycode = k.getKeyCode();
   switch (keycode) {
     case KeyEvent.VK_LEFT:
       player.moveLeft();
       break;
     case KeyEvent.VK_RIGHT:
       player.moveRight();
     case KeyEvent.VK_SPACE:
       player.water();
       break;
     case KeyEvent.VK_ENTER:
       player.plantSeed();
       pickupAudio.play();
       break;
   }
 }
Example #20
0
  public BearSweeper() {
    super("BearSweeper");

    Container contentPane = getContentPane();
    panel = new DrawingPanel();
    contentPane.add(panel, BorderLayout.CENTER);

    timerOn = true;
    time = 0;
    timer = new Timer(100, new TimerEventHandler());

    Square.loadGraphics();
    addMenus();
    newGame();
    timer.start();

    // Loads and plays background music in a loop
    backgroundMusic = Applet.newAudioClip(getCompleteURL("background.wav"));
    backgroundMusic.loop();
  } // Constructor
 public void checkJumperCollision() {
   // same as all the other collsions
   for (Jumper j : jumperList) {
     if (j.getOnScreen()) { //
       if (j.checkCollision(j.getImage(), player1)) {
         player1.setVelo(50);
         player1.setDown(false);
         if (musicOn) {
           bounce.play();
         }
       }
     } else {
       jRemove.add(j);
     }
   }
   for (Jumper j : jRemove) {
     jumperList.remove(j);
   }
   jRemove = new ArrayList<Jumper>();
 }
Example #22
0
  public void startGame() {

    bread.loop();
    gameOn = true;
    yellow.removeFromCanvas();
    pink.removeFromCanvas();
    purple.removeFromCanvas();
    green.removeFromCanvas();
    grey.removeFromCanvas();
    button.removeFromCanvas();
    author.removeFromCanvas();
    title.removeFromCanvas();

    start = new Location(canvas.getWidth() / 2, canvas.getHeight() / 2);
    theFish = new TheFish(fishPic, start, canvas, 50, 25);
    ocean = new Ocean(angryFishPic, angryFishL, bubblePic, canvas, theFish);

    score = new Text("Score: " + currentScore, 0, 0, canvas);
    score.setFontSize(16);
    score.moveTo((canvas.getWidth() - score.getWidth()) / 2, 50);

    bubbles = new Bubbles(dopeBubble, canvas);
  }
  public void musicClicked() {
    // Mutes/unmutes music
    // checks to see if mute/unmute button is clicked
    if (muteB.clicked(mx, my, true) && pause == true && musicOn == true) {
      clickedSound();
      musicOn = false;
      clicked.stop();
      bckGrndMusic.stop();
      coinSound.stop();
      starSound.stop();
      bounce.stop();

    } else if (unmuteB.clicked(mx, my, true) && pause == true && musicOn == false) {
      clickedSound();
      musicOn = true;
      bckGrndMusic.loop();
    }
  }
 public void checkBoxCollision() { // pretty much the same thing as all the other collisions
   for (Box b : boxList) {
     if (b.getOnScreen()) { // checks if its on the screen
       if (b.checkCollision(b.getImage(), player1)) {
         player1.setVelo(50);
         player1.setDown(false);
         b.setPcount(
             b.getPcount() - 1); // sets the type to one less so then you can  bounce on it twice
         if (b.getPcount() == 0) {
           bRemove.add(b); // removes the box
         }
         if (musicOn) {
           bounce.play();
         }
       }
     } else {
       bRemove.add(b);
     }
   }
   for (Box b : bRemove) {
     boxList.remove(b);
   }
   bRemove = new ArrayList<Box>();
 }
 public void checkCoinCollision() {
   for (Coin c : coinList) {
     if (c.getOnScreen()) { // check if the coin is on the screen
       if (c.checkCollision(
           c.getPics().get(c.getCounter()), player1)) { // if the player collides with the coin
         cRemove.add(c); // remove the coin
         player1.setVelo(50); // set the velocity so the player moves up
         player1.setDown(false); // set the down false (players moving up)
         coins += c.getValue(); // check the coins collected
         score += c.getPoints(); // get the score
         if (musicOn) {
           coinSound.play(); // play the sound
         }
       }
     } else {
       cRemove.add(c); // remove the coin
     }
   }
   for (Coin c : cRemove) {
     poofList.add(new Poof(c.getX(), c.getY(), 0));
     coinList.remove(c);
   }
   cRemove = new ArrayList<Coin>();
 }
 private void playMusic(String nameOfSoundFile) {
   AudioClip sound = JApplet.newAudioClip(getClass().getResource(nameOfSoundFile));
   sound.play();
 }
Example #27
0
 public static void pararSonido(AudioClip sonido) {
   sonido.stop();
 }
 public void stop() {
   myClip.stop();
 }
 public void play() {
   myClip.play();
 }
 public void loop() {
   myClip.loop();
 }