コード例 #1
0
ファイル: TamaJPanel.java プロジェクト: julien34/Tamagoshi
  /**
   * 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
  }
コード例 #2
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
  }
コード例 #3
0
 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>();
 }
コード例 #4
0
 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>();
 }
コード例 #5
0
ファイル: YamModele.java プロジェクト: ncoutenet/Yams
  /*
   * 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();
    }
  }
コード例 #6
0
ファイル: YamModele.java プロジェクト: ncoutenet/Yams
  /*
   * 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();
    }
  }
コード例 #7
0
 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;
   }
 }
コード例 #8
0
  public static AudioClip reproducirSonido(AudioClip sonido, boolean loop) {
    if (loop) {
      sonido.loop();
    }

    sonido.play();

    return sonido;
  }
コード例 #9
0
  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);
    }
  }
コード例 #10
0
ファイル: SquareFishy.java プロジェクト: mtkent/MunchyFish
 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();
   }
 }
コード例 #11
0
ファイル: Tetris.java プロジェクト: akash-vartak/Tetris
    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();
    }
コード例 #12
0
 /**
  * Plays an audio file (in .wav, .mid, or .au format) in a background thread.
  *
  * @param filename the name of the audio file
  */
 public void play(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.play();
 }
コード例 #13
0
ファイル: Breakout_Extension.java プロジェクト: czptv/CS106A
 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;
 }
コード例 #14
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);
  }
コード例 #15
0
  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);
    }
  }
コード例 #16
0
 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;
   }
 }
コード例 #17
0
 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>();
 }
コード例 #18
0
 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>();
 }
コード例 #19
0
 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>();
 }
コード例 #20
0
ファイル: AudioFilePlayer.java プロジェクト: pashri/CS1332
  public static void start(String file) throws IOException {
    URL songPath = new URL(BASE + file);
    AudioClip song = Applet.newAudioClip(songPath);

    song.play();
  }
コード例 #21
0
 public void play() {
   myClip.play();
 }
コード例 #22
0
 public void play() {
   if (clip != null) clip.play();
 }
コード例 #23
0
ファイル: SoundEffects.java プロジェクト: yxbook/swingsource
 public void turn() {
   if (turningClip != null) {
     turningClip.play();
   }
 }
コード例 #24
0
ファイル: CowTimer.java プロジェクト: Love4653/Level-0
 private void playSound(String fileName) {
   AudioClip sound = JApplet.newAudioClip(getClass().getResource(fileName));
   sound.play();
 }
コード例 #25
0
ファイル: MainWindow.java プロジェクト: mpatric/lurgee
 public void playAudioClip(Integer key) {
   AudioClip audioClip = audioClips.get(key);
   if (audioClip != null) {
     audioClip.play();
   }
 }
コード例 #26
0
 public void clickedSound() {
   // plays button sound when button is clicked
   if (musicOn) {
     clicked.play();
   }
 }
コード例 #27
0
  public synchronized void play() {

    if (audioClip != null) audioClip.play();
  }
コード例 #28
0
ファイル: Tetris.java プロジェクト: akash-vartak/Tetris
 public void playGameOverSound() {
   if (gameOverSound == null) return;
   gameOverSound.play();
 }
コード例 #29
0
 private void playMusic(String nameOfSoundFile) {
   AudioClip sound = JApplet.newAudioClip(getClass().getResource(nameOfSoundFile));
   sound.play();
 }
コード例 #30
0
 public static void playSound(String fileName) {
   AudioClip audioClip =
       JApplet.newAudioClip(new DontForgetTheLyrics().getClass().getResource(fileName));
   audioClip.play();
 }