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;
|
2014-07-04 22:41:52 +02:00
|
|
|
import itdelatrisu.opsu.GameImage;
|
2014-07-16 22:01:36 +02:00
|
|
|
import itdelatrisu.opsu.GameMod;
|
2014-06-30 04:17:04 +02:00
|
|
|
import itdelatrisu.opsu.OsuFile;
|
|
|
|
import itdelatrisu.opsu.OsuHitObject;
|
2014-07-02 01:32:03 +02:00
|
|
|
import itdelatrisu.opsu.Utils;
|
2015-01-30 02:36:23 +01:00
|
|
|
import itdelatrisu.opsu.objects.curves.CircumscribedCircle;
|
|
|
|
import itdelatrisu.opsu.objects.curves.Curve;
|
|
|
|
import itdelatrisu.opsu.objects.curves.LinearBezier;
|
2014-06-30 04:17:04 +02:00
|
|
|
import itdelatrisu.opsu.states.Game;
|
|
|
|
|
|
|
|
import org.newdawn.slick.Color;
|
|
|
|
import org.newdawn.slick.GameContainer;
|
2015-01-16 09:47:37 +01:00
|
|
|
import org.newdawn.slick.Graphics;
|
2014-06-30 04:17:04 +02:00
|
|
|
import org.newdawn.slick.Image;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Data type representing a slider object.
|
|
|
|
*/
|
2015-01-16 09:47:37 +01:00
|
|
|
public class Slider implements HitObject {
|
2015-03-19 08:04:35 +01:00
|
|
|
/** Slider ball frames. */
|
2015-03-16 04:05:27 +01:00
|
|
|
private static Image[] sliderBallImages;
|
2015-03-19 08:04:35 +01:00
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** Slider movement speed multiplier. */
|
2014-06-30 04:17:04 +02:00
|
|
|
private static float sliderMultiplier = 1.0f;
|
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** Rate at which slider ticks are placed. */
|
2014-06-30 04:17:04 +02:00
|
|
|
private static float sliderTickRate = 1.0f;
|
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** The associated OsuHitObject. */
|
2014-06-30 04:17:04 +02:00
|
|
|
private OsuHitObject hitObject;
|
|
|
|
|
2015-03-13 01:12:43 +01:00
|
|
|
/** The scaled starting x, y coordinates. */
|
|
|
|
protected float x, y;
|
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** The associated Game object. */
|
2014-06-30 04:17:04 +02:00
|
|
|
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 color of this slider. */
|
2014-06-30 04:17:04 +02:00
|
|
|
private Color color;
|
|
|
|
|
2015-01-30 02:36:23 +01:00
|
|
|
/** The underlying Curve. */
|
|
|
|
private Curve curve;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** The time duration of the slider, in milliseconds. */
|
2014-06-30 04:17:04 +02:00
|
|
|
private float sliderTime = 0f;
|
2015-01-16 21:44:13 +01:00
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** The time duration of the slider including repeats, in milliseconds. */
|
2014-06-30 04:17:04 +02:00
|
|
|
private float sliderTimeTotal = 0f;
|
|
|
|
|
2015-02-21 23:12:18 +01:00
|
|
|
/** Whether or not the result of the initial/final hit circles have been processed. */
|
|
|
|
private boolean sliderClickedInitial = false, sliderClickedFinal = false;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** Whether or not to show the follow circle. */
|
2014-06-30 04:17:04 +02:00
|
|
|
private boolean followCircleActive = false;
|
2015-01-16 21:44:13 +01:00
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** Whether or not the slider result ends the combo streak. */
|
2014-06-30 04:17:04 +02:00
|
|
|
private boolean comboEnd;
|
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** The number of repeats that have passed so far. */
|
2014-06-30 04:17:04 +02:00
|
|
|
private int currentRepeats = 0;
|
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** The t values of the slider ticks. */
|
2014-06-30 04:17:04 +02:00
|
|
|
private float[] ticksT;
|
2015-01-16 21:44:13 +01:00
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** The tick index in the ticksT[] array. */
|
2014-06-30 04:17:04 +02:00
|
|
|
private int tickIndex = 0;
|
2015-01-16 21:44:13 +01:00
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** Number of ticks hit and tick intervals so far. */
|
2014-06-30 04:17:04 +02:00
|
|
|
private int ticksHit = 0, tickIntervals = 1;
|
|
|
|
|
2015-03-15 20:38:04 +01:00
|
|
|
/** Container dimensions. */
|
|
|
|
private static int containerWidth, containerHeight;
|
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
/**
|
|
|
|
* Initializes the Slider data type with images and dimensions.
|
|
|
|
* @param container the game container
|
|
|
|
* @param circleSize the map's circleSize value
|
|
|
|
* @param osu the associated OsuFile object
|
|
|
|
*/
|
2015-01-22 00:56:53 +01:00
|
|
|
public static void init(GameContainer container, float circleSize, OsuFile osu) {
|
2015-03-15 20:38:04 +01:00
|
|
|
containerWidth = container.getWidth();
|
|
|
|
containerHeight = container.getHeight();
|
|
|
|
|
2015-02-14 19:45:14 +01:00
|
|
|
int diameter = (int) (104 - (circleSize * 8));
|
2015-02-10 03:40:38 +01:00
|
|
|
diameter = (int) (diameter * OsuHitObject.getXMultiplier()); // convert from Osupixels (640x480)
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2014-07-04 22:41:52 +02:00
|
|
|
// slider ball
|
2015-01-21 23:10:31 +01:00
|
|
|
if (GameImage.SLIDER_BALL.hasSkinImages() ||
|
|
|
|
(!GameImage.SLIDER_BALL.hasSkinImage() && GameImage.SLIDER_BALL.getImages() != null))
|
|
|
|
sliderBallImages = GameImage.SLIDER_BALL.getImages();
|
|
|
|
else
|
|
|
|
sliderBallImages = new Image[]{ GameImage.SLIDER_BALL.getImage() };
|
|
|
|
for (int i = 0; i < sliderBallImages.length; i++)
|
|
|
|
sliderBallImages[i] = sliderBallImages[i].getScaledCopy(diameter * 118 / 128, diameter * 118 / 128);
|
2015-03-19 08:04:35 +01:00
|
|
|
|
2014-07-04 22:41:52 +02:00
|
|
|
GameImage.SLIDER_FOLLOWCIRCLE.setImage(GameImage.SLIDER_FOLLOWCIRCLE.getImage().getScaledCopy(diameter * 259 / 128, diameter * 259 / 128));
|
|
|
|
GameImage.REVERSEARROW.setImage(GameImage.REVERSEARROW.getImage().getScaledCopy(diameter, diameter));
|
|
|
|
GameImage.SLIDER_TICK.setImage(GameImage.SLIDER_TICK.getImage().getScaledCopy(diameter / 4, diameter / 4));
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
sliderMultiplier = osu.sliderMultiplier;
|
|
|
|
sliderTickRate = osu.sliderTickRate;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
* @param hitObject the associated OsuHitObject
|
|
|
|
* @param game the associated Game object
|
2015-01-27 09:19:39 +01:00
|
|
|
* @param data the associated GameData object
|
2015-01-30 02:36:23 +01:00
|
|
|
* @param color the color of this slider
|
2014-06-30 04:17:04 +02:00
|
|
|
* @param comboEnd true if this is the last hit object in the combo
|
|
|
|
*/
|
2015-01-27 09:19:39 +01:00
|
|
|
public Slider(OsuHitObject hitObject, Game game, GameData data, Color color, boolean comboEnd) {
|
2014-06-30 04:17:04 +02:00
|
|
|
this.hitObject = hitObject;
|
2015-03-13 01:12:43 +01:00
|
|
|
this.x = hitObject.getScaledX();
|
|
|
|
this.y = hitObject.getScaledY();
|
2014-06-30 04:17:04 +02:00
|
|
|
this.game = game;
|
2015-01-27 09:19:39 +01:00
|
|
|
this.data = data;
|
2014-06-30 04:17:04 +02:00
|
|
|
this.color = color;
|
|
|
|
this.comboEnd = comboEnd;
|
|
|
|
|
2015-03-14 13:11:33 +01:00
|
|
|
if (hitObject.getSliderType() == OsuHitObject.SLIDER_PASSTHROUGH && hitObject.getSliderX().length == 2)
|
2015-01-30 02:36:23 +01:00
|
|
|
this.curve = new CircumscribedCircle(hitObject, color);
|
|
|
|
else
|
|
|
|
this.curve = new LinearBezier(hitObject, color);
|
2015-03-28 13:11:43 +01:00
|
|
|
|
|
|
|
// slider time calculations
|
|
|
|
this.sliderTime = game.getBeatLength() * (hitObject.getPixelLength() / sliderMultiplier) / 100f;
|
|
|
|
this.sliderTimeTotal = sliderTime * hitObject.getRepeatCount();
|
|
|
|
|
|
|
|
// ticks
|
|
|
|
float tickLengthDiv = 100f * sliderMultiplier / sliderTickRate / game.getTimingPointMultiplier();
|
|
|
|
int tickCount = (int) Math.ceil(hitObject.getPixelLength() / tickLengthDiv) - 1;
|
|
|
|
if (tickCount > 0) {
|
|
|
|
this.ticksT = new float[tickCount];
|
|
|
|
float tickTOffset = 1f / (tickCount + 1);
|
|
|
|
float t = tickTOffset;
|
|
|
|
for (int i = 0; i < tickCount; i++, t += tickTOffset)
|
|
|
|
ticksT[i] = t;
|
|
|
|
}
|
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) {
|
2014-07-18 21:11:57 +02:00
|
|
|
int timeDiff = hitObject.getTime() - trackPosition;
|
2015-02-15 07:40:01 +01:00
|
|
|
float scale = timeDiff / (float) game.getApproachTime();
|
|
|
|
float approachScale = 1 + scale * 3;
|
2015-02-24 00:12:31 +01:00
|
|
|
float alpha = Utils.clamp(1 - scale, 0, 1);
|
2015-02-15 07:40:01 +01:00
|
|
|
|
2015-01-18 18:39:30 +01:00
|
|
|
float oldAlpha = color.a;
|
2015-02-24 00:12:31 +01:00
|
|
|
color.a = alpha;
|
2014-12-24 08:45:43 +01:00
|
|
|
Utils.COLOR_WHITE_FADE.a = alpha;
|
2015-02-15 07:40:01 +01:00
|
|
|
|
2015-01-30 02:36:23 +01:00
|
|
|
// curve
|
|
|
|
curve.draw();
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
// ticks
|
2015-03-07 21:38:59 +01:00
|
|
|
if (timeDiff < 0 && ticksT != null) {
|
2014-12-24 08:45:43 +01:00
|
|
|
Image tick = GameImage.SLIDER_TICK.getImage();
|
2014-06-30 04:17:04 +02:00
|
|
|
for (int i = 0; i < ticksT.length; i++) {
|
2015-01-30 02:36:23 +01:00
|
|
|
float[] c = curve.pointAt(ticksT[i]);
|
2014-12-24 08:45:43 +01:00
|
|
|
tick.drawCentered(c[0], c[1]);
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-24 08:45:43 +01:00
|
|
|
Image hitCircleOverlay = GameImage.HITCIRCLE_OVERLAY.getImage();
|
|
|
|
Image hitCircle = GameImage.HITCIRCLE.getImage();
|
2015-02-15 07:40:01 +01:00
|
|
|
color.a = alpha;
|
2015-02-24 00:12:31 +01:00
|
|
|
Utils.COLOR_WHITE_FADE.a = 1f;
|
2014-12-24 08:45:43 +01:00
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
// end circle
|
2015-01-30 02:36:23 +01:00
|
|
|
float[] endPos = curve.pointAt(1);
|
2015-02-19 06:33:32 +01:00
|
|
|
hitCircle.drawCentered(endPos[0], endPos[1], color);
|
|
|
|
hitCircleOverlay.drawCentered(endPos[0], endPos[1], Utils.COLOR_WHITE_FADE);
|
2015-01-30 02:36:23 +01:00
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
// start circle
|
2015-02-19 06:33:32 +01:00
|
|
|
hitCircle.drawCentered(x, y, color);
|
|
|
|
hitCircleOverlay.drawCentered(x, y, Utils.COLOR_WHITE_FADE);
|
2015-02-21 23:12:18 +01:00
|
|
|
if (sliderClickedInitial)
|
2014-06-30 04:17:04 +02:00
|
|
|
; // don't draw current combo number if already clicked
|
|
|
|
else
|
2015-01-27 09:19:39 +01:00
|
|
|
data.drawSymbolNumber(hitObject.getComboNumber(), x, y,
|
|
|
|
hitCircle.getWidth() * 0.40f / data.getDefaultSymbolImage(0).getHeight());
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2015-01-18 18:39:30 +01:00
|
|
|
color.a = oldAlpha;
|
2014-12-24 08:45:43 +01:00
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
// repeats
|
2015-03-15 20:38:04 +01:00
|
|
|
for (int tcurRepeat = currentRepeats; tcurRepeat <= currentRepeats + 1; tcurRepeat++) {
|
2015-01-28 06:30:51 +01:00
|
|
|
if (hitObject.getRepeatCount() - 1 > tcurRepeat) {
|
|
|
|
Image arrow = GameImage.REVERSEARROW.getImage();
|
2015-01-30 02:36:23 +01:00
|
|
|
if (tcurRepeat != currentRepeats) {
|
2015-03-16 04:05:27 +01:00
|
|
|
if (sliderTime == 0)
|
|
|
|
continue;
|
|
|
|
float t = Math.max(getT(trackPosition, true), 0);
|
2015-01-30 02:36:23 +01:00
|
|
|
arrow.setAlpha((float) (t - Math.floor(t)));
|
|
|
|
} else
|
2015-01-28 06:30:51 +01:00
|
|
|
arrow.setAlpha(1f);
|
2015-01-30 02:36:23 +01:00
|
|
|
if (tcurRepeat % 2 == 0) {
|
|
|
|
// last circle
|
|
|
|
arrow.setRotation(curve.getEndAngle());
|
2015-01-28 06:30:51 +01:00
|
|
|
arrow.drawCentered(endPos[0], endPos[1]);
|
2015-01-30 02:36:23 +01:00
|
|
|
} else {
|
|
|
|
// first circle
|
|
|
|
arrow.setRotation(curve.getStartAngle());
|
2015-01-28 06:30:51 +01:00
|
|
|
arrow.drawCentered(x, y);
|
|
|
|
}
|
2014-07-03 05:38:30 +02:00
|
|
|
}
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (timeDiff >= 0) {
|
|
|
|
// approach circle
|
2015-02-14 19:45:14 +01:00
|
|
|
color.a = 1 - scale;
|
2015-02-19 06:33:32 +01:00
|
|
|
GameImage.APPROACHCIRCLE.getImage().getScaledCopy(approachScale).drawCentered(x, y, color);
|
2014-06-30 04:17:04 +02:00
|
|
|
} else {
|
2015-03-19 08:04:35 +01:00
|
|
|
// Since update() might not have run before drawing during a replay, the
|
|
|
|
// slider time may not have been calculated, which causes NAN numbers and flicker.
|
2015-03-16 04:05:27 +01:00
|
|
|
if (sliderTime == 0)
|
|
|
|
return;
|
2015-03-19 08:04:35 +01:00
|
|
|
|
2015-01-30 02:36:23 +01:00
|
|
|
float[] c = curve.pointAt(getT(trackPosition, false));
|
2015-02-10 03:40:38 +01:00
|
|
|
float[] c2 = curve.pointAt(getT(trackPosition, false) + 0.01f);
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2015-03-16 04:05:27 +01:00
|
|
|
float t = getT(trackPosition, false);
|
2015-03-19 08:04:35 +01:00
|
|
|
// float dis = hitObject.getPixelLength() * OsuHitObject.getXMultiplier() * (t - (int) t);
|
|
|
|
// Image sliderBallFrame = sliderBallImages[(int) (dis / (diameter * Math.PI) * 30) % sliderBallImages.length];
|
|
|
|
Image sliderBallFrame = sliderBallImages[(int) (t * sliderTime * 60 / 1000) % sliderBallImages.length];
|
2015-02-15 07:40:01 +01:00
|
|
|
float angle = (float) (Math.atan2(c2[1] - c[1], c2[0] - c[0]) * 180 / Math.PI);
|
2015-02-10 03:40:38 +01:00
|
|
|
sliderBallFrame.setRotation(angle);
|
|
|
|
sliderBallFrame.drawCentered(c[0], c[1]);
|
2015-02-15 07:40:01 +01:00
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
// follow circle
|
2015-03-15 20:38:04 +01:00
|
|
|
if (followCircleActive) {
|
2014-07-04 22:41:52 +02:00
|
|
|
GameImage.SLIDER_FOLLOWCIRCLE.getImage().drawCentered(c[0], c[1]);
|
2015-03-15 20:38:04 +01:00
|
|
|
|
|
|
|
// "flashlight" mod: dim the screen
|
|
|
|
if (GameMod.FLASHLIGHT.isActive()) {
|
|
|
|
float oldAlphaBlack = Utils.COLOR_BLACK_ALPHA.a;
|
|
|
|
Utils.COLOR_BLACK_ALPHA.a = 0.75f;
|
|
|
|
g.setColor(Utils.COLOR_BLACK_ALPHA);
|
|
|
|
g.fillRect(0, 0, containerWidth, containerHeight);
|
|
|
|
Utils.COLOR_BLACK_ALPHA.a = oldAlphaBlack;
|
|
|
|
}
|
|
|
|
}
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculates the slider 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
|
|
|
float tickRatio = (float) ticksHit / tickIntervals;
|
|
|
|
|
|
|
|
int result;
|
|
|
|
if (tickRatio >= 1.0f)
|
2015-01-27 09:19:39 +01:00
|
|
|
result = GameData.HIT_300;
|
2014-06-30 04:17:04 +02:00
|
|
|
else if (tickRatio >= 0.5f)
|
2015-01-27 09:19:39 +01:00
|
|
|
result = GameData.HIT_100;
|
2014-06-30 04:17:04 +02:00
|
|
|
else if (tickRatio > 0f)
|
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-30 02:36:23 +01:00
|
|
|
if (currentRepeats % 2 == 0) { // last circle
|
|
|
|
float[] lastPos = curve.pointAt(1);
|
2015-01-27 09:19:39 +01:00
|
|
|
data.hitResult(hitObject.getTime() + (int) sliderTimeTotal, result,
|
2015-03-01 19:58:03 +01:00
|
|
|
lastPos[0], lastPos[1], color, comboEnd, hitObject, currentRepeats + 1);
|
2015-01-30 02:36:23 +01:00
|
|
|
} else { // first circle
|
2015-01-27 09:19:39 +01:00
|
|
|
data.hitResult(hitObject.getTime() + (int) sliderTimeTotal, result,
|
2015-03-13 01:12:43 +01:00
|
|
|
x, y, color, comboEnd, hitObject, currentRepeats + 1);
|
2015-01-30 02:36:23 +01:00
|
|
|
}
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-01-16 21:44:13 +01:00
|
|
|
@Override
|
2015-03-15 19:15:34 +01:00
|
|
|
public boolean mousePressed(int x, int y, int trackPosition) {
|
2015-02-21 23:12:18 +01:00
|
|
|
if (sliderClickedInitial) // first circle already processed
|
2014-06-30 04:17:04 +02:00
|
|
|
return false;
|
|
|
|
|
2015-03-13 01:12:43 +01:00
|
|
|
double distance = Math.hypot(this.x - x, this.y - y);
|
2014-07-04 22:41:52 +02:00
|
|
|
int circleRadius = GameImage.HITCIRCLE.getImage().getWidth() / 2;
|
2014-06-30 04:17:04 +02:00
|
|
|
if (distance < circleRadius) {
|
2014-07-18 21:11:57 +02:00
|
|
|
int timeDiff = Math.abs(trackPosition - hitObject.getTime());
|
2014-06-30 04:17:04 +02:00
|
|
|
int[] hitResultOffset = game.getHitResultOffsets();
|
2015-01-16 21:44:13 +01:00
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
int result = -1;
|
2015-01-27 09:19:39 +01:00
|
|
|
if (timeDiff < hitResultOffset[GameData.HIT_50]) {
|
|
|
|
result = GameData.HIT_SLIDER30;
|
2014-06-30 04:17:04 +02:00
|
|
|
ticksHit++;
|
2015-01-27 09:19:39 +01:00
|
|
|
} else if (timeDiff < hitResultOffset[GameData.HIT_MISS])
|
|
|
|
result = GameData.HIT_MISS;
|
2014-06-30 04:17:04 +02:00
|
|
|
//else not a hit
|
|
|
|
|
|
|
|
if (result > -1) {
|
2015-02-15 04:15:41 +01:00
|
|
|
data.addHitError(hitObject.getTime(), x,y,trackPosition - hitObject.getTime());
|
2015-02-21 23:12:18 +01:00
|
|
|
sliderClickedInitial = true;
|
2015-03-13 01:12:43 +01:00
|
|
|
data.sliderTickResult(hitObject.getTime(), result, this.x, this.y, hitObject, currentRepeats);
|
2014-06-30 04:17:04 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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-07-18 21:11:57 +02:00
|
|
|
int repeatCount = hitObject.getRepeatCount();
|
2015-01-16 21:44:13 +01:00
|
|
|
int[] hitResultOffset = game.getHitResultOffsets();
|
2014-07-16 22:01:36 +02:00
|
|
|
boolean isAutoMod = GameMod.AUTO.isActive();
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2015-02-21 23:12:18 +01:00
|
|
|
if (!sliderClickedInitial) {
|
2014-07-18 21:11:57 +02:00
|
|
|
int time = hitObject.getTime();
|
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
// start circle time passed
|
2015-01-27 09:19:39 +01:00
|
|
|
if (trackPosition > time + hitResultOffset[GameData.HIT_50]) {
|
2015-02-21 23:12:18 +01:00
|
|
|
sliderClickedInitial = true;
|
2014-06-30 04:17:04 +02:00
|
|
|
if (isAutoMod) { // "auto" mod: catch any missed notes due to lag
|
|
|
|
ticksHit++;
|
2015-03-13 01:12:43 +01:00
|
|
|
data.sliderTickResult(time, GameData.HIT_SLIDER30, x, y, hitObject, currentRepeats);
|
2014-06-30 04:17:04 +02:00
|
|
|
} else
|
2015-03-13 01:12:43 +01:00
|
|
|
data.sliderTickResult(time, GameData.HIT_MISS, x, y, hitObject, currentRepeats);
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// "auto" mod: send a perfect hit result
|
|
|
|
else if (isAutoMod) {
|
2015-01-27 09:19:39 +01:00
|
|
|
if (Math.abs(trackPosition - time) < hitResultOffset[GameData.HIT_300]) {
|
2014-06-30 04:17:04 +02:00
|
|
|
ticksHit++;
|
2015-02-21 23:12:18 +01:00
|
|
|
sliderClickedInitial = true;
|
2015-03-13 01:12:43 +01:00
|
|
|
data.sliderTickResult(time, GameData.HIT_SLIDER30, x, y, hitObject, currentRepeats);
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
}
|
2015-03-06 06:25:48 +01:00
|
|
|
|
|
|
|
// "relax" mod: click automatically
|
|
|
|
else if (GameMod.RELAX.isActive() && trackPosition >= time)
|
2015-03-15 19:15:34 +01:00
|
|
|
mousePressed(mouseX, mouseY, trackPosition);
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// end of slider
|
2014-07-18 21:11:57 +02:00
|
|
|
if (overlap || trackPosition > hitObject.getTime() + sliderTimeTotal) {
|
2014-06-30 04:17:04 +02:00
|
|
|
tickIntervals++;
|
|
|
|
|
|
|
|
// check if cursor pressed and within end circle
|
2015-03-09 23:32:43 +01:00
|
|
|
if (keyPressed || GameMod.RELAX.isActive()) {
|
2015-01-30 02:36:23 +01:00
|
|
|
float[] c = curve.pointAt(getT(trackPosition, false));
|
2014-07-19 03:13:17 +02:00
|
|
|
double distance = Math.hypot(c[0] - mouseX, c[1] - mouseY);
|
2014-07-04 22:41:52 +02:00
|
|
|
int followCircleRadius = GameImage.SLIDER_FOLLOWCIRCLE.getImage().getWidth() / 2;
|
2014-06-30 04:17:04 +02:00
|
|
|
if (distance < followCircleRadius)
|
2015-02-21 23:12:18 +01:00
|
|
|
sliderClickedFinal = true;
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
2014-07-06 03:00:52 +02:00
|
|
|
|
2015-02-21 23:12:18 +01:00
|
|
|
// final circle hit
|
|
|
|
if (sliderClickedFinal)
|
|
|
|
ticksHit++;
|
|
|
|
|
|
|
|
// "auto" mod: always send a perfect hit result
|
|
|
|
if (isAutoMod)
|
|
|
|
ticksHit = tickIntervals;
|
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
// calculate and send slider result
|
|
|
|
hitResult();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// repeats
|
|
|
|
boolean isNewRepeat = false;
|
2014-07-18 21:11:57 +02:00
|
|
|
if (repeatCount - 1 > currentRepeats) {
|
2014-06-30 04:17:04 +02:00
|
|
|
float t = getT(trackPosition, true);
|
|
|
|
if (Math.floor(t) > currentRepeats) {
|
|
|
|
currentRepeats++;
|
|
|
|
tickIntervals++;
|
|
|
|
isNewRepeat = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ticks
|
|
|
|
boolean isNewTick = false;
|
|
|
|
if (ticksT != null &&
|
2014-07-18 21:11:57 +02:00
|
|
|
tickIntervals < (ticksT.length * (currentRepeats + 1)) + repeatCount &&
|
|
|
|
tickIntervals < (ticksT.length * repeatCount) + repeatCount) {
|
2014-06-30 04:17:04 +02:00
|
|
|
float t = getT(trackPosition, true);
|
|
|
|
if (t - Math.floor(t) >= ticksT[tickIndex]) {
|
|
|
|
tickIntervals++;
|
|
|
|
tickIndex = (tickIndex + 1) % ticksT.length;
|
|
|
|
isNewTick = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// holding slider...
|
2015-01-30 02:36:23 +01:00
|
|
|
float[] c = curve.pointAt(getT(trackPosition, false));
|
2014-06-30 04:17:04 +02:00
|
|
|
double distance = Math.hypot(c[0] - mouseX, c[1] - mouseY);
|
2014-07-04 22:41:52 +02:00
|
|
|
int followCircleRadius = GameImage.SLIDER_FOLLOWCIRCLE.getImage().getWidth() / 2;
|
2015-03-09 23:32:43 +01:00
|
|
|
if (((keyPressed || GameMod.RELAX.isActive()) && distance < followCircleRadius) || isAutoMod) {
|
2014-06-30 04:17:04 +02:00
|
|
|
// mouse pressed and within follow circle
|
|
|
|
followCircleActive = true;
|
2015-01-27 09:19:39 +01:00
|
|
|
data.changeHealth(delta * GameData.HP_DRAIN_MULTIPLIER);
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
// held during new repeat
|
|
|
|
if (isNewRepeat) {
|
|
|
|
ticksHit++;
|
2015-03-13 01:12:43 +01:00
|
|
|
if (currentRepeats % 2 > 0) { // last circle
|
|
|
|
int lastIndex = hitObject.getSliderX().length;
|
2015-01-27 09:19:39 +01:00
|
|
|
data.sliderTickResult(trackPosition, GameData.HIT_SLIDER30,
|
2015-03-13 01:12:43 +01:00
|
|
|
curve.getX(lastIndex), curve.getY(lastIndex), hitObject, currentRepeats);
|
|
|
|
} else // first circle
|
2015-01-27 09:19:39 +01:00
|
|
|
data.sliderTickResult(trackPosition, GameData.HIT_SLIDER30,
|
2015-03-01 17:06:46 +01:00
|
|
|
c[0], c[1], hitObject, currentRepeats);
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// held during new tick
|
|
|
|
if (isNewTick) {
|
|
|
|
ticksHit++;
|
2015-01-27 09:19:39 +01:00
|
|
|
data.sliderTickResult(trackPosition, GameData.HIT_SLIDER10,
|
2015-03-01 17:06:46 +01:00
|
|
|
c[0], c[1], hitObject, currentRepeats);
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
2015-02-21 23:12:18 +01:00
|
|
|
|
|
|
|
// held near end of slider
|
|
|
|
if (!sliderClickedFinal && trackPosition > hitObject.getTime() + sliderTimeTotal - hitResultOffset[GameData.HIT_300])
|
|
|
|
sliderClickedFinal = true;
|
2014-06-30 04:17:04 +02:00
|
|
|
} else {
|
|
|
|
followCircleActive = false;
|
|
|
|
|
|
|
|
if (isNewRepeat)
|
2015-03-01 17:06:46 +01:00
|
|
|
data.sliderTickResult(trackPosition, GameData.HIT_MISS, 0, 0, hitObject, currentRepeats);
|
2014-06-30 04:17:04 +02:00
|
|
|
if (isNewTick)
|
2015-03-01 17:06:46 +01:00
|
|
|
data.sliderTickResult(trackPosition, GameData.HIT_MISS, 0, 0, hitObject, currentRepeats);
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-03-28 13:11:43 +01:00
|
|
|
@Override
|
|
|
|
public void updatePosition() {
|
|
|
|
this.x = hitObject.getScaledX();
|
|
|
|
this.y = hitObject.getScaledY();
|
|
|
|
}
|
|
|
|
|
2015-03-17 19:48:13 +01:00
|
|
|
@Override
|
|
|
|
public float[] getPointAt(int trackPosition) {
|
|
|
|
if (trackPosition <= hitObject.getTime())
|
|
|
|
return new float[] { x, y };
|
|
|
|
else if (trackPosition >= hitObject.getTime() + sliderTimeTotal) {
|
|
|
|
if (hitObject.getRepeatCount() % 2 == 0)
|
|
|
|
return new float[] { x, y };
|
|
|
|
else {
|
|
|
|
int lastIndex = hitObject.getSliderX().length;
|
|
|
|
return new float[] { curve.getX(lastIndex), curve.getY(lastIndex) };
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
return curve.pointAt(getT(trackPosition, false));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getEndTime() { return hitObject.getTime() + (int) sliderTimeTotal; }
|
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
/**
|
|
|
|
* Returns the t value based on the given track position.
|
|
|
|
* @param trackPosition the current track position
|
|
|
|
* @param raw if false, ensures that the value lies within [0, 1] by looping repeats
|
|
|
|
* @return the t value: raw [0, repeats] or looped [0, 1]
|
|
|
|
*/
|
2015-01-16 09:47:37 +01:00
|
|
|
private float getT(int trackPosition, boolean raw) {
|
2014-07-18 21:11:57 +02:00
|
|
|
float t = (trackPosition - hitObject.getTime()) / sliderTime;
|
2014-06-30 04:17:04 +02:00
|
|
|
if (raw)
|
|
|
|
return t;
|
|
|
|
else {
|
|
|
|
float floor = (float) Math.floor(t);
|
|
|
|
return (floor % 2 == 0) ? t - floor : floor + 1 - t;
|
|
|
|
}
|
|
|
|
}
|
2015-03-18 04:47:33 +01:00
|
|
|
}
|