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-28 06:30:51 +01:00
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.LinkedList;
|
|
|
|
|
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-01-27 09:19:39 +01:00
|
|
|
import itdelatrisu.opsu.GameData;
|
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-08 01:29:51 +01:00
|
|
|
import itdelatrisu.opsu.audio.MusicController;
|
2014-06-30 04:17:04 +02:00
|
|
|
import itdelatrisu.opsu.states.Game;
|
|
|
|
|
|
|
|
import org.newdawn.slick.Animation;
|
|
|
|
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-01-22 06:44:45 +01:00
|
|
|
/** Slider ball animation. */
|
2014-06-30 04:17:04 +02:00
|
|
|
private static Animation sliderBall;
|
|
|
|
|
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-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-22 06:44:45 +01:00
|
|
|
/** The underlying Bezier object. */
|
2015-01-28 06:30:51 +01:00
|
|
|
private Curve bezier;
|
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-01-22 06:44:45 +01:00
|
|
|
/** Whether or not the result of the initial hit circle has been processed. */
|
2014-06-30 04:17:04 +02:00
|
|
|
private boolean sliderClicked = false;
|
|
|
|
|
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-01-28 06:30:51 +01:00
|
|
|
private abstract class Curve{
|
2015-01-29 06:37:25 +01:00
|
|
|
/**
|
|
|
|
* Returns the point on the curve at a value t.
|
|
|
|
* @param t the t value [0, 1]
|
|
|
|
* @return the point [x, y]
|
|
|
|
*/
|
2015-01-28 06:30:51 +01:00
|
|
|
public abstract float[] pointAt(float t);
|
|
|
|
|
2015-01-29 06:37:25 +01:00
|
|
|
/**
|
|
|
|
* Draws the full Bezier curve to the graphics context.
|
|
|
|
*/
|
2015-01-28 06:30:51 +01:00
|
|
|
public abstract void draw();
|
|
|
|
|
2015-01-29 06:37:25 +01:00
|
|
|
/**
|
|
|
|
* Returns the angle of the first control point.
|
|
|
|
*/
|
2015-01-28 06:30:51 +01:00
|
|
|
public abstract float getEndAngle();
|
2015-01-29 06:37:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the angle of the last control point.
|
|
|
|
*/
|
2015-01-28 06:30:51 +01:00
|
|
|
public abstract float getStartAngle();
|
|
|
|
}
|
2015-01-29 06:37:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A two dimensional vector
|
|
|
|
*/
|
2015-01-28 06:30:51 +01:00
|
|
|
private class Vec2f{
|
|
|
|
float x, y;
|
2015-01-29 06:37:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor of the (nx, ny) Vector
|
|
|
|
* @param nx
|
|
|
|
* @param ny
|
|
|
|
*/
|
2015-01-28 06:30:51 +01:00
|
|
|
public Vec2f(float nx, float ny) {
|
|
|
|
x=nx;
|
|
|
|
y=ny;
|
|
|
|
}
|
2015-01-29 06:37:25 +01:00
|
|
|
/**
|
|
|
|
* Constructor of the (0,0) Vector
|
|
|
|
*/
|
2015-01-28 06:30:51 +01:00
|
|
|
public Vec2f() {
|
|
|
|
}
|
2015-01-29 06:37:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Finds the midpoint between this Vector and "o" Vector
|
|
|
|
* @param o the other Vector
|
|
|
|
* @return midpoint vector
|
|
|
|
*/
|
2015-01-28 06:30:51 +01:00
|
|
|
public Vec2f midPoint(Vec2f o){
|
|
|
|
return new Vec2f((x+o.x)/2, (y+o.y)/2);
|
|
|
|
}
|
2015-01-29 06:37:25 +01:00
|
|
|
/**
|
|
|
|
* Subtracts the "o" vector from this vector
|
|
|
|
* @param o the other Vector
|
|
|
|
* @return itself for chaining
|
|
|
|
*/
|
2015-01-28 06:30:51 +01:00
|
|
|
public Vec2f sub(Vec2f o){
|
|
|
|
x-=o.x;
|
|
|
|
y-=o.y;
|
|
|
|
return this;
|
|
|
|
}
|
2015-01-29 06:37:25 +01:00
|
|
|
/**
|
|
|
|
* Sets this Vector to the normal of this Vector
|
|
|
|
* @return itself for chaining
|
|
|
|
*/
|
2015-01-28 06:30:51 +01:00
|
|
|
public Vec2f nor(){
|
|
|
|
float nx = -y, ny =x;
|
|
|
|
x=nx;
|
|
|
|
y=ny;
|
|
|
|
return this;
|
|
|
|
}
|
2015-01-29 06:37:25 +01:00
|
|
|
/**
|
|
|
|
* Makes a new Vector that is a copy of this Vector
|
|
|
|
* @return a copy of this Vector
|
|
|
|
*/
|
2015-01-28 06:30:51 +01:00
|
|
|
public Vec2f cpy(){
|
|
|
|
return new Vec2f(x, y);
|
|
|
|
}
|
2015-01-29 06:37:25 +01:00
|
|
|
/**
|
|
|
|
* Adds nx to the x component and ny to the y component of this Vector
|
|
|
|
* @param nx
|
|
|
|
* @param ny
|
|
|
|
* @return
|
|
|
|
*/
|
2015-01-28 06:30:51 +01:00
|
|
|
public Vec2f add(float nx, float ny) {
|
|
|
|
x+=nx;
|
|
|
|
y+=ny;
|
|
|
|
return this;
|
|
|
|
}
|
2015-01-29 06:37:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Finds the length of this Vector
|
|
|
|
* @return the length of this Vector
|
|
|
|
*/
|
2015-01-28 06:30:51 +01:00
|
|
|
public float len() {
|
|
|
|
return (float) Math.sqrt(x*x + y*y);
|
|
|
|
}
|
2015-01-29 06:37:25 +01:00
|
|
|
/**
|
|
|
|
* Compares this vector to another Vector
|
|
|
|
* @param o the Other Vector
|
|
|
|
* @return true if the two Vector are numerically equal
|
|
|
|
*/
|
2015-01-28 06:30:51 +01:00
|
|
|
public boolean equals(Vec2f o){
|
|
|
|
return x==o.x && y==o.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2015-01-29 06:37:25 +01:00
|
|
|
/**
|
|
|
|
* Representation of a curve along a Circumscribed Circle of three points.
|
|
|
|
* http://en.wikipedia.org/wiki/Circumscribed_circle
|
|
|
|
*/
|
2015-01-28 06:30:51 +01:00
|
|
|
private class CircumscribedCircle extends Curve{
|
2015-01-29 06:37:25 +01:00
|
|
|
/** The center of the Circumscribed Circle */
|
2015-01-28 06:30:51 +01:00
|
|
|
Vec2f circleCenter;
|
2015-01-29 06:37:25 +01:00
|
|
|
|
|
|
|
/** The radius of the Circumscribed Circle */
|
|
|
|
float radius;
|
|
|
|
|
|
|
|
/** * The three points to create the Circumscribed Circle from */
|
2015-01-28 06:30:51 +01:00
|
|
|
Vec2f start ,mid ,end;
|
2015-01-29 06:37:25 +01:00
|
|
|
|
|
|
|
/** The three angles relative to the circle center */
|
2015-01-28 06:30:51 +01:00
|
|
|
float startAng,endAng,midAng;
|
2015-01-29 06:37:25 +01:00
|
|
|
|
|
|
|
/** The start and end angles for drawing */
|
2015-01-28 06:30:51 +01:00
|
|
|
float drawStartAngle,drawEndAngle;
|
2015-01-29 06:37:25 +01:00
|
|
|
|
|
|
|
/** Two times Pi or one full circle in radians */
|
|
|
|
final float TWO_PI = (float) (2*Math.PI);
|
|
|
|
/** Pi divided by two or a quarter of a circle in radians */
|
|
|
|
final float HALF_PI = (float) (Math.PI/2);
|
|
|
|
|
|
|
|
/** The number of steps in the curve to draw */
|
2015-01-28 06:30:51 +01:00
|
|
|
private float step;
|
|
|
|
|
2015-01-29 06:37:25 +01:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
2015-01-28 06:30:51 +01:00
|
|
|
public CircumscribedCircle(){
|
|
|
|
this.step = hitObject.getPixelLength() / 5;
|
|
|
|
|
2015-01-29 06:37:25 +01:00
|
|
|
//construct the three points
|
|
|
|
start = new Vec2f(getX(0), getY(0));
|
|
|
|
mid = new Vec2f(getX(1), getY(1));
|
|
|
|
end = new Vec2f(getX(2), getY(2));
|
|
|
|
|
|
|
|
//find the circle center
|
2015-01-28 06:30:51 +01:00
|
|
|
Vec2f mida = start.midPoint(mid);
|
|
|
|
Vec2f midb = end.midPoint(mid);
|
|
|
|
Vec2f nora = mid.cpy().sub(start).nor();
|
|
|
|
Vec2f norb = mid.cpy().sub(end).nor();
|
|
|
|
|
|
|
|
circleCenter = intersect(mida, nora, midb, norb);
|
|
|
|
|
2015-01-29 06:37:25 +01:00
|
|
|
//find the angles relative to the circle center
|
2015-01-28 06:30:51 +01:00
|
|
|
Vec2f startAngPoint = start.cpy().sub(circleCenter);
|
|
|
|
Vec2f midAngPoint = mid.cpy().sub(circleCenter);
|
|
|
|
Vec2f endAngPoint = end.cpy().sub(circleCenter);
|
|
|
|
|
|
|
|
startAng = (float) Math.atan2(startAngPoint.y, startAngPoint.x);
|
|
|
|
midAng = (float) Math.atan2(midAngPoint.y, midAngPoint.x);
|
|
|
|
endAng = (float) Math.atan2(endAngPoint.y, endAngPoint.x);
|
|
|
|
|
|
|
|
|
|
|
|
//find angles that passes thru midAng
|
|
|
|
if(!isIn(startAng,midAng,endAng)){
|
2015-01-29 06:37:25 +01:00
|
|
|
if(Math.abs(startAng+TWO_PI-endAng)<TWO_PI && isIn(startAng+(TWO_PI),midAng,endAng)){
|
|
|
|
startAng+=TWO_PI;
|
|
|
|
}else if(Math.abs(startAng-(endAng+TWO_PI))<TWO_PI && isIn(startAng,midAng,endAng+(TWO_PI))){
|
|
|
|
endAng+=TWO_PI;
|
|
|
|
}else if(Math.abs(startAng-TWO_PI-endAng)<TWO_PI && isIn(startAng-(TWO_PI),midAng,endAng)){
|
|
|
|
startAng-=TWO_PI;
|
|
|
|
}else if(Math.abs(startAng-(endAng-TWO_PI))<TWO_PI && isIn(startAng,midAng,endAng-(TWO_PI))){
|
|
|
|
endAng-=TWO_PI;
|
2015-01-28 06:30:51 +01:00
|
|
|
}else{
|
|
|
|
throw new Error("Cannot find Angles between midAng "+startAng+" "+midAng+" "+endAng);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-01-29 06:37:25 +01:00
|
|
|
//Find an angle with an arc length of pixellength along this cirlce
|
2015-01-28 06:30:51 +01:00
|
|
|
radius = startAngPoint.len();
|
|
|
|
float pixelLength = hitObject.getPixelLength() * OsuHitObject.getMultiplier();
|
|
|
|
float arcAng = pixelLength / radius; //len = theta * r / theta = len/r
|
|
|
|
|
2015-01-29 06:37:25 +01:00
|
|
|
//now use it for our new end angle
|
2015-01-28 06:30:51 +01:00
|
|
|
if(endAng>startAng){
|
|
|
|
endAng=startAng+arcAng;
|
|
|
|
}else{
|
|
|
|
endAng=startAng-arcAng;
|
|
|
|
}
|
|
|
|
|
2015-01-29 06:37:25 +01:00
|
|
|
//finds the angles to draw for repeats
|
|
|
|
drawEndAngle = (float) ((endAng+(startAng>endAng?HALF_PI:-HALF_PI)) * 180 / Math.PI);
|
|
|
|
drawStartAngle = (float) ((startAng+(startAng>endAng?-HALF_PI:HALF_PI)) * 180 / Math.PI);
|
2015-01-28 06:30:51 +01:00
|
|
|
|
|
|
|
}
|
2015-01-29 06:37:25 +01:00
|
|
|
/**
|
|
|
|
* Checks to see if "b" is between "a" and "c"
|
|
|
|
* @param a
|
|
|
|
* @param b
|
|
|
|
* @param c
|
|
|
|
* @return true if b is between a and c
|
|
|
|
*/
|
2015-01-28 06:30:51 +01:00
|
|
|
private boolean isIn(float a,float b,float c){
|
|
|
|
return (b>a && b<c) || (b<a && b>c);
|
|
|
|
}
|
2015-01-29 06:37:25 +01:00
|
|
|
/**
|
|
|
|
* Finds the point of intersection between two parametric lines of A = a + ta*t and B = b + tb*u
|
|
|
|
* http://gamedev.stackexchange.com/questions/44720/line-intersection-from-parametric-equation
|
|
|
|
* @param a the initial position of the line A
|
|
|
|
* @param ta the direction of the line A
|
|
|
|
* @param b the initial position of the line B
|
|
|
|
* @param tb the direction of the line B
|
|
|
|
* @return the point at which the two lines interssect
|
|
|
|
*/
|
2015-01-28 06:30:51 +01:00
|
|
|
private Vec2f intersect(Vec2f a, Vec2f ta, Vec2f b, Vec2f tb) {
|
|
|
|
// xy = a + ta * t = b + tb * u
|
|
|
|
// t =(b + tb*u -a)/ta
|
|
|
|
//t(x) == t(y)
|
|
|
|
//(b.x + tb.x*u -a.x)/ta.x = (b.y + tb.y*u -a.y)/ta.y
|
|
|
|
// b.x*ta.y + tb.x*u*ta.y -a.x*ta.y = b.y*ta.x + tb.y*u*ta.x -a.y*ta.x
|
|
|
|
// tb.x*u*ta.y - tb.y*u*ta.x= b.y*ta.x -a.y*ta.x -b.x*ta.y +a.x*ta.y
|
|
|
|
//u *(tb.x*ta.y - tb.y*ta.x) = (b.y-a.y)ta.x +(a.x-b.x)ta.y
|
|
|
|
//u = ((b.y-a.y)ta.x +(a.x-b.x)ta.y) / (tb.x*ta.y - tb.y*ta.x);
|
|
|
|
|
|
|
|
float des = tb.x*ta.y - tb.y*ta.x;
|
|
|
|
if(Math.abs(des)<0.00001f){
|
|
|
|
throw new Error("parallel ");
|
|
|
|
}
|
|
|
|
float u = ((b.y-a.y)*ta.x + (a.x-b.x)*ta.y) / des;
|
|
|
|
return b.cpy().add(tb.x*u,tb.y*u);
|
|
|
|
}
|
2015-01-29 06:37:25 +01:00
|
|
|
|
|
|
|
@Override
|
2015-01-28 06:30:51 +01:00
|
|
|
public float[] pointAt(float t) {
|
|
|
|
float ang = lerp(startAng, endAng, t);
|
|
|
|
return new float[]{(float) (Math.cos(ang)*radius+circleCenter.x),(float) (Math.sin(ang)*radius+circleCenter.y)};
|
|
|
|
}
|
2015-01-29 06:37:25 +01:00
|
|
|
@Override
|
2015-01-28 06:30:51 +01:00
|
|
|
public void draw() {
|
|
|
|
Image hitCircle = GameImage.HITCIRCLE.getImage();
|
|
|
|
Image hitCircleOverlay = GameImage.HITCIRCLE_OVERLAY.getImage();
|
|
|
|
// draw overlay and hit circle
|
|
|
|
for(int i=0; i<step; i++){
|
|
|
|
float[] xy = pointAt(i/step);
|
|
|
|
Utils.drawCentered(hitCircleOverlay, xy[0], xy[1], Utils.COLOR_WHITE_FADE);
|
|
|
|
}
|
|
|
|
for(int i=0; i<step; i++){
|
|
|
|
float[] xy = pointAt(i/step);
|
|
|
|
Utils.drawCentered(hitCircle, xy[0], xy[1], color);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public float getEndAngle() {
|
|
|
|
return drawEndAngle;
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public float getStartAngle() {
|
|
|
|
return drawStartAngle;
|
|
|
|
}
|
|
|
|
}
|
2014-06-30 04:17:04 +02:00
|
|
|
/**
|
|
|
|
* Representation of a Bezier curve, the main component of a slider.
|
|
|
|
*
|
|
|
|
* @author Alex Gheorghiu (http://html5tutorial.com/how-to-draw-n-grade-bezier-curve-with-canvas-api/)
|
|
|
|
* @author pictuga (https://github.com/pictuga/osu-web)
|
|
|
|
*/
|
|
|
|
private class Bezier {
|
2015-01-22 06:44:45 +01:00
|
|
|
/** The order of the Bezier curve. */
|
2014-06-30 04:17:04 +02:00
|
|
|
private int order;
|
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** The step size (used for drawing). */
|
2014-06-30 04:17:04 +02:00
|
|
|
private float step;
|
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** The curve points for drawing with step size given by 'step'. */
|
2014-06-30 04:17:04 +02:00
|
|
|
private float[] curveX, curveY;
|
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** The angles of the first and last control points. */
|
2014-07-03 05:38:30 +02:00
|
|
|
private float startAngle, endAngle;
|
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*/
|
2014-07-03 05:38:30 +02:00
|
|
|
public Bezier() {
|
2014-07-18 21:11:57 +02:00
|
|
|
this.order = hitObject.getSliderX().length + 1;
|
|
|
|
this.step = 5 / hitObject.getPixelLength();
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
// calculate curve points for drawing
|
|
|
|
int N = (int) (1 / step);
|
2014-07-09 04:17:48 +02:00
|
|
|
this.curveX = new float[N + 1];
|
|
|
|
this.curveY = new float[N + 1];
|
2014-06-30 04:17:04 +02:00
|
|
|
float t = 0f;
|
|
|
|
for (int i = 0; i < N; i++, t += step) {
|
|
|
|
float[] c = pointAt(t);
|
|
|
|
curveX[i] = c[0];
|
|
|
|
curveY[i] = c[1];
|
|
|
|
}
|
2014-07-09 04:17:48 +02:00
|
|
|
curveX[N] = getX(order - 1);
|
|
|
|
curveY[N] = getY(order - 1);
|
2014-07-03 05:38:30 +02:00
|
|
|
|
|
|
|
// calculate angles (if needed)
|
2014-07-18 21:11:57 +02:00
|
|
|
if (hitObject.getRepeatCount() > 1) {
|
2014-07-03 05:38:30 +02:00
|
|
|
float[] c1 = pointAt(0f);
|
2014-07-09 04:17:48 +02:00
|
|
|
float[] c2 = pointAt(step);
|
2014-07-03 05:38:30 +02:00
|
|
|
startAngle = (float) (Math.atan2(c2[1] - c1[1], c2[0] - c1[0]) * 180 / Math.PI);
|
|
|
|
c1 = pointAt(1f);
|
2014-07-09 04:17:48 +02:00
|
|
|
c2 = pointAt(1f - step);
|
2014-07-03 05:38:30 +02:00
|
|
|
endAngle = (float) (Math.atan2(c2[1] - c1[1], c2[0] - c1[0]) * 180 / Math.PI);
|
|
|
|
}
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the x coordinate of the control point at index i.
|
|
|
|
*/
|
|
|
|
private float getX(int i) {
|
2014-07-18 21:11:57 +02:00
|
|
|
return (i == 0) ? hitObject.getX() : hitObject.getSliderX()[i - 1];
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
2014-07-03 05:38:30 +02:00
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
/**
|
|
|
|
* Returns the y coordinate of the control point at index i.
|
|
|
|
*/
|
|
|
|
private float getY(int i) {
|
2014-07-18 21:11:57 +02:00
|
|
|
return (i == 0) ? hitObject.getY() : hitObject.getSliderY()[i - 1];
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
2014-07-03 05:38:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the angle of the first control point.
|
|
|
|
*/
|
|
|
|
private float getStartAngle() { return startAngle; }
|
2015-01-16 21:44:13 +01:00
|
|
|
|
2014-07-03 05:38:30 +02:00
|
|
|
/**
|
|
|
|
* Returns the angle of the last control point.
|
|
|
|
*/
|
|
|
|
private float getEndAngle() { return endAngle; }
|
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
/**
|
|
|
|
* Calculates the factorial of a number.
|
|
|
|
*/
|
|
|
|
private long factorial(int n) {
|
|
|
|
return (n <= 1 || n > 20) ? 1 : n * factorial(n - 1);
|
|
|
|
}
|
2014-07-03 05:38:30 +02:00
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
/**
|
|
|
|
* Calculates the Bernstein polynomial.
|
|
|
|
* @param i the index
|
|
|
|
* @param n the degree of the polynomial (i.e. number of points)
|
|
|
|
* @param t the t value [0, 1]
|
|
|
|
*/
|
|
|
|
private double bernstein(int i, int n, float t) {
|
|
|
|
return factorial(n) / (factorial(i) * factorial(n-i)) *
|
|
|
|
Math.pow(t, i) * Math.pow(1-t, n-i);
|
|
|
|
}
|
2014-07-03 05:38:30 +02:00
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
/**
|
|
|
|
* Returns the point on the Bezier curve at a value t.
|
|
|
|
* For curves of order greater than 4, points will be generated along
|
|
|
|
* a path of overlapping cubic (at most) Beziers.
|
|
|
|
* @param t the t value [0, 1]
|
|
|
|
* @return the point [x, y]
|
|
|
|
*/
|
|
|
|
public float[] pointAt(float t) {
|
|
|
|
float[] c = { 0f, 0f };
|
|
|
|
int n = order - 1;
|
|
|
|
if (n < 4) { // normal curve
|
|
|
|
for (int i = 0; i <= n; i++) {
|
2014-12-20 21:30:20 +01:00
|
|
|
c[0] += getX(i) * bernstein(i, n, t);
|
|
|
|
c[1] += getY(i) * bernstein(i, n, t);
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
} else { // split curve into path
|
|
|
|
// TODO: this is probably wrong...
|
|
|
|
int segmentCount = (n / 3) + 1;
|
|
|
|
int segment = (int) Math.floor(t * segmentCount);
|
|
|
|
int startIndex = 3 * segment;
|
|
|
|
int segmentOrder = Math.min(startIndex + 3, n) - startIndex;
|
|
|
|
float segmentT = (t * segmentCount) - segment;
|
|
|
|
for (int i = 0; i <= segmentOrder; i++) {
|
2014-12-20 21:30:20 +01:00
|
|
|
c[0] += getX(i + startIndex) * bernstein(i, segmentOrder, segmentT);
|
|
|
|
c[1] += getY(i + startIndex) * bernstein(i, segmentOrder, segmentT);
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draws the full Bezier curve to the graphics context.
|
|
|
|
*/
|
|
|
|
public void draw() {
|
2014-07-04 22:41:52 +02:00
|
|
|
Image hitCircle = GameImage.HITCIRCLE.getImage();
|
|
|
|
Image hitCircleOverlay = GameImage.HITCIRCLE_OVERLAY.getImage();
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
// draw overlay and hit circle
|
|
|
|
for (int i = curveX.length - 1; i >= 0; i--)
|
2014-12-24 08:45:43 +01:00
|
|
|
Utils.drawCentered(hitCircleOverlay, curveX[i], curveY[i], Utils.COLOR_WHITE_FADE);
|
2014-06-30 04:17:04 +02:00
|
|
|
for (int i = curveX.length - 1; i >= 0; i--)
|
2014-07-02 01:32:03 +02:00
|
|
|
Utils.drawCentered(hitCircle, curveX[i], curveY[i], color);
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
}
|
2015-01-28 06:30:51 +01:00
|
|
|
|
2015-01-29 06:37:25 +01:00
|
|
|
/**
|
|
|
|
* Representation of a Bezier curve with equal distant points.
|
|
|
|
* http://pomax.github.io/bezierinfo/#tracing
|
|
|
|
*/
|
2015-01-28 06:30:51 +01:00
|
|
|
private class LinearBezier extends Curve{
|
2015-01-29 06:37:25 +01:00
|
|
|
/** The angles of the first and last control points for drawing. */
|
2015-01-28 06:30:51 +01:00
|
|
|
private float startAngle, endAngle;
|
2015-01-29 06:37:25 +01:00
|
|
|
|
|
|
|
/** List of Bezier curves in the set of points */
|
2015-01-28 06:30:51 +01:00
|
|
|
LinkedList<Bezier2> beziers = new LinkedList<Bezier2>();
|
2015-01-29 06:37:25 +01:00
|
|
|
|
|
|
|
/** Points along the curve at equal distance. */
|
2015-01-28 06:30:51 +01:00
|
|
|
Vec2f[] curve;
|
2015-01-29 06:37:25 +01:00
|
|
|
|
|
|
|
/** The number of points along the curve */
|
2015-01-28 06:30:51 +01:00
|
|
|
int ncurve;
|
2015-01-29 06:37:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
2015-01-28 06:30:51 +01:00
|
|
|
public LinearBezier(){
|
|
|
|
//splits points into different beziers if has the same points(Red points)
|
|
|
|
|
2015-01-29 06:37:25 +01:00
|
|
|
int npoints = hitObject.getSliderX().length + 1; //The number of control points
|
|
|
|
LinkedList<Vec2f> points = new LinkedList<Vec2f>(); // a temporary list of points to separete different bezier curves
|
2015-01-28 06:30:51 +01:00
|
|
|
Vec2f lastPoi = null;
|
|
|
|
for(int i=0; i<npoints; i++){
|
|
|
|
Vec2f tpoi = new Vec2f(getX(i), getY(i));
|
|
|
|
if(lastPoi!=null && tpoi.equals(lastPoi)){
|
2015-01-29 07:08:23 +01:00
|
|
|
if(points.size()>=2){
|
|
|
|
beziers.add(new Bezier2(points.toArray(new Vec2f[0])));
|
|
|
|
}
|
2015-01-28 06:30:51 +01:00
|
|
|
points.clear();
|
|
|
|
}
|
|
|
|
points.add(tpoi);
|
|
|
|
lastPoi = tpoi;
|
|
|
|
|
|
|
|
}
|
|
|
|
if(points.size()<2){
|
2015-01-29 06:37:25 +01:00
|
|
|
//Ending on a red point (probably) just ignore
|
|
|
|
//throw new Error("trying to continue Beziers with less than 2 points");
|
2015-01-28 06:30:51 +01:00
|
|
|
}else{
|
|
|
|
beziers.add(new Bezier2(points.toArray(new Vec2f[0])));
|
|
|
|
points.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
//find the length of all beziers
|
|
|
|
//int totalDistance = 0;
|
|
|
|
//for(Bezier2 bez : beziers){
|
|
|
|
// totalDistance += bez.totalDistance();
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
//now try to creates points the are equal distance to eachother
|
|
|
|
ncurve = (int) (hitObject.getPixelLength()/5f);
|
|
|
|
curve = new Vec2f[ncurve+1];
|
|
|
|
|
|
|
|
float distanceAt = 0;
|
|
|
|
Iterator<Bezier2> ita = beziers.iterator();
|
|
|
|
|
|
|
|
int curPoint=0;
|
|
|
|
Bezier2 curBezier=ita.next();
|
|
|
|
|
|
|
|
Vec2f lastCurve = curBezier.curve[0];
|
|
|
|
float lastDistanceAt = 0;
|
|
|
|
//length of Bezier should equal pixel length (in 640x480)
|
|
|
|
float pixelLength = hitObject.getPixelLength()*OsuHitObject.getMultiplier();
|
2015-01-29 06:37:25 +01:00
|
|
|
|
|
|
|
//For each distance, try to get in between the two points that is between it.
|
2015-01-28 06:30:51 +01:00
|
|
|
for(int i=0;i<ncurve+1;i++){
|
|
|
|
int prefDistance = (int) (i*pixelLength/ncurve);
|
|
|
|
while(distanceAt<prefDistance){
|
|
|
|
lastDistanceAt = distanceAt;
|
|
|
|
lastCurve = curBezier.curve[curPoint];
|
|
|
|
distanceAt+=curBezier.curveDis[curPoint++];
|
|
|
|
|
|
|
|
if(curPoint >= curBezier.ncurve){
|
|
|
|
if(ita.hasNext()){
|
|
|
|
curBezier = ita.next();
|
|
|
|
curPoint = 0;
|
|
|
|
}else{
|
|
|
|
curPoint = curBezier.ncurve -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Vec2f thisCurve = curBezier.curve[curPoint];
|
|
|
|
//interpolate the point between the two closest distances
|
|
|
|
if(distanceAt-lastDistanceAt > 1){
|
|
|
|
float t = (prefDistance-lastDistanceAt)/(float)(distanceAt-lastDistanceAt);
|
|
|
|
curve[i] = new Vec2f( lerp(lastCurve.x,thisCurve.x,t), lerp(lastCurve.y,thisCurve.y,t));
|
|
|
|
//System.out.println("Dis "+i+" "+prefDistance+" "+lastDistanceAt+" "+distanceAt+" "+curPoint+" "+t);
|
|
|
|
|
|
|
|
}else{
|
|
|
|
curve[i] = thisCurve;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//if (hitObject.getRepeatCount() > 1) {
|
|
|
|
Vec2f c1 = curve[0];
|
2015-01-29 07:08:23 +01:00
|
|
|
int cnt = 1;
|
|
|
|
Vec2f c2 = curve[cnt++];
|
|
|
|
while(c2.cpy().sub(c1).len()<1){
|
|
|
|
c2 = curve[cnt++];
|
|
|
|
}
|
2015-01-28 06:30:51 +01:00
|
|
|
startAngle = (float) (Math.atan2(c2.y - c1.y, c2.x - c1.x) * 180 / Math.PI);
|
|
|
|
c1 = curve[ncurve-1];
|
2015-01-29 07:08:23 +01:00
|
|
|
cnt= ncurve-2;
|
|
|
|
c2 = curve[cnt];
|
|
|
|
while(c2.cpy().sub(c1).len()<1){
|
|
|
|
c2 = curve[cnt--];
|
|
|
|
}
|
2015-01-28 06:30:51 +01:00
|
|
|
endAngle = (float) (Math.atan2(c2.y - c1.y, c2.x - c1.x) * 180 / Math.PI);
|
|
|
|
//}
|
|
|
|
//System.out.println("Total Distance: "+totalDistance+" "+distanceAt+" "+beziers.size()+" "+hitObject.getPixelLength()+" "+hitObject.xMultiplier);
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public float[] pointAt(float t) {
|
|
|
|
|
|
|
|
float index = t * ncurve;
|
|
|
|
|
|
|
|
if((int)index>=ncurve){
|
|
|
|
Vec2f poi = curve[ncurve-1];
|
|
|
|
return new float[]{poi.x, poi.y};
|
|
|
|
}
|
|
|
|
|
|
|
|
Vec2f poi = curve[(int)index];
|
|
|
|
float t2 = index - (int)index;
|
|
|
|
Vec2f poi2 = curve[(int)index+1];
|
|
|
|
return new float[]{lerp(poi.x,poi2.x,t2),lerp(poi.y,poi2.y,t2)};
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public void draw() {
|
|
|
|
Image hitCircle = GameImage.HITCIRCLE.getImage();
|
|
|
|
Image hitCircleOverlay = GameImage.HITCIRCLE_OVERLAY.getImage();
|
|
|
|
|
|
|
|
// draw overlay and hit circle
|
|
|
|
for (int i = curve.length - 2; i >= 0; i--)
|
|
|
|
Utils.drawCentered(hitCircleOverlay, curve[i].x, curve[i].y, Utils.COLOR_WHITE_FADE);
|
|
|
|
for (int i = curve.length - 2; i >= 0; i--)
|
|
|
|
Utils.drawCentered(hitCircle, curve[i].x, curve[i].y, color);
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public float getEndAngle() {
|
|
|
|
return endAngle;
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public float getStartAngle() {
|
|
|
|
return startAngle;
|
|
|
|
}
|
|
|
|
}
|
2015-01-29 06:37:25 +01:00
|
|
|
/**
|
|
|
|
* Representation of a Bezier curve with the distance between each point calculated.
|
|
|
|
*/
|
2015-01-28 06:30:51 +01:00
|
|
|
private class Bezier2{
|
2015-01-29 06:37:25 +01:00
|
|
|
/** The control points of the Bezier curve */
|
2015-01-28 06:30:51 +01:00
|
|
|
Vec2f[] points;
|
2015-01-29 06:37:25 +01:00
|
|
|
|
|
|
|
/** Points along the curve of the Bezier curve */
|
2015-01-28 06:30:51 +01:00
|
|
|
Vec2f[] curve;
|
2015-01-29 06:37:25 +01:00
|
|
|
|
|
|
|
/** distance between this point of the curve and the last point */
|
2015-01-28 06:30:51 +01:00
|
|
|
float[] curveDis;
|
2015-01-29 06:37:25 +01:00
|
|
|
|
|
|
|
/** The number of points along the curve */
|
2015-01-28 06:30:51 +01:00
|
|
|
int ncurve;
|
2015-01-29 06:37:25 +01:00
|
|
|
|
|
|
|
/** The total distances of this Bezier */
|
2015-01-28 06:30:51 +01:00
|
|
|
float totalDistance;
|
|
|
|
|
2015-01-29 06:37:25 +01:00
|
|
|
/*
|
|
|
|
* Constructor
|
|
|
|
*/
|
2015-01-28 06:30:51 +01:00
|
|
|
public Bezier2(Vec2f[] points) {
|
|
|
|
|
|
|
|
this.points = points;
|
|
|
|
//approximate by finding the length of all points(which should be the max possible length of the curve)
|
|
|
|
float approxlength = 0;
|
|
|
|
for(int i=0;i<points.length-1;i++){
|
|
|
|
approxlength+= points[i].cpy().sub(points[i+1]).len();
|
|
|
|
}
|
|
|
|
|
|
|
|
//subdivide the curve
|
|
|
|
ncurve= (int)(approxlength/4);
|
|
|
|
curve = new Vec2f[ncurve];
|
|
|
|
for(int i=0; i<ncurve; i++){
|
|
|
|
curve[i] = pointAt(i/(float)ncurve);
|
|
|
|
}
|
|
|
|
|
2015-01-29 06:37:25 +01:00
|
|
|
//find the distance of each point from the previous point
|
2015-01-28 06:30:51 +01:00
|
|
|
curveDis= new float[ncurve];
|
|
|
|
for(int i=0; i<ncurve; i++){
|
|
|
|
if(i==0)
|
|
|
|
curveDis[i] = 0;
|
|
|
|
else
|
|
|
|
curveDis[i] = curve[i].cpy().sub(curve[i-1]).len();
|
|
|
|
totalDistance+=curveDis[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
//System.out.println("New Bezier2 "+points.length+" "+approxlength+" "+totalDistance());
|
|
|
|
|
|
|
|
}
|
2015-01-29 06:37:25 +01:00
|
|
|
/**
|
|
|
|
* Returns the total Distances of this Bezier Curve
|
|
|
|
*/
|
2015-01-28 06:30:51 +01:00
|
|
|
public float totalDistance(){
|
|
|
|
return totalDistance;
|
|
|
|
}
|
2015-01-29 06:37:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the point on the Bezier curve at a value t.
|
|
|
|
* @param t the t value [0, 1]
|
|
|
|
* @return the point [x, y]
|
|
|
|
*/
|
2015-01-28 06:30:51 +01:00
|
|
|
public Vec2f pointAt(float t) {
|
|
|
|
Vec2f c = new Vec2f();
|
|
|
|
int n = points.length-1;
|
|
|
|
for (int i = 0; i <= n; i++) {
|
|
|
|
c.x += points[i].x * bernstein(i, n, t);
|
|
|
|
c.y += points[i].y * bernstein(i, n, t);
|
|
|
|
}
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Calculates the factorial of a number.
|
|
|
|
*/
|
|
|
|
private long factorial(int n) {
|
|
|
|
return (n <= 1 || n > 20) ? 1 : n * factorial(n - 1);
|
|
|
|
}
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2015-01-28 06:30:51 +01:00
|
|
|
/**
|
|
|
|
* Calculates the Bernstein polynomial.
|
|
|
|
* @param i the index
|
|
|
|
* @param n the degree of the polynomial (i.e. number of points)
|
|
|
|
* @param t the t value [0, 1]
|
|
|
|
*/
|
|
|
|
private double bernstein(int i, int n, float t) {
|
|
|
|
return factorial(n) / (factorial(i) * factorial(n-i)) *
|
|
|
|
Math.pow(t, i) * Math.pow(1-t, n-i);
|
|
|
|
}
|
|
|
|
}
|
2015-01-29 06:37:25 +01:00
|
|
|
/**
|
|
|
|
* Linear interpolation of a and b at t
|
|
|
|
* @param a
|
|
|
|
* @param b
|
|
|
|
* @param t
|
|
|
|
* @return
|
|
|
|
*/
|
2015-01-28 06:30:51 +01:00
|
|
|
private float lerp(float a, float b, float t){
|
|
|
|
return a*(1-t) + b*t;
|
|
|
|
}
|
2015-01-29 06:37:25 +01:00
|
|
|
/**
|
|
|
|
* "a recursive method to evaluate polynomials in Bernstein form or Bezier curves"
|
|
|
|
* http://en.wikipedia.org/wiki/De_Casteljau%27s_algorithm
|
|
|
|
*/
|
2015-01-28 06:30:51 +01:00
|
|
|
private float deCasteljau (float[] a, int i, int order, float t){
|
|
|
|
if(order==0)
|
|
|
|
return a[i];
|
|
|
|
return lerp( deCasteljau(a,i,order-1,t), deCasteljau(a,i+1,order-1,t), t);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Returns the x coordinate of the control point at index i.
|
|
|
|
*/
|
|
|
|
private float getX(int i) {
|
|
|
|
return (i == 0) ? hitObject.getX() : hitObject.getSliderX()[i - 1];
|
|
|
|
}
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2015-01-28 06:30:51 +01:00
|
|
|
/**
|
|
|
|
* Returns the y coordinate of the control point at index i.
|
|
|
|
*/
|
|
|
|
private float getY(int i) {
|
|
|
|
return (i == 0) ? hitObject.getY() : hitObject.getSliderY()[i - 1];
|
|
|
|
}
|
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) {
|
2014-06-30 10:03:39 +02:00
|
|
|
int diameter = (int) (96 - (circleSize * 8));
|
2014-06-30 04:17:04 +02:00
|
|
|
diameter = diameter * container.getWidth() / 640; // convert from Osupixels (640x480)
|
|
|
|
|
2014-07-04 22:41:52 +02:00
|
|
|
// slider ball
|
2015-01-21 23:10:31 +01:00
|
|
|
Image[] sliderBallImages;
|
|
|
|
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);
|
|
|
|
sliderBall = new Animation(sliderBallImages, 60);
|
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
|
2014-06-30 04:17:04 +02:00
|
|
|
* @param color the color of this circle
|
|
|
|
* @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;
|
|
|
|
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-01-28 06:30:51 +01:00
|
|
|
if(hitObject.getSliderType() == 'P' && hitObject.getSliderX().length==2){
|
|
|
|
this.bezier = new CircumscribedCircle();
|
|
|
|
}else {
|
|
|
|
this.bezier = new LinearBezier();
|
|
|
|
}
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-01-16 21:44:13 +01:00
|
|
|
@Override
|
2015-01-16 09:47:37 +01:00
|
|
|
public void draw(int trackPosition, boolean currentObject, Graphics g) {
|
2014-07-18 21:11:57 +02:00
|
|
|
float x = hitObject.getX(), y = hitObject.getY();
|
|
|
|
float[] sliderX = hitObject.getSliderX(), sliderY = hitObject.getSliderY();
|
|
|
|
int timeDiff = hitObject.getTime() - trackPosition;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2014-12-24 08:45:43 +01:00
|
|
|
float approachScale = (timeDiff >= 0) ? 1 + (timeDiff * 2f / game.getApproachTime()) : 1f;
|
|
|
|
float alpha = (approachScale > 3.3f) ? 0f : 1f - (approachScale - 1f) / 2.7f;
|
2015-01-18 18:39:30 +01:00
|
|
|
float oldAlpha = color.a;
|
|
|
|
float oldAlphaFade = Utils.COLOR_WHITE_FADE.a;
|
2014-12-24 08:45:43 +01:00
|
|
|
color.a = alpha;
|
|
|
|
Utils.COLOR_WHITE_FADE.a = alpha;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
// bezier
|
|
|
|
bezier.draw();
|
|
|
|
|
|
|
|
// ticks
|
|
|
|
if (currentObject && 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++) {
|
|
|
|
float[] c = bezier.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();
|
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
// end circle
|
2015-01-28 06:30:51 +01:00
|
|
|
//int lastIndex = sliderX.length - 1;
|
|
|
|
float[] endPos = bezier.pointAt(1);
|
|
|
|
Utils.drawCentered(hitCircle, endPos[0], endPos[1], color);
|
|
|
|
Utils.drawCentered(hitCircleOverlay, endPos[0], endPos[1], Utils.COLOR_WHITE_FADE);
|
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
// start circle
|
2014-12-24 08:45:43 +01:00
|
|
|
Utils.drawCentered(hitCircleOverlay, x, y, Utils.COLOR_WHITE_FADE);
|
2014-07-18 21:11:57 +02:00
|
|
|
Utils.drawCentered(hitCircle, x, y, color);
|
2014-06-30 04:17:04 +02:00
|
|
|
if (sliderClicked)
|
|
|
|
; // 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;
|
|
|
|
Utils.COLOR_WHITE_FADE.a = oldAlphaFade;
|
2014-12-24 08:45:43 +01:00
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
// repeats
|
2015-01-28 06:30:51 +01:00
|
|
|
for(int tcurRepeat = currentRepeats; tcurRepeat<=currentRepeats+1; tcurRepeat++){
|
|
|
|
if (hitObject.getRepeatCount() - 1 > tcurRepeat) {
|
|
|
|
Image arrow = GameImage.REVERSEARROW.getImage();
|
|
|
|
if(tcurRepeat != currentRepeats){
|
|
|
|
float t = getT(trackPosition, true);
|
|
|
|
arrow.setAlpha((float) (t-Math.floor(t)));
|
|
|
|
}else{
|
|
|
|
arrow.setAlpha(1f);
|
|
|
|
}
|
|
|
|
if (tcurRepeat % 2 == 0) { // last circle
|
|
|
|
arrow.setRotation(bezier.getEndAngle());
|
|
|
|
arrow.drawCentered(endPos[0], endPos[1]);
|
|
|
|
} else { // first circle
|
|
|
|
arrow.setRotation(bezier.getStartAngle());
|
|
|
|
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
|
2014-07-18 21:11:57 +02:00
|
|
|
Utils.drawCentered(GameImage.APPROACHCIRCLE.getImage().getScaledCopy(approachScale), x, y, color);
|
2014-06-30 04:17:04 +02:00
|
|
|
} else {
|
|
|
|
float[] c = bezier.pointAt(getT(trackPosition, false));
|
|
|
|
|
|
|
|
// slider ball
|
2014-07-02 01:32:03 +02:00
|
|
|
Utils.drawCentered(sliderBall, c[0], c[1]);
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
// follow circle
|
|
|
|
if (followCircleActive)
|
2014-07-04 22:41:52 +02:00
|
|
|
GameImage.SLIDER_FOLLOWCIRCLE.getImage().drawCentered(c[0], c[1]);
|
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-07-18 21:11:57 +02:00
|
|
|
int lastIndex = hitObject.getSliderX().length - 1;
|
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-28 06:30:51 +01:00
|
|
|
if (currentRepeats % 2 == 0) {// last circle
|
|
|
|
float[] lastPos = bezier.pointAt(1);
|
2015-01-27 09:19:39 +01:00
|
|
|
data.hitResult(hitObject.getTime() + (int) sliderTimeTotal, result,
|
2015-01-28 06:30:51 +01:00
|
|
|
lastPos[0],lastPos[1],
|
2014-07-18 21:11:57 +02:00
|
|
|
color, comboEnd, hitObject.getHitSoundType());
|
2015-01-28 06:30:51 +01:00
|
|
|
}else // first circle
|
2015-01-27 09:19:39 +01:00
|
|
|
data.hitResult(hitObject.getTime() + (int) sliderTimeTotal, result,
|
2014-07-18 21:11:57 +02:00
|
|
|
hitObject.getX(), hitObject.getY(), color, comboEnd, hitObject.getHitSoundType());
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-01-16 21:44:13 +01:00
|
|
|
@Override
|
2014-06-30 04:17:04 +02:00
|
|
|
public boolean mousePressed(int x, int y) {
|
|
|
|
if (sliderClicked) // first circle already processed
|
|
|
|
return false;
|
|
|
|
|
2014-07-18 21:11:57 +02:00
|
|
|
double distance = Math.hypot(hitObject.getX() - x, hitObject.getY() - 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) {
|
|
|
|
int trackPosition = MusicController.getPosition();
|
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) {
|
|
|
|
sliderClicked = true;
|
2015-01-27 09:19:39 +01:00
|
|
|
data.sliderTickResult(hitObject.getTime(), result,
|
2014-07-18 21:11:57 +02:00
|
|
|
hitObject.getX(), hitObject.getY(), hitObject.getHitSoundType());
|
2014-06-30 04:17:04 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-01-16 21:44:13 +01:00
|
|
|
@Override
|
2014-06-30 04:17:04 +02:00
|
|
|
public boolean update(boolean overlap, int delta, int mouseX, int mouseY) {
|
2014-07-18 21:11:57 +02:00
|
|
|
int repeatCount = hitObject.getRepeatCount();
|
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
// slider time and tick calculations
|
|
|
|
if (sliderTimeTotal == 0f) {
|
|
|
|
// slider time
|
2014-07-18 21:11:57 +02:00
|
|
|
this.sliderTime = game.getBeatLength() * (hitObject.getPixelLength() / sliderMultiplier) / 100f;
|
|
|
|
this.sliderTimeTotal = sliderTime * repeatCount;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
// ticks
|
|
|
|
float tickLengthDiv = 100f * sliderMultiplier / sliderTickRate / game.getTimingPointMultiplier();
|
2014-07-18 21:11:57 +02:00
|
|
|
int tickCount = (int) Math.ceil(hitObject.getPixelLength() / tickLengthDiv) - 1;
|
2014-06-30 04:17:04 +02:00
|
|
|
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-07-18 21:11:57 +02:00
|
|
|
byte hitSound = hitObject.getHitSoundType();
|
2014-06-30 04:17:04 +02:00
|
|
|
int trackPosition = MusicController.getPosition();
|
2015-01-16 21:44:13 +01:00
|
|
|
int[] hitResultOffset = game.getHitResultOffsets();
|
2014-07-18 21:11:57 +02:00
|
|
|
int lastIndex = hitObject.getSliderX().length - 1;
|
2014-07-16 22:01:36 +02:00
|
|
|
boolean isAutoMod = GameMod.AUTO.isActive();
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
if (!sliderClicked) {
|
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]) {
|
2014-06-30 04:17:04 +02:00
|
|
|
sliderClicked = true;
|
|
|
|
if (isAutoMod) { // "auto" mod: catch any missed notes due to lag
|
|
|
|
ticksHit++;
|
2015-01-27 09:19:39 +01:00
|
|
|
data.sliderTickResult(time, GameData.HIT_SLIDER30,
|
2014-07-18 21:11:57 +02:00
|
|
|
hitObject.getX(), hitObject.getY(), hitSound);
|
2014-06-30 04:17:04 +02:00
|
|
|
} else
|
2015-01-27 09:19:39 +01:00
|
|
|
data.sliderTickResult(time, GameData.HIT_MISS,
|
2014-07-18 21:11:57 +02:00
|
|
|
hitObject.getX(), hitObject.getY(), hitSound);
|
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++;
|
|
|
|
sliderClicked = true;
|
2015-01-27 09:19:39 +01:00
|
|
|
data.sliderTickResult(time, GameData.HIT_SLIDER30,
|
2014-07-18 21:11:57 +02:00
|
|
|
hitObject.getX(), hitObject.getY(), hitSound);
|
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++;
|
|
|
|
|
|
|
|
// "auto" mod: send a perfect hit result
|
|
|
|
if (isAutoMod)
|
|
|
|
ticksHit++;
|
|
|
|
|
|
|
|
// check if cursor pressed and within end circle
|
2014-07-18 05:58:37 +02:00
|
|
|
else if (Utils.isGameKeyPressed()) {
|
2014-07-19 03:13:17 +02:00
|
|
|
float[] c = bezier.pointAt(getT(trackPosition, false));
|
|
|
|
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)
|
|
|
|
ticksHit++;
|
|
|
|
}
|
2014-07-06 03:00:52 +02:00
|
|
|
|
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...
|
|
|
|
float[] c = bezier.pointAt(getT(trackPosition, false));
|
|
|
|
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-07-18 05:58:37 +02:00
|
|
|
if ((Utils.isGameKeyPressed() && 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++;
|
|
|
|
if (currentRepeats % 2 > 0) // last circle
|
2015-01-27 09:19:39 +01:00
|
|
|
data.sliderTickResult(trackPosition, GameData.HIT_SLIDER30,
|
2014-07-18 21:11:57 +02:00
|
|
|
hitObject.getSliderX()[lastIndex], hitObject.getSliderY()[lastIndex], hitSound);
|
2014-06-30 04:17:04 +02:00
|
|
|
else // first circle
|
2015-01-27 09:19:39 +01:00
|
|
|
data.sliderTickResult(trackPosition, GameData.HIT_SLIDER30,
|
2014-07-18 21:11:57 +02:00
|
|
|
c[0], c[1], hitSound);
|
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,
|
2014-07-01 07:14:03 +02:00
|
|
|
c[0], c[1], (byte) -1);
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
followCircleActive = false;
|
|
|
|
|
|
|
|
if (isNewRepeat)
|
2015-01-27 09:19:39 +01:00
|
|
|
data.sliderTickResult(trackPosition, GameData.HIT_MISS, 0, 0, (byte) -1);
|
2014-06-30 04:17:04 +02:00
|
|
|
if (isNewTick)
|
2015-01-27 09:19:39 +01:00
|
|
|
data.sliderTickResult(trackPosition, GameData.HIT_MISS, 0, 0, (byte) -1);
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|