Star stream updates. (mad-s/opsu@701ef796)

- Make StarStream directional.
- Burst stars when score rank increases.
This commit is contained in:
Jeffrey Han 2016-12-23 00:40:36 -05:00
parent 81c8a61bb8
commit 8a7b67b578
3 changed files with 96 additions and 34 deletions

View File

@ -50,6 +50,7 @@ import itdelatrisu.opsu.replay.ReplayFrame;
import itdelatrisu.opsu.ui.Colors; import itdelatrisu.opsu.ui.Colors;
import itdelatrisu.opsu.ui.Fonts; import itdelatrisu.opsu.ui.Fonts;
import itdelatrisu.opsu.ui.MenuButton; import itdelatrisu.opsu.ui.MenuButton;
import itdelatrisu.opsu.ui.StarStream;
import itdelatrisu.opsu.ui.UI; import itdelatrisu.opsu.ui.UI;
import itdelatrisu.opsu.ui.animations.AnimationEquation; import itdelatrisu.opsu.ui.animations.AnimationEquation;
@ -277,6 +278,9 @@ public class Game extends BasicGameState {
/** The current alpha of the scoreboard. */ /** The current alpha of the scoreboard. */
private float currentScoreboardAlpha; private float currentScoreboardAlpha;
/** The star stream shown when passing another score. */
private StarStream scoreboardStarStream;
/** Music position bar background colors. */ /** Music position bar background colors. */
private static final Color private static final Color
MUSICBAR_NORMAL = new Color(12, 9, 10, 0.25f), MUSICBAR_NORMAL = new Color(12, 9, 10, 0.25f),
@ -314,6 +318,13 @@ public class Game extends BasicGameState {
musicBarWidth = Math.max(width * 0.005f, 7); musicBarWidth = Math.max(width * 0.005f, 7);
musicBarHeight = height * 0.9f; musicBarHeight = height * 0.9f;
// initialize scoreboard star stream
scoreboardStarStream = new StarStream(
0, height * 2f / 3f,
width / 3, 0,
height / 20, 0.2f
);
// create the associated GameData object // create the associated GameData object
data = new GameData(width, height); data = new GameData(width, height);
} }
@ -597,6 +608,7 @@ public class Game extends BasicGameState {
ScoreData currentScore = data.getCurrentScoreData(beatmap, true); ScoreData currentScore = data.getCurrentScoreData(beatmap, true);
while (currentRank > 0 && previousScores[currentRank - 1].score < currentScore.score) { while (currentRank > 0 && previousScores[currentRank - 1].score < currentScore.score) {
currentRank--; currentRank--;
scoreboardStarStream.burst(20);
lastRankUpdateTime = trackPosition; lastRankUpdateTime = trackPosition;
} }
@ -605,6 +617,9 @@ public class Game extends BasicGameState {
); );
int scoreboardPosition = 2 * container.getHeight() / 3; int scoreboardPosition = 2 * container.getHeight() / 3;
// draw star stream behind the scores
scoreboardStarStream.draw();
if (currentRank < 4) { if (currentRank < 4) {
// draw the (new) top 5 ranks // draw the (new) top 5 ranks
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
@ -687,6 +702,7 @@ public class Game extends BasicGameState {
playbackSpeed.getButton().hoverUpdate(delta, mouseX, mouseY); playbackSpeed.getButton().hoverUpdate(delta, mouseX, mouseY);
int trackPosition = MusicController.getPosition(); int trackPosition = MusicController.getPosition();
int firstObjectTime = beatmap.objects[0].getTime(); int firstObjectTime = beatmap.objects[0].getTime();
scoreboardStarStream.update(delta, false);
// returning from pause screen: must click previous mouse position // returning from pause screen: must click previous mouse position
if (pauseTime > -1) { if (pauseTime > -1) {

View File

@ -451,7 +451,11 @@ public class SongMenu extends BasicGameState {
}); });
// star stream // star stream
starStream = new StarStream(width, height); starStream = new StarStream(
width, (height - GameImage.STAR.getImage().getHeight()) / 2,
-width, 0,
height / 20f, 0.1f
);
} }
@Override @Override
@ -766,7 +770,7 @@ public class SongMenu extends BasicGameState {
} }
// star stream // star stream
starStream.update(delta); starStream.update(delta, true);
// search // search
search.setFocus(true); search.setFocus(true);

View File

@ -20,6 +20,7 @@ package itdelatrisu.opsu.ui;
import itdelatrisu.opsu.GameImage; import itdelatrisu.opsu.GameImage;
import itdelatrisu.opsu.Utils; import itdelatrisu.opsu.Utils;
import itdelatrisu.opsu.objects.curves.Vec2f;
import itdelatrisu.opsu.ui.animations.AnimatedValue; import itdelatrisu.opsu.ui.animations.AnimatedValue;
import itdelatrisu.opsu.ui.animations.AnimationEquation; import itdelatrisu.opsu.ui.animations.AnimationEquation;
@ -34,8 +35,17 @@ import org.newdawn.slick.Image;
* Horizontal star stream. * Horizontal star stream.
*/ */
public class StarStream { public class StarStream {
/** The container dimensions. */ /** The origin of the star stream. */
private final int containerWidth, containerHeight; private Vec2f position;
/** The direction of the star stream. */
private Vec2f direction;
/** The spread of the stars' starting position. */
private float positionSpread;
/** The spread of the stars' direction. */
private float directionSpread;
/** The star image. */ /** The star image. */
private final Image starImg; private final Image starImg;
@ -51,25 +61,31 @@ public class StarStream {
/** Contains data for a single star. */ /** Contains data for a single star. */
private class Star { private class Star {
/** The star position offset. */
private final Vec2f offset;
/** The star direction vector. */
private final Vec2f dir;
/** The star image rotation angle. */
private final int angle;
/** The star animation progress. */ /** The star animation progress. */
private final AnimatedValue animatedValue; private final AnimatedValue animatedValue;
/** The star properties. */
private final int distance, yOffset, angle;
/** /**
* Creates a star with the given properties. * Creates a star with the given properties.
* @param offset the position offset vector
* @param direction the direction vector
* @param angle the image rotation angle
* @param duration the time, in milliseconds, to show the star * @param duration the time, in milliseconds, to show the star
* @param distance the distance for the star to travel in {@code duration}
* @param yOffset the vertical offset from the center of the container
* @param angle the rotation angle
* @param eqn the animation equation to use * @param eqn the animation equation to use
*/ */
public Star(int duration, int distance, int yOffset, int angle, AnimationEquation eqn) { public Star(Vec2f offset, Vec2f direction, int angle, int duration, AnimationEquation eqn) {
this.animatedValue = new AnimatedValue(duration, 0f, 1f, eqn); this.offset = offset;
this.distance = distance; this.dir = direction;
this.yOffset = yOffset;
this.angle = angle; this.angle = angle;
this.animatedValue = new AnimatedValue(duration, 0f, 1f, eqn);
} }
/** /**
@ -79,8 +95,9 @@ public class StarStream {
float t = animatedValue.getValue(); float t = animatedValue.getValue();
starImg.setImageColor(1f, 1f, 1f, Math.min((1 - t) * 5f, 1f)); starImg.setImageColor(1f, 1f, 1f, Math.min((1 - t) * 5f, 1f));
starImg.drawEmbedded( starImg.drawEmbedded(
containerWidth - (distance * t), ((containerHeight - starImg.getHeight()) / 2) + yOffset, offset.x + t * dir.x, offset.y + t * dir.y,
starImg.getWidth(), starImg.getHeight(), angle); starImg.getWidth(), starImg.getHeight(), angle
);
} }
/** /**
@ -93,12 +110,19 @@ public class StarStream {
/** /**
* Initializes the star stream. * Initializes the star stream.
* @param width the container width * @param x the x position
* @param height the container height * @param y the y position
* @param dirX the x-axis direction
* @param dirY the y-axis direction
* @param posSpread the spread of the stars' starting position
* @param dirSpread the spread of the stars' direction
*/ */
public StarStream(int width, int height) { public StarStream(float x, float y, float dirX, float dirY, float posSpread, float dirSpread) {
this.containerWidth = width; this.position = new Vec2f(x, y);
this.containerHeight = height; this.direction = new Vec2f(dirX, dirY);
this.positionSpread = posSpread;
this.directionSpread = dirSpread;
this.starImg = GameImage.STAR2.getImage().copy(); this.starImg = GameImage.STAR2.getImage().copy();
this.stars = new ArrayList<Star>(); this.stars = new ArrayList<Star>();
this.random = new Random(); this.random = new Random();
@ -120,8 +144,9 @@ public class StarStream {
/** /**
* Updates the stars in the stream by a delta interval. * Updates the stars in the stream by a delta interval.
* @param delta the delta interval since the last call * @param delta the delta interval since the last call
* @param createNew whether to spawn new stars
*/ */
public void update(int delta) { public void update(int delta, boolean createNew) {
// update current stars // update current stars
Iterator<Star> iter = stars.iterator(); Iterator<Star> iter = stars.iterator();
while (iter.hasNext()) { while (iter.hasNext()) {
@ -131,20 +156,37 @@ public class StarStream {
} }
// create new stars // create new stars
if (createNew) {
for (int i = stars.size(); i < MAX_STARS; i++) { for (int i = stars.size(); i < MAX_STARS; i++) {
if (Math.random() < ((i < 5) ? 0.25 : 0.66)) if (Math.random() < ((i < 5) ? 0.25 : 0.66))
break; break;
// generate star properties stars.add(createStar());
}
}
}
/**
* Creates a new star with randomized properties.
*/
private Star createStar() {
float distanceRatio = Utils.clamp((float) getGaussian(0.65, 0.25), 0.2f, 0.925f); float distanceRatio = Utils.clamp((float) getGaussian(0.65, 0.25), 0.2f, 0.925f);
int distance = (int) (containerWidth * distanceRatio); Vec2f offset = position.cpy().add(direction.cpy().nor().normalize().scale((float) getGaussian(0, positionSpread)));
int duration = (int) (distanceRatio * getGaussian(1300, 300)); Vec2f dir = direction.cpy().scale(distanceRatio).add((float) getGaussian(0, directionSpread), (float) getGaussian(0, directionSpread));
int yOffset = (int) getGaussian(0, containerHeight / 20);
int angle = (int) getGaussian(0, 22.5); int angle = (int) getGaussian(0, 22.5);
int duration = (int) (distanceRatio * getGaussian(1300, 300));
AnimationEquation eqn = random.nextBoolean() ? AnimationEquation.IN_OUT_QUAD : AnimationEquation.OUT_QUAD; AnimationEquation eqn = random.nextBoolean() ? AnimationEquation.IN_OUT_QUAD : AnimationEquation.OUT_QUAD;
stars.add(new Star(duration, distance, yOffset, angle, eqn)); return new Star(offset, dir, angle, duration, eqn);
} }
/**
* Creates a burst of stars instantly.
* @param count the number of stars to create
*/
public void burst(int count) {
for (int i = 0; i < count; i++)
stars.add(createStar());
} }
/** /**