Follow-up to #37.
- Removed 'currentObject' parameter from HitObject.draw() since it's no longer used. - Changed "spun out" rpm. - Formatting changes. Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
parent
f4d17b9148
commit
4718cb9aa5
|
@ -18,14 +18,14 @@
|
||||||
|
|
||||||
package itdelatrisu.opsu;
|
package itdelatrisu.opsu;
|
||||||
|
|
||||||
|
import itdelatrisu.opsu.audio.SoundController;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
|
|
||||||
import itdelatrisu.opsu.audio.SoundController;
|
|
||||||
|
|
||||||
import org.newdawn.slick.Animation;
|
import org.newdawn.slick.Animation;
|
||||||
import org.newdawn.slick.Color;
|
import org.newdawn.slick.Color;
|
||||||
import org.newdawn.slick.GameContainer;
|
import org.newdawn.slick.GameContainer;
|
||||||
|
|
|
@ -79,7 +79,7 @@ public class Circle implements HitObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(int trackPosition, boolean currentObject, Graphics g) {
|
public void draw(Graphics g, int trackPosition) {
|
||||||
int timeDiff = hitObject.getTime() - trackPosition;
|
int timeDiff = hitObject.getTime() - trackPosition;
|
||||||
|
|
||||||
if (timeDiff >= 0) {
|
if (timeDiff >= 0) {
|
||||||
|
|
|
@ -26,11 +26,10 @@ import org.newdawn.slick.Graphics;
|
||||||
public interface HitObject {
|
public interface HitObject {
|
||||||
/**
|
/**
|
||||||
* Draws the hit object to the graphics context.
|
* Draws the hit object to the graphics context.
|
||||||
* @param trackPosition the current track position
|
|
||||||
* @param currentObject true if this is the current hit object
|
|
||||||
* @param g the graphics context
|
* @param g the graphics context
|
||||||
|
* @param trackPosition the current track position
|
||||||
*/
|
*/
|
||||||
public void draw(int trackPosition, boolean currentObject, Graphics g);
|
public void draw(Graphics g, int trackPosition);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the hit object.
|
* Updates the hit object.
|
||||||
|
|
|
@ -143,7 +143,7 @@ public class Slider implements HitObject {
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@Override
|
@Override
|
||||||
public void draw(int trackPosition, boolean currentObject, Graphics g) {
|
public void draw(Graphics g, int trackPosition) {
|
||||||
int timeDiff = hitObject.getTime() - trackPosition;
|
int timeDiff = hitObject.getTime() - trackPosition;
|
||||||
float scale = timeDiff / (float) game.getApproachTime();
|
float scale = timeDiff / (float) game.getApproachTime();
|
||||||
float approachScale = 1 + scale * 3;
|
float approachScale = 1 + scale * 3;
|
||||||
|
@ -158,7 +158,7 @@ public class Slider implements HitObject {
|
||||||
curve.draw();
|
curve.draw();
|
||||||
|
|
||||||
// ticks
|
// ticks
|
||||||
if (currentObject && ticksT != null) {
|
if (timeDiff < 0 && ticksT != null) {
|
||||||
Image tick = GameImage.SLIDER_TICK.getImage();
|
Image tick = GameImage.SLIDER_TICK.getImage();
|
||||||
for (int i = 0; i < ticksT.length; i++) {
|
for (int i = 0; i < ticksT.length; i++) {
|
||||||
float[] c = curve.pointAt(ticksT[i]);
|
float[] c = curve.pointAt(ticksT[i]);
|
||||||
|
|
|
@ -40,19 +40,15 @@ public class Spinner implements HitObject {
|
||||||
/** Container dimensions. */
|
/** Container dimensions. */
|
||||||
private static int width, height;
|
private static int width, height;
|
||||||
|
|
||||||
|
|
||||||
// Currently it takes about 200ms to spin up (4 * 50)
|
|
||||||
/** The number of rotation velocities to store. */
|
/** The number of rotation velocities to store. */
|
||||||
|
// note: currently takes about 200ms to spin up (4 * 50)
|
||||||
private static final int MAX_ROTATION_VELOCITIES = 50;
|
private static final int MAX_ROTATION_VELOCITIES = 50;
|
||||||
|
|
||||||
/** The amount of time in ms before another velocity is stored */
|
/** The amount of time, in milliseconds, before another velocity is stored. */
|
||||||
private static final int DELTA_UPDATE_TIME = 4;
|
private static final int DELTA_UPDATE_TIME = 4;
|
||||||
|
|
||||||
/** The amount of time in ms to fade in the spinner*/
|
/** The amount of time, in milliseconds, to fade in the spinner. */
|
||||||
private static final float FADE_IN_TIME = 500;
|
private static final int FADE_IN_TIME = 500;
|
||||||
|
|
||||||
/** The remaining amount of time that was not used */
|
|
||||||
private int deltaOverflow;
|
|
||||||
|
|
||||||
/** PI constants. */
|
/** PI constants. */
|
||||||
private static final float TWO_PI = (float) (Math.PI * 2);
|
private static final float TWO_PI = (float) (Math.PI * 2);
|
||||||
|
@ -69,12 +65,15 @@ public class Spinner implements HitObject {
|
||||||
/** The current number of rotations. */
|
/** The current number of rotations. */
|
||||||
private float rotations = 0f;
|
private float rotations = 0f;
|
||||||
|
|
||||||
/** The current rotation to draw */
|
/** The current rotation to draw. */
|
||||||
private float drawRotation = 0f;
|
private float drawRotation = 0f;
|
||||||
|
|
||||||
/** The total number of rotations needed to clear the spinner. */
|
/** The total number of rotations needed to clear the spinner. */
|
||||||
private float rotationsNeeded;
|
private float rotationsNeeded;
|
||||||
|
|
||||||
|
/** The remaining amount of time that was not used. */
|
||||||
|
private int deltaOverflow;
|
||||||
|
|
||||||
/** The sum of all the velocities in storedVelocities. */
|
/** The sum of all the velocities in storedVelocities. */
|
||||||
private float sumVelocity = 0f;
|
private float sumVelocity = 0f;
|
||||||
|
|
||||||
|
@ -112,30 +111,29 @@ public class Spinner implements HitObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(int trackPosition, boolean currentObject, Graphics g) {
|
public void draw(Graphics g, int trackPosition) {
|
||||||
|
// only draw spinners shortly before start time
|
||||||
int timeDiff = hitObject.getTime() - trackPosition;
|
int timeDiff = hitObject.getTime() - trackPosition;
|
||||||
boolean spinnerComplete = (rotations >= rotationsNeeded);
|
if (timeDiff - FADE_IN_TIME > 0)
|
||||||
|
|
||||||
// only draw spinners if
|
|
||||||
if (timeDiff - FADE_IN_TIME > 0 )
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
boolean spinnerComplete = (rotations >= rotationsNeeded);
|
||||||
|
|
||||||
// darken screen
|
// darken screen
|
||||||
float alpha = Utils.clamp(1 - timeDiff / FADE_IN_TIME, 0f, 1f);
|
float alpha = Utils.clamp(1 - (float) timeDiff / FADE_IN_TIME, 0f, 1f);
|
||||||
if (timeDiff > 0) {
|
float oldAlpha = Utils.COLOR_BLACK_ALPHA.a;
|
||||||
Color c = new Color(Utils.COLOR_BLACK_ALPHA);
|
if (timeDiff > 0)
|
||||||
c.a *= alpha;
|
Utils.COLOR_BLACK_ALPHA.a *= alpha;
|
||||||
g.setColor(c);
|
|
||||||
} else
|
|
||||||
g.setColor(Utils.COLOR_BLACK_ALPHA);
|
g.setColor(Utils.COLOR_BLACK_ALPHA);
|
||||||
g.fillRect(0, 0, width, height);
|
g.fillRect(0, 0, width, height);
|
||||||
|
Utils.COLOR_BLACK_ALPHA.a = oldAlpha;
|
||||||
|
|
||||||
|
// rpm
|
||||||
int rpm = Math.abs(Math.round(sumVelocity / storedVelocities.length * 60));
|
int rpm = Math.abs(Math.round(sumVelocity / storedVelocities.length * 60));
|
||||||
Image rpmImg = GameImage.SPINNER_RPM.getImage();
|
Image rpmImg = GameImage.SPINNER_RPM.getImage();
|
||||||
rpmImg.setAlpha(alpha);
|
rpmImg.setAlpha(alpha);
|
||||||
rpmImg.drawCentered(width / 2f, height - rpmImg.getHeight() / 2f);
|
rpmImg.drawCentered(width / 2f, height - rpmImg.getHeight() / 2f);
|
||||||
if(timeDiff < 0)
|
if (timeDiff < 0)
|
||||||
data.drawSymbolString(Integer.toString(rpm), (int) ((width + rpmImg.getWidth() * 0.95f) / 2f),
|
data.drawSymbolString(Integer.toString(rpm), (int) ((width + rpmImg.getWidth() * 0.95f) / 2f),
|
||||||
(int) (height - data.getScoreSymbolImage('0').getHeight() * 1.025f), 1f, 1f, true);
|
(int) (height - data.getScoreSymbolImage('0').getHeight() * 1.025f), 1f, 1f, true);
|
||||||
|
|
||||||
|
@ -150,8 +148,7 @@ public class Spinner implements HitObject {
|
||||||
spinnerMetreSub.draw(0, height - spinnerMetreSub.getHeight());
|
spinnerMetreSub.draw(0, height - spinnerMetreSub.getHeight());
|
||||||
|
|
||||||
// main spinner elements
|
// main spinner elements
|
||||||
float approachScale = 1 - Utils.clamp( ((float) timeDiff / (hitObject.getTime() - hitObject.getEndTime())), 0f, 1f);
|
float approachScale = 1 - Utils.clamp(((float) timeDiff / (hitObject.getTime() - hitObject.getEndTime())), 0f, 1f);
|
||||||
|
|
||||||
GameImage.SPINNER_CIRCLE.getImage().setAlpha(alpha);
|
GameImage.SPINNER_CIRCLE.getImage().setAlpha(alpha);
|
||||||
GameImage.SPINNER_CIRCLE.getImage().setRotation(drawRotation * 360f);
|
GameImage.SPINNER_CIRCLE.getImage().setRotation(drawRotation * 360f);
|
||||||
GameImage.SPINNER_CIRCLE.getImage().drawCentered(width / 2, height / 2);
|
GameImage.SPINNER_CIRCLE.getImage().drawCentered(width / 2, height / 2);
|
||||||
|
@ -210,24 +207,22 @@ public class Spinner implements HitObject {
|
||||||
if (isSpinning && !(Utils.isGameKeyPressed() || GameMod.RELAX.isActive()))
|
if (isSpinning && !(Utils.isGameKeyPressed() || GameMod.RELAX.isActive()))
|
||||||
isSpinning = false;
|
isSpinning = false;
|
||||||
|
|
||||||
|
// spin automatically
|
||||||
float angle;
|
|
||||||
// http://osu.ppy.sh/wiki/FAQ#Spinners
|
// http://osu.ppy.sh/wiki/FAQ#Spinners
|
||||||
// spin automatically (TODO: correct rotation angles)
|
float angle;
|
||||||
if (GameMod.AUTO.isActive()) {
|
if (GameMod.AUTO.isActive()) {
|
||||||
// "auto" mod (fast)
|
// "auto" mod (fast: 477rpm)
|
||||||
lastAngle = 0;
|
lastAngle = 0;
|
||||||
//angle = 477/60f * delta/1000f * TWO_PI; ~delta/20
|
angle = delta / 20f; // angle = 477/60f * delta/1000f * TWO_PI;
|
||||||
angle = delta / 20f;
|
|
||||||
isSpinning = true;
|
isSpinning = true;
|
||||||
} else if (GameMod.SPUN_OUT.isActive()) {
|
} else if (GameMod.SPUN_OUT.isActive()) {
|
||||||
// "spun out" mod (slow)
|
// "spun out" mod (slow: 287rpm)
|
||||||
lastAngle = 0;
|
lastAngle = 0;
|
||||||
//angle = 287/60f * delta/1000f * TWO_PI;
|
angle = delta / 33.25f; // angle = 287/60f * delta/1000f * TWO_PI;
|
||||||
angle = delta / 32f;
|
|
||||||
isSpinning = true;
|
isSpinning = true;
|
||||||
} else {
|
} else {
|
||||||
angle = (float) Math.atan2(mouseY - (height / 2), mouseX - (width / 2));
|
angle = (float) Math.atan2(mouseY - (height / 2), mouseX - (width / 2));
|
||||||
|
|
||||||
// set initial angle to current mouse position to skip first click
|
// set initial angle to current mouse position to skip first click
|
||||||
if (!isSpinning && (Utils.isGameKeyPressed() || GameMod.RELAX.isActive())) {
|
if (!isSpinning && (Utils.isGameKeyPressed() || GameMod.RELAX.isActive())) {
|
||||||
lastAngle = angle;
|
lastAngle = angle;
|
||||||
|
@ -236,11 +231,9 @@ public class Spinner implements HitObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
float angleDiff = angle - lastAngle;
|
|
||||||
|
|
||||||
// make angleDiff the smallest angle change possible
|
// make angleDiff the smallest angle change possible
|
||||||
// (i.e. 1/4 rotation instead of 3/4 rotation)
|
// (i.e. 1/4 rotation instead of 3/4 rotation)
|
||||||
|
float angleDiff = angle - lastAngle;
|
||||||
if (angleDiff < -Math.PI)
|
if (angleDiff < -Math.PI)
|
||||||
angleDiff += TWO_PI;
|
angleDiff += TWO_PI;
|
||||||
else if (angleDiff > Math.PI)
|
else if (angleDiff > Math.PI)
|
||||||
|
@ -252,7 +245,7 @@ public class Spinner implements HitObject {
|
||||||
cursorVelocity = Utils.clamp(angleDiff / TWO_PI / delta * 1000, -8f, 8f);
|
cursorVelocity = Utils.clamp(angleDiff / TWO_PI / delta * 1000, -8f, 8f);
|
||||||
|
|
||||||
deltaOverflow += delta;
|
deltaOverflow += delta;
|
||||||
while(deltaOverflow >= DELTA_UPDATE_TIME){
|
while (deltaOverflow >= DELTA_UPDATE_TIME) {
|
||||||
sumVelocity -= storedVelocities[velocityIndex];
|
sumVelocity -= storedVelocities[velocityIndex];
|
||||||
sumVelocity += cursorVelocity;
|
sumVelocity += cursorVelocity;
|
||||||
storedVelocities[velocityIndex++] = cursorVelocity;
|
storedVelocities[velocityIndex++] = cursorVelocity;
|
||||||
|
@ -273,7 +266,7 @@ public class Spinner implements HitObject {
|
||||||
* @param angle the angle to rotate (in radians)
|
* @param angle the angle to rotate (in radians)
|
||||||
*/
|
*/
|
||||||
private void rotate(float angle) {
|
private void rotate(float angle) {
|
||||||
drawRotation += (angle / TWO_PI);
|
drawRotation += angle / TWO_PI;
|
||||||
angle = Math.abs(angle);
|
angle = Math.abs(angle);
|
||||||
float newRotations = rotations + (angle / TWO_PI);
|
float newRotations = rotations + (angle / TWO_PI);
|
||||||
|
|
||||||
|
|
|
@ -341,7 +341,7 @@ public class Game extends BasicGameState {
|
||||||
stack.add(i);
|
stack.add(i);
|
||||||
|
|
||||||
while (!stack.isEmpty())
|
while (!stack.isEmpty())
|
||||||
hitObjects[stack.pop()].draw(trackPosition, stack.isEmpty(), g);
|
hitObjects[stack.pop()].draw(g, trackPosition);
|
||||||
|
|
||||||
// draw OsuHitObjectResult objects
|
// draw OsuHitObjectResult objects
|
||||||
data.drawHitResults(trackPosition);
|
data.drawHitResults(trackPosition);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user