From 7ec6e81e8fec2560d51aea06baaa50af6da2e6b6 Mon Sep 17 00:00:00 2001 From: Terrence Date: Mon, 9 Feb 2015 17:57:20 -0600 Subject: [PATCH] Further implementation of "weighted" spinner Current Issues: - Need to handle change in direction better - Spinning speed seems to be inaccurate --- src/itdelatrisu/opsu/objects/Spinner.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/itdelatrisu/opsu/objects/Spinner.java b/src/itdelatrisu/opsu/objects/Spinner.java index 54c2e288..1be3d237 100644 --- a/src/itdelatrisu/opsu/objects/Spinner.java +++ b/src/itdelatrisu/opsu/objects/Spinner.java @@ -38,8 +38,8 @@ import org.newdawn.slick.Image; */ public class Spinner implements HitObject { - /** The rate at which the spinner slows down in radians/second^2. */ - private static final float angularDrag = 500f; + /** The rate at which the spinner slows down in rotations/second^2. */ + private static final float angularDrag = 20f; /** Container dimensions. */ private static int width, height; @@ -59,7 +59,7 @@ public class Spinner implements HitObject { /** The total number of rotations needed to clear the spinner. */ private float rotationsNeeded; - /** The current angular velocity of the spinner in radians/second. */ + /** The current angular velocity of the spinner in rotations/second. */ private float angularVelocity; /** @@ -126,6 +126,10 @@ public class Spinner implements HitObject { if (extraRotations > 0) data.drawSymbolNumber(extraRotations * 1000, width / 2, height * 2 / 3, 1.0f); } + + // rotations per minute + g.setColor(new Color(0,0,0)); + g.drawString(String.format("RPM: %d", Math.round(angularVelocity * 60)), 100, 100); } /** @@ -179,9 +183,11 @@ public class Spinner implements HitObject { return false; } - // not spinning: nothing to do + // not spinning: spinner slows down if (!Utils.isGameKeyPressed()) { lastAngle = -1f; + angularVelocity = Math.max(0, angularVelocity - angularDrag * delta / 1000); + rotate(angularVelocity * (float)Math.PI * 2 * delta / 1000); return false; } @@ -193,10 +199,10 @@ public class Spinner implements HitObject { if (lastAngle >= 0f) { // skip initial clicks float angleDiff = Math.abs(lastAngle - angle); if (angleDiff < Math.PI / 2) { // skip huge angle changes... - angularVelocity = Math.max(angularVelocity - angularDrag * delta / 1000, + angularVelocity = (float)Math.max(angularVelocity - angularDrag * delta / 1000, angleDiff / (Math.PI * 2) / ((float)delta / 1000)); data.changeHealth(delta * GameData.HP_DRAIN_MULTIPLIER); - rotate(angularVelocity * delta / 1000); + rotate(angularVelocity * (float)Math.PI * 2 * delta / 1000); } }