|
|
|
@@ -37,10 +37,15 @@ import org.newdawn.slick.Image;
|
|
|
|
* Data type representing a spinner object.
|
|
|
|
* Data type representing a spinner object.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public class Spinner implements HitObject {
|
|
|
|
public class Spinner implements HitObject {
|
|
|
|
|
|
|
|
|
|
|
|
/** Container dimensions. */
|
|
|
|
/** Container dimensions. */
|
|
|
|
private static int width, height;
|
|
|
|
private static int width, height;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** The number of rotation velocities to store. */
|
|
|
|
|
|
|
|
private static final int MAX_ROTATION_VELOCITIES = 50;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** PI constants. */
|
|
|
|
|
|
|
|
private static final float TWO_PI = (float) (Math.PI * 2);
|
|
|
|
|
|
|
|
|
|
|
|
/** The associated OsuHitObject. */
|
|
|
|
/** The associated OsuHitObject. */
|
|
|
|
private OsuHitObject hitObject;
|
|
|
|
private OsuHitObject hitObject;
|
|
|
|
|
|
|
|
|
|
|
|
@@ -56,17 +61,17 @@ public class Spinner implements HitObject {
|
|
|
|
/** 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 sum of all the velocities in storedVelocities. */
|
|
|
|
/** The sum of all the velocities in storedVelocities. */
|
|
|
|
private float sumVelocity = 0f;
|
|
|
|
private float sumVelocity = 0f;
|
|
|
|
|
|
|
|
|
|
|
|
/** Array of the last 50 rotation velocities. */
|
|
|
|
/** Array holding the most recent rotation velocities. */
|
|
|
|
private float[] storedVelocities = new float[50];
|
|
|
|
private float[] storedVelocities = new float[MAX_ROTATION_VELOCITIES];
|
|
|
|
|
|
|
|
|
|
|
|
/** True if the mouse cursor is pressed. */
|
|
|
|
/** True if the mouse cursor is pressed. */
|
|
|
|
private boolean isSpinning;
|
|
|
|
private boolean isSpinning;
|
|
|
|
|
|
|
|
|
|
|
|
/** Current index of the stored velocities in rotations/second. */
|
|
|
|
/** Current index of the stored velocities in rotations/second. */
|
|
|
|
private int velocityIndex = 0;
|
|
|
|
private int velocityIndex = 0;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Initializes the Spinner data type with images and dimensions.
|
|
|
|
* Initializes the Spinner data type with images and dimensions.
|
|
|
|
@@ -134,8 +139,9 @@ public class Spinner implements HitObject {
|
|
|
|
data.drawSymbolNumber(extraRotations * 1000, width / 2, height * 2 / 3, 1.0f);
|
|
|
|
data.drawSymbolNumber(extraRotations * 1000, width / 2, height * 2 / 3, 1.0f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int rpm = Math.abs(Math.round(sumVelocity/storedVelocities.length*60));
|
|
|
|
// TODO: add rpm meter at bottom of spinner
|
|
|
|
//TODO: add rpm meter at bottom of spinner
|
|
|
|
// TODO 2: make this work for Auto/Spun-Out mods
|
|
|
|
|
|
|
|
// int rpm = Math.abs(Math.round(sumVelocity / storedVelocities.length * 60));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
@@ -190,9 +196,8 @@ public class Spinner implements HitObject {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// game button is released
|
|
|
|
// game button is released
|
|
|
|
if (isSpinning && !Utils.isGameKeyPressed()) {
|
|
|
|
if (isSpinning && !Utils.isGameKeyPressed())
|
|
|
|
isSpinning = false;
|
|
|
|
isSpinning = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float angle = (float) Math.atan2(mouseY - (height / 2), mouseX - (width / 2));
|
|
|
|
float angle = (float) Math.atan2(mouseY - (height / 2), mouseX - (width / 2));
|
|
|
|
|
|
|
|
|
|
|
|
@@ -207,36 +212,37 @@ public class Spinner implements HitObject {
|
|
|
|
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
if (angleDiff < -Math.PI) {
|
|
|
|
if (angleDiff < -Math.PI)
|
|
|
|
angleDiff = (float) (angleDiff + Math.PI*2);
|
|
|
|
angleDiff += TWO_PI;
|
|
|
|
} else if (angleDiff > Math.PI) {
|
|
|
|
else if (angleDiff > Math.PI)
|
|
|
|
angleDiff = (float) (angleDiff - Math.PI*2);
|
|
|
|
angleDiff -= TWO_PI;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// spin caused by the cursor
|
|
|
|
// spin caused by the cursor
|
|
|
|
float cursorVelocity = 0;
|
|
|
|
float cursorVelocity = 0;
|
|
|
|
if (isSpinning)
|
|
|
|
if (isSpinning)
|
|
|
|
cursorVelocity = Math.min((float)(angleDiff / (Math.PI*2) / delta * 1000), 8f);
|
|
|
|
cursorVelocity = Math.min(angleDiff / TWO_PI / delta * 1000, 8f);
|
|
|
|
|
|
|
|
|
|
|
|
sumVelocity -= storedVelocities[velocityIndex];
|
|
|
|
sumVelocity -= storedVelocities[velocityIndex];
|
|
|
|
sumVelocity += cursorVelocity;
|
|
|
|
sumVelocity += cursorVelocity;
|
|
|
|
storedVelocities[velocityIndex++] = cursorVelocity;
|
|
|
|
storedVelocities[velocityIndex++] = cursorVelocity;
|
|
|
|
velocityIndex %= storedVelocities.length;
|
|
|
|
velocityIndex %= storedVelocities.length;
|
|
|
|
|
|
|
|
|
|
|
|
data.changeHealth(delta * GameData.HP_DRAIN_MULTIPLIER);
|
|
|
|
float rotationAngle = sumVelocity / storedVelocities.length * TWO_PI * delta / 1000;
|
|
|
|
rotate(sumVelocity / storedVelocities.length * (float)Math.PI*2 * delta / 1000);
|
|
|
|
rotate(rotationAngle);
|
|
|
|
|
|
|
|
if (rotationAngle > 0.00001f)
|
|
|
|
|
|
|
|
data.changeHealth(delta * GameData.HP_DRAIN_MULTIPLIER);
|
|
|
|
|
|
|
|
|
|
|
|
lastAngle = angle;
|
|
|
|
lastAngle = angle;
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Rotates the spinner by a number of radians.
|
|
|
|
* Rotates the spinner by an angle.
|
|
|
|
* @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) {
|
|
|
|
angle = Math.abs(angle);
|
|
|
|
angle = Math.abs(angle);
|
|
|
|
float newRotations = rotations + (angle / (float) (2 * Math.PI));
|
|
|
|
float newRotations = rotations + (angle / TWO_PI);
|
|
|
|
|
|
|
|
|
|
|
|
// added one whole rotation...
|
|
|
|
// added one whole rotation...
|
|
|
|
if (Math.floor(newRotations) > rotations) {
|
|
|
|
if (Math.floor(newRotations) > rotations) {
|
|
|
|
|