
SpriteShootout - Java
By: a guest on
Jul 24th, 2011 | syntax:
Java 5 | size: 0.95 KB | hits: 92 | expires: Never
protected void animate(
final float[] sprites,
final FloatBuffer spritesRender,
final int ballSize, final int ballIndex, final int batchSize, final int delta
) {
final float ballRadius = ballSize * 0.5f;
final float boundW = SCREEN_WIDTH - ballRadius;
final float boundH = SCREEN_HEIGHT - ballRadius;
for ( int b = ballIndex * 4, len = (ballIndex + batchSize) * 4; b < len; b += 4 ) {
float x = sprites[b + 0];
float dx = sprites[b + 2];
x += dx * delta;
if ( x < ballRadius ) {
x = ballRadius;
sprites[b + 2] = -dx;
} else if ( x > boundW ) {
x = boundW;
sprites[b + 2] = -dx;
}
sprites[b + 0] = x;
float y = sprites[b + 1];
float dy = sprites[b + 3];
y += dy * delta;
if ( y < ballRadius ) {
y = ballRadius;
sprites[b + 3] = -dy;
} else if ( y > boundH ) {
y = boundH;
sprites[b + 3] = -dy;
}
sprites[b + 1] = y;
spritesRender.put(x).put(y);
}
spritesRender.clear();
}