This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

SpriteShootout - Java

By: a guest on Jul 24th, 2011  |  syntax: Java 5  |  size: 0.95 KB  |  views: 94  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. protected void animate(
  2.         final float[] sprites,
  3.         final FloatBuffer spritesRender,
  4.         final int ballSize, final int ballIndex, final int batchSize, final int delta
  5. ) {
  6.         final float ballRadius = ballSize * 0.5f;
  7.         final float boundW = SCREEN_WIDTH - ballRadius;
  8.         final float boundH = SCREEN_HEIGHT - ballRadius;
  9.  
  10.         for ( int b = ballIndex * 4, len = (ballIndex + batchSize) * 4; b < len; b += 4 ) {
  11.                 float x = sprites[b + 0];
  12.                 float dx = sprites[b + 2];
  13.  
  14.                 x += dx * delta;
  15.                 if ( x < ballRadius ) {
  16.                         x = ballRadius;
  17.                         sprites[b + 2] = -dx;
  18.                 } else if ( x > boundW ) {
  19.                         x = boundW;
  20.                         sprites[b + 2] = -dx;
  21.                 }
  22.                 sprites[b + 0] = x;
  23.  
  24.                 float y = sprites[b + 1];
  25.                 float dy = sprites[b + 3];
  26.  
  27.                 y += dy * delta;
  28.                 if ( y < ballRadius ) {
  29.                         y = ballRadius;
  30.                         sprites[b + 3] = -dy;
  31.                 } else if ( y > boundH ) {
  32.                         y = boundH;
  33.                         sprites[b + 3] = -dy;
  34.                 }
  35.                 sprites[b + 1] = y;
  36.  
  37.                 spritesRender.put(x).put(y);
  38.         }
  39.         spritesRender.clear();
  40. }
clone this paste RAW Paste Data