Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.92 KB | None | 0 0
  1. public void DrawPlayer(OnlinePlayer player)
  2.     {
  3.         Vector2Int[] positions;
  4.         byte[] jumpIndices;
  5.        
  6.  
  7.         while ((positions = player.GetPositions()) != null)
  8.         {
  9.             jumpIndices = player.GetJumps();
  10.             int jumpCounter = 0;
  11.             for (int i = 1; i < positions.Length; ++i)
  12.             {
  13.                 Vector2Int playerPosition = positions[i];
  14.                 Vector2Int playerLastPostion = positions[i - 1];
  15.                 DrawCircle(playerPosition, player.radius, player.Color);
  16.                
  17.                 if ((jumpIndices.Length <= jumpCounter) || (!(jumpIndices[jumpCounter] == i) && playerLastPostion != playerPosition))
  18.                 {
  19.                     Vector2 directionVector = (player.position - player.lastPosition).normalized;
  20.                     Vector2 directionVectorTurnedLeft = new Vector2(Mathf.Cos(Mathf.Deg2Rad * 90) * directionVector.x - Mathf.Sin(Mathf.Deg2Rad * 90) * directionVector.y, Mathf.Sin(Mathf.Deg2Rad * 90) * directionVector.x + Mathf.Cos(Mathf.Deg2Rad * 90) * directionVector.y);
  21.                     Vector2 directionVectorTurnedRight = -1 * directionVectorTurnedLeft;
  22.                     Vector2 bottomLeftVertice = player.lastPosition + directionVectorTurnedLeft * player.radius;
  23.                     Vector2 bottomRightVertice = player.lastPosition + directionVectorTurnedRight * player.radius;
  24.                     Vector2 topLeftVertice = player.position + directionVectorTurnedLeft * player.radius;
  25.                     Vector2 topRightVertice = player.position + directionVectorTurnedRight * player.radius;
  26.                     DrawTriangle(VectorToInt(bottomLeftVertice), VectorToInt(bottomRightVertice), VectorToInt(topLeftVertice), player.Color);
  27.                     DrawTriangle(VectorToInt(topLeftVertice), VectorToInt(topRightVertice), VectorToInt(bottomRightVertice), player.Color);
  28.                 }
  29.             }
  30.         }
  31.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement