@@ -53,6 +53,10 @@ public class DropRenderer {
53
53
private static final float BLACK_KEY_WIDTH_RATIO = 0.6F ;
54
54
private static final float BLACK_KEY_HEIGHT_RATIO = 0.6F ;
55
55
private static final float PIANO_HEIGHT_DIVIDER = 7F ;
56
+ private static final int KEY_LINE_HEIGHT = 2 ;
57
+ private static final int KEY_LINE_OFFSET = 25 ;
58
+ private static final int KEY_PRESS_DEPTH = 20 ;
59
+ private static final long KEY_ANIMATION_DURATION = 250_000_000L ;
56
60
57
61
private final SoundSystemSongPlayer songPlayer ;
58
62
private Font robotoFont ;
@@ -207,7 +211,12 @@ private void drawNotes(final Matrix4fStack positionMatrix) {
207
211
Renderer2D .INSTANCE .filledRect (positionMatrix , x , y , x + noteSize , y + noteSize , Color .WHITE .withAlphaF (alpha ));
208
212
}
209
213
if (tick == currentTick ) {
210
- this .pianoKeyLastPlayed [nbsKey ] = System .nanoTime ();
214
+ final long currentTime = System .nanoTime ();
215
+ if (currentTime - this .pianoKeyLastPlayed [nbsKey ] < currentTime + KEY_ANIMATION_DURATION / 2 ) {
216
+ this .pianoKeyLastPlayed [nbsKey ] = currentTime - KEY_ANIMATION_DURATION / 2 ;
217
+ } else {
218
+ this .pianoKeyLastPlayed [nbsKey ] = System .nanoTime ();
219
+ }
211
220
}
212
221
this .renderedNotes ++;
213
222
}
@@ -226,20 +235,22 @@ private void drawPiano(final Matrix4fStack positionMatrix) {
226
235
227
236
for (int nbsKey = 0 ; nbsKey < this .pianoKeyPositions .length ; nbsKey ++) {
228
237
final float x = this .pianoKeyPositions [nbsKey ];
238
+ final float progress = this .pianoKeyLastColors [nbsKey ] != null ? MathUtils .clamp ((System .nanoTime () - this .pianoKeyLastPlayed [nbsKey ]) / (float ) KEY_ANIMATION_DURATION , 0F , 1F ) : 1F ;
239
+ final float pressOffset = KEY_PRESS_DEPTH - KEY_PRESS_DEPTH * (progress < 0.5F ? 1F - progress : progress );
229
240
if (!this .isBlackKey (nbsKey )) {
230
- Renderer2D .INSTANCE .filledRect (positionMatrix , x + 1 , 0 , x + whiteKeyWidth - 1 , height , Color .WHITE );
241
+ Renderer2D .INSTANCE .filledRect (positionMatrix , x + 1 , pressOffset , x + whiteKeyWidth - 1 , height , Color .WHITE );
231
242
if (this .pianoKeyLastColors [nbsKey ] != null ) {
232
- final float alpha = 1F - MathUtils .clamp ((System .nanoTime () - this .pianoKeyLastPlayed [nbsKey ]) / 500_000_000F , 0F , 1F );
233
- Renderer2D .INSTANCE .filledRect (positionMatrix , x + 1 , 0 , x + whiteKeyWidth - 1 , height , this .pianoKeyLastColors [nbsKey ].withAlpha (Math .round (200 * alpha )));
243
+ Renderer2D .INSTANCE .filledRect (positionMatrix , x + 1 , pressOffset , x + whiteKeyWidth - 1 , height , this .pianoKeyLastColors [nbsKey ].withAlpha (Math .round (200 * (1 - progress ))));
234
244
}
245
+ Renderer2D .INSTANCE .filledRect (positionMatrix , x , height - KEY_LINE_OFFSET + pressOffset , x + whiteKeyWidth , height - KEY_LINE_OFFSET - KEY_LINE_HEIGHT + pressOffset , Color .GRAY );
235
246
} else {
236
247
positionMatrix .pushMatrix ();
237
248
positionMatrix .translate (0 , 0 , 1 );
238
- Renderer2D .INSTANCE .filledRect (positionMatrix , x , 0 , x + blackKeyWidth , height * BLACK_KEY_HEIGHT_RATIO , Color .BLACK );
249
+ Renderer2D .INSTANCE .filledRect (positionMatrix , x , pressOffset , x + blackKeyWidth , height * BLACK_KEY_HEIGHT_RATIO , Color .BLACK );
239
250
if (this .pianoKeyLastColors [nbsKey ] != null ) {
240
- final float alpha = 1F - MathUtils .clamp ((System .nanoTime () - this .pianoKeyLastPlayed [nbsKey ]) / 500_000_000F , 0F , 1F );
241
- Renderer2D .INSTANCE .filledRect (positionMatrix , x , 0 , x + blackKeyWidth , height * BLACK_KEY_HEIGHT_RATIO , this .pianoKeyLastColors [nbsKey ].withAlpha (Math .round (200 * alpha )));
251
+ Renderer2D .INSTANCE .filledRect (positionMatrix , x , pressOffset , x + blackKeyWidth , height * BLACK_KEY_HEIGHT_RATIO , this .pianoKeyLastColors [nbsKey ].withAlpha (Math .round (200 * (1 - progress ))));
242
252
}
253
+ Renderer2D .INSTANCE .filledRect (positionMatrix , x , height * BLACK_KEY_HEIGHT_RATIO - KEY_LINE_OFFSET + pressOffset , x + blackKeyWidth , height * BLACK_KEY_HEIGHT_RATIO - KEY_LINE_OFFSET - KEY_LINE_HEIGHT + pressOffset , Color .GRAY );
243
254
positionMatrix .popMatrix ();
244
255
}
245
256
}
0 commit comments