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

View File

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

View File

@ -20,6 +20,7 @@ package itdelatrisu.opsu.ui;
import itdelatrisu.opsu.GameImage;
import itdelatrisu.opsu.Utils;
import itdelatrisu.opsu.objects.curves.Vec2f;
import itdelatrisu.opsu.ui.animations.AnimatedValue;
import itdelatrisu.opsu.ui.animations.AnimationEquation;
@ -34,8 +35,17 @@ import org.newdawn.slick.Image;
* Horizontal star stream.
*/
public class StarStream {
/** The container dimensions. */
private final int containerWidth, containerHeight;
/** The origin of the star stream. */
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. */
private final Image starImg;
@ -51,25 +61,31 @@ public class StarStream {
/** Contains data for a single 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. */
private final AnimatedValue animatedValue;
/** The star properties. */
private final int distance, yOffset, angle;
/**
* 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 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
*/
public Star(int duration, int distance, int yOffset, int angle, AnimationEquation eqn) {
this.animatedValue = new AnimatedValue(duration, 0f, 1f, eqn);
this.distance = distance;
this.yOffset = yOffset;
public Star(Vec2f offset, Vec2f direction, int angle, int duration, AnimationEquation eqn) {
this.offset = offset;
this.dir = direction;
this.angle = angle;
this.animatedValue = new AnimatedValue(duration, 0f, 1f, eqn);
}
/**
@ -79,8 +95,9 @@ public class StarStream {
float t = animatedValue.getValue();
starImg.setImageColor(1f, 1f, 1f, Math.min((1 - t) * 5f, 1f));
starImg.drawEmbedded(
containerWidth - (distance * t), ((containerHeight - starImg.getHeight()) / 2) + yOffset,
starImg.getWidth(), starImg.getHeight(), angle);
offset.x + t * dir.x, offset.y + t * dir.y,
starImg.getWidth(), starImg.getHeight(), angle
);
}
/**
@ -93,12 +110,19 @@ public class StarStream {
/**
* Initializes the star stream.
* @param width the container width
* @param height the container height
* @param x the x position
* @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) {
this.containerWidth = width;
this.containerHeight = height;
public StarStream(float x, float y, float dirX, float dirY, float posSpread, float dirSpread) {
this.position = new Vec2f(x, y);
this.direction = new Vec2f(dirX, dirY);
this.positionSpread = posSpread;
this.directionSpread = dirSpread;
this.starImg = GameImage.STAR2.getImage().copy();
this.stars = new ArrayList<Star>();
this.random = new Random();
@ -120,8 +144,9 @@ public class StarStream {
/**
* Updates the stars in the stream by a delta interval.
* @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
Iterator<Star> iter = stars.iterator();
while (iter.hasNext()) {
@ -131,22 +156,39 @@ public class StarStream {
}
// create new stars
for (int i = stars.size(); i < MAX_STARS; i++) {
if (Math.random() < ((i < 5) ? 0.25 : 0.66))
break;
if (createNew) {
for (int i = stars.size(); i < MAX_STARS; i++) {
if (Math.random() < ((i < 5) ? 0.25 : 0.66))
break;
// generate star properties
float distanceRatio = Utils.clamp((float) getGaussian(0.65, 0.25), 0.2f, 0.925f);
int distance = (int) (containerWidth * distanceRatio);
int duration = (int) (distanceRatio * getGaussian(1300, 300));
int yOffset = (int) getGaussian(0, containerHeight / 20);
int angle = (int) getGaussian(0, 22.5);
AnimationEquation eqn = random.nextBoolean() ? AnimationEquation.IN_OUT_QUAD : AnimationEquation.OUT_QUAD;
stars.add(new Star(duration, distance, yOffset, angle, eqn));
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);
Vec2f offset = position.cpy().add(direction.cpy().nor().normalize().scale((float) getGaussian(0, positionSpread)));
Vec2f dir = direction.cpy().scale(distanceRatio).add((float) getGaussian(0, directionSpread), (float) getGaussian(0, directionSpread));
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;
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());
}
/**
* Clears the stars currently in the stream.
*/