/** * 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 }
/* -------------------------------------------------------------*/ 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 }
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>(); }
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>(); }
/* * 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(); } }
/* * 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(); } }
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; } }
public static AudioClip reproducirSonido(AudioClip sonido, boolean loop) { if (loop) { sonido.loop(); } sonido.play(); return sonido; }
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); } }
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 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 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(); }
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 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); }
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); } }
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; } }
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>(); }
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>(); }
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 static void start(String file) throws IOException { URL songPath = new URL(BASE + file); AudioClip song = Applet.newAudioClip(songPath); song.play(); }
public void play() { myClip.play(); }
public void play() { if (clip != null) clip.play(); }
public void turn() { if (turningClip != null) { turningClip.play(); } }
private void playSound(String fileName) { AudioClip sound = JApplet.newAudioClip(getClass().getResource(fileName)); sound.play(); }
public void playAudioClip(Integer key) { AudioClip audioClip = audioClips.get(key); if (audioClip != null) { audioClip.play(); } }
public void clickedSound() { // plays button sound when button is clicked if (musicOn) { clicked.play(); } }
public synchronized void play() { if (audioClip != null) audioClip.play(); }
public void playGameOverSound() { if (gameOverSound == null) return; gameOverSound.play(); }
private void playMusic(String nameOfSoundFile) { AudioClip sound = JApplet.newAudioClip(getClass().getResource(nameOfSoundFile)); sound.play(); }
public static void playSound(String fileName) { AudioClip audioClip = JApplet.newAudioClip(new DontForgetTheLyrics().getClass().getResource(fileName)); audioClip.play(); }