Make music pitch and speed go down on fail (like in osu!)

This commit is contained in:
MatteoS
2015-11-16 14:30:49 +01:00
parent 06c423a4dd
commit 13e0bdb81e
3 changed files with 59 additions and 4 deletions

View File

@@ -98,7 +98,19 @@ public class Music {
private boolean positioning;
/** The position that was requested */
private float requiredPosition = -1;
/** The pitch of this music */
private float pitch = 1.0f;
/** Start pitch for fading pitch */
private float pitchStart;
/** End pitch for fading pitch */
private float pitchEnd;
/** Countdown for fading pitch */
private int pitchTime;
/** Duration for fading pitch */
private int pitchDuration;
/**
* Create and load a piece of music (either OGG or MOD/XM)
*
@@ -373,6 +385,17 @@ public class Music {
SoundStore.get().setCurrentMusicVolume(volume);
}
}
/**
* Set the pitch of the music as a factor of it's normal pitch
*
* @param pitch The pitch to play music at.
*/
public void setPitch(float pitch) {
this.pitch = pitch;
if (currentMusic == this) {
SoundStore.get().setMusicPitch(pitch);
}
}
/**
* Get the individual volume of the music
@@ -397,6 +420,19 @@ public class Music {
fadeTime = duration;
}
/**
* Fade the pitch and speed of this music to the pitch specified
*
* @param duration Pitch fade time in milliseconds
* @param endPitch The target pitch (and speed)
*/
public void pitchFade (int duration, float endPitch) {
pitchStart = pitch;
pitchEnd = endPitch;
pitchDuration = duration;
pitchTime = duration;
}
/**
* Update the current music applying any effects that need to updated per
* tick.
@@ -421,6 +457,15 @@ public class Music {
float offset = (fadeEndGain - fadeStartGain) * (1 - (fadeTime / (float)fadeDuration));
setVolume(fadeStartGain + offset);
}
if (pitchTime > 0) {
pitchTime -= delta;
if (pitchTime < 0) {
pitchTime = 0;
}
float offset = (pitchEnd - pitchStart) * (1 - (pitchTime / (float)pitchDuration));
setPitch(pitchStart + offset);
}
}
/**