예제 #1
0
 public void Draw(XnaRenderer renderer)
 {
     Tile[] parts = _body.ToArray();
     for (int i = 0; i < parts.Length; i++)
     {
         Texture texture;
         float   angle = 0;
         Tile    part  = parts[i];
         if (i == parts.Length - 1)
         {
             texture = _headAnimation.CurrentTexture;
             angle   = Compass.GetAngle(MoveDirection);
         }
         else if (i == 0)
         {
             texture = _tailTexture;
             CardinalDirection directionOfLast = Compass.GetDirection(parts[i + 1].Position - parts[i].Position);
             angle = Compass.GetAngle(directionOfLast);
         }
         else
         {
             CardinalDirection directionOfNext = Compass.GetDirection(parts[i - 1].Position - parts[i].Position);
             CardinalDirection directionOfLast = Compass.GetDirection(parts[i + 1].Position - parts[i].Position);
             if (Compass.GetOppositeDirection(directionOfLast) == directionOfNext)
             {
                 texture = _bodyNsTexture;
                 if (directionOfNext == CardinalDirection.East || directionOfNext == CardinalDirection.West)
                 {
                     angle = MathHelper.PiOver2;
                 }
             }
             else
             {
                 texture = _bodyNeTexture;
                 if (directionOfLast == CardinalDirection.North && directionOfNext == CardinalDirection.West)
                 {
                     angle = MathHelper.PiOver2 * 3;
                 }
                 if (directionOfLast == CardinalDirection.East && directionOfNext == CardinalDirection.South)
                 {
                     angle = MathHelper.PiOver2;
                 }
                 if (directionOfLast == CardinalDirection.South && directionOfNext == CardinalDirection.East)
                 {
                     angle = MathHelper.PiOver2;
                 }
                 if (directionOfLast == CardinalDirection.South && directionOfNext == CardinalDirection.West)
                 {
                     angle = MathHelper.Pi;
                 }
                 if (directionOfLast == CardinalDirection.West && directionOfNext == CardinalDirection.South)
                 {
                     angle = MathHelper.Pi;
                 }
                 if (directionOfLast == CardinalDirection.West && directionOfNext == CardinalDirection.North)
                 {
                     angle = MathHelper.PiOver2 * 3;
                 }
             }
         }
         renderer.DrawSprite(texture, new Vector2(part.Position.X + 0.5f, part.Position.Y + 0.5f), new Vector2(1f, 1f), angle, Color.Green, 1f);
     }
 }