private void ExplodeBomb(DynamicClickBombObject bomb, GridCell gCell, float delay, Action completeCallBack) { bomb.PlayExplodeAnimation(gCell, delay, () => { bomb.ExplodeArea(gCell, 0, true, true, false, true, completeCallBack); }); }
/// <summary> /// Create new MainObject for gridcell /// </summary> /// <param name="parent"></param> /// <param name="oData"></param> /// <param name="addCollider"></param> /// <param name="radius"></param> /// <param name="isTrigger"></param> /// <returns></returns> public static DynamicClickBombObject Create(GridCell parent, DynamicClickBombObjectData oData, bool addCollider, bool isTrigger, Action <int> TargetCollectEvent) { if (!parent || oData == null) { return(null); } SpriteRenderer sR = Creator.CreateSprite(parent.transform, oData.ObjectImage, parent.transform.position); GameObject gO = sR.gameObject; DynamicClickBombObject gridObject = gO.AddComponent <DynamicClickBombObject>(); if (addCollider) { BoxCollider2D cC = gridObject.gameObject.GetOrAddComponent <BoxCollider2D>(); cC.isTrigger = isTrigger; } if (oData.iddleAnimPrefab) { Creator.InstantiatePrefab(oData.iddleAnimPrefab, gridObject.transform, gridObject.transform.position, 0, SortingOrder.Main + 2); } gridObject.SRenderer = sR; gridObject.TargetCollectEvent = TargetCollectEvent; gridObject.SetData(oData); return(gridObject); }
internal void SetDynamicClickBomb(DynamicClickBombObjectData mObjectData) { if (mObjectData == null || IsDisabled || Blocked) { return; } // Debug.Log("set dynamic click bomb : " + mObjectData.ID); if (DynamicObject) { GameObject old = DynamicObject; DestroyImmediate(old); } if (StaticBlocker) { GameObject old = StaticBlocker.gameObject; DestroyImmediate(old); } DynamicClickBombObject.Create(this, mObjectData, false, true, MBoard.TargetCollectEventHandler); DynamicClickBomb.SetToFront(false); }
private DynamicClickBombObjectData sourceColorBombData; // need only for color bomb public void CombineAndExplode(GridCell gCell, DynamicClickBombObject bomb, Action completeCallBack) { if (!gCell || !bomb) { completeCallBack?.Invoke(); return; } NeighBors nG = gCell.Neighbors; BombDir bd1 = bomb.GetBombDir(); BombCombine bC = BombCombine.None; List <DynamicClickBombObject> nBs = GetNeighBombs(gCell); if (bomb.GetBombDir() == BombDir.Color) { sourceColorBombData = bomb.OData; } foreach (var item in nBs) // search color bomb { BombDir bd2 = item.GetBombDir(); if (bd2 == BombDir.Color) { if (sourceColorBombData == null) { sourceColorBombData = item.OData; } bC = GetCombineType(bd1, bd2); break; } } if (bC == BombCombine.None) // search radial bomb { foreach (var item in nBs) { BombDir bd2 = item.GetBombDir(); if (bd2 == BombDir.Radial) { bC = GetCombineType(bd1, bd2); break; } } } if (bC == BombCombine.None) // search hor or vert bomb { foreach (var item in nBs) { BombDir bd2 = item.GetBombDir(); if (bd2 == BombDir.Horizontal || bd2 == BombDir.Vertical) { bC = GetCombineType(bd1, bd2); break; } } } switch (bC) { case BombCombine.ColorBombAndColorBomb: // clean full board collectTween = new ParallelTween(); nBs.Add(bomb); foreach (var item in nBs) { item.transform.parent = null; item.SetToFront(true); Creator.CreateSprite(item.transform, glow, item.transform.position, SortingOrder.BombCreator - 1); collectTween.Add((callBack) => { item.MoveToBomb(gCell, 0, () => { Destroy(item.gameObject); callBack(); }); }); } collectTween.Start(() => { MSound.SoundPlayMakeBomb(0.05f, null); CombinedColorBombAndColorBomb bigBomb = Instantiate(colorBombAndColorBombPrefab); bigBomb.transform.localScale = gCell.transform.lossyScale; bigBomb.transform.position = gCell.transform.position; bigBomb.ApplyToGrid(gCell, 0.2f, completeCallBack); }); break; case BombCombine.BombAndBomb: // big bomb explode collectTween = new ParallelTween(); nBs.Add(bomb); foreach (var item in nBs) { item.transform.parent = null; item.SetToFront(true); Creator.CreateSprite(item.transform, glow, item.transform.position, SortingOrder.BombCreator - 1); collectTween.Add((callBack) => { item.MoveToBomb(gCell, 0, () => { Destroy(item.gameObject); callBack(); }); }); } collectTween.Start(() => { MSound.SoundPlayMakeBomb(0.05f, null); CombinedBombAndBomb bigBomb = Instantiate(bombAndBombPrefab); bigBomb.transform.localScale = gCell.transform.lossyScale; bigBomb.transform.position = gCell.transform.position; bigBomb.ApplyToGrid(gCell, 0.2f, completeCallBack); }); break; case BombCombine.RocketAndRocket: // 2 rows or 2 columns collectTween = new ParallelTween(); nBs.Add(bomb); foreach (var item in nBs) { item.transform.parent = null; item.SetToFront(true); Creator.CreateSprite(item.transform, glow, item.transform.position, SortingOrder.BombCreator - 1); collectTween.Add((callBack) => { item.MoveToBomb(gCell, 0, () => { Destroy(item.gameObject, 0.2f); callBack(); }); }); } collectTween.Start(() => { MSound.SoundPlayMakeBomb(0.05f, null); CombinedRocketAndRocket bigBomb = Instantiate(rocketAndRocketPrefab); bigBomb.transform.localScale = gCell.transform.lossyScale; bigBomb.transform.position = gCell.transform.position; bigBomb.ApplyToGrid(gCell, 0.2f, completeCallBack); }); break; case BombCombine.ColorBombAndBomb: // replace color match with bomb collectTween = new ParallelTween(); nBs.Add(bomb); foreach (var item in nBs) { item.transform.parent = null; item.SetToFront(true); Creator.CreateSprite(item.transform, glow, item.transform.position, SortingOrder.BombCreator - 1); collectTween.Add((callBack) => { item.MoveToBomb(gCell, 0, () => { Destroy(item.gameObject); callBack(); }); }); } collectTween.Start(() => { MSound.SoundPlayMakeBomb(0.05f, null); CombinedColorBombAndBomb colorBombAndBomb = Instantiate(colorBombAndBombPrefab); colorBombAndBomb.transform.localScale = gCell.transform.lossyScale; colorBombAndBomb.transform.position = gCell.transform.position; colorBombAndBomb.OData = sourceColorBombData; colorBombAndBomb.ApplyToGrid(gCell, 0.2f, completeCallBack); colorBombAndBomb.GetComponent <SpriteRenderer>().sprite = sourceColorBombData.ObjectImage; }); break; case BombCombine.BombAndRocket: // 3 rows and 3 columns collectTween = new ParallelTween(); nBs.Add(bomb); foreach (var item in nBs) { item.transform.parent = null; item.SetToFront(true); Creator.CreateSprite(item.transform, glow, item.transform.position, SortingOrder.BombCreator - 1); collectTween.Add((callBack) => { item.MoveToBomb(gCell, 0, () => { Destroy(item.gameObject); callBack(); }); }); } collectTween.Start(() => { MSound.SoundPlayMakeBomb(0.05f, null); CombinedBombAndRocket bombAndRocket = Instantiate(bombAndRocketPrefab); bombAndRocket.transform.localScale = gCell.transform.lossyScale; bombAndRocket.transform.position = gCell.transform.position; bombAndRocket.ApplyToGrid(gCell, 0.2f, completeCallBack); }); break; case BombCombine.ColorBombAndRocket: // replace color bomb with rockets collectTween = new ParallelTween(); nBs.Add(bomb); foreach (var item in nBs) { item.transform.parent = null; item.SetToFront(true); Creator.CreateSprite(item.transform, glow, item.transform.position, SortingOrder.BombCreator - 1); collectTween.Add((callBack) => { item.MoveToBomb(gCell, 0, () => { Destroy(item.gameObject); callBack(); }); }); } collectTween.Start(() => { MSound.SoundPlayMakeBomb(0.05f, null); CombinedColorBombAndRocket colorBombAndRocket = Instantiate(colorBombAndRocketPrefab); colorBombAndRocket.transform.localScale = gCell.transform.lossyScale; colorBombAndRocket.transform.position = gCell.transform.position; colorBombAndRocket.OData = sourceColorBombData; colorBombAndRocket.ApplyToGrid(gCell, 0.2f, completeCallBack); colorBombAndRocket.GetComponent <SpriteRenderer>().sprite = sourceColorBombData.ObjectImage; }); break; case BombCombine.None: // simple explode gCell.ExplodeBomb(0.0f, true, true, bd1 == BombDir.Color, false, () => { completeCallBack?.Invoke(); }); break; default: completeCallBack?.Invoke(); break; } }
internal override void PlayExplodeAnimation(GridCell gCell, float delay, Action completeCallBack) { if (!gCell || explodePrefab == null || OData == null) { completeCallBack?.Invoke(); } Debug.Log(name + ": play explode animation"); TweenSeq anim = new TweenSeq(); pT = new ParallelTween(); anim.Add((callBack) => // delay { delayAction(gameObject, delay, callBack); }); anim.Add((callBack) => // scale out { SimpleTween.Value(gameObject, 1, 1.5f, 0.2f).SetOnUpdate((float val) => { transform.localScale = gCell.transform.lossyScale * val; }).AddCompleteCallBack(callBack); }); anim.Add((callBack) => // scale in explode prefab { SimpleTween.Value(gameObject, 1.5f, 1.0f, 0.15f).SetOnUpdate((float val) => { transform.localScale = gCell.transform.lossyScale * val; }).AddCompleteCallBack(callBack); GameObject g = Instantiate(explodePrefab); g.transform.position = transform.position; g.transform.localScale = transform.localScale * .50f; }); anim.Add((callBack) => // explode wave { MBoard.ExplodeWave(0, transform.position, 5, null); callBack(); }); anim.Add((callBack) => // sound { MSound.PlayClip(0, explodeClip); callBack(); }); eArea = GetArea(gCell); // trails ParallelTween pT1 = new ParallelTween(); float incDelay = 0f; foreach (var item in eArea.Cells) { incDelay += 0.0f; float t = incDelay; pT1.Add((cB) => { delayAction(item.gameObject, t, () => // delay tween { Vector2 relativePos = (item.transform.position - gCell.transform.position).normalized; Quaternion rotation = Quaternion.FromToRotation(new Vector2(-1, 0), relativePos); // Debug.Log("Dir: " +(item.transform.position - gCell.transform.position) + " : " + rotation.eulerAngles ); GameObject cb = Instantiate(OData.additAnimPrefab, transform.position, rotation); cb.transform.localScale = transform.lossyScale * 1.0f; SimpleTween.Move(cb, cb.transform.position, item.transform.position, 0.2f).AddCompleteCallBack(cB).SetEase(EaseAnim.EaseOutSine); }); }); } anim.Add((callBack) => { pT1.Start(callBack); }); anim.Add((callBack) => // create bombs { foreach (var item in eArea.Cells) { BombDir bd = BombDir.Radial; DynamicClickBombObject r = DynamicClickBombObject.Create(item, GOSet.GetDynamicClickBombObject(bd, 0), false, false, MBoard.TargetCollectEventHandler); r.transform.parent = null; r.SetToFront(true); pT.Add((cB) => { ExplodeBomb(r, item, 0.5f, cB); }); } callBack(); }); anim.Add((callBack) => // delay { delayAction(gameObject, 0, callBack); }); anim.Add((callBack) => { completeCallBack?.Invoke(); callBack(); }); anim.Start(); }
internal override void PlayExplodeAnimation(GridCell gCell, float delay, Action completeCallBack) { if (!gCell || explodePrefab == null) { completeCallBack?.Invoke(); } // Debug.Log(name + "play explode animation"); TweenSeq anim = new TweenSeq(); pT = new ParallelTween(); rockets = new List <DynamicClickBombObject>(); anim.Add((callBack) => // delay { delayAction(gameObject, delay, callBack); }); anim.Add((callBack) => { SimpleTween.Value(gameObject, 1, 1.5f, 0.2f).SetOnUpdate((float val) => { transform.localScale = gCell.transform.lossyScale * val; }).AddCompleteCallBack(callBack); }); anim.Add((callBack) => // scale in and explode prefab { SimpleTween.Value(gameObject, 1.5f, 1.0f, 0.15f).SetOnUpdate((float val) => { transform.localScale = gCell.transform.lossyScale * val; }).AddCompleteCallBack(callBack); GameObject g = Instantiate(explodePrefab); g.transform.position = transform.position; g.transform.localScale = transform.localScale * .50f; }); anim.Add((callBack) => // create rockets { DynamicClickBombObject r1 = DynamicClickBombObject.Create(gCell, GOSet.GetDynamicClickBombObject(BombDir.Horizontal, 0), false, false, MBoard.TargetCollectEventHandler); r1.transform.parent = null; r1.SetToFront(true); pT.Add((cB) => { ExplodeRocket(r1, gCell, 0, cB); }); rockets.Add(r1); DynamicClickBombObject r2 = DynamicClickBombObject.Create(gCell, GOSet.GetDynamicClickBombObject(BombDir.Vertical, 0), false, false, MBoard.TargetCollectEventHandler); r2.transform.parent = null; r2.SetToFront(true); pT.Add((cB) => { ExplodeRocket(r2, gCell, 0, cB); }); rockets.Add(r2); callBack(); }); anim.Add((callBack) => // explode wave { MBoard.ExplodeWave(0, transform.position, 5, null); callBack(); }); anim.Add((callBack) => { MSound.PlayClip(0, explodeClip); callBack(); }); anim.Add((callBack) => // delay { delayAction(gameObject, 0, callBack); }); anim.Add((callBack) => { completeCallBack?.Invoke(); callBack(); }); anim.Start(); }