MagusZero

Snake Update

Dec 20th, 2012
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.82 KB | None | 0 0
  1. public void Update(GameTime theGameTime)
  2.         {
  3.             Sprite previous = null;
  4.             foreach (var sprite in body)
  5.             {
  6.                 if (previous != null)
  7.                 {
  8.                     if (previous.position != sprite.position)
  9.                     {
  10.                         //float x = sprite.position.X - previous.position.X;
  11.                         //float y = sprite.position.Y - previous.position.Y;
  12.                         Vector2 tempDirection = sprite.position - previous.position;
  13.                         tempDirection.Normalize();
  14.                         Vector2 tempSpeed = new Vector2(tempDirection.X != 0 ? SNAKE_SPEED : 0, tempDirection.Y != 0 ? SNAKE_SPEED : 0);
  15.                         sprite.Update(theGameTime, tempSpeed, tempDirection);
  16.                         //sprite.Update(theGameTime, tempDirection, tempDirection);
  17.                     }
  18.                 }
  19.                 else
  20.                 {
  21.                     KeyboardState currentKeyboardState = Keyboard.GetState();
  22.                     UpdateMovement(currentKeyboardState);
  23.                     previousKeyboardState = currentKeyboardState;
  24.                     sprite.Update(theGameTime, speed, direction);
  25.                 }
  26.  
  27.                 /*if (previous == null)
  28.                 {
  29.                     KeyboardState currentKeyboardState = Keyboard.GetState();
  30.                     UpdateMovement(currentKeyboardState);
  31.                     previousKeyboardState = currentKeyboardState;
  32.                     sprite.Update(theGameTime, speed, direction);
  33.                 }
  34.                 else
  35.                 {
  36.                     UpdateMovement(previousKeyboardState);
  37.                     sprite.Update(theGameTime, speed, direction);
  38.                 }*/
  39.  
  40.                 previous = sprite;
  41.             }
  42.         }
Advertisement
Add Comment
Please, Sign In to add comment