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);
}
}
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);
}
}
}
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);
}
}
}
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));
}
}
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);
}
}
}
}
Aggregations