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 11:33:12 +02:00
|
|
|
import itdelatrisu.opsu.Options;
|
2014-07-02 01:32:03 +02:00
|
|
|
import itdelatrisu.opsu.Utils;
|
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;
|
2015-01-16 09:47:37 +01:00
|
|
|
import org.newdawn.slick.Graphics;
|
2016-09-29 23:34:11 +02:00
|
|
|
import yugecin.opsudance.Dancer;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Data type representing a circle object.
|
|
|
|
*/
|
2016-09-27 18:26:53 +02:00
|
|
|
public class Circle extends GameObject {
|
2015-06-30 02:22:38 +02:00
|
|
|
/** The diameter of hit circles. */
|
2016-09-27 21:29:03 +02:00
|
|
|
public static float diameter;
|
2015-06-30 02:22:38 +02:00
|
|
|
|
2015-05-17 03:42:03 +02:00
|
|
|
/** The associated HitObject. */
|
|
|
|
private HitObject hitObject;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2015-03-13 01:12:43 +01:00
|
|
|
/** The scaled starting x, y coordinates. */
|
|
|
|
private 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 circle. */
|
2014-06-30 04:17:04 +02:00
|
|
|
private Color color;
|
2016-09-30 19:05:53 +02:00
|
|
|
private Color mirrorColor;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** Whether or not the circle result ends the combo streak. */
|
2014-06-30 04:17:04 +02:00
|
|
|
private boolean comboEnd;
|
|
|
|
|
2016-11-13 00:58:50 +01:00
|
|
|
private int comboColorIndex;
|
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
/**
|
|
|
|
* Initializes the Circle data type with map modifiers, images, and dimensions.
|
|
|
|
* @param container the game container
|
2015-08-31 02:01:40 +02:00
|
|
|
* @param circleDiameter the circle diameter
|
2014-06-30 04:17:04 +02:00
|
|
|
*/
|
2015-08-31 02:01:40 +02:00
|
|
|
public static void init(GameContainer container, float circleDiameter) {
|
|
|
|
diameter = circleDiameter * HitObject.getXMultiplier(); // convert from Osupixels (640x480)
|
2015-06-30 02:22:38 +02:00
|
|
|
int diameterInt = (int) diameter;
|
2015-04-05 17:24:05 +02:00
|
|
|
GameImage.HITCIRCLE.setImage(GameImage.HITCIRCLE.getImage().getScaledCopy(diameterInt, diameterInt));
|
|
|
|
GameImage.HITCIRCLE_OVERLAY.setImage(GameImage.HITCIRCLE_OVERLAY.getImage().getScaledCopy(diameterInt, diameterInt));
|
|
|
|
GameImage.APPROACHCIRCLE.setImage(GameImage.APPROACHCIRCLE.getImage().getScaledCopy(diameterInt, diameterInt));
|
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
|
2016-09-30 21:32:24 +02:00
|
|
|
* @param comboColorIndex index of the combo color of this circle
|
2014-06-30 04:17:04 +02:00
|
|
|
* @param comboEnd true if this is the last hit object in the combo
|
|
|
|
*/
|
2016-09-30 21:32:24 +02:00
|
|
|
public Circle(HitObject hitObject, Game game, GameData data, int comboColorIndex, 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.comboEnd = comboEnd;
|
2016-11-13 00:58:50 +01:00
|
|
|
this.comboColorIndex = comboColorIndex;
|
|
|
|
updateColor();
|
2015-03-31 05:06:52 +02:00
|
|
|
updatePosition();
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
|
2016-11-12 18:25:44 +01:00
|
|
|
public Circle(float x, float y, int time) {
|
|
|
|
hitObject = new HitObject(x, y, time);
|
|
|
|
super.updateStartEndPositions(time);
|
|
|
|
}
|
|
|
|
|
2015-01-16 21:44:13 +01:00
|
|
|
@Override
|
2016-09-29 21:40:42 +02:00
|
|
|
public void draw(Graphics g, int trackPosition, boolean mirror) {
|
2016-09-29 21:55:23 +02:00
|
|
|
Color orig = color;
|
|
|
|
if (mirror) {
|
2016-09-30 19:05:53 +02:00
|
|
|
color = mirrorColor;
|
2016-09-29 21:55:23 +02:00
|
|
|
}
|
|
|
|
|
2014-07-18 21:11:57 +02:00
|
|
|
int timeDiff = hitObject.getTime() - trackPosition;
|
2015-08-29 04:12:47 +02:00
|
|
|
final int approachTime = game.getApproachTime();
|
|
|
|
final int fadeInTime = game.getFadeInTime();
|
|
|
|
float scale = timeDiff / (float) approachTime;
|
2015-03-30 16:06:16 +02:00
|
|
|
float approachScale = 1 + scale * 3;
|
2015-08-29 04:12:47 +02:00
|
|
|
float fadeinScale = (timeDiff - approachTime + fadeInTime) / (float) fadeInTime;
|
2015-03-30 16:06:16 +02:00
|
|
|
float alpha = Utils.clamp(1 - fadeinScale, 0, 1);
|
2015-08-09 02:15:49 +02:00
|
|
|
|
2016-09-29 21:40:42 +02:00
|
|
|
g.pushTransform();
|
|
|
|
if (mirror) {
|
|
|
|
g.rotate(x, y, -180f);
|
|
|
|
}
|
|
|
|
|
2015-08-08 21:12:02 +02:00
|
|
|
if (GameMod.HIDDEN.isActive()) {
|
2015-08-29 04:12:47 +02:00
|
|
|
final int hiddenDecayTime = game.getHiddenDecayTime();
|
|
|
|
final int hiddenTimeDiff = game.getHiddenTimeDiff();
|
|
|
|
if (fadeinScale <= 0f && timeDiff < hiddenTimeDiff + hiddenDecayTime) {
|
|
|
|
float hiddenAlpha = (timeDiff < hiddenTimeDiff) ? 0f : (timeDiff - hiddenTimeDiff) / (float) hiddenDecayTime;
|
|
|
|
alpha = Math.min(alpha, hiddenAlpha);
|
|
|
|
}
|
2015-08-08 21:12:02 +02:00
|
|
|
}
|
2015-08-09 02:15:49 +02:00
|
|
|
|
2015-08-21 03:02:23 +02:00
|
|
|
float oldAlpha = Colors.WHITE_FADE.a;
|
|
|
|
Colors.WHITE_FADE.a = color.a = alpha;
|
2015-02-14 19:45:14 +01:00
|
|
|
|
2016-09-29 23:34:11 +02:00
|
|
|
if (timeDiff >= 0 && !GameMod.HIDDEN.isActive() && Dancer.drawApproach)
|
2015-02-19 06:33:32 +01:00
|
|
|
GameImage.APPROACHCIRCLE.getImage().getScaledCopy(approachScale).drawCentered(x, y, color);
|
2015-03-30 16:06:16 +02:00
|
|
|
GameImage.HITCIRCLE.getImage().drawCentered(x, y, color);
|
2015-05-25 11:33:12 +02:00
|
|
|
boolean overlayAboveNumber = Options.getSkin().isHitCircleOverlayAboveNumber();
|
|
|
|
if (!overlayAboveNumber)
|
2015-08-21 03:02:23 +02:00
|
|
|
GameImage.HITCIRCLE_OVERLAY.getImage().drawCentered(x, y, Colors.WHITE_FADE);
|
2015-03-30 16:06:16 +02:00
|
|
|
data.drawSymbolNumber(hitObject.getComboNumber(), x, y,
|
2015-04-01 01:46:58 +02:00
|
|
|
GameImage.HITCIRCLE.getImage().getWidth() * 0.40f / data.getDefaultSymbolImage(0).getHeight(), alpha);
|
2015-05-25 11:33:12 +02:00
|
|
|
if (overlayAboveNumber)
|
2015-08-21 03:02:23 +02:00
|
|
|
GameImage.HITCIRCLE_OVERLAY.getImage().drawCentered(x, y, Colors.WHITE_FADE);
|
2015-02-14 19:45:14 +01:00
|
|
|
|
2015-08-21 03:02:23 +02:00
|
|
|
Colors.WHITE_FADE.a = oldAlpha;
|
2016-09-29 21:40:42 +02:00
|
|
|
|
|
|
|
g.popTransform();
|
2016-09-29 21:55:23 +02:00
|
|
|
color = orig;
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculates the circle hit result.
|
|
|
|
* @param time the hit object time (difference between track time)
|
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(int time) {
|
2015-02-14 19:45:14 +01:00
|
|
|
int timeDiff = Math.abs(time);
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
int[] hitResultOffset = game.getHitResultOffsets();
|
|
|
|
int result = -1;
|
2015-04-05 17:24:05 +02:00
|
|
|
if (timeDiff <= hitResultOffset[GameData.HIT_300])
|
2015-01-27 09:19:39 +01:00
|
|
|
result = GameData.HIT_300;
|
2015-04-05 17:24:05 +02:00
|
|
|
else if (timeDiff <= hitResultOffset[GameData.HIT_100])
|
2015-01-27 09:19:39 +01:00
|
|
|
result = GameData.HIT_100;
|
2015-04-05 17:24:05 +02:00
|
|
|
else if (timeDiff <= hitResultOffset[GameData.HIT_50])
|
2015-01-27 09:19:39 +01:00
|
|
|
result = GameData.HIT_50;
|
2015-06-22 04:57:30 +02:00
|
|
|
else if (timeDiff <= hitResultOffset[GameData.HIT_MISS])
|
2015-01-27 09:19:39 +01:00
|
|
|
result = GameData.HIT_MISS;
|
2014-06-30 04:17:04 +02:00
|
|
|
//else not a hit
|
|
|
|
|
|
|
|
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-03-13 01:12:43 +01:00
|
|
|
double distance = Math.hypot(this.x - x, this.y - y);
|
2015-06-30 02:22:38 +02:00
|
|
|
if (distance < diameter / 2) {
|
2015-02-14 19:45:14 +01:00
|
|
|
int timeDiff = trackPosition - hitObject.getTime();
|
|
|
|
int result = hitResult(timeDiff);
|
2015-02-15 07:40:01 +01:00
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
if (result > -1) {
|
2015-02-15 04:15:41 +01:00
|
|
|
data.addHitError(hitObject.getTime(), x, y, timeDiff);
|
2015-06-30 02:22:38 +02:00
|
|
|
data.hitResult(trackPosition, result, this.x, this.y, color, comboEnd, hitObject, HitObjectType.CIRCLE, true, 0, null, false);
|
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 time = hitObject.getTime();
|
|
|
|
|
2014-06-30 04:17:04 +02: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-04-05 17:24:05 +02:00
|
|
|
if (trackPosition > time + hitResultOffset[GameData.HIT_50]) {
|
2016-09-30 23:51:28 +02:00
|
|
|
if (isAutoMod) {// "auto" mod: catch any missed notes due to lag
|
2015-06-30 02:22:38 +02:00
|
|
|
data.hitResult(time, GameData.HIT_300, x, y, color, comboEnd, hitObject, HitObjectType.CIRCLE, true, 0, null, false);
|
2016-10-01 12:39:52 +02:00
|
|
|
if (Dancer.mirror && GameMod.AUTO.isActive()) {
|
2016-09-30 23:56:07 +02:00
|
|
|
float[] m = Utils.mirrorPoint(x, y);
|
2016-10-01 00:25:55 +02:00
|
|
|
data.hitResult(time, GameData.HIT_300, m[0], m[1], mirrorColor, comboEnd, hitObject, HitObjectType.CIRCLE, true, 0, null, false, false);
|
2016-09-30 23:51:28 +02:00
|
|
|
}
|
|
|
|
}
|
2015-01-16 21:44:13 +01:00
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
else // no more points can be scored, so send a miss
|
2015-06-30 02:22:38 +02:00
|
|
|
data.hitResult(trackPosition, GameData.HIT_MISS, x, y, null, comboEnd, hitObject, HitObjectType.CIRCLE, true, 0, null, false);
|
2014-06-30 04:17:04 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// "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]) {
|
2015-06-30 02:22:38 +02:00
|
|
|
data.hitResult(time, GameData.HIT_300, x, y, color, comboEnd, hitObject, HitObjectType.CIRCLE, true, 0, null, false);
|
2016-10-01 12:39:52 +02:00
|
|
|
if (Dancer.mirror && GameMod.AUTO.isActive()) {
|
2016-09-30 23:56:07 +02:00
|
|
|
float[] m = Utils.mirrorPoint(x, y);
|
2016-10-01 00:25:55 +02:00
|
|
|
data.hitResult(time, GameData.HIT_300, m[0], m[1], mirrorColor, comboEnd, hitObject, HitObjectType.CIRCLE, true, 0, null, false, false);
|
2016-09-30 23:51:28 +02:00
|
|
|
}
|
2014-06-30 04:17:04 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
return mousePressed(mouseX, mouseY, trackPosition);
|
2015-03-06 06:25:48 +01:00
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
return false;
|
|
|
|
}
|
2015-03-17 19:48:13 +01:00
|
|
|
|
|
|
|
@Override
|
2015-09-05 19:53:42 +02:00
|
|
|
public Vec2f getPointAt(int trackPosition) { return new Vec2f(x, y); }
|
2015-03-17 19:48:13 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getEndTime() { return hitObject.getTime(); }
|
2015-03-28 13:11:43 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updatePosition() {
|
|
|
|
this.x = hitObject.getScaledX();
|
|
|
|
this.y = hitObject.getScaledY();
|
2016-11-12 18:25:44 +01:00
|
|
|
super.updateStartEndPositions(hitObject.getTime());
|
2015-03-28 13:11:43 +01:00
|
|
|
}
|
2015-04-05 17:24:05 +02:00
|
|
|
|
|
|
|
@Override
|
2015-06-30 02:22:38 +02:00
|
|
|
public void reset() {}
|
2016-09-27 18:26:53 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isCircle() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isSlider() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isSpinner() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-09-30 19:38:02 +02:00
|
|
|
@Override
|
|
|
|
public Color getColor() {
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Color getMirroredColor() {
|
|
|
|
return mirrorColor;
|
|
|
|
}
|
|
|
|
|
2016-11-13 00:58:50 +01:00
|
|
|
@Override
|
|
|
|
public void updateColor() {
|
|
|
|
color = Dancer.colorOverride.getColor(comboColorIndex);
|
|
|
|
mirrorColor = Dancer.colorMirrorOverride.getColor(comboColorIndex);
|
|
|
|
}
|
|
|
|
|
2015-03-18 04:47:33 +01:00
|
|
|
}
|