Added HitObject interface for OsuHitObjects during gameplay.

This greatly simplifies object-handling code, and is slightly more time and memory efficient.

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han
2015-01-16 03:47:37 -05:00
parent bcf1fa301a
commit 7bd9eba2f5
5 changed files with 90 additions and 118 deletions

View File

@@ -28,12 +28,13 @@ import itdelatrisu.opsu.states.Game;
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
/**
* Data type representing a circle object.
*/
public class Circle {
public class Circle implements HitObject {
/**
* The associated OsuHitObject.
*/
@@ -89,11 +90,7 @@ public class Circle {
this.comboEnd = comboEnd;
}
/**
* Draws the circle to the graphics context.
* @param trackPosition the current track position
*/
public void draw(int trackPosition) {
public void draw(int trackPosition, boolean currentObject, Graphics g) {
int timeDiff = hitObject.getTime() - trackPosition;
if (timeDiff >= 0) {
@@ -117,7 +114,7 @@ public class Circle {
* @param time the hit object time (difference between track time)
* @return the hit result (GameScore.HIT_* constants)
*/
public int hitResult(int time) {
private int hitResult(int time) {
int trackPosition = MusicController.getPosition();
int timeDiff = Math.abs(trackPosition - time);
@@ -136,13 +133,6 @@ public class Circle {
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) {
double distance = Math.hypot(hitObject.getX() - x, hitObject.getY() - y);
int circleRadius = GameImage.HITCIRCLE.getImage().getWidth() / 2;
@@ -160,12 +150,7 @@ public class Circle {
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) {
public boolean update(boolean overlap, int delta, int mouseX, int mouseY) {
int time = hitObject.getTime();
float x = hitObject.getX(), y = hitObject.getY();
byte hitSound = hitObject.getHitSoundType();