Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

SpriteShootout - Mapped naive

By: a guest on Jul 24th, 2011  |  syntax: Java 5  |  size: 1.04 KB  |  views: 105  |  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 Sprite sprite,
  3.         final SpriteRender spriteRender,
  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.         final Sprite[] sprites = sprite.asArray();
  11.         final SpriteRender[] spritesRender = spriteRender.asArray();
  12.         for ( int b = ballIndex, r = 0, len = (ballIndex + batchSize); b < len; b++, r++ ) {
  13.                 float x = sprites[b].x;
  14.                 float dx = sprites[b].dx;
  15.  
  16.                 x += dx * delta;
  17.                 if ( x < ballRadius ) {
  18.                         x = ballRadius;
  19.                         sprites[b].dx = -dx;
  20.                 } else if ( x > boundW ) {
  21.                         x = boundW;
  22.                         sprites[b].dx = -dx;
  23.                 }
  24.                 sprites[b].x = x;
  25.  
  26.                 float y = sprites[b].y;
  27.                 float dy = sprites[b].dy;
  28.  
  29.                 y += dy * delta;
  30.                 if ( y < ballRadius ) {
  31.                         y = ballRadius;
  32.                         sprites[b].dy = -dy;
  33.                 } else if ( y > boundH ) {
  34.                         y = boundH;
  35.                         sprites[b].dy = -dy;
  36.                 }
  37.                 sprites[b].y = y;
  38.  
  39.                 spritesRender[r].x = x;
  40.                 spritesRender[r].y = y;
  41.         }
  42.  
  43. }
clone this paste RAW Paste Data