2014-06-30 04:17:04 +02:00
|
|
|
/*
|
|
|
|
* opsu! - an open-source osu! client
|
2015-01-16 18:05:44 +01:00
|
|
|
* Copyright (C) 2014, 2015 Jeffrey Han
|
2014-06-30 04:17:04 +02:00
|
|
|
*
|
|
|
|
* opsu! is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* opsu! is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with opsu!. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package itdelatrisu.opsu.objects;
|
|
|
|
|
2015-01-30 02:36:23 +01:00
|
|
|
import itdelatrisu.opsu.GameData;
|
2015-04-08 08:05:12 +02:00
|
|
|
import itdelatrisu.opsu.GameData.HitObjectType;
|
2014-07-04 22:41:52 +02:00
|
|
|
import itdelatrisu.opsu.GameImage;
|
2014-07-16 22:01:36 +02:00
|
|
|
import itdelatrisu.opsu.GameMod;
|
2015-05-25 04:17:45 +02:00
|
|
|
import itdelatrisu.opsu.Options;
|
2014-07-02 01:32:03 +02:00
|
|
|
import itdelatrisu.opsu.Utils;
|
2015-01-08 01:29:51 +01:00
|
|
|
import itdelatrisu.opsu.audio.SoundController;
|
|
|
|
import itdelatrisu.opsu.audio.SoundEffect;
|
2015-05-17 03:42:03 +02:00
|
|
|
import itdelatrisu.opsu.beatmap.HitObject;
|
2015-09-05 19:53:42 +02:00
|
|
|
import itdelatrisu.opsu.objects.curves.Vec2f;
|
2014-06-30 04:17:04 +02:00
|
|
|
import itdelatrisu.opsu.states.Game;
|
2015-08-21 03:02:23 +02:00
|
|
|
import itdelatrisu.opsu.ui.Colors;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
import org.newdawn.slick.Color;
|
|
|
|
import org.newdawn.slick.GameContainer;
|
|
|
|
import org.newdawn.slick.Graphics;
|
|
|
|
import org.newdawn.slick.Image;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Data type representing a spinner object.
|
|
|
|
*/
|
2015-05-17 03:42:03 +02:00
|
|
|
public class Spinner implements GameObject {
|
2015-01-22 06:44:45 +01:00
|
|
|
/** Container dimensions. */
|
2014-06-30 04:17:04 +02:00
|
|
|
private static int width, height;
|
|
|
|
|
2015-06-14 18:59:12 +02:00
|
|
|
/** The map's overall difficulty value. */
|
|
|
|
private static float overallDifficulty = 5f;
|
|
|
|
|
2015-02-14 07:07:17 +01:00
|
|
|
/** The number of rotation velocities to store. */
|
2015-06-22 01:45:38 +02:00
|
|
|
private int maxStoredDeltaAngles;
|
2015-02-14 07:07:17 +01:00
|
|
|
|
2015-03-07 21:38:59 +01:00
|
|
|
/** The amount of time, in milliseconds, before another velocity is stored. */
|
2015-04-05 17:24:05 +02:00
|
|
|
private static final float DELTA_UPDATE_TIME = 1000 / 60f;
|
2015-03-07 21:38:59 +01:00
|
|
|
|
2015-03-18 00:03:50 +01:00
|
|
|
/** Angle mod multipliers: "auto" (477rpm), "spun out" (287rpm) */
|
|
|
|
private static final float
|
|
|
|
AUTO_MULTIPLIER = 1 / 20f, // angle = 477/60f * delta/1000f * TWO_PI;
|
|
|
|
SPUN_OUT_MULTIPLIER = 1 / 33.25f; // angle = 287/60f * delta/1000f * TWO_PI;
|
|
|
|
|
2015-06-30 02:22:38 +02:00
|
|
|
/** Maximum angle difference. */
|
|
|
|
private static final float MAX_ANG_DIFF = DELTA_UPDATE_TIME * AUTO_MULTIPLIER; // ~95.3
|
|
|
|
|
2015-02-14 07:07:17 +01:00
|
|
|
/** PI constants. */
|
2015-03-17 19:48:13 +01:00
|
|
|
private static final float
|
|
|
|
TWO_PI = (float) (Math.PI * 2),
|
|
|
|
HALF_PI = (float) (Math.PI / 2);
|
2015-02-14 07:07:17 +01:00
|
|
|
|
2015-05-17 03:42:03 +02:00
|
|
|
/** The associated HitObject. */
|
|
|
|
private HitObject hitObject;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2015-08-29 04:12:47 +02:00
|
|
|
/** The associated Game object. */
|
|
|
|
private Game game;
|
|
|
|
|
2015-01-27 09:19:39 +01:00
|
|
|
/** The associated GameData object. */
|
|
|
|
private GameData data;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** The last rotation angle. */
|
2015-02-14 00:12:04 +01:00
|
|
|
private float lastAngle = 0f;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** The current number of rotations. */
|
2014-06-30 04:17:04 +02:00
|
|
|
private float rotations = 0f;
|
2015-03-07 21:38:59 +01:00
|
|
|
|
|
|
|
/** The current rotation to draw. */
|
2015-03-06 05:33:40 +01:00
|
|
|
private float drawRotation = 0f;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** The total number of rotations needed to clear the spinner. */
|
2014-06-30 04:17:04 +02:00
|
|
|
private float rotationsNeeded;
|
2015-02-14 07:07:17 +01:00
|
|
|
|
2015-03-07 21:38:59 +01:00
|
|
|
/** The remaining amount of time that was not used. */
|
2015-04-05 17:24:05 +02:00
|
|
|
private float deltaOverflow;
|
2015-03-07 21:38:59 +01:00
|
|
|
|
2015-02-14 07:07:17 +01:00
|
|
|
/** The sum of all the velocities in storedVelocities. */
|
2015-04-05 17:24:05 +02:00
|
|
|
private float sumDeltaAngle = 0f;
|
2015-02-14 07:07:17 +01:00
|
|
|
|
|
|
|
/** Array holding the most recent rotation velocities. */
|
2015-06-22 01:45:38 +02:00
|
|
|
private float[] storedDeltaAngle;
|
2015-02-14 07:07:17 +01:00
|
|
|
|
2015-02-14 00:12:04 +01:00
|
|
|
/** True if the mouse cursor is pressed. */
|
|
|
|
private boolean isSpinning;
|
2015-02-14 07:07:17 +01:00
|
|
|
|
|
|
|
/** Current index of the stored velocities in rotations/second. */
|
2015-04-05 17:24:05 +02:00
|
|
|
private int deltaAngleIndex = 0;
|
2015-06-30 02:22:38 +02:00
|
|
|
|
2015-06-22 01:45:38 +02:00
|
|
|
/** The remaining amount of the angle that was not used. */
|
2015-04-05 17:24:05 +02:00
|
|
|
private float deltaAngleOverflow = 0;
|
2015-06-30 02:22:38 +02:00
|
|
|
|
2015-06-22 01:45:38 +02:00
|
|
|
/** The RPM that is drawn to the screen. */
|
2015-04-05 17:24:05 +02:00
|
|
|
private int drawnRPM = 0;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes the Spinner data type with images and dimensions.
|
|
|
|
* @param container the game container
|
2015-06-14 18:59:12 +02:00
|
|
|
* @param difficulty the map's overall difficulty value
|
2014-06-30 04:17:04 +02:00
|
|
|
*/
|
2015-06-14 18:59:12 +02:00
|
|
|
public static void init(GameContainer container, float difficulty) {
|
2014-06-30 04:17:04 +02:00
|
|
|
width = container.getWidth();
|
|
|
|
height = container.getHeight();
|
2015-06-14 18:59:12 +02:00
|
|
|
overallDifficulty = difficulty;
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor.
|
2015-05-17 03:42:03 +02:00
|
|
|
* @param hitObject the associated HitObject
|
2014-06-30 04:17:04 +02:00
|
|
|
* @param game the associated Game object
|
2015-01-27 09:19:39 +01:00
|
|
|
* @param data the associated GameData object
|
2014-06-30 04:17:04 +02:00
|
|
|
*/
|
2015-05-17 03:42:03 +02:00
|
|
|
public Spinner(HitObject hitObject, Game game, GameData data) {
|
2014-06-30 04:17:04 +02:00
|
|
|
this.hitObject = hitObject;
|
2015-08-29 04:12:47 +02:00
|
|
|
this.game = game;
|
2015-01-27 09:19:39 +01:00
|
|
|
this.data = data;
|
2015-06-30 02:22:38 +02:00
|
|
|
|
2015-06-22 01:45:38 +02:00
|
|
|
/*
|
|
|
|
1 beat = 731.707317073171ms
|
|
|
|
RPM at frame X with spinner Y beats long
|
|
|
|
10 20 30 40 50 60 <frame#
|
2015-06-30 02:22:38 +02:00
|
|
|
1.00 306 418 457 470
|
|
|
|
1.25 323 424 459 471 475
|
2015-06-22 01:45:38 +02:00
|
|
|
1.5 305 417 456 470 475 477
|
2015-06-30 02:22:38 +02:00
|
|
|
1.75 322 417 456 471 475
|
2015-06-22 01:45:38 +02:00
|
|
|
2.00 304 410 454 469 474 476
|
|
|
|
2.25 303 410 451 467 474 476
|
|
|
|
2.50 303 417 456 470 475 476
|
|
|
|
2.75 302 416 456 470 475 476
|
|
|
|
3.00 301 416 456 470 475 <-- ~2sec
|
2015-06-30 02:22:38 +02:00
|
|
|
4.00 274 414 453 470 475
|
|
|
|
5.00 281 409 454 469 475
|
2015-06-22 01:45:38 +02:00
|
|
|
6.00 232 392 451 467 472 476
|
2015-06-30 02:22:38 +02:00
|
|
|
6.25 193 378 443 465
|
|
|
|
6.50 133 344 431 461
|
2015-06-22 01:45:38 +02:00
|
|
|
6.75 85 228 378 435 463 472 <-- ~5sec
|
2015-06-30 02:22:38 +02:00
|
|
|
7.00 53 154 272 391 447
|
|
|
|
8.00 53 154 272 391 447
|
|
|
|
9.00 53 154 272 400 450
|
|
|
|
10.00 53 154 272 400 450
|
2015-06-22 01:45:38 +02:00
|
|
|
15.00 53 154 272 391 444 466
|
2015-06-30 02:22:38 +02:00
|
|
|
20.00 61 154 272 400 447
|
2015-06-22 01:45:38 +02:00
|
|
|
25.00 53 154 272 391 447 466
|
|
|
|
^beats
|
|
|
|
*/
|
2015-06-30 02:22:38 +02:00
|
|
|
// TODO not correct at all, but close enough?
|
|
|
|
// <2sec ~ 12 ~ 200ms
|
|
|
|
// >5sec ~ 48 ~ 800ms
|
|
|
|
|
2015-06-22 01:45:38 +02:00
|
|
|
final int minVel = 12;
|
|
|
|
final int maxVel = 48;
|
|
|
|
final int minTime = 2000;
|
|
|
|
final int maxTime = 5000;
|
2015-08-06 07:53:30 +02:00
|
|
|
maxStoredDeltaAngles = Utils.clamp((hitObject.getEndTime() - hitObject.getTime() - minTime)
|
2015-06-30 02:22:38 +02:00
|
|
|
* (maxVel - minVel) / (maxTime - minTime) + minVel, minVel, maxVel);
|
2015-06-22 01:45:38 +02:00
|
|
|
storedDeltaAngle = new float[maxStoredDeltaAngles];
|
2015-06-30 02:22:38 +02:00
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
// calculate rotations needed
|
2015-06-14 18:59:12 +02:00
|
|
|
float spinsPerMinute = 100 + (overallDifficulty * 15);
|
2014-07-18 21:11:57 +02:00
|
|
|
rotationsNeeded = spinsPerMinute * (hitObject.getEndTime() - hitObject.getTime()) / 60000f;
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
|
2015-01-16 21:44:13 +01:00
|
|
|
@Override
|
2015-03-07 21:38:59 +01:00
|
|
|
public void draw(Graphics g, int trackPosition) {
|
|
|
|
// only draw spinners shortly before start time
|
2014-07-18 21:11:57 +02:00
|
|
|
int timeDiff = hitObject.getTime() - trackPosition;
|
2015-08-29 04:12:47 +02:00
|
|
|
final int fadeInTime = game.getFadeInTime();
|
|
|
|
if (timeDiff - fadeInTime > 0)
|
2015-03-07 21:38:59 +01:00
|
|
|
return;
|
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
boolean spinnerComplete = (rotations >= rotationsNeeded);
|
2015-08-29 04:12:47 +02:00
|
|
|
float alpha = Utils.clamp(1 - (float) timeDiff / fadeInTime, 0f, 1f);
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
// darken screen
|
2015-05-25 04:17:45 +02:00
|
|
|
if (Options.getSkin().isSpinnerFadePlayfield()) {
|
2015-08-21 03:02:23 +02:00
|
|
|
float oldAlpha = Colors.BLACK_ALPHA.a;
|
2015-05-25 04:17:45 +02:00
|
|
|
if (timeDiff > 0)
|
2015-08-21 03:02:23 +02:00
|
|
|
Colors.BLACK_ALPHA.a *= alpha;
|
|
|
|
g.setColor(Colors.BLACK_ALPHA);
|
2015-05-25 04:17:45 +02:00
|
|
|
g.fillRect(0, 0, width, height);
|
2015-08-21 03:02:23 +02:00
|
|
|
Colors.BLACK_ALPHA.a = oldAlpha;
|
2015-05-25 04:17:45 +02:00
|
|
|
}
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2015-03-07 21:38:59 +01:00
|
|
|
// rpm
|
2015-02-20 22:56:41 +01:00
|
|
|
Image rpmImg = GameImage.SPINNER_RPM.getImage();
|
2015-03-06 05:33:40 +01:00
|
|
|
rpmImg.setAlpha(alpha);
|
2015-02-20 22:56:41 +01:00
|
|
|
rpmImg.drawCentered(width / 2f, height - rpmImg.getHeight() / 2f);
|
2015-03-07 21:38:59 +01:00
|
|
|
if (timeDiff < 0)
|
2015-04-05 17:24:05 +02:00
|
|
|
data.drawSymbolString(Integer.toString(drawnRPM), (width + rpmImg.getWidth() * 0.95f) / 2f,
|
2015-03-13 04:53:25 +01:00
|
|
|
height - data.getScoreSymbolImage('0').getHeight() * 1.025f, 1f, 1f, true);
|
2015-02-20 22:56:41 +01:00
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
// spinner meter (subimage)
|
2014-07-04 22:41:52 +02:00
|
|
|
Image spinnerMetre = GameImage.SPINNER_METRE.getImage();
|
2014-06-30 04:17:04 +02:00
|
|
|
int spinnerMetreY = (spinnerComplete) ? 0 : (int) (spinnerMetre.getHeight() * (1 - (rotations / rotationsNeeded)));
|
|
|
|
Image spinnerMetreSub = spinnerMetre.getSubImage(
|
|
|
|
0, spinnerMetreY,
|
|
|
|
spinnerMetre.getWidth(), spinnerMetre.getHeight() - spinnerMetreY
|
|
|
|
);
|
2015-03-06 05:33:40 +01:00
|
|
|
spinnerMetreSub.setAlpha(alpha);
|
2014-06-30 04:17:04 +02:00
|
|
|
spinnerMetreSub.draw(0, height - spinnerMetreSub.getHeight());
|
|
|
|
|
|
|
|
// main spinner elements
|
2015-08-09 02:15:49 +02:00
|
|
|
GameImage.SPINNER_CIRCLE.getImage().setAlpha(alpha);
|
|
|
|
GameImage.SPINNER_CIRCLE.getImage().setRotation(drawRotation * 360f);
|
|
|
|
GameImage.SPINNER_CIRCLE.getImage().drawCentered(width / 2, height / 2);
|
|
|
|
if (!GameMod.HIDDEN.isActive()) {
|
|
|
|
float approachScale = 1 - Utils.clamp(((float) timeDiff / (hitObject.getTime() - hitObject.getEndTime())), 0f, 1f);
|
|
|
|
Image approachCircleScaled = GameImage.SPINNER_APPROACHCIRCLE.getImage().getScaledCopy(approachScale);
|
|
|
|
approachCircleScaled.setAlpha(alpha);
|
|
|
|
approachCircleScaled.drawCentered(width / 2, height / 2);
|
2015-08-09 01:20:45 +02:00
|
|
|
}
|
2015-03-06 05:33:40 +01:00
|
|
|
GameImage.SPINNER_SPIN.getImage().setAlpha(alpha);
|
2014-07-04 22:41:52 +02:00
|
|
|
GameImage.SPINNER_SPIN.getImage().drawCentered(width / 2, height * 3 / 4);
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
if (spinnerComplete) {
|
2014-07-04 22:41:52 +02:00
|
|
|
GameImage.SPINNER_CLEAR.getImage().drawCentered(width / 2, height / 4);
|
2014-06-30 04:17:04 +02:00
|
|
|
int extraRotations = (int) (rotations - rotationsNeeded);
|
|
|
|
if (extraRotations > 0)
|
2015-04-01 01:46:58 +02:00
|
|
|
data.drawSymbolNumber(extraRotations * 1000, width / 2, height * 2 / 3, 1f, 1f);
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
}
|
2015-01-16 21:44:13 +01:00
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
/**
|
|
|
|
* Calculates and sends the spinner hit result.
|
2015-01-27 09:19:39 +01:00
|
|
|
* @return the hit result (GameData.HIT_* constants)
|
2014-06-30 04:17:04 +02:00
|
|
|
*/
|
2015-01-16 09:47:37 +01:00
|
|
|
private int hitResult() {
|
2014-06-30 04:17:04 +02:00
|
|
|
// TODO: verify ratios
|
|
|
|
int result;
|
|
|
|
float ratio = rotations / rotationsNeeded;
|
2015-03-18 00:03:50 +01:00
|
|
|
if (ratio >= 1.0f || GameMod.AUTO.isActive() || GameMod.AUTOPILOT.isActive() || GameMod.SPUN_OUT.isActive()) {
|
2015-01-27 09:19:39 +01:00
|
|
|
result = GameData.HIT_300;
|
2015-01-08 01:29:51 +01:00
|
|
|
SoundController.playSound(SoundEffect.SPINNEROSU);
|
2015-02-20 22:56:41 +01:00
|
|
|
} else if (ratio >= 0.9f)
|
2015-01-27 09:19:39 +01:00
|
|
|
result = GameData.HIT_100;
|
2015-02-20 22:56:41 +01:00
|
|
|
else if (ratio >= 0.75f)
|
2015-01-27 09:19:39 +01:00
|
|
|
result = GameData.HIT_50;
|
2014-06-30 04:17:04 +02:00
|
|
|
else
|
2015-01-27 09:19:39 +01:00
|
|
|
result = GameData.HIT_MISS;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2015-01-27 09:19:39 +01:00
|
|
|
data.hitResult(hitObject.getEndTime(), result, width / 2, height / 2,
|
2015-06-30 02:22:38 +02:00
|
|
|
Color.transparent, true, hitObject, HitObjectType.SPINNER, true, 0, null, false);
|
2014-06-30 04:17:04 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-01-16 21:44:13 +01:00
|
|
|
@Override
|
2015-06-30 02:22:38 +02:00
|
|
|
public boolean mousePressed(int x, int y, int trackPosition) {
|
2015-04-05 17:24:05 +02:00
|
|
|
lastAngle = (float) Math.atan2(x - (height / 2), y - (width / 2));
|
|
|
|
return false;
|
|
|
|
}
|
2015-01-16 09:47:37 +01:00
|
|
|
|
2015-01-16 21:44:13 +01:00
|
|
|
@Override
|
2015-03-15 19:15:34 +01:00
|
|
|
public boolean update(boolean overlap, int delta, int mouseX, int mouseY, boolean keyPressed, int trackPosition) {
|
2014-06-30 04:17:04 +02:00
|
|
|
// end of spinner
|
2015-01-30 03:24:21 +01:00
|
|
|
if (overlap || trackPosition > hitObject.getEndTime()) {
|
2014-06-30 04:17:04 +02:00
|
|
|
hitResult();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-03-06 05:33:40 +01:00
|
|
|
// game button is released
|
2015-03-09 23:32:43 +01:00
|
|
|
if (isSpinning && !(keyPressed || GameMod.RELAX.isActive()))
|
2015-03-06 05:33:40 +01:00
|
|
|
isSpinning = false;
|
|
|
|
|
2015-04-05 17:24:05 +02:00
|
|
|
// spin automatically
|
|
|
|
// http://osu.ppy.sh/wiki/FAQ#Spinners
|
2015-06-30 02:22:38 +02:00
|
|
|
|
2015-04-03 20:00:59 +02:00
|
|
|
deltaOverflow += delta;
|
2015-06-30 02:22:38 +02:00
|
|
|
|
2015-06-22 01:45:38 +02:00
|
|
|
float angleDiff = 0;
|
|
|
|
if (GameMod.AUTO.isActive()) {
|
|
|
|
angleDiff = delta * AUTO_MULTIPLIER;
|
|
|
|
isSpinning = true;
|
|
|
|
} else if (GameMod.SPUN_OUT.isActive() || GameMod.AUTOPILOT.isActive()) {
|
|
|
|
angleDiff = delta * SPUN_OUT_MULTIPLIER;
|
|
|
|
isSpinning = true;
|
|
|
|
} else {
|
|
|
|
float angle = (float) Math.atan2(mouseY - (height / 2), mouseX - (width / 2));
|
|
|
|
|
|
|
|
// set initial angle to current mouse position to skip first click
|
|
|
|
if (!isSpinning && (keyPressed || GameMod.RELAX.isActive())) {
|
|
|
|
lastAngle = angle;
|
2015-03-06 05:33:40 +01:00
|
|
|
isSpinning = true;
|
2015-06-22 01:45:38 +02:00
|
|
|
return false;
|
|
|
|
}
|
2015-06-30 02:22:38 +02:00
|
|
|
|
2015-06-22 01:45:38 +02:00
|
|
|
angleDiff = angle - lastAngle;
|
2015-06-30 02:22:38 +02:00
|
|
|
if (Math.abs(angleDiff) > 0.01f)
|
2015-06-22 01:45:38 +02:00
|
|
|
lastAngle = angle;
|
2015-06-30 02:22:38 +02:00
|
|
|
else
|
2015-06-22 01:45:38 +02:00
|
|
|
angleDiff = 0;
|
2015-04-05 17:24:05 +02:00
|
|
|
}
|
2015-06-22 01:45:38 +02:00
|
|
|
|
|
|
|
// make angleDiff the smallest angle change possible
|
|
|
|
// (i.e. 1/4 rotation instead of 3/4 rotation)
|
|
|
|
if (angleDiff < -Math.PI)
|
|
|
|
angleDiff += TWO_PI;
|
|
|
|
else if (angleDiff > Math.PI)
|
|
|
|
angleDiff -= TWO_PI;
|
2015-06-30 02:22:38 +02:00
|
|
|
|
|
|
|
// may be a problem at higher frame rate due to floating point round off
|
2015-06-22 01:45:38 +02:00
|
|
|
if (isSpinning)
|
|
|
|
deltaAngleOverflow += angleDiff;
|
2015-06-30 02:22:38 +02:00
|
|
|
|
2015-04-05 17:24:05 +02:00
|
|
|
while (deltaOverflow >= DELTA_UPDATE_TIME) {
|
|
|
|
// spin caused by the cursor
|
2015-06-30 02:22:38 +02:00
|
|
|
float deltaAngle = 0;
|
|
|
|
if (isSpinning) {
|
2015-04-05 17:24:05 +02:00
|
|
|
deltaAngle = deltaAngleOverflow * DELTA_UPDATE_TIME / deltaOverflow;
|
|
|
|
deltaAngleOverflow -= deltaAngle;
|
2015-06-30 02:22:38 +02:00
|
|
|
deltaAngle = Utils.clamp(deltaAngle, -MAX_ANG_DIFF, MAX_ANG_DIFF);
|
2015-04-05 17:24:05 +02:00
|
|
|
}
|
|
|
|
sumDeltaAngle -= storedDeltaAngle[deltaAngleIndex];
|
|
|
|
sumDeltaAngle += deltaAngle;
|
|
|
|
storedDeltaAngle[deltaAngleIndex++] = deltaAngle;
|
|
|
|
deltaAngleIndex %= storedDeltaAngle.length;
|
|
|
|
deltaOverflow -= DELTA_UPDATE_TIME;
|
2015-06-30 02:22:38 +02:00
|
|
|
|
2015-06-22 01:45:38 +02:00
|
|
|
float rotationAngle = sumDeltaAngle / maxStoredDeltaAngles;
|
2015-06-30 02:22:38 +02:00
|
|
|
rotationAngle = Utils.clamp(rotationAngle, -MAX_ANG_DIFF, MAX_ANG_DIFF);
|
|
|
|
float rotationPerSec = rotationAngle * (1000 / DELTA_UPDATE_TIME) / TWO_PI;
|
|
|
|
|
|
|
|
drawnRPM = (int) (Math.abs(rotationPerSec * 60));
|
2015-04-05 17:24:05 +02:00
|
|
|
|
2015-04-03 20:00:59 +02:00
|
|
|
rotate(rotationAngle);
|
|
|
|
if (Math.abs(rotationAngle) > 0.00001f)
|
2015-04-05 17:24:05 +02:00
|
|
|
data.changeHealth(DELTA_UPDATE_TIME * GameData.HP_DRAIN_MULTIPLIER);
|
2015-04-03 20:00:59 +02:00
|
|
|
}
|
2015-06-30 02:22:38 +02:00
|
|
|
|
2015-06-22 01:45:38 +02:00
|
|
|
//TODO may need to update 1 more time when the spinner ends?
|
2014-06-30 04:17:04 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-03-28 13:11:43 +01:00
|
|
|
@Override
|
|
|
|
public void updatePosition() {}
|
|
|
|
|
2015-03-17 19:48:13 +01:00
|
|
|
@Override
|
2015-09-05 19:53:42 +02:00
|
|
|
public Vec2f getPointAt(int trackPosition) {
|
2015-03-17 19:48:13 +01:00
|
|
|
// get spinner time
|
|
|
|
int timeDiff;
|
|
|
|
float x = hitObject.getScaledX(), y = hitObject.getScaledY();
|
|
|
|
if (trackPosition <= hitObject.getTime())
|
|
|
|
timeDiff = 0;
|
|
|
|
else if (trackPosition >= hitObject.getEndTime())
|
|
|
|
timeDiff = hitObject.getEndTime() - hitObject.getTime();
|
|
|
|
else
|
|
|
|
timeDiff = trackPosition - hitObject.getTime();
|
|
|
|
|
|
|
|
// calculate point
|
2015-03-18 00:03:50 +01:00
|
|
|
float multiplier = (GameMod.AUTO.isActive()) ? AUTO_MULTIPLIER : SPUN_OUT_MULTIPLIER;
|
|
|
|
float angle = (timeDiff * multiplier) - HALF_PI;
|
2015-03-17 19:48:13 +01:00
|
|
|
final float r = height / 10f;
|
2015-09-05 19:53:42 +02:00
|
|
|
return new Vec2f((float) (x + r * Math.cos(angle)), (float) (y + r * Math.sin(angle)));
|
2015-03-17 19:48:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getEndTime() { return hitObject.getEndTime(); }
|
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
/**
|
2015-02-14 07:07:17 +01:00
|
|
|
* Rotates the spinner by an angle.
|
2015-02-10 00:11:49 +01:00
|
|
|
* @param angle the angle to rotate (in radians)
|
2014-06-30 04:17:04 +02:00
|
|
|
*/
|
2015-02-10 00:11:49 +01:00
|
|
|
private void rotate(float angle) {
|
2015-03-07 21:38:59 +01:00
|
|
|
drawRotation += angle / TWO_PI;
|
2015-02-14 00:12:04 +01:00
|
|
|
angle = Math.abs(angle);
|
2015-02-14 07:07:17 +01:00
|
|
|
float newRotations = rotations + (angle / TWO_PI);
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
// added one whole rotation...
|
|
|
|
if (Math.floor(newRotations) > rotations) {
|
2015-04-05 17:24:05 +02:00
|
|
|
//TODO seems to give 1100 points per spin but also an extra 100 for some spinners
|
2014-07-01 07:14:03 +02:00
|
|
|
if (newRotations > rotationsNeeded) { // extra rotations
|
2015-01-27 09:19:39 +01:00
|
|
|
data.changeScore(1000);
|
2015-01-08 01:29:51 +01:00
|
|
|
SoundController.playSound(SoundEffect.SPINNERBONUS);
|
2015-04-05 17:24:05 +02:00
|
|
|
}
|
|
|
|
data.changeScore(100);
|
|
|
|
SoundController.playSound(SoundEffect.SPINNERSPIN);
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
2015-06-30 02:22:38 +02:00
|
|
|
|
|
|
|
// extra 100 for some spinners (mostly wrong)
|
|
|
|
// if (Math.floor(newRotations + 0.5f) > rotations + 0.5f) {
|
|
|
|
// if (newRotations + 0.5f > rotationsNeeded) // extra rotations
|
|
|
|
// data.changeScore(100);
|
|
|
|
// }
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
rotations = newRotations;
|
|
|
|
}
|
2015-04-05 17:24:05 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void reset() {
|
|
|
|
deltaAngleIndex = 0;
|
|
|
|
sumDeltaAngle = 0;
|
2015-06-30 02:22:38 +02:00
|
|
|
for (int i = 0; i < storedDeltaAngle.length; i++)
|
2015-04-05 17:24:05 +02:00
|
|
|
storedDeltaAngle[i] = 0;
|
|
|
|
drawRotation = 0;
|
|
|
|
rotations = 0;
|
|
|
|
deltaOverflow = 0;
|
|
|
|
isSpinning = false;
|
|
|
|
}
|
2015-02-10 00:11:49 +01:00
|
|
|
}
|