public void HitByRain() { if (m_distortState == DistortState.NONE) { m_distortState = DistortState.FALLING; rainSound = Sound.PlayCue("rain"); } else { m_distortRestoreDelay = k_rainRestoreDelay; //if (m_distortState != DistortState.FALLING) //{ // if (rainSound != null) // { // rainSound.Stop(AudioStopOptions.AsAuthored); // rainSound = null; // } //} } }
private void UpdateDistortion(float elapsedTime) { bool init = (m_lastDistortState != m_distortState); m_lastDistortState = m_distortState; m_distortedPosition += m_distortedVel * elapsedTime; switch (m_distortState) { case DistortState.NONE: if (init) { m_distortedVel = 0.0f; m_distortedPosition = 0.0f; } break; case DistortState.FALLING: if (init) { m_distortedVel = k_distortedFallVel; } if (m_distortedPosition >= k_distortAmount) { m_distortedPosition = k_distortAmount; m_distortState = DistortState.FALLEN; } break; case DistortState.FALLEN: if (init) { m_distortRestoreDelay = k_rainRestoreDelay; m_distortedVel = 0.0f; } m_distortRestoreDelay -= elapsedTime; if (m_distortRestoreDelay <= 0.0f) { m_distortState = DistortState.RISING; if (rainSound != null) { rainSound.Stop(AudioStopOptions.AsAuthored); rainSound = null; } } break; case DistortState.RISING: if (init) { m_distortedVel = k_distortedResetVel; } if (m_distortedPosition < 0.0f) { m_distortState = DistortState.NONE; m_distortedPosition = 0.0f; } break; } VertexColor = Color.Lerp(Color.White, Color.CornflowerBlue, MathUtils.Clamp(m_distortedPosition / k_distortAmount, 0.0f, 1.0f)); }