2014-06-30 04:17:04 +02:00
|
|
|
/*
|
|
|
|
* opsu! - an open-source osu! client
|
|
|
|
* Copyright (C) 2014 Jeffrey Han
|
|
|
|
*
|
|
|
|
* 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;
|
|
|
|
|
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.GameScore;
|
|
|
|
import itdelatrisu.opsu.MusicController;
|
|
|
|
import itdelatrisu.opsu.OsuHitObject;
|
2014-07-02 01:32:03 +02:00
|
|
|
import itdelatrisu.opsu.Utils;
|
2014-06-30 04:17:04 +02:00
|
|
|
import itdelatrisu.opsu.states.Game;
|
|
|
|
|
|
|
|
import org.newdawn.slick.Color;
|
|
|
|
import org.newdawn.slick.GameContainer;
|
|
|
|
import org.newdawn.slick.SlickException;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Data type representing a circle object.
|
|
|
|
*/
|
|
|
|
public class Circle {
|
|
|
|
/**
|
|
|
|
* The associated OsuHitObject.
|
|
|
|
*/
|
|
|
|
private OsuHitObject hitObject;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The associated Game object.
|
|
|
|
*/
|
|
|
|
private Game game;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The associated GameScore object.
|
|
|
|
*/
|
|
|
|
private GameScore score;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The color of this circle.
|
|
|
|
*/
|
|
|
|
private Color color;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether or not the circle result ends the combo streak.
|
|
|
|
*/
|
|
|
|
private boolean comboEnd;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes the Circle data type with map modifiers, images, and dimensions.
|
|
|
|
* @param container the game container
|
|
|
|
* @param circleSize the map's circleSize value
|
|
|
|
* @throws SlickException
|
|
|
|
*/
|
2014-06-30 10:03:39 +02:00
|
|
|
public static void init(GameContainer container, float circleSize) throws SlickException {
|
|
|
|
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
|
|
|
GameImage.HITCIRCLE.setImage(GameImage.HITCIRCLE.getImage().getScaledCopy(diameter, diameter));
|
|
|
|
GameImage.HITCIRCLE_OVERLAY.setImage(GameImage.HITCIRCLE_OVERLAY.getImage().getScaledCopy(diameter, diameter));
|
|
|
|
GameImage.APPROACHCIRCLE.setImage(GameImage.APPROACHCIRCLE.getImage().getScaledCopy(diameter, diameter));
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
* @param hitObject the associated OsuHitObject
|
|
|
|
* @param game the associated Game object
|
|
|
|
* @param score the associated GameScore object
|
|
|
|
* @param color the color of this circle
|
|
|
|
* @param comboEnd true if this is the last hit object in the combo
|
|
|
|
*/
|
|
|
|
public Circle(OsuHitObject hitObject, Game game, GameScore score, Color color, boolean comboEnd) {
|
|
|
|
this.hitObject = hitObject;
|
|
|
|
this.game = game;
|
|
|
|
this.score = score;
|
|
|
|
this.color = color;
|
|
|
|
this.comboEnd = comboEnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draws the circle to the graphics context.
|
|
|
|
* @param trackPosition the current track position
|
|
|
|
*/
|
2014-07-18 21:11:57 +02:00
|
|
|
public void draw(int trackPosition) {
|
|
|
|
int timeDiff = hitObject.getTime() - trackPosition;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
if (timeDiff >= 0) {
|
2014-07-18 21:11:57 +02:00
|
|
|
float x = hitObject.getX(), y = hitObject.getY();
|
2014-06-30 04:17:04 +02:00
|
|
|
float approachScale = 1 + (timeDiff * 2f / game.getApproachTime());
|
2014-07-18 21:11:57 +02:00
|
|
|
Utils.drawCentered(GameImage.APPROACHCIRCLE.getImage().getScaledCopy(approachScale), x, y, color);
|
2014-12-24 08:45:43 +01:00
|
|
|
float alpha = (approachScale > 3.3f) ? 0f : 1f - (approachScale - 1f) / 2.7f;
|
|
|
|
color.a = alpha;
|
|
|
|
Utils.COLOR_WHITE_FADE.a = alpha;
|
|
|
|
Utils.drawCentered(GameImage.HITCIRCLE_OVERLAY.getImage(), x, y, Utils.COLOR_WHITE_FADE);
|
2014-07-18 21:11:57 +02:00
|
|
|
Utils.drawCentered(GameImage.HITCIRCLE.getImage(), x, y, color);
|
2014-12-24 08:45:43 +01:00
|
|
|
color.a = 1f;
|
|
|
|
Utils.COLOR_WHITE_FADE.a = 1f;
|
2014-07-18 21:11:57 +02:00
|
|
|
score.drawSymbolNumber(hitObject.getComboNumber(), x, y,
|
2014-07-04 22:41:52 +02:00
|
|
|
GameImage.HITCIRCLE.getImage().getWidth() * 0.40f / score.getDefaultSymbolImage(0).getHeight());
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculates the circle hit result.
|
|
|
|
* @param time the hit object time (difference between track time)
|
|
|
|
* @return the hit result (GameScore.HIT_* constants)
|
|
|
|
*/
|
|
|
|
public int hitResult(int time) {
|
|
|
|
int trackPosition = MusicController.getPosition();
|
|
|
|
int timeDiff = Math.abs(trackPosition - time);
|
|
|
|
|
|
|
|
int[] hitResultOffset = game.getHitResultOffsets();
|
|
|
|
int result = -1;
|
|
|
|
if (timeDiff < hitResultOffset[GameScore.HIT_300])
|
|
|
|
result = GameScore.HIT_300;
|
|
|
|
else if (timeDiff < hitResultOffset[GameScore.HIT_100])
|
|
|
|
result = GameScore.HIT_100;
|
|
|
|
else if (timeDiff < hitResultOffset[GameScore.HIT_50])
|
|
|
|
result = GameScore.HIT_50;
|
|
|
|
else if (timeDiff < hitResultOffset[GameScore.HIT_MISS])
|
|
|
|
result = GameScore.HIT_MISS;
|
|
|
|
//else not a hit
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Processes a mouse click.
|
|
|
|
* @param x the x coordinate of the mouse
|
|
|
|
* @param y the y coordinate of the mouse
|
|
|
|
* @param comboEnd if this is the last object in the combo
|
|
|
|
* @return true if a hit result was processed
|
|
|
|
*/
|
|
|
|
public boolean mousePressed(int x, int y) {
|
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) {
|
2014-07-18 21:11:57 +02:00
|
|
|
int result = hitResult(hitObject.getTime());
|
2014-06-30 04:17:04 +02:00
|
|
|
if (result > -1) {
|
2014-07-18 21:11:57 +02:00
|
|
|
score.hitResult(
|
|
|
|
hitObject.getTime(), result,
|
|
|
|
hitObject.getX(), hitObject.getY(),
|
|
|
|
color, comboEnd, hitObject.getHitSoundType()
|
2014-07-01 07:14:03 +02:00
|
|
|
);
|
2014-06-30 04:17:04 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the circle object.
|
|
|
|
* @param overlap true if the next object's start time has already passed
|
|
|
|
* @return true if a hit result (miss) was processed
|
|
|
|
*/
|
|
|
|
public boolean update(boolean overlap) {
|
2014-07-18 21:11:57 +02:00
|
|
|
int time = hitObject.getTime();
|
|
|
|
float x = hitObject.getX(), y = hitObject.getY();
|
|
|
|
byte hitSound = hitObject.getHitSoundType();
|
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
int trackPosition = MusicController.getPosition();
|
|
|
|
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
|
|
|
|
2014-07-18 21:11:57 +02:00
|
|
|
if (overlap || trackPosition > time + hitResultOffset[GameScore.HIT_50]) {
|
2014-06-30 04:17:04 +02:00
|
|
|
if (isAutoMod) // "auto" mod: catch any missed notes due to lag
|
2014-07-18 21:11:57 +02:00
|
|
|
score.hitResult(time, GameScore.HIT_300, x, y, color, comboEnd, hitSound);
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
else // no more points can be scored, so send a miss
|
2014-07-18 21:11:57 +02:00
|
|
|
score.hitResult(time, GameScore.HIT_MISS, x, y, null, comboEnd, hitSound);
|
2014-06-30 04:17:04 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// "auto" mod: send a perfect hit result
|
|
|
|
else if (isAutoMod) {
|
2014-07-18 21:11:57 +02:00
|
|
|
if (Math.abs(trackPosition - time) < hitResultOffset[GameScore.HIT_300]) {
|
|
|
|
score.hitResult(time, GameScore.HIT_300, x, y, color, comboEnd, hitSound);
|
2014-06-30 04:17:04 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|