mainmenu: make logo movement animation changing fluent

This commit is contained in:
yugecin 2018-07-07 01:43:33 +02:00
parent a9d8e10ff5
commit be97bcbead
No known key found for this signature in database
GPG Key ID: 2C5AC035A7068E44

View File

@ -88,7 +88,8 @@ public class MainMenu extends BaseOpsuState {
private int logoTimer = 0; private int logoTimer = 0;
/** Logo horizontal offset for opening and closing actions. */ /** Logo horizontal offset for opening and closing actions. */
private AnimatedValue logoOpen, logoClose; private AnimatedValue logoPosition;
private float logoPositionOffsetX;
/** Logo button alpha levels. */ /** Logo button alpha levels. */
private AnimatedValue logoButtonAlpha; private AnimatedValue logoButtonAlpha;
@ -254,9 +255,8 @@ public class MainMenu extends BaseOpsuState {
starFountain = new StarFountain(displayContainer.width, displayContainer.height); starFountain = new StarFountain(displayContainer.width, displayContainer.height);
// logo animations // logo animations
float centerOffsetX = displayContainer.width / 6.5f; logoPositionOffsetX = 0.4f * MENU_LOGO.getImage().getHeight();
logoOpen = new AnimatedValue(100, 0, centerOffsetX, AnimationEquation.OUT_QUAD); logoPosition = new AnimatedValue(1, 0, 1, AnimationEquation.OUT_QUAD);
logoClose = new AnimatedValue(2200, centerOffsetX, 0, AnimationEquation.OUT_QUAD);
logoButtonAlpha = new AnimatedValue(200, 0f, 1f, AnimationEquation.LINEAR); logoButtonAlpha = new AnimatedValue(200, 0f, 1f, AnimationEquation.LINEAR);
} }
@ -491,8 +491,8 @@ public class MainMenu extends BaseOpsuState {
case DEFAULT: case DEFAULT:
break; break;
case OPENING: case OPENING:
if (logoOpen.update(delta)) // shifting to left if (logoPosition.update(delta)) // shifting to left
logo.setX(centerX - logoOpen.getValue()); logo.setX(centerX - logoPosition.getValue());
else { else {
logoState = LogoState.OPEN; logoState = LogoState.OPEN;
logoTimer = 0; logoTimer = 0;
@ -505,11 +505,10 @@ public class MainMenu extends BaseOpsuState {
playButton.getImage().setAlpha(currentLogoButtonAlpha); playButton.getImage().setAlpha(currentLogoButtonAlpha);
exitButton.getImage().setAlpha(currentLogoButtonAlpha); exitButton.getImage().setAlpha(currentLogoButtonAlpha);
} else if (logoTimer >= LOGO_IDLE_DELAY) { // timer over: shift back to center } else if (logoTimer >= LOGO_IDLE_DELAY) { // timer over: shift back to center
logoState = LogoState.CLOSING; this.closeLogo();
logoClose.setTime(0); } else {
logoTimer = 0;
} else // increment timer
logoTimer += delta; logoTimer += delta;
}
break; break;
case CLOSING: case CLOSING:
if (logoButtonAlpha.update(-delta)) { // fade out buttons if (logoButtonAlpha.update(-delta)) { // fade out buttons
@ -517,8 +516,8 @@ public class MainMenu extends BaseOpsuState {
playButton.getImage().setAlpha(currentLogoButtonAlpha); playButton.getImage().setAlpha(currentLogoButtonAlpha);
exitButton.getImage().setAlpha(currentLogoButtonAlpha); exitButton.getImage().setAlpha(currentLogoButtonAlpha);
} }
if (logoClose.update(delta)) // shifting to right if (logoPosition.update(-delta)) // shifting to right
logo.setX(centerX - logoClose.getValue()); logo.setX(centerX - logoPosition.getValue());
break; break;
} }
@ -550,8 +549,7 @@ public class MainMenu extends BaseOpsuState {
super.enter(); super.enter();
logo.setX(displayContainer.width / 2); logo.setX(displayContainer.width / 2);
logoOpen.setTime(0); logoPosition.setTime(0);
logoClose.setTime(0);
logoButtonAlpha.setTime(0); logoButtonAlpha.setTime(0);
nowPlayingPosition.setTime(0); nowPlayingPosition.setTime(0);
logoTimer = 0; logoTimer = 0;
@ -712,11 +710,7 @@ public class MainMenu extends BaseOpsuState {
// start moving logo (if clicked) // start moving logo (if clicked)
if (logoState == LogoState.DEFAULT || logoState == LogoState.CLOSING) { if (logoState == LogoState.DEFAULT || logoState == LogoState.CLOSING) {
if (logo.contains(x, y, 0.25f)) { if (logo.contains(x, y, 0.25f)) {
logoState = LogoState.OPENING; this.openLogo();
logoOpen.setTime(0);
logoTimer = 0;
playButton.getImage().setAlpha(0f);
exitButton.getImage().setAlpha(0f);
SoundController.playSound(SoundEffect.MENUHIT); SoundController.playSound(SoundEffect.MENUHIT);
return true; return true;
} }
@ -756,9 +750,7 @@ public class MainMenu extends BaseOpsuState {
case KEY_ESCAPE: case KEY_ESCAPE:
case KEY_Q: case KEY_Q:
if (logoTimer > 0) { if (logoTimer > 0) {
logoState = LogoState.CLOSING; this.closeLogo();
logoClose.setTime(0);
logoTimer = 0;
break; break;
} }
buttonState.setMenuState(MenuState.EXIT); buttonState.setMenuState(MenuState.EXIT);
@ -767,13 +759,10 @@ public class MainMenu extends BaseOpsuState {
case KEY_P: case KEY_P:
SoundController.playSound(SoundEffect.MENUHIT); SoundController.playSound(SoundEffect.MENUHIT);
if (logoState == LogoState.DEFAULT || logoState == LogoState.CLOSING) { if (logoState == LogoState.DEFAULT || logoState == LogoState.CLOSING) {
logoState = LogoState.OPENING; this.openLogo();
logoOpen.setTime(0); } else {
logoTimer = 0;
playButton.getImage().setAlpha(0f);
exitButton.getImage().setAlpha(0f);
} else
enterSongMenu(); enterSongMenu();
}
return true; return true;
case KEY_D: case KEY_D:
SoundController.playSound(SoundEffect.MENUHIT); SoundController.playSound(SoundEffect.MENUHIT);
@ -839,6 +828,19 @@ public class MainMenu extends BaseOpsuState {
displayContainer.switchState(state); displayContainer.switchState(state);
} }
private void openLogo() {
logoPosition.change(100, 0, logoPositionOffsetX, OUT_QUAD);
logoState = LogoState.OPENING;
logoTimer = 0;
playButton.getImage().setAlpha(0f);
exitButton.getImage().setAlpha(0f);
}
private void closeLogo() {
logoPosition.change(2200, 0, logoPositionOffsetX, IN_QUAD);
logoState = LogoState.CLOSING;
}
private static class PulseData { private static class PulseData {
private int position; private int position;
private float initialScale; private float initialScale;