/// <summary> /// Update the curAnimalDirection everytime its changes /// </summary> /// <param name="animalSlot"></param> private void UpdateCurAnimalDirections(AnimalSlot animalSlot) { if (curAnimalDirections.animalPoint.Equals(animalSlot.index)) { return; } curAnimalDirections.animalPoint = animalSlot.index; ResetDirectionsToUse(); }
/// <summary> /// Set animal on this slot /// </summary> /// <param name="animalSlot"></param> public void SetSlot(AnimalSlot animalSlot) { _animalSlot = animalSlot; animal = _animalSlot == null ? AnimalType.Empty : _animalSlot.animal; if (_animalSlot == null) { return; } _animalSlot.SetIndex(index); }
/// <summary> /// Called to afirm that we are dealing with a drag swap /// </summary> /// <param name="animalSlot"></param> /// <param name="startedPosition"></param> private void EnableSwap(AnimalSlot animalSlot, Vector2 startedPosition) { _curSwapMode = SwapType.Drag; if (_animalSlotDragMoving != null) { return; } _animalSlotDragMoving = animalSlot; _mouseStart = startedPosition; }
/// <summary> /// Event called when user click on some animal, can be a drag or click until this moment /// </summary> /// <param name="animalSlot"></param> public void OnAnimalClickDown(AnimalSlot animalSlot) { _curSwapMode = SwapType.Click; UpdateCurAnimalDirections(animalSlot); if (_possibleAnimalSlotMoving != null) { return; } _possibleAnimalSlotMoving = animalSlot; _possibleMouseStart = Input.mousePosition; }
public AnimalSlot GetOtherPiece(AnimalSlot p) { if (p == one) { return(two); } else if (p == two) { return(one); } else { return(null); } }
/// <summary> /// Called when we do a full click, so it is called also when we do a OnPointerUp event /// </summary> /// <param name="animalSlot"></param> public void OnAnimalClick(AnimalSlot animalSlot) { //Cleaning possible values because we want to clear our mouse if (_possibleAnimalSlotMoving != null) { _possibleAnimalSlotMoving = null; } _possibleMouseStart = Vector2.zero; if (_possibleAnimalSlotMoving == null && _animalSlotDragMoving == null) { _animalSlotClickMoving = animalSlot; _curSwapMode = SwapType.Click; SwapAnimalByClick(); } }
private void Update() { if (_possibleAnimalSlotMoving != null) { var possibleDir = ((Vector2)Input.mousePosition - _possibleMouseStart); var dirMagnitude = possibleDir.magnitude; if (dirMagnitude > gameConfig.SwapThreshold) { EnableSwap(_possibleAnimalSlotMoving, _possibleMouseStart); _possibleAnimalSlotMoving = null; _possibleMouseStart = Vector2.zero; return; } } if (_curSwapMode == SwapType.Drag) { SwapAnimalByDrag(); } }
/// <summary> /// Drop our animal for swap, if it was a click swap, it will be called the same way /// </summary> public void OnAnimalClickUp() { if (_curSwapMode == SwapType.Drag) { //checking if we have a animal to move using swap if (_animalSlotDragMoving == null) { return; } if (!_newIndex.Equals(_animalSlotDragMoving.index)) { gameBoard.FlipAnimal(_animalSlotDragMoving.index, _newIndex, true); } else { gameBoard.ResetAnimalSlot(_animalSlotDragMoving); } _animalSlotDragMoving = null; } else { //checking if we have a animal to move using click if (_animalSlotClickMoving == null) { return; } if (!_newIndex.Equals(_animalSlotClickMoving.index)) { gameBoard.FlipAnimal(_animalSlotClickMoving.index, _newIndex, true); } else { gameBoard.ResetAnimalSlot(_animalSlotClickMoving); } _animalSlotClickMoving = null; } }
/// <summary> /// Reset some animal slot /// </summary> /// <param name="animalSlot"></param> public void ResetAnimalSlot(AnimalSlot animalSlot) { animalSlot.ResetPosition(); _update.Add(animalSlot); }
private void Update() { if (!_started) { return; } var finishedUpdating = _update.Where(animalSlot => !animalSlot.UpdatePiece()).ToList(); foreach (var aSlot in finishedUpdating) { var flip = GetFlipped(aSlot); AnimalSlot flippedPiece = null; var x = aSlot.index.x; _fills[x] = Mathf.Clamp(_fills[x] - 1, 0, gameConfig.Width); var connected = ConnectedPoints(aSlot.index, true); var wasFlipped = (flip != null); //checking if the slot was flipped if (wasFlipped) { flippedPiece = flip.GetOtherPiece(aSlot); AddMatchedPoints(ref connected, ConnectedPoints(flippedPiece.index, true)); } //check if we have no connecteds, no matches at all if (connected.Count == 0) { //if it was flipped, flip back then if (wasFlipped) { FlipAnimal(aSlot.index, flippedPiece.index, false); } } else //If we have some match { var volume = 0.7f + (connected.Count * gameConfig.AnimalPopMultiplier); SfxPlayer.Instance.PlayPop(volume); var shakeMult = connected.Count * gameConfig.AnimalShakeMultiplier; BoardShake.Instance.Shake(shakeMult); //remove every animal slot connected on that match foreach (var pnt in connected) { KillAnimal(pnt); var slot = GetSlotAtPoint(pnt); var animalSlot = slot.GetAnimalSlot(); if (animalSlot != null) { animalSlot.gameObject.SetActive(false); _dead.Add(animalSlot); } slot.SetSlot(null); } ApplyGravityToBoard(); } //Removing flip _flipped.Remove(flip); _update.Remove(aSlot); } }
private FlippedPieces GetFlipped(AnimalSlot animalSlot) { return(_flipped.FirstOrDefault(t => t.GetOtherPiece(animalSlot) != null)); }
public FlippedPieces(AnimalSlot o, AnimalSlot t) { one = o; two = t; }