/// <summary> /// checks the direction of the swipe /// </summary> /// <param name="pos"> last position of the finger when the function is called </param> /// <returns></returns> private SwipeDIrection CheckInputDirection(Vector3 pos) { Vector3 dir = pos - startSwipePos; float positiveX = Mathf.Abs(dir.x); float positiveZ = Mathf.Abs(dir.y); if (positiveX > positiveZ) { swipeDir = (dir.x > 0) ? SwipeDIrection.Right : SwipeDIrection.Left; } else { swipeDir = (dir.y > 0) ? SwipeDIrection.Up : SwipeDIrection.Down; } return(swipeDir); }
/// <summary> /// given a direction, returns the ID of a neighbour Ingredient of selectedIngredient /// </summary> /// <param name="dir"></param> /// <returns></returns> public int GetTargetIngredient(SwipeDIrection dir) { if (selectedIngredient != null) { int x = -1, y = -1; //find the index of the destination ingredient switch (dir) { case SwipeDIrection.Up: if (selectedIngredient.YIndex < boardHeight) { x = selectedIngredient.XIndex; y = selectedIngredient.YIndex + 1; } else { ResetIngredients(); return(-1); } break; case SwipeDIrection.Down: if (selectedIngredient.YIndex > 0) { x = selectedIngredient.XIndex; y = selectedIngredient.YIndex - 1; } else { ResetIngredients(); return(-1); } break; case SwipeDIrection.Right: if (selectedIngredient.XIndex < boardLength) { x = selectedIngredient.XIndex + 1; y = selectedIngredient.YIndex; } else { ResetIngredients(); return(-1); } break; case SwipeDIrection.Left: if (selectedIngredient.XIndex > 0) { x = selectedIngredient.XIndex - 1; y = selectedIngredient.YIndex; } else { ResetIngredients(); return(-1); } break; default: ResetIngredients(); break; } targetIngredient = logicMatrix[x, y]; return(targetIngredient.ActualID); } else { ResetIngredients(); return(-1); } }