Example usage for com.badlogic.gdx.audio Sound play

List of usage examples for com.badlogic.gdx.audio Sound play

Introduction

In this page you can find the example usage for com.badlogic.gdx.audio Sound play.

Prototype

public long play();

Source Link

Document

Plays the sound.

Usage

From source file:com.codefiddler.libgdx.spinit.level.Level.java

License:Apache License

public void doEnding() {
    int howManySegments = howManyWheelSegments();
    Sound sound = soundEffects.getSound(1);

    if (bottle.isFlyingOff()) {
        bottle.resetPosition();/*from  w  w  w  .  ja  v  a 2 s  .c  o m*/
    }

    for (int i = 0; i < howManySegments; i++) {
        if (bottleIsWithSegment(i, howManySegments, bottle.getRot())) {
            Segment tickSprite = tickSprites.get(i);
            if (tickSprite.getSelected()) {
                sound = soundEffects.getOpps(i);
            } else {
                sound = soundEffects.getSound(i);
            }
            tickSprite.toggleSelect();

            break;
        }
    }

    if (areAllTicksActive()) {
        sound = winnerSound();
        triggerEnding = 0;
    }
    ;

    sound.play();

}

From source file:com.cyphercove.dayinspace.shared.SpeakingLabel.java

License:Apache License

private void sound(final Sound sound) {
    addAction(run(new Runnable() {
        @Override//from ww  w.ja  v a2s.co m
        public void run() {
            sound.play();
        }
    }));
}

From source file:com.cyphercove.dayinspace.shared.SpeakingLabel.java

License:Apache License

private void sound(final Sound sound, final float delay) {
    if (delay == 0) {
        sound(sound);/* w  w  w .  jav a2s .  c om*/
        return;
    }

    addAction(sequence(delay(delay), run(new Runnable() {
        @Override
        public void run() {
            sound.play();
        }
    })));
}

From source file:com.gamestudio24.martianrun.utils.AudioUtils.java

License:Apache License

public void playSound(Sound sound) {
    boolean soundOn = getPreferences().getBoolean(SOUND_ON_PREFERENCE, true);
    if (soundOn) {
        sound.play();
    }/*from   ww  w  . j  a  va 2  s  . c om*/
}

From source file:com.mygdx.game.systems.PlayerSystem.java

License:Apache License

@Override
public void processEntity(Entity entity, float deltaTime) {
    TransformComponent t = tm.get(entity);
    StateComponent state = sm.get(entity);
    MovementComponent mov = mm.get(entity);
    PlayerComponent bob = bm.get(entity);
    if (state.get() != PlayerComponent.STATE_HEADBUTT) {
        if (Gdx.input.isKeyPressed(Keys.A)) {
            accelX = -200f;// w ww  . ja va 2s .co m
        } else if (Gdx.input.isKeyPressed(Keys.D)) {
            accelX = 200f;
        } else {
            accelX = 0;
        }
        if (Gdx.input.isKeyPressed(Keys.S)) {
            accelY = -200f;
        } else if (Gdx.input.isKeyPressed(Keys.W)) {
            accelY = 200f;
        } else {
            accelY = 0;
        }
        if (accelY == 0 && accelX == 0) {
            state.set(PlayerComponent.STATE_IDLE);
        } else {
            state.set(PlayerComponent.STATE_WALKING);
        }
        if (Gdx.input.isButtonPressed(Buttons.LEFT)) {
            state.set(PlayerComponent.STATE_HEADBUTT);
            Sound headbut = world.game.assetManager.get("Sound/headbut.mp3.mp3");
            headbut.play();
        }

        Vector2 playerPos = BossSystem.getDeepCopyCentralPos(entity);
        Vector3 mousePos = world.game.camera.unproject(new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0));
        Vector2 mousePos2 = new Vector2(mousePos.x, mousePos.y);
        t.rotation = mousePos2.sub(playerPos).angle();
    } else {
        // t.rotation needs to be locked
        Vector2 newVelocity = new Vector2(300, 0).rotate(t.rotation);
        this.accelX = newVelocity.x;
        this.accelY = newVelocity.y;
        headButtCooldown += deltaTime;
        if (headButtCooldown >= PlayerComponent.ATTACK_DURATION) {
            headButtCooldown = 0;
            state.set(PlayerComponent.STATE_IDLE);
        }

    }

    mov.velocity.set(accelX, accelY);
}

From source file:com.saltosion.gladiator.util.Jukebox.java

License:Open Source License

/**
 * Simply plays the sound//from  w ww  . j  a  v  a  2 s.  c o m
 *
 * @param sound
 * @return long returns sound's id
 */
public long playSound(Sound sound) {
    return sound.play();
}

From source file:dk.gruppeseks.bodtrd.managers.AudioPlayer.java

private void handleAudioTask(AssetManager am, AudioTask audioTask) {
    AudioAction audioAction = audioTask.getAudioAction();
    if (audioTask.getAudioType() == AudioType.SOUND) {

        Sound sound = am.get(audioTask.getFileName(), Sound.class);
        switch (audioAction) {
        case PLAY:
            sound.play();
            break;
        case RESUME:
            sound.resume();//from   ww w  . j a va2s .co  m
            break;
        case PAUSE:
            sound.pause();
            break;
        case STOP:
            sound.stop();
            break;
        case LOOP:
            sound.loop();
            break;
        case DISPOSE:
            sound.dispose();
            break;
        default:
            break;
        }
    } else {
        Music music = am.get(audioTask.getFileName(), Music.class);
        switch (audioAction) {
        case PLAY:
            music.play();
            break;
        case LOOP:
            music.play();
            music.setLooping(true);
            break;
        case PAUSE:
            music.pause();
            break;
        case STOP:
            music.stop();
            break;
        default:
            break;
        }
    }
}

From source file:gui.entity.bomb.CubicBomb.java

@Override
public void explode(Sound sound) {
    //cubic explosion for barrel and dynamite
    //own constant cubic explosion range [1,2,3]
    //dynamite max 2

    //To Execute the sound only once
    if (ExplodeAudioId == -1 && sound != null) {
        ExplodeAudioId = sound.play();
    }//from  w  w w  . j av a  2s.com

    Player player = entityManager.getPlayerManager().getCurrentPlayerObject();
    if (player != null && sound != null) {
        player.playSoundInDistance(sound, ExplodeAudioId, pos, Constants.CUBICBOMBEXPLOSIONMOD);
    }

    TiledMapTileLayer.Cell cell = new TiledMapTileLayer.Cell();
    cell.setTile(new StaticTiledMapTile(explosionCubic));
    cell.getTile().getProperties().put("deadly", null);

    for (int i = super.cellPos.getX() - cubicRange; i <= super.cellPos.getX() + cubicRange; i++) {
        for (int j = super.cellPos.getY() - cubicRange; j <= super.cellPos.getY() + cubicRange; j++) {
            map.getBombLayer().setCell(i, j, cell);
        }
    }

}

From source file:gui.entity.bomb.HomingBomb.java

@Override
public void explode(Sound sound) {
    //To Execute the sound only once
    if (ExplodeAudioId == -1) {
        ExplodeAudioId = sound.play();
    }/*from   w w w . ja  v a 2 s.  com*/

    Player player = entityManager.getPlayerManager().getCurrentPlayerObject();
    if (player != null && sound != null) {
        player.playSoundInDistance(sound, ExplodeAudioId, pos, Constants.NORMALBOMBEXPLOSIONMOD);
    }

    //Create new cell and set texture
    TiledMapTileLayer.Cell cellCenter = new TiledMapTileLayer.Cell();
    cellCenter.setTile(new StaticTiledMapTile(explosionCenter));
    cellCenter.getTile().getProperties().put("deadly", null);

    //Explosion center, replaces bomb texture
    map.getBombLayer().setCell(super.cellPos.getX(), super.cellPos.getY(), cellCenter);

    //Explode DOWN
    for (int y = 1; y <= explosionRange; y++) {
        //If explosion hits block
        if (map.isCellBlocked(new MapCellCoordinates(super.cellPos.getX(), super.cellPos.getY() - y))) {
            //Set ending texture and break out of loop
            TiledMapTileLayer.Cell cellDown = new TiledMapTileLayer.Cell();
            cellDown.setTile(new StaticTiledMapTile(explosionDownEnd));
            cellDown.getTile().getProperties().put("deadly", null);

            map.getBombLayer().setCell(super.cellPos.getX(), super.cellPos.getY() - y, cellDown);
            break;
        }

        if (y != explosionRange) // If not end of explosion
        {
            TiledMapTileLayer.Cell cell = new TiledMapTileLayer.Cell();
            cell.setTile(new StaticTiledMapTile(explosionYMiddle));
            cell.getTile().getProperties().put("deadly", null);

            map.getBombLayer().setCell(super.cellPos.getX(), super.cellPos.getY() - y, cell);
        } else {
            TiledMapTileLayer.Cell cellDown = new TiledMapTileLayer.Cell();
            cellDown.setTile(new StaticTiledMapTile(explosionDownEnd));
            cellDown.getTile().getProperties().put("deadly", null);

            map.getBombLayer().setCell(super.cellPos.getX(), super.cellPos.getY() - y, cellDown);
        }
    }

    //Explode UP
    for (int y = 1; y <= explosionRange; y++) {
        //If explosion hits block
        if (map.isCellBlocked(new MapCellCoordinates(cellPos.getX(), cellPos.getY() + y))) {
            //Set ending texture and break out of loop
            TiledMapTileLayer.Cell cellDown = new TiledMapTileLayer.Cell();
            cellDown.setTile(new StaticTiledMapTile(explosionUpEnd));
            cellDown.getTile().getProperties().put("deadly", null);

            map.getBombLayer().setCell(super.cellPos.getX(), super.cellPos.getY() + y, cellDown);
            break;
        }

        if (y != explosionRange) // If not end of explosion
        {
            TiledMapTileLayer.Cell cell = new TiledMapTileLayer.Cell();
            cell.setTile(new StaticTiledMapTile(explosionYMiddle));
            cell.getTile().getProperties().put("deadly", null);

            map.getBombLayer().setCell(super.cellPos.getX(), super.cellPos.getY() + y, cell);
        } else {
            //Set end of explosion
            TiledMapTileLayer.Cell cellUp = new TiledMapTileLayer.Cell();
            cellUp.setTile(new StaticTiledMapTile(explosionUpEnd));
            cellUp.getTile().getProperties().put("deadly", null);

            map.getBombLayer().setCell(super.cellPos.getX(), super.cellPos.getY() + y, cellUp);
        }
    }

    //Explode RIGHT
    for (int x = 1; x <= explosionRange; x++) {
        //If explosion hits block
        if (map.isCellBlocked(new MapCellCoordinates(cellPos.getX() + x, cellPos.getY()))) {
            //Set ending texture and break out of loop
            TiledMapTileLayer.Cell cellDown = new TiledMapTileLayer.Cell();
            cellDown.setTile(new StaticTiledMapTile(explosionRightEnd));
            cellDown.getTile().getProperties().put("deadly", null);

            map.getBombLayer().setCell(super.cellPos.getX() + x, super.cellPos.getY(), cellDown);
            break;
        }

        if (x != explosionRange) // If not end of explosion
        {
            //Set cell with middle explosion texture
            TiledMapTileLayer.Cell cell = new TiledMapTileLayer.Cell();
            cell.setTile(new StaticTiledMapTile(explosionXMiddle));
            cell.getTile().getProperties().put("deadly", null);

            map.getBombLayer().setCell(super.cellPos.getX() + x, super.cellPos.getY(), cell);

        } else {
            //Set end of explosion
            TiledMapTileLayer.Cell cellRight = new TiledMapTileLayer.Cell();
            cellRight.setTile(new StaticTiledMapTile(explosionRightEnd));
            cellRight.getTile().getProperties().put("deadly", null);

            map.getBombLayer().setCell(super.cellPos.getX() + x, super.cellPos.getY(), cellRight);
        }
    }

    //Explode LEFT
    for (int x = 1; x <= explosionRange; x++) {
        //If explosion hits block
        if (map.isCellBlocked(new MapCellCoordinates(cellPos.getX() - x, cellPos.getY()))) {
            //Set ending texture and break out of loop
            TiledMapTileLayer.Cell cellDown = new TiledMapTileLayer.Cell();
            cellDown.setTile(new StaticTiledMapTile(explosionLeftEnd));
            cellDown.getTile().getProperties().put("deadly", null);

            map.getBombLayer().setCell(super.cellPos.getX() - x, super.cellPos.getY(), cellDown);
            break;
        }

        if (x != explosionRange) // If not end of explosion
        {
            //Set cell with middle explosion texture
            TiledMapTileLayer.Cell cell = new TiledMapTileLayer.Cell();
            cell.setTile(new StaticTiledMapTile(explosionXMiddle));
            cell.getTile().getProperties().put("deadly", null);

            map.getBombLayer().setCell(super.cellPos.getX() - x, super.cellPos.getY(), cell);

        } else {
            TiledMapTileLayer.Cell cellLeft = new TiledMapTileLayer.Cell();
            cellLeft.setTile(new StaticTiledMapTile(explosionLeftEnd));
            cellLeft.getTile().getProperties().put("deadly", null);

            map.getBombLayer().setCell(super.cellPos.getX() - x, super.cellPos.getY(), cellLeft);
        }
    }
}

From source file:gui.entity.bomb.Mine.java

@Override
protected void explode(Sound sound) {
    //To Execute the sound only once
    if (ExplodeAudioId == -1) {
        ExplodeAudioId = sound.play();
    }//  ww  w  .ja v  a2  s  .  c o  m

    Player player = entityManager.getPlayerManager().getCurrentPlayerObject();
    if (player != null && sound != null) {
        player.playSoundInDistance(sound, ExplodeAudioId, pos, Constants.NORMALBOMBEXPLOSIONMOD);
    }

    //Create new cell and set texture
    TiledMapTileLayer.Cell cellCenter = new TiledMapTileLayer.Cell();
    cellCenter.setTile(new StaticTiledMapTile(explosionCenter));
    cellCenter.getTile().getProperties().put("deadly", null);

    //Explosion center, replaces bomb texture
    map.getBombLayer().setCell(super.cellPos.getX(), super.cellPos.getY(), cellCenter);

    //Explode DOWN
    for (int y = 1; y <= explosionRange; y++) {
        //If explosion hits block
        if (map.isCellBlocked(new MapCellCoordinates(super.cellPos.getX(), super.cellPos.getY() - y))) {
            //Set ending texture and break out of loop
            TiledMapTileLayer.Cell cellDown = new TiledMapTileLayer.Cell();
            cellDown.setTile(new StaticTiledMapTile(explosionDownEnd));
            cellDown.getTile().getProperties().put("deadly", null);

            map.getBombLayer().setCell(super.cellPos.getX(), super.cellPos.getY() - y, cellDown);
            break;
        }

        if (y != explosionRange) // If not end of explosion
        {
            TiledMapTileLayer.Cell cell = new TiledMapTileLayer.Cell();
            cell.setTile(new StaticTiledMapTile(explosionYMiddle));
            cell.getTile().getProperties().put("deadly", null);

            map.getBombLayer().setCell(super.cellPos.getX(), super.cellPos.getY() - y, cell);
        } else {
            TiledMapTileLayer.Cell cellDown = new TiledMapTileLayer.Cell();
            cellDown.setTile(new StaticTiledMapTile(explosionDownEnd));
            cellDown.getTile().getProperties().put("deadly", null);

            map.getBombLayer().setCell(super.cellPos.getX(), super.cellPos.getY() - y, cellDown);
        }
    }

    //Explode UP
    for (int y = 1; y <= explosionRange; y++) {
        //If explosion hits block
        if (map.isCellBlocked(new MapCellCoordinates(cellPos.getX(), cellPos.getY() + y))) {
            //Set ending texture and break out of loop
            TiledMapTileLayer.Cell cellDown = new TiledMapTileLayer.Cell();
            cellDown.setTile(new StaticTiledMapTile(explosionUpEnd));
            cellDown.getTile().getProperties().put("deadly", null);

            map.getBombLayer().setCell(super.cellPos.getX(), super.cellPos.getY() + y, cellDown);
            break;
        }

        if (y != explosionRange) // If not end of explosion
        {
            TiledMapTileLayer.Cell cell = new TiledMapTileLayer.Cell();
            cell.setTile(new StaticTiledMapTile(explosionYMiddle));
            cell.getTile().getProperties().put("deadly", null);

            map.getBombLayer().setCell(super.cellPos.getX(), super.cellPos.getY() + y, cell);
        } else {
            //Set end of explosion
            TiledMapTileLayer.Cell cellUp = new TiledMapTileLayer.Cell();
            cellUp.setTile(new StaticTiledMapTile(explosionUpEnd));
            cellUp.getTile().getProperties().put("deadly", null);

            map.getBombLayer().setCell(super.cellPos.getX(), super.cellPos.getY() + y, cellUp);
        }
    }

    //Explode RIGHT
    for (int x = 1; x <= explosionRange; x++) {
        //If explosion hits block
        if (map.isCellBlocked(new MapCellCoordinates(cellPos.getX() + x, cellPos.getY()))) {
            //Set ending texture and break out of loop
            TiledMapTileLayer.Cell cellDown = new TiledMapTileLayer.Cell();
            cellDown.setTile(new StaticTiledMapTile(explosionRightEnd));
            cellDown.getTile().getProperties().put("deadly", null);

            map.getBombLayer().setCell(super.cellPos.getX() + x, super.cellPos.getY(), cellDown);
            break;
        }

        if (x != explosionRange) // If not end of explosion
        {
            //Set cell with middle explosion texture
            TiledMapTileLayer.Cell cell = new TiledMapTileLayer.Cell();
            cell.setTile(new StaticTiledMapTile(explosionXMiddle));
            cell.getTile().getProperties().put("deadly", null);

            map.getBombLayer().setCell(super.cellPos.getX() + x, super.cellPos.getY(), cell);

        } else {
            //Set end of explosion
            TiledMapTileLayer.Cell cellRight = new TiledMapTileLayer.Cell();
            cellRight.setTile(new StaticTiledMapTile(explosionRightEnd));
            cellRight.getTile().getProperties().put("deadly", null);

            map.getBombLayer().setCell(super.cellPos.getX() + x, super.cellPos.getY(), cellRight);
        }
    }

    //Explode LEFT
    for (int x = 1; x <= explosionRange; x++) {
        //If explosion hits block
        if (map.isCellBlocked(new MapCellCoordinates(cellPos.getX() - x, cellPos.getY()))) {
            //Set ending texture and break out of loop
            TiledMapTileLayer.Cell cellDown = new TiledMapTileLayer.Cell();
            cellDown.setTile(new StaticTiledMapTile(explosionLeftEnd));
            cellDown.getTile().getProperties().put("deadly", null);

            map.getBombLayer().setCell(super.cellPos.getX() - x, super.cellPos.getY(), cellDown);
            break;
        }

        if (x != explosionRange) // If not end of explosion
        {
            //Set cell with middle explosion texture
            TiledMapTileLayer.Cell cell = new TiledMapTileLayer.Cell();
            cell.setTile(new StaticTiledMapTile(explosionXMiddle));
            cell.getTile().getProperties().put("deadly", null);

            map.getBombLayer().setCell(super.cellPos.getX() - x, super.cellPos.getY(), cell);

        } else {
            TiledMapTileLayer.Cell cellLeft = new TiledMapTileLayer.Cell();
            cellLeft.setTile(new StaticTiledMapTile(explosionLeftEnd));
            cellLeft.getTile().getProperties().put("deadly", null);

            map.getBombLayer().setCell(super.cellPos.getX() - x, super.cellPos.getY(), cellLeft);
        }
    }
}