private void playMovementSound() { if (_godMode) return; if ((MathHelper.fastAbs(_velocity.x) > 0.01 || MathHelper.fastAbs(_velocity.z) > 0.01) && _touchingGround) { if (_currentFootstepSound == null) { Vector3d playerDirection = directionOfReferencePoint(); _currentFootstepSound = _footstepSounds[ MathHelper.fastAbs(_parent.getWorldProvider().getRandom().randomInt()) % 5]; _currentFootstepSound.playAsSoundEffect( 0.7f + (float) MathHelper.fastAbs(_parent.getWorldProvider().getRandom().randomDouble()) * 0.3f, 0.2f + (float) MathHelper.fastAbs(_parent.getWorldProvider().getRandom().randomDouble()) * 0.2f, false, (float) playerDirection.x, (float) playerDirection.y, (float) playerDirection.z); } else { long timeDiff = Terasology.getInstance().getTime() - _lastFootStepSoundPlayed; if (!_currentFootstepSound.isPlaying() && timeDiff > 400 / (_activeWalkingSpeed / _walkingSpeed)) { _lastFootStepSoundPlayed = Terasology.getInstance().getTime(); _currentFootstepSound = null; } } } }
public void update(int delta) { if (enabled) { if (musicPlaying == null) { musicDelay -= delta; if (musicDelay <= 0) { musicPlaying = music.get((int) (Math.random() * music.size())); musicPlaying.playAsMusic(1.0f, 1.0f, false); soundStore.setSoundVolume(0.5f); } } else if (!soundStore.isMusicPlaying()) { musicPlaying.stop(); musicDelay = (int) (Math.random() * 90000) + 30000; musicPlaying = null; soundStore.setSoundVolume(0.75f); } if (ambientMusicPlaying == null) { ambientMusicDelay -= delta; if (ambientMusicDelay <= 0) { ambientMusicPlaying = ambientMusic.get((int) (Math.random() * ambientMusic.size())); ambientMusicPlaying.playAsSoundEffect(1.0f, (float) Math.random() * 0.2f + 1f, false); } } else if (!ambientMusicPlaying.isPlaying()) { ambientMusicPlaying.stop(); ambientMusicDelay = (int) (Math.random() * 6000) + 1000; ambientMusicPlaying = null; } if (ambientNoisePlaying[0] == null) { ambientNoiseDelay[0] -= delta; if (ambientNoiseDelay[0] <= 0) { ambientNoisePlaying[0] = ambientNoise.get((int) (Math.random() * ambientNoise.size())); ambientNoisePlaying[0].playAsSoundEffect(1.0f, (float) Math.random() * 0.2f + 1f, false); } } else if (!ambientNoisePlaying[0].isPlaying()) { ambientNoisePlaying[0].stop(); ambientNoiseDelay[0] = (int) (Math.random() * 16000) + 1000; ambientNoisePlaying[0] = null; } if (ambientNoisePlaying[1] == null) { ambientNoiseDelay[1] -= delta; if (ambientNoiseDelay[1] <= 0) { ambientNoisePlaying[1] = ambientNoise.get((int) (Math.random() * ambientNoise.size())); ambientNoisePlaying[1].playAsSoundEffect(1.0f, (float) Math.random() * 0.2f + 1f, false); } } else if (!ambientNoisePlaying[1].isPlaying()) { ambientNoisePlaying[1].stop(); ambientNoiseDelay[1] = (int) (Math.random() * 16000) + 1000; ambientNoisePlaying[1] = null; } soundStore.poll(delta); } }