public void DestroyBoard(bool playSound = true) { if (_gameBoard == null) { return; } // Destroy the lattice grid _lattice.DestroyGrid(); // Destroy all objects in the game board var i = 0; foreach (var node in NodeMap.Values) { node.WaveOut(i++, NodeMap.Count, playSound: playSound); } foreach (var field in FieldMap.Fields) { field.Highlight(false); } foreach (Transform child in transform) { var node = child.gameObject.GetComponent <NodeView>(); var arc = child.gameObject.GetComponent <ArcView>(); var field = child.gameObject.GetComponent <FieldView>(); // Only destroy board pieces if (node != null) { _itemPool.Release(node, 3f); } else if (arc != null) { _itemPool.Release(arc, 3f); } else if (field != null) { _itemPool.Release(field, 3f); } } NodeMap.Clear(); ArcMap.Clear(); FieldMap.Clear(); _gameBoard = null; if (!playSound) { return; } // TODO: make configurable const float volume = 0.5f; _gameAudio.Play(GameClip.GameEnd, volume: volume); }
public void PushSound() { switch (Arc.Length) { case 1: _gameAudio.Play(GameClip.MovePushHigh, volume: MoveVolume); break; case 2: _gameAudio.Play(GameClip.MovePushMid, volume: MoveVolume); break; default: _gameAudio.Play(GameClip.MovePushLow, volume: MoveVolume); break; } }
public void WaveIn(int delay, int maxDelay, Action onComplete = null, float animationSpeed = 1f, float delayScale = 1f) { onComplete = onComplete ?? (() => {}); var pos = transform.localPosition; // Set node far away and transparent transform.Translate(WaveInTravel * Vector3.forward); var colorizers = GetComponentsInChildren <Colorizer>(); foreach (var colorizer in colorizers) { colorizer.Fade(0f); } // TODO: use smooth function over linear delay var moveDelay = WaveInMoveDelayStart * delayScale + (WaveInMoveDelayOffsetScale * delay) / maxDelay; // Start a nice animation effect LeanTween.moveLocal(gameObject, pos, WaveInTime * animationSpeed) .setOnStart(() => { _gameAudio.Play(GameClip.NodeEnter, WaveInAudioDelay); if (_checkmark == null) { return; } _checkmark.SetActive(true); LeanTween.moveLocal(_checkmark, Vector3.back * 0.5f, WaveInTime * animationSpeed / 2f) .setEase(LeanTweenType.easeInOutSine); }) .setDelay(moveDelay) .setEase(WaveInMoveEase) .setOnComplete(onComplete); foreach (var colorizer in colorizers) { colorizer.Previous(WaveInTime, moveDelay, WaveInColorEase); } }
public void Play(NodeView nodeView, Direction dir) { if (!enabled) { return; } if (_viewUpdating || LeanTween.isTweening(nodeView.gameObject)) { // If the animations are running, queue up the move if (_moveQueue.Count < MaxMovesInQueue) { _moveQueue.Enqueue(new Tuple <NodeView, Direction>(nodeView, dir)); } return; } // If this level has a tutorial, and this is not the expected move, don't play it if (_puzzleState.IsTutorial) { var move = _puzzleState.TutorialMove; if (!nodeView.Node.Position.Equals(move.Point) || move.Direction != dir) { return; } } _viewUpdating = true; // Try to play the move var movePlayed = _puzzleState.Play(nodeView, dir); // Modify the game view accordingly if (!movePlayed) { // Even though no move has been played, if there are no arcs parallel // to the swipe, we can have the nodes/arcs rotate for effect // (but not in the case where there is a pulled arc on the node) var canRotate = !_puzzleState.HasArcAt(nodeView.Position, dir) && !_puzzleState.HasArcAt(nodeView.Position, dir.Opposite()); var pushMove = _puzzleState.IsPulled && nodeView.Position.Equals(_puzzleState.PullPosition); if (pushMove) { // In the case of an invalid push move, shake the node _puzzleView.Shake(nodeView, dir); _gameAudio.Play(GameClip.InvalidRotate); } else if (canRotate) { _puzzleView.Rotate(nodeView, dir, true); _gameAudio.Play(GameClip.NodeRotate90); } else { _puzzleView.Shake(nodeView, dir); _gameAudio.Play(GameClip.InvalidRotate); } } else if (_puzzleState.IsPulled) { // Pull move _puzzleView.Rotate(nodeView, _puzzleState.PulledArcView, dir, true); _puzzleState.PulledArcView.PullSound(); _puzzleView.Shake(dir); _puzzleView.FloatIsland(true); HighlightAll(); } else { // Push move // If a push move has been played, move the arc to the node, then rotate it _puzzleView.MoveRotate(_puzzleState.PushNodePath, _puzzleState.PulledArcView, dir, () => _puzzleView.FloatIsland(false)); _puzzleView.Shake(dir); HighlightAll(); } _numActions++; }