Search in sources :

Example 11 with StaticSound

use of org.terasology.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.audio.StaticSound) PlaySoundEvent(org.terasology.audio.events.PlaySoundEvent) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 12 with StaticSound

use of org.terasology.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.audio.StaticSound) Vector3f(org.terasology.math.geom.Vector3f) PlaySoundEvent(org.terasology.audio.events.PlaySoundEvent) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 13 with StaticSound

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

the class CharacterSoundSystem method onEnterBlock.

@ReceiveEvent
public void onEnterBlock(OnEnterBlockEvent event, EntityRef entity, CharacterSoundComponent characterSounds) {
    // only play this sound if the feet hit the water
    if (event.getCharacterRelativePosition().y == 0 && characterSounds.lastSoundTime + MIN_TIME < time.getGameTimeInMs()) {
        boolean oldBlockIsLiquid = event.getOldBlock().isLiquid();
        boolean newBlockIsLiquid = event.getNewBlock().isLiquid();
        StaticSound sound = null;
        if (!oldBlockIsLiquid && newBlockIsLiquid) {
            sound = random.nextItem(characterSounds.enterWaterSounds);
        } else if (oldBlockIsLiquid && !newBlockIsLiquid) {
            sound = random.nextItem(characterSounds.leaveWaterSounds);
        }
        if (sound != null) {
            entity.send(new PlaySoundEvent(entity, sound, characterSounds.diveVolume));
            characterSounds.lastSoundTime = time.getGameTimeInMs();
            entity.saveComponent(characterSounds);
        }
    }
}
Also used : StaticSound(org.terasology.audio.StaticSound) PlaySoundEvent(org.terasology.audio.events.PlaySoundEvent) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 14 with StaticSound

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

the class BlockDamageAuthoritySystem method onPlayBlockDamageCommon.

private void onPlayBlockDamageCommon(BlockFamily family, Vector3f location, EntityRef entityRef) {
    createBlockParticleEffect(family, location);
    BlockSounds sounds = family.getArchetypeBlock().getSounds();
    if (!sounds.getDigSounds().isEmpty()) {
        StaticSound sound = random.nextItem(sounds.getDigSounds());
        entityRef.send(new PlaySoundEvent(sound, 1f));
    }
}
Also used : BlockSounds(org.terasology.world.block.sounds.BlockSounds) StaticSound(org.terasology.audio.StaticSound) PlaySoundEvent(org.terasology.audio.events.PlaySoundEvent)

Example 15 with StaticSound

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

the class HealthAuthoritySystem method onCrash.

@ReceiveEvent
public void onCrash(HorizontalCollisionEvent event, EntityRef entity, CharacterSoundComponent characterSounds, HealthComponent healthComponent) {
    Vector3f horizVelocity = new Vector3f(event.getVelocity());
    horizVelocity.y = 0;
    float velocity = horizVelocity.length();
    if (velocity > healthComponent.horizontalDamageSpeedThreshold) {
        if (characterSounds.lastSoundTime + CharacterSoundSystem.MIN_TIME < time.getGameTimeInMs()) {
            StaticSound sound = random.nextItem(characterSounds.landingSounds);
            if (sound != null) {
                entity.send(new PlaySoundEvent(sound, characterSounds.landingVolume));
                characterSounds.lastSoundTime = time.getGameTimeInMs();
                entity.saveComponent(characterSounds);
            }
        }
    }
}
Also used : StaticSound(org.terasology.audio.StaticSound) Vector3f(org.terasology.math.geom.Vector3f) PlaySoundEvent(org.terasology.audio.events.PlaySoundEvent) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Aggregations

StaticSound (org.terasology.audio.StaticSound)15 PlaySoundEvent (org.terasology.audio.events.PlaySoundEvent)13 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)13 Vector3f (org.terasology.math.geom.Vector3f)4 BlockSounds (org.terasology.world.block.sounds.BlockSounds)2 PlaySoundForOwnerEvent (org.terasology.audio.events.PlaySoundForOwnerEvent)1 EntityBuilder (org.terasology.entitySystem.entity.EntityBuilder)1 LocationComponent (org.terasology.logic.location.LocationComponent)1 Vector3i (org.terasology.math.geom.Vector3i)1 Block (org.terasology.world.block.Block)1 BlockDamageModifierComponent (org.terasology.world.block.entity.damage.BlockDamageModifierComponent)1