Exemple #1
0
        public static void ExplodeCell(GridCell gCell, float delay, bool showPrefab, bool fly, bool hitProtection, Action completeCallBack)
        {
            if (gCell.GetBomb() && !gCell.MatchProtected)
            {
                gCell.ExplodeBomb(delay, true, true, true, false, completeCallBack);
                return;
            }

            if (gCell.Overlay && gCell.Overlay.BlockMatch)
            {
                delayAction(gCell.gameObject, delay, () => { gCell.DirectHitOverlay(null); completeCallBack?.Invoke(); });
                return;
            }

            if (gCell.DynamicBlocker)
            {
                delayAction(gCell.gameObject, delay, () =>
                {
                    gCell.DirectHitBlocker(null);
                    if (gCell.Overlay)
                    {
                        gCell.DirectHitOverlay(null);
                    }
                    completeCallBack?.Invoke();
                });
                return;
            }

            if (gCell.StaticBlocker)
            {
                delayAction(gCell.gameObject, delay, () =>
                {
                    gCell.DirectHitBlocker(null);
                    if (gCell.Overlay)
                    {
                        gCell.DirectHitOverlay(null);
                    }
                    completeCallBack?.Invoke();
                });
                return;
            }

            if (gCell.Match && gCell.IsMatchable)
            {
                gCell.Match.Explode(gCell, showPrefab, fly, hitProtection, hitProtection, delay, completeCallBack);
                return;
            }

            if (gCell.Underlay)
            {
                delayAction(gCell.gameObject, delay, () => { gCell.DirectHitUnderlay(null); completeCallBack?.Invoke(); });
                return;
            }

            completeCallBack?.Invoke();
        }
Exemple #2
0
        /// <summary>
        /// If matched > = 4 cretate bomb from items
        /// </summary>
        /// <param name="bombCell"></param>
        /// <param name="completeCallBack"></param>
        internal void MoveMatchToBomb(GridCell fromCell, GridCell toCell, float delay, bool hitProtection, Action completeCallBack)
        {
            //  Debug.Log("Move to bomb");
            if (hitProtection)
            {
                fromCell.DirectHitUnderlay(null);
                fromCell.DirectHitOverlay(null);
                fromCell.Neighbors.Cells.ForEach((GridCell c) => { c.SideHit(null); });
            }

            SetToFront(true);
            //scale
            SimpleTween.Value(gameObject, gameObject.transform.localScale, gameObject.transform.localScale * 1.05f, 0.1f).SetOnUpdate((val) => { gameObject.transform.localScale = val; });

            // move
            SimpleTween.Move(gameObject, transform.position, toCell.transform.position, 0.25f).AddCompleteCallBack(completeCallBack).SetEase(EaseAnim.EaseInBack).SetDelay(delay);
        }
Exemple #3
0
 internal void DirectHitOverlay(GridCell gCell, Action completeCallBack)
 {
     gCell.DirectHitUnderlay(null);
     gCell.DirectHitOverlay(null);
     completeCallBack?.Invoke();
 }
Exemple #4
0
        /// <summary>
        /// Collect match object, hit overlays, hit underlays
        /// </summary>
        /// <param name="completeCallBack"></param>
        internal void Collect(GridCell gCell, float delay, bool showPrefab, bool fly, bool hitProtection, bool sideHitProtection, Action completeCallBack)
        {
            this.gCell       = gCell;
            transform.parent = null;

            GameObject animPrefab = OData.collectAnimPrefab;

            collectSequence = new TweenSeq();
            if (delay > 0)
            {
                collectSequence.Add((callBack) => {
                    SimpleTween.Value(gameObject, 0, 1, delay).AddCompleteCallBack(callBack);
                });
            }

            // play sound
            collectSequence.Add((callBack) =>
            {
                MSound.PlayClip(0, OData.privateClip);
                callBack();
            });

            // sprite seq animation
            if (showPrefab)
            {
                collectSequence.Add((callBack) =>
                {
                    if (this && !fly)
                    {
                        GetComponent <SpriteRenderer>().enabled = false;
                    }
                    GameObject aG = Creator.InstantiateAnimPrefab(animPrefab, transform, transform.position, SortingOrder.Main, false,
                                                                  () =>
                    {
                        if (this && fly)
                        {
                            SetToFront(true);
                        }
                        callBack();
                    });
                    aG.transform.parent = null; // unparent for play full animation
                });
            }

            // hit protection
            collectSequence.Add((callBack) =>
            {
                if (hitProtection)
                {
                    gCell.DirectHitUnderlay(null);
                    gCell.DirectHitOverlay(null);
                }
                if (sideHitProtection)
                {
                    gCell.Neighbors.Cells.ForEach((GridCell c) => { c.SideHit(null); });
                }
                callBack();
            });

            //fly
            if (fly)
            {
                collectSequence.Add((callBack) =>
                {
                    SimpleTween.Move(gameObject, transform.position, MatchBoard.Instance.FlyTarget, 0.4f).AddCompleteCallBack(() =>
                    {
                        //  callBack();
                    });
                    callBack(); // not wait
                });
                collectSequence.Add((callBack) => {
                    SimpleTween.Value(gameObject, 0, 1, 0.15f).AddCompleteCallBack(callBack);
                });
            }
            // finish
            collectSequence.Add((callBack) =>
            {
                // Debug.Log(ToString()+  " collected");
                ScoreCollectEvent?.Invoke();
                TargetCollectEvent?.Invoke(OData.ID);
                completeCallBack?.Invoke();
                Destroy(gameObject, (fly) ? 0.4f: 0);
            });

            collectSequence.Start();
        }