Reformatting of #17 and #18, and minor bug fix in #17.

Fixed not losing any health at near-zero rotation angles.

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han 2015-02-14 01:07:17 -05:00
parent 2c59b345b5
commit 54806303f4
6 changed files with 49 additions and 42 deletions

View File

@ -177,7 +177,6 @@ public class OsuGroupList {
if (audioFile != null && audioFile.equals(osu.audioFilename)) {
MusicController.reset();
System.gc(); // TODO: why can't files be deleted without calling this?
// TODO 2: this is broken as of 800014e
}
}

View File

@ -245,7 +245,7 @@ public class MusicController {
public static boolean setPosition(int position) {
return (trackExists() && position >= 0 && player.setPosition(position / 1000f));
}
/**
* Plays the current track.
*/

View File

@ -37,10 +37,15 @@ import org.newdawn.slick.Image;
* Data type representing a spinner object.
*/
public class Spinner implements HitObject {
/** Container dimensions. */
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. */
private OsuHitObject hitObject;
@ -55,18 +60,18 @@ public class Spinner implements HitObject {
/** The total number of rotations needed to clear the spinner. */
private float rotationsNeeded;
/** The sum of all the velocities in storedVelocities. */
private float sumVelocity = 0f;
/** Array of the last 50 rotation velocities. */
private float[] storedVelocities = new float[50];
/** The sum of all the velocities in storedVelocities. */
private float sumVelocity = 0f;
/** Array holding the most recent rotation velocities. */
private float[] storedVelocities = new float[MAX_ROTATION_VELOCITIES];
/** True if the mouse cursor is pressed. */
private boolean isSpinning;
/** Current index of the stored velocities in rotations/second. */
private int velocityIndex = 0;
/** Current index of the stored velocities in rotations/second. */
private int velocityIndex = 0;
/**
* Initializes the Spinner data type with images and dimensions.
@ -133,9 +138,10 @@ public class Spinner implements HitObject {
if (extraRotations > 0)
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,53 +196,53 @@ public class Spinner implements HitObject {
}
// game button is released
if (isSpinning && !Utils.isGameKeyPressed()) {
if (isSpinning && !Utils.isGameKeyPressed())
isSpinning = false;
}
float angle = (float) Math.atan2(mouseY - (height / 2), mouseX - (width / 2));
// set initial angle to current mouse position to skip first click
if (!isSpinning && Utils.isGameKeyPressed()) {
lastAngle = angle;
isSpinning = true;
return false;
}
float angleDiff = angle - lastAngle;
// make angleDiff the smallest angle change possible
// (i.e. 1/4 rotation instead of 3/4 rotation)
if (angleDiff < -Math.PI) {
angleDiff = (float) (angleDiff + Math.PI*2);
} else if (angleDiff > Math.PI) {
angleDiff = (float) (angleDiff - Math.PI*2);
}
if (angleDiff < -Math.PI)
angleDiff += TWO_PI;
else if (angleDiff > Math.PI)
angleDiff -= TWO_PI;
// spin caused by the cursor
float cursorVelocity = 0;
if (isSpinning)
cursorVelocity = Math.min((float)(angleDiff / (Math.PI*2) / delta * 1000), 8f);
sumVelocity -= storedVelocities[velocityIndex];
sumVelocity += cursorVelocity;
storedVelocities[velocityIndex++] = cursorVelocity;
velocityIndex %= storedVelocities.length;
cursorVelocity = Math.min(angleDiff / TWO_PI / delta * 1000, 8f);
sumVelocity -= storedVelocities[velocityIndex];
sumVelocity += cursorVelocity;
storedVelocities[velocityIndex++] = cursorVelocity;
velocityIndex %= storedVelocities.length;
float rotationAngle = sumVelocity / storedVelocities.length * TWO_PI * delta / 1000;
rotate(rotationAngle);
if (rotationAngle > 0.00001f)
data.changeHealth(delta * GameData.HP_DRAIN_MULTIPLIER);
data.changeHealth(delta * GameData.HP_DRAIN_MULTIPLIER);
rotate(sumVelocity / storedVelocities.length * (float)Math.PI*2 * delta / 1000);
lastAngle = angle;
return false;
}
/**
* Rotates the spinner by a number of radians.
* Rotates the spinner by an angle.
* @param angle the angle to rotate (in radians)
*/
private void rotate(float angle) {
angle = Math.abs(angle);
float newRotations = rotations + (angle / (float) (2 * Math.PI));
float newRotations = rotations + (angle / TWO_PI);
// added one whole rotation...
if (Math.floor(newRotations) > rotations) {

View File

@ -699,7 +699,7 @@ public class Game extends BasicGameState {
// reset game data
resetGameData();
// needs to play before setting position to resume without lag later
MusicController.play();
MusicController.setPosition(0);

View File

@ -393,15 +393,17 @@ public class OpenALStreamPlayer {
lastUpdateTime = System.currentTimeMillis() - offsetTime;
}
/**
* Closes the stream.
*/
public void close() {
if(audio != null){
if (audio != null) {
try {
audio.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}

View File

@ -916,7 +916,7 @@ public class SoundStore {
return;
}
if(this.stream != null){
if (this.stream != null) {
this.stream.close();
}
currentMusic = sources.get(0);