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 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);
float digitWidth = getDefaultSymbolImage(0).getWidth() * scale;
float cx = x + ((length - 1) * (digitWidth / 2));
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;
n /= 10;
}

View File

@ -33,6 +33,9 @@ import org.newdawn.slick.Graphics;
* Data type representing a circle object.
*/
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. */
private OsuHitObject hitObject;
@ -84,26 +87,22 @@ public class Circle implements HitObject {
@Override
public void draw(Graphics g, int trackPosition) {
int timeDiff = hitObject.getTime() - trackPosition;
if (timeDiff >= 0) {
float oldAlpha = color.a;
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;
color.a = 1 - scale;
GameImage.APPROACHCIRCLE.getImage().getScaledCopy(approachScale).drawCentered(x, y, color);
float alpha = Utils.clamp(1 - fadeinScale, 0, 1);
float alpha = Utils.clamp((1 - scale) * 2, 0, 1);
color.a = alpha;
Utils.COLOR_WHITE_FADE.a = alpha;
float oldAlpha = Utils.COLOR_WHITE_FADE.a;
Utils.COLOR_WHITE_FADE.a = color.a = alpha;
if(timeDiff >= 0 )
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);
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());
}
GameImage.HITCIRCLE.getImage().getWidth() * 0.40f / data.getDefaultSymbolImage(0).getHeight(), Utils.COLOR_WHITE_FADE);
Utils.COLOR_WHITE_FADE.a = oldAlpha;
}
/**

View File

@ -47,6 +47,9 @@ public class Slider implements HitObject {
/** Rate at which slider ticks are placed. */
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. */
private OsuHitObject hitObject;
@ -161,29 +164,27 @@ public class Slider implements HitObject {
public void draw(Graphics g, int 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 - scale, 0, 1);
float alpha = Utils.clamp(1 - fadeinScale, 0, 1);
float oldAlpha = color.a;
color.a = alpha;
Utils.COLOR_WHITE_FADE.a = alpha;
float oldAlpha = Utils.COLOR_WHITE_FADE.a;
Utils.COLOR_WHITE_FADE.a = color.a = alpha;
// curve
curve.draw();
// ticks
if (timeDiff < 0 && ticksT != null) {
if (ticksT != null) {
Image tick = GameImage.SLIDER_TICK.getImage();
for (int i = 0; i < ticksT.length; 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 hitCircle = GameImage.HITCIRCLE.getImage();
color.a = alpha;
Utils.COLOR_WHITE_FADE.a = 1f;
// end circle
float[] endPos = curve.pointAt(1);
@ -197,9 +198,7 @@ public class Slider implements HitObject {
; // don't draw current combo number if already clicked
else
data.drawSymbolNumber(hitObject.getComboNumber(), x, y,
hitCircle.getWidth() * 0.40f / data.getDefaultSymbolImage(0).getHeight());
color.a = oldAlpha;
hitCircle.getWidth() * 0.40f / data.getDefaultSymbolImage(0).getHeight(), Utils.COLOR_WHITE_FADE);
// repeats
for (int tcurRepeat = currentRepeats; tcurRepeat <= currentRepeats + 1; tcurRepeat++) {
@ -226,7 +225,6 @@ public class Slider implements HitObject {
if (timeDiff >= 0) {
// approach circle
color.a = 1 - scale;
GameImage.APPROACHCIRCLE.getImage().getScaledCopy(approachScale).drawCentered(x, y, color);
} else {
// 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);
int extraRotations = (int) (rotations - rotationsNeeded);
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);
}
}