opsu-dance/src/yugecin/opsudance/Dancer.java

161 lines
4.3 KiB
Java
Raw Normal View History

2016-09-27 21:29:03 +02:00
/*
* opsu!dance - fork of opsu! with cursordance auto
* Copyright (C) 2016 yugecin
*
* opsu!dance 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!dance. If not, see <http://www.gnu.org/licenses/>.
*/
package yugecin.opsudance;
import itdelatrisu.opsu.Options;
import itdelatrisu.opsu.Utils;
2016-09-27 22:23:14 +02:00
import itdelatrisu.opsu.objects.Circle;
2016-09-27 21:29:03 +02:00
import itdelatrisu.opsu.objects.GameObject;
2016-09-27 22:23:14 +02:00
import itdelatrisu.opsu.objects.Slider;
2016-09-27 21:29:03 +02:00
import itdelatrisu.opsu.objects.curves.Vec2f;
import yugecin.opsudance.movers.Mover;
import yugecin.opsudance.movers.factories.*;
import yugecin.opsudance.spinners.RektSpinner;
import yugecin.opsudance.spinners.Spinner;
import java.util.Random;
public class Dancer {
public static MoverFactory[] moverFactories = new MoverFactory[] {
new AutoMoverFactory(),
new AutoEllipseMoverFactory(),
new CircleMoverFactory(),
new HalfCircleMoverFactory(),
new HalfEllipseMoverFactory(),
new HalfLowEllipseMoverFactory(),
new JumpMoverFactory(),
new LinearMoverFactory(),
new QuartCircleMoverFactory()
};
public static Spinner[] spinners = new Spinner[] {
new RektSpinner()
};
public static Dancer instance = new Dancer();
private int dir;
private GameObject p;
private Random rand;
private MoverFactory moverFactory;
private Mover mover;
private Spinner spinner;
2016-09-27 22:02:49 +02:00
private int moverFactoryIndex;
private int spinnerIndex;
2016-09-27 21:29:03 +02:00
public float x;
public float y;
2016-09-27 22:23:14 +02:00
private boolean isCurrentLazySlider;
public static boolean LAZY_SLIDERS;
2016-09-27 21:29:03 +02:00
public Dancer() {
moverFactory = moverFactories[0];
spinner = spinners[0];
}
public void init(String mapname) {
2016-09-27 22:23:14 +02:00
isCurrentLazySlider = false;
2016-09-27 21:29:03 +02:00
p = null;
rand = new Random(mapname.hashCode());
dir = 1;
for (Spinner s : spinners) {
s.init();
}
}
2016-09-27 22:02:49 +02:00
public int getSpinnerIndex() {
return spinnerIndex;
}
public void setSpinnerIndex(int spinnerIndex) {
2016-09-27 22:04:14 +02:00
if (spinnerIndex < 0 || spinnerIndex >= spinners.length) {
spinnerIndex = 0;
}
2016-09-27 22:02:49 +02:00
this.spinnerIndex = spinnerIndex;
spinner = spinners[spinnerIndex];
}
public int getMoverFactoryIndex() {
return moverFactoryIndex;
}
public void setMoverFactoryIndex(int moverFactoryIndex) {
2016-09-27 22:04:14 +02:00
if (moverFactoryIndex < 0 || moverFactoryIndex >= moverFactories.length) {
moverFactoryIndex = 0;
}
2016-09-27 22:02:49 +02:00
this.moverFactoryIndex = moverFactoryIndex;
moverFactory = moverFactories[moverFactoryIndex];
}
2016-09-27 21:29:03 +02:00
public void update(int time, GameObject p, GameObject c) {
if (this.p != p) {
this.p = p;
2016-09-27 22:23:14 +02:00
isCurrentLazySlider = false;
// detect lazy sliders, should work pretty good
if (c.isSlider() && LAZY_SLIDERS && Utils.distance(c.start.x, c.start.y, c.end.x , c.end.y) <= Circle.diameter * 0.8f) {
Slider s = (Slider) c;
Vec2f mid = s.getCurve().pointAt(1f);
if (s.getRepeats() == 1 || Utils.distance(c.start.x, c.start.y, mid.x, mid.y) <= Circle.diameter * 0.8f) {
mid = s.getCurve().pointAt(0.5f);
if (Utils.distance(c.start.x, c.start.y, mid.x, mid.y) <= Circle.diameter * 0.8f) {
isCurrentLazySlider = true;
}
}
}
2016-09-27 21:29:03 +02:00
if (rand.nextInt(2) == 1) {
dir *= -1;
}
if (c.isSpinner()) {
double[] spinnerStartPoint = spinner.getPoint();
c.start = new Vec2f((float) spinnerStartPoint[0], (float) spinnerStartPoint[1]);
}
mover = moverFactory.create(p, c, dir);
}
if (time < c.getTime()) {
if (!p.isSpinner() || !c.isSpinner()) {
double[] point = mover.getPointAt(time);
x = (float) point[0];
y = (float) point[1];
}
x = Utils.clamp(x, 10, Options.width - 10);
y = Utils.clamp(y, 10, Options.height - 10);
} else {
if (c.isSpinner()) {
double[] point = spinner.getPoint();
x = (float) point[0];
y = (float) point[1];
c.end = new Vec2f(x, y);
} else {
Vec2f point = c.getPointAt(time);
2016-09-27 22:23:14 +02:00
if (isCurrentLazySlider) {
point = c.start;
}
2016-09-27 21:29:03 +02:00
x = point.x;
y = point.y;
}
}
}
}