Search in sources :

Example 1 with StaticSound

use of org.terasology.engine.audio.StaticSound in project Terasology by MovingBlocks.

the class PlaySoundAction method onActivationPredicted.

/**
 * This method plays sound in prediction for preventing not playing song because of server lags
 *
 * @param event contains the details for the predicted event, used here for location purposes
 * @param entity is source of the playsound
 */
@ReceiveEvent(components = PlaySoundActionComponent.class)
public void onActivationPredicted(ActivationPredicted event, EntityRef entity) {
    PlaySoundActionComponent playSound = entity.getComponent(PlaySoundActionComponent.class);
    StaticSound sound = random.nextItem(playSound.sounds);
    if (sound != null) {
        Vector3f pos;
        switch(playSound.relativeTo) {
            case Target:
                pos = event.getTargetLocation();
                break;
            default:
                pos = event.getInstigatorLocation();
                break;
        }
        if (pos == null) {
            pos = event.getOrigin();
        }
        audioManager.playSound(sound, pos, playSound.volume, AudioManager.PRIORITY_NORMAL);
    }
}
Also used : StaticSound(org.terasology.engine.audio.StaticSound) Vector3f(org.joml.Vector3f) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 2 with StaticSound

use of org.terasology.engine.audio.StaticSound in project Terasology by MovingBlocks.

the class CharacterSoundSystem method onJump.

@ReceiveEvent
public void onJump(JumpEvent event, EntityRef entity, CharacterSoundComponent characterSounds) {
    if (characterSounds.lastSoundTime + MIN_TIME < time.getGameTimeInMs()) {
        StaticSound sound = null;
        if (characterSounds.jumpSounds.size() > 0) {
            sound = random.nextItem(characterSounds.jumpSounds);
        } else if (characterSounds.footstepSounds.size() > 0) {
            sound = random.nextItem(characterSounds.footstepSounds);
        }
        if (sound != null) {
            entity.send(new PlaySoundEvent(entity, sound, characterSounds.jumpVolume));
            characterSounds.lastSoundTime = time.getGameTimeInMs();
            entity.saveComponent(characterSounds);
        }
    }
}
Also used : StaticSound(org.terasology.engine.audio.StaticSound) PlaySoundEvent(org.terasology.engine.audio.events.PlaySoundEvent) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 3 with StaticSound

use of org.terasology.engine.audio.StaticSound in project Terasology by MovingBlocks.

the class CharacterSoundSystem method onDeath.

@ReceiveEvent
public void onDeath(DoDestroyEvent event, EntityRef entity, CharacterSoundComponent characterSounds) {
    if (characterSounds.deathSounds.size() > 0) {
        StaticSound sound = random.nextItem(characterSounds.deathSounds);
        entity.send(new PlaySoundEvent(entity, sound, characterSounds.deathVolume));
    }
}
Also used : StaticSound(org.terasology.engine.audio.StaticSound) PlaySoundEvent(org.terasology.engine.audio.events.PlaySoundEvent) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 4 with StaticSound

use of org.terasology.engine.audio.StaticSound in project Terasology by MovingBlocks.

the class CharacterSoundSystem method onLanded.

@ReceiveEvent
public void onLanded(VerticalCollisionEvent event, EntityRef entity, CharacterSoundComponent characterSounds) {
    Vector3f velocity = event.getVelocity();
    float soundVolumeModifier = (velocity.y * -1 - LANDING_VELOCITY_THRESHOLD) * LANDING_VOLUME_MODIFIER;
    if (soundVolumeModifier <= 0f) {
        return;
    }
    if (soundVolumeModifier > LANDING_VOLUME_MAX) {
        soundVolumeModifier = LANDING_VOLUME_MAX;
    }
    if (characterSounds.lastSoundTime + MIN_TIME < time.getGameTimeInMs()) {
        StaticSound sound = null;
        if (characterSounds.landingSounds.size() > 0) {
            sound = random.nextItem(characterSounds.landingSounds);
        } else if (characterSounds.footstepSounds.size() > 0) {
            sound = random.nextItem(characterSounds.footstepSounds);
        }
        if (sound != null) {
            entity.send(new PlaySoundEvent(entity, sound, characterSounds.landingVolume * soundVolumeModifier));
            characterSounds.lastSoundTime = time.getGameTimeInMs();
            entity.saveComponent(characterSounds);
        }
    }
}
Also used : StaticSound(org.terasology.engine.audio.StaticSound) Vector3f(org.joml.Vector3f) PlaySoundEvent(org.terasology.engine.audio.events.PlaySoundEvent) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 5 with StaticSound

use of org.terasology.engine.audio.StaticSound in project Terasology by MovingBlocks.

the class CharacterSoundSystem method onSwimStroke.

@ReceiveEvent
public void onSwimStroke(SwimStrokeEvent event, EntityRef entity, CharacterSoundComponent characterSounds) {
    if (characterSounds.swimSounds.size() > 0 && characterSounds.lastSoundTime + MIN_TIME < time.getGameTimeInMs()) {
        StaticSound sound = random.nextItem(characterSounds.swimSounds);
        entity.send(new PlaySoundEvent(entity, sound, characterSounds.swimmingVolume));
        characterSounds.lastSoundTime = time.getGameTimeInMs();
        entity.saveComponent(characterSounds);
    }
}
Also used : StaticSound(org.terasology.engine.audio.StaticSound) PlaySoundEvent(org.terasology.engine.audio.events.PlaySoundEvent) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Aggregations

StaticSound (org.terasology.engine.audio.StaticSound)11 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)10 PlaySoundEvent (org.terasology.engine.audio.events.PlaySoundEvent)9 Vector3f (org.joml.Vector3f)4 Vector3i (org.joml.Vector3i)1 EntityBuilder (org.terasology.engine.entitySystem.entity.EntityBuilder)1 LocationComponent (org.terasology.engine.logic.location.LocationComponent)1 Block (org.terasology.engine.world.block.Block)1 BlockDamageModifierComponent (org.terasology.engine.world.block.entity.damage.BlockDamageModifierComponent)1 BlockSounds (org.terasology.engine.world.block.sounds.BlockSounds)1