int GetTileForTail(SnakeBodyPart newTail) { if (newTail.CurrentTile > 4) { return(newTail.PreviousDirection + 8); } return(newTail.CurrentTile + 8); }
internal void Move(Vector2 newPosition, int previousHeadDirection) { SnakeBodyPart newFirstPart = bodyParts.Last(); SnakeBodyPart newTail = newFirstPart.Next; newFirstPart.Position = newPosition; newFirstPart.PreviousDirection = HeadDirection; newFirstPart.CurrentTile = GetTileForFirstBodyPart(previousHeadDirection); newTail.CurrentTile = GetTileForTail(newTail); bodyParts.Insert(0, newFirstPart); bodyParts.RemoveAt(Length); }
internal void Grow(Vector2 newPosition, int previousHeadDirection) { SnakeBodyPart firstPart = bodyParts.First(); SnakeBodyPart tail = bodyParts.Last(); SnakeBodyPart newPart = new SnakeBodyPart(snakeBodySprite) { Position = newPosition, CurrentTile = GetTileForFirstBodyPart(previousHeadDirection), PreviousDirection = HeadDirection, Next = tail }; firstPart.Next = newPart; bodyParts.Insert(0, newPart); }