Merge pull request #63 from DarkTigrus/fadein-fix

Circle and slider fade in.
This commit is contained in:
Jeffrey Han 2015-03-31 19:29:18 -04:00
commit 1d9ec52c8a
4 changed files with 30 additions and 31 deletions

View File

@ -444,13 +444,13 @@ public class GameData {
* @param y the center y coordinate * @param y the center y coordinate
* @param scale the scale to apply * @param scale the scale to apply
*/ */
public void drawSymbolNumber(int n, float x, float y, float scale) { public void drawSymbolNumber(int n, float x, float y, float scale, Color color) {
int length = (int) (Math.log10(n) + 1); int length = (int) (Math.log10(n) + 1);
float digitWidth = getDefaultSymbolImage(0).getWidth() * scale; float digitWidth = getDefaultSymbolImage(0).getWidth() * scale;
float cx = x + ((length - 1) * (digitWidth / 2)); float cx = x + ((length - 1) * (digitWidth / 2));
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
getDefaultSymbolImage(n % 10).getScaledCopy(scale).drawCentered(cx, y); getDefaultSymbolImage(n % 10).getScaledCopy(scale).drawCentered(cx, y, color);
cx -= digitWidth; cx -= digitWidth;
n /= 10; n /= 10;
} }

View File

@ -33,6 +33,9 @@ import org.newdawn.slick.Graphics;
* Data type representing a circle object. * Data type representing a circle object.
*/ */
public class Circle implements HitObject { public class Circle implements HitObject {
/** The amount of time, in milliseconds, to fade in the circle. */
private static final int FADE_IN_TIME = 375;
/** The associated OsuHitObject. */ /** The associated OsuHitObject. */
private OsuHitObject hitObject; private OsuHitObject hitObject;
@ -84,26 +87,22 @@ public class Circle implements HitObject {
@Override @Override
public void draw(Graphics g, int trackPosition) { public void draw(Graphics g, int trackPosition) {
int timeDiff = hitObject.getTime() - trackPosition; int timeDiff = hitObject.getTime() - trackPosition;
float scale = timeDiff / (float) game.getApproachTime();
float fadeinScale = (timeDiff - game.getApproachTime() + FADE_IN_TIME) / (float) FADE_IN_TIME;
float approachScale = 1 + scale * 3;
float alpha = Utils.clamp(1 - fadeinScale, 0, 1);
if (timeDiff >= 0) { float oldAlpha = Utils.COLOR_WHITE_FADE.a;
float oldAlpha = color.a; Utils.COLOR_WHITE_FADE.a = color.a = alpha;
float scale = timeDiff / (float)game.getApproachTime();
float approachScale = 1 + scale * 3; if(timeDiff >= 0 )
color.a = 1 - scale;
GameImage.APPROACHCIRCLE.getImage().getScaledCopy(approachScale).drawCentered(x, y, color); GameImage.APPROACHCIRCLE.getImage().getScaledCopy(approachScale).drawCentered(x, y, color);
GameImage.HITCIRCLE.getImage().drawCentered(x, y, color);
GameImage.HITCIRCLE_OVERLAY.getImage().drawCentered(x, y, Utils.COLOR_WHITE_FADE);
data.drawSymbolNumber(hitObject.getComboNumber(), x, y,
GameImage.HITCIRCLE.getImage().getWidth() * 0.40f / data.getDefaultSymbolImage(0).getHeight(), Utils.COLOR_WHITE_FADE);
float alpha = Utils.clamp((1 - scale) * 2, 0, 1); Utils.COLOR_WHITE_FADE.a = oldAlpha;
color.a = alpha;
Utils.COLOR_WHITE_FADE.a = alpha;
GameImage.HITCIRCLE.getImage().drawCentered(x, y, color);
GameImage.HITCIRCLE_OVERLAY.getImage().drawCentered(x, y, Utils.COLOR_WHITE_FADE);
color.a = oldAlpha;
Utils.COLOR_WHITE_FADE.a = 1f;
data.drawSymbolNumber(hitObject.getComboNumber(), x, y,
GameImage.HITCIRCLE.getImage().getWidth() * 0.40f / data.getDefaultSymbolImage(0).getHeight());
}
} }
/** /**

View File

@ -47,6 +47,9 @@ public class Slider implements HitObject {
/** Rate at which slider ticks are placed. */ /** Rate at which slider ticks are placed. */
private static float sliderTickRate = 1.0f; private static float sliderTickRate = 1.0f;
/** The amount of time, in milliseconds, to fade in the slider. */
private static final int FADE_IN_TIME = 375;
/** The associated OsuHitObject. */ /** The associated OsuHitObject. */
private OsuHitObject hitObject; private OsuHitObject hitObject;
@ -161,29 +164,27 @@ public class Slider implements HitObject {
public void draw(Graphics g, int trackPosition) { public void draw(Graphics g, int trackPosition) {
int timeDiff = hitObject.getTime() - trackPosition; int timeDiff = hitObject.getTime() - trackPosition;
float scale = timeDiff / (float) game.getApproachTime(); float scale = timeDiff / (float) game.getApproachTime();
float fadeinScale = (timeDiff - game.getApproachTime() + FADE_IN_TIME) / (float) FADE_IN_TIME;
float approachScale = 1 + scale * 3; float approachScale = 1 + scale * 3;
float alpha = Utils.clamp(1 - scale, 0, 1); float alpha = Utils.clamp(1 - fadeinScale, 0, 1);
float oldAlpha = color.a; float oldAlpha = Utils.COLOR_WHITE_FADE.a;
color.a = alpha; Utils.COLOR_WHITE_FADE.a = color.a = alpha;
Utils.COLOR_WHITE_FADE.a = alpha;
// curve // curve
curve.draw(); curve.draw();
// ticks // ticks
if (timeDiff < 0 && ticksT != null) { if (ticksT != null) {
Image tick = GameImage.SLIDER_TICK.getImage(); Image tick = GameImage.SLIDER_TICK.getImage();
for (int i = 0; i < ticksT.length; i++) { for (int i = 0; i < ticksT.length; i++) {
float[] c = curve.pointAt(ticksT[i]); float[] c = curve.pointAt(ticksT[i]);
tick.drawCentered(c[0], c[1]); tick.drawCentered(c[0], c[1], Utils.COLOR_WHITE_FADE);
} }
} }
Image hitCircleOverlay = GameImage.HITCIRCLE_OVERLAY.getImage(); Image hitCircleOverlay = GameImage.HITCIRCLE_OVERLAY.getImage();
Image hitCircle = GameImage.HITCIRCLE.getImage(); Image hitCircle = GameImage.HITCIRCLE.getImage();
color.a = alpha;
Utils.COLOR_WHITE_FADE.a = 1f;
// end circle // end circle
float[] endPos = curve.pointAt(1); float[] endPos = curve.pointAt(1);
@ -197,9 +198,7 @@ public class Slider implements HitObject {
; // don't draw current combo number if already clicked ; // don't draw current combo number if already clicked
else else
data.drawSymbolNumber(hitObject.getComboNumber(), x, y, data.drawSymbolNumber(hitObject.getComboNumber(), x, y,
hitCircle.getWidth() * 0.40f / data.getDefaultSymbolImage(0).getHeight()); hitCircle.getWidth() * 0.40f / data.getDefaultSymbolImage(0).getHeight(), Utils.COLOR_WHITE_FADE);
color.a = oldAlpha;
// repeats // repeats
for (int tcurRepeat = currentRepeats; tcurRepeat <= currentRepeats + 1; tcurRepeat++) { for (int tcurRepeat = currentRepeats; tcurRepeat <= currentRepeats + 1; tcurRepeat++) {
@ -226,7 +225,6 @@ public class Slider implements HitObject {
if (timeDiff >= 0) { if (timeDiff >= 0) {
// approach circle // approach circle
color.a = 1 - scale;
GameImage.APPROACHCIRCLE.getImage().getScaledCopy(approachScale).drawCentered(x, y, color); GameImage.APPROACHCIRCLE.getImage().getScaledCopy(approachScale).drawCentered(x, y, color);
} else { } else {
// Since update() might not have run before drawing during a replay, the // Since update() might not have run before drawing during a replay, the
@ -259,6 +257,8 @@ public class Slider implements HitObject {
} }
} }
} }
Utils.COLOR_WHITE_FADE.a = oldAlpha;
} }
/** /**

View File

@ -168,7 +168,7 @@ public class Spinner implements HitObject {
GameImage.SPINNER_CLEAR.getImage().drawCentered(width / 2, height / 4); GameImage.SPINNER_CLEAR.getImage().drawCentered(width / 2, height / 4);
int extraRotations = (int) (rotations - rotationsNeeded); int extraRotations = (int) (rotations - rotationsNeeded);
if (extraRotations > 0) if (extraRotations > 0)
data.drawSymbolNumber(extraRotations * 1000, width / 2, height * 2 / 3, 1.0f); data.drawSymbolNumber(extraRotations * 1000, width / 2, height * 2 / 3, 1.0f, Color.white);
} }
} }