Added star fountains to main menu.
- Added MusicController methods to get measure progress (similar to beat progress). - Workaround for inaccurate track positions after looping by not looping. - Make sure star duration is positive. Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
85
src/itdelatrisu/opsu/ui/StarFountain.java
Normal file
85
src/itdelatrisu/opsu/ui/StarFountain.java
Normal file
@@ -0,0 +1,85 @@
|
||||
package itdelatrisu.opsu.ui;
|
||||
|
||||
import itdelatrisu.opsu.GameImage;
|
||||
import itdelatrisu.opsu.ui.animations.AnimatedValue;
|
||||
import itdelatrisu.opsu.ui.animations.AnimationEquation;
|
||||
|
||||
import org.newdawn.slick.Image;
|
||||
|
||||
/**
|
||||
* Star fountain consisting of two star streams.
|
||||
*/
|
||||
public class StarFountain {
|
||||
/** The (approximate) number of stars in each burst. */
|
||||
private static final int BURST_SIZE = 80;
|
||||
|
||||
/** Star streams. */
|
||||
private final StarStream left, right;
|
||||
|
||||
/** Burst progress. */
|
||||
private final AnimatedValue burstProgress = new AnimatedValue(800, 0, 1, AnimationEquation.LINEAR);
|
||||
|
||||
/**
|
||||
* Initializes the star fountain.
|
||||
* @param containerWidth the container width
|
||||
* @param containerHeight the container height
|
||||
*/
|
||||
public StarFountain(int containerWidth, int containerHeight) {
|
||||
Image img = GameImage.STAR2.getImage();
|
||||
float xDir = containerWidth * 0.4f, yDir = containerHeight * 0.75f;
|
||||
this.left = new StarStream(-img.getWidth(), containerHeight, xDir, -yDir, 0);
|
||||
this.right = new StarStream(containerWidth, containerHeight, -xDir, -yDir, 0);
|
||||
setStreamProperties(left);
|
||||
setStreamProperties(right);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets attributes for the given star stream.
|
||||
*/
|
||||
private void setStreamProperties(StarStream stream) {
|
||||
stream.setDirectionSpread(60f);
|
||||
stream.setDurationSpread(1100, 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the star fountain.
|
||||
*/
|
||||
public void draw() {
|
||||
left.draw();
|
||||
right.draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the stars in the fountain by a delta interval.
|
||||
* @param delta the delta interval since the last call
|
||||
*/
|
||||
public void update(int delta) {
|
||||
left.update(delta);
|
||||
right.update(delta);
|
||||
if (burstProgress.update(delta)) {
|
||||
int size = Math.round((float) delta / burstProgress.getDuration() * BURST_SIZE);
|
||||
left.burst(size);
|
||||
right.burst(size);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a burst of stars to be processed during the next {@link #update(int)} call.
|
||||
* @param wait if {@code true}, will not burst if a previous burst is in progress
|
||||
*/
|
||||
public void burst(boolean wait) {
|
||||
if (wait && (burstProgress.getTime() < burstProgress.getDuration() || !left.isEmpty() || !right.isEmpty()))
|
||||
return;
|
||||
|
||||
burstProgress.setTime(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the stars currently in the fountain.
|
||||
*/
|
||||
public void clear() {
|
||||
left.clear();
|
||||
right.clear();
|
||||
burstProgress.setTime(burstProgress.getDuration());
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,7 @@ import java.util.Random;
|
||||
import org.newdawn.slick.Image;
|
||||
|
||||
/**
|
||||
* Horizontal star stream.
|
||||
* Star stream.
|
||||
*/
|
||||
public class StarStream {
|
||||
/** The origin of the star stream. */
|
||||
@@ -196,7 +196,7 @@ public class StarStream {
|
||||
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(durationBase, durationSpread));
|
||||
int duration = Math.max(0, (int) (distanceRatio * getGaussian(durationBase, durationSpread)));
|
||||
AnimationEquation eqn = random.nextBoolean() ? AnimationEquation.IN_OUT_QUAD : AnimationEquation.OUT_QUAD;
|
||||
|
||||
return new Star(offset, dir, angle, duration, eqn);
|
||||
@@ -216,6 +216,11 @@ public class StarStream {
|
||||
*/
|
||||
public void clear() { stars.clear(); }
|
||||
|
||||
/**
|
||||
* Returns whether there are any stars currently in this stream.
|
||||
*/
|
||||
public boolean isEmpty() { return stars.isEmpty(); }
|
||||
|
||||
/**
|
||||
* Returns the next pseudorandom, Gaussian ("normally") distributed {@code double} value
|
||||
* with the given mean and standard deviation.
|
||||
|
||||
Reference in New Issue
Block a user