From 38d1bdf14b1fd2c7c0c5d7a591a1f42d51880654 Mon Sep 17 00:00:00 2001 From: yugecin Date: Sun, 13 Nov 2016 02:10:09 +0100 Subject: [PATCH] cleanup the mess --- src/itdelatrisu/opsu/states/MainMenu.java | 83 ++++++++++++----------- 1 file changed, 42 insertions(+), 41 deletions(-) diff --git a/src/itdelatrisu/opsu/states/MainMenu.java b/src/itdelatrisu/opsu/states/MainMenu.java index fb94a394..aed55520 100644 --- a/src/itdelatrisu/opsu/states/MainMenu.java +++ b/src/itdelatrisu/opsu/states/MainMenu.java @@ -271,50 +271,23 @@ public class MainMenu extends BasicGameState { exitButton.draw(); } - float scale = 1f; - double position = 0; - double beatLength = 1; - int realtime = 1; + Double position = getBPMPiecePosition(); - if (MusicController.isPlaying() && MusicController.getBeatmap() != null) { - int trackposition = MusicController.getPosition(); - Beatmap map = MusicController.getBeatmap(); - TimingPoint p = null; - if (map.timingPoints != null) { - int time = 0; - float beatlen = 0f; - int i = 0; - for (TimingPoint pts : map.timingPoints) { - if (p == null || pts.getTime() < MusicController.getPosition()) { - i++; - p = pts; - if (!p.isInherited() && p.getBeatLength() > 0) { - beatlen = p.getBeatLength(); - time = p.getTime(); - } - } - } - if (p != null) { - beatLength = beatlen * 100; - realtime = trackposition * 100; - position = (((realtime/* - time * 100 idk.. */) % beatLength) / beatLength); - scale -= (0 - position) * 0.05; - } - } + if (position != null) { + double scale = 1 - (0 - position) * 0.05; + logo.draw(Color.white, (float) scale); + Image piece = GameImage.MENU_LOGO_PIECE.getImage(); + float xRadius = piece.getWidth() / 2; + float yRadius = piece.getHeight() / 2; + piece = piece.getScaledCopy(logo.getCurrentScale()); + float scaleposmodx = piece.getWidth() / 2 - xRadius; + float scaleposmody = piece.getHeight() / 2 - yRadius; + piece.rotate((float)(position * 360)); + piece.draw(logo.getX() - xRadius - scaleposmodx, logo.getY() - yRadius - scaleposmody); + } else { + logo.draw(); } - //scale = 1f; - logo.draw(Color.white, scale); - - Image piece = GameImage.MENU_LOGO_PIECE.getImage(); - float xRadius = piece.getWidth() / 2; - float yRadius = piece.getHeight() / 2; - piece = piece.getScaledCopy(logo.getCurrentScale()); - float scaleposmodx = piece.getWidth() / 2 - xRadius; - float scaleposmody = piece.getHeight() / 2 - yRadius; - piece.rotate((float)(position * 360)); - piece.draw(logo.getX() - xRadius - scaleposmodx, logo.getY() - yRadius - scaleposmody); - // draw music buttons if (MusicController.isPlaying()) musicPause.draw(); @@ -385,6 +358,34 @@ public class MainMenu extends BasicGameState { UI.draw(g); } + private Double getBPMPiecePosition() { + if (!MusicController.isPlaying() || MusicController.getBeatmap() == null) { + return null; + } + Beatmap map = MusicController.getBeatmap(); + if (map.timingPoints == null) { + return null; + } + int trackposition = MusicController.getPosition(); + TimingPoint p = null; + float beatlen = 0f; + //int time = 0; + for (TimingPoint pts : map.timingPoints) { + if (p == null || pts.getTime() < MusicController.getPosition()) { + p = pts; + if (!p.isInherited() && p.getBeatLength() > 0) { + beatlen = p.getBeatLength(); + //time = p.getTime(); + } + } + } + if (p == null) { + return null; + } + double beatLength = beatlen * 100; + return (((trackposition * 100/* - time * 100 idk.. */) % beatLength) / beatLength); + } + @Override public void update(GameContainer container, StateBasedGame game, int delta) throws SlickException {