Beispiel #1
0
        private IEnumerator AnimateSend(GridScript gridScript, Player sender)
        {
            for (int i = 0; i < 10; i++)
            {
                var s = CreateStar(100 + i);
                s.transform.localScale = Vector3.one * Random.Range(0.25f, 0.69f);

                var rotater = s.AddComponent <RotaterScript>();
                rotater.speed = 5f;

                // s.GetComponent<SpriteRenderer>().color = color;

                Loom.RunCoroutine(AnimateSendSingle(gridScript, s));
                yield return(new WaitForSeconds(Random.Range(0.015f, 0.135f)));
            }

            yield return(null);
        }
Beispiel #2
0
        public static Image CreateObjectiveIcon(GridScript grid, ObjectiveWidget obj, Vector3 loc)
        {
            if (obj == null)
            {
                return(null);
            }

            var go = new GameObject("Star");

            go.transform.parent     = grid.ui.transform;
            go.transform.position   = loc;
            go.transform.localScale = Vector3.one;

            var image = go.AddComponent <Image>();

            image.sprite = obj.Icon.sprite;

            return(image);
        }
Beispiel #3
0
        public static void DisplayChainWidget(GridScript grid, int chainCount, long score, Color color, Vector3 position)
        {
            if (Instance == null)
            {
                return;
            }
            var prefab = Instance.chainPrefab;

            if (prefab == null)
            {
                Log.Error("Missing Chain widget prefab");
                return;
            }

            var go = Instantiate(prefab.gameObject, grid.ui.transform, true);

            go.transform.position   = position + RandomEx.GetVector3(-0.5f, 0.5f, -0.25f, 0.25f, 0, 0);
            go.transform.localScale = Vector3.one;

            var comboWidget = go.AddOrGetComponent <ComboTextWidget>();

            comboWidget.SetMultiplier(chainCount, color);

            ObjectiveWidget targetWidget = null;
            var             widgets      = GetWidgets(grid.player.index);

            widgets = widgets.Where(w => w != null).ToArray();

            // Chains
            foreach (var w in widgets)
            {
                if (w.Objective != null && (w.Objective.GetObjectiveType() == ObjectiveStatType.HighestChain ||
                                            w.Objective.GetObjectiveType() == ObjectiveStatType.TotalChains))
                {
                    AnimateObjectiveUpdate(grid, w, position);
                    targetWidget = w;
                }
            }

            AnimateComboScoreWidget(comboWidget, targetWidget, chainCount);
        }
Beispiel #4
0
        private static void AnimateObjectiveUpdate(GridScript grid, ObjectiveWidget obj, Vector3 loc)
        {
            if (obj.IsCompleted)
            {
                return;
            }

            var image = CreateObjectiveIcon(grid, obj, loc);

            image.transform.localScale = Vector3.zero;

            var seq = DOTween.Sequence();

            // Move slightly up
            seq.Append(image.transform.DOMove(
                           new Vector3(image.transform.position.x + Random.Range(-1f, 1f),
                                       image.transform.position.y + Random.Range(-1f, 1f)), 0.35f)
                       .SetEase(Ease.OutQuart));
            seq.Join(image.transform.DOScale(Vector3.one, 0.25f).SetEase(Ease.OutBack));

            seq.AppendInterval(0.25f);

            // Create a random path to the icon
            var            destination = obj.Icon.transform.position;
            List <Vector3> path        = new List <Vector3>();
            int            count       = Random.Range(1, 3);

            for (int i = 1; i < count; i++)
            {
                var point = Vector3.Lerp(loc, destination, i / (float)count);
                point += RandomEx.GetVector3(-0.15f, 0.15f, -0.15f, 0.15f, 0, 0);
                path.Add(point);
            }

            path.Add(destination);

            seq.Append(image.transform.DOPath(path.ToArray(), 0.85f, PathType.CatmullRom).SetEase(Ease.InCubic));
            seq.AppendCallback(obj.Highlight);
            seq.Append(image.transform.DOScale(Vector3.zero, 0.15f));
            seq.AppendCallback(() => { Destroy(image.gameObject); });
        }
Beispiel #5
0
        private static IEnumerator AnimateSendSingle(GridScript gridScript, GameObject s)
        {
            const float DURATION = 1.35f;
            float       t        = 0f;

            Vector3 start = gridScript.transform.position
                            + new Vector3(gridScript.settings.width, gridScript.settings.height, 0)
                            + RandomEx.GetVector3(0f, 4f, 0f, 4f, 0, 0);
            Vector3 end = start + new Vector3(-12, -13, 0);

            while (t < DURATION)
            {
                t += Time.deltaTime;
                float p = Interpolators.EaseOutCurve.Evaluate(t / DURATION);

                s.transform.position = Vector3.Lerp(start, end, p);

                yield return(new WaitForEndOfFrame());
            }

            Destroy(s);
        }
Beispiel #6
0
 protected void EndPowerOnOpponent(GridScript gridScript, Grid grid)
 {
     Log.Info(gridScript.player.name + ": Power side effect END " + this);
 }
Beispiel #7
0
 protected abstract IEnumerator UsePowerOnOpponent(GridScript gridScript, Grid grid, PowerUseParams param);
Beispiel #8
0
 protected abstract IEnumerator UsePowerRoutine(GridScript gridScript, Grid grid);
Beispiel #9
0
        private void GenerateGarbage(GridScript g, ComboData c)
        {
            // Every action send garbages, but not always a lot of it.
            int width = 0;
            int count = 1;

            if (c.isChain == false)
            {
                // 3 blocs = 1x1 every 3 combos
                if (c.blockCount == 3 && c.multiplier % 3 == 0)
                {
                    width = 1;
                    count = 1;
                }
                // 4 blocs = 1x1
                else if (c.blockCount == 4)
                {
                    width = 1;
                    count = 1;
                }
                // 5 blocks
                else if (c.blockCount == 5)
                {
                    width = 3;
                    count = 1;
                } // L-shaped block = wow
                else if (c.blockCount > 5)
                {
                    width = 5;
                    count = 1;
                }
            }
            else
            {
                width = players[0].grid.settings.width;
            }

            // Factors
            if (settings.garbagesType == GarbagesType.None)
            {
                return;
            }
            if (settings.garbagesType == GarbagesType.Low)
            {
                if (width == 5)
                {
                    count = 2;
                }

                width = 1;
            }

            if (width > 0)
            {
                var si     = g.player.index;
                var sender = players.First(p => p.player.index == si);
                if (sender.lastPlayerTarget < 0)
                {
                    sender.lastPlayerTarget = sender.player.index;
                }
                sender.lastPlayerTarget++;
                if (sender.lastPlayerTarget >= players.Count)
                {
                    sender.lastPlayerTarget = 0;
                }

                var alivePlayers = players.Where(p => p.player.GameOver == false).ToArray();
                foreach (var p in alivePlayers)
                {
                    int pi = p.player.index;
                    if (
                        // Target the other player
                        (alivePlayers.Length <= 2 && pi != si)
                        ||
                        // Target rotation
                        (pi >= sender.lastPlayerTarget &&
                         pi != si &&
                         p.player.GameOver == false))
                    {
                        sender.lastPlayerTarget = pi;
                        width = Mathf.Clamp(width, 1, settings.gridSettings.width);

                        for (int i = 0; i < count; i++)
                        {
                            p.grid.AddGarbage(width, c.isChain, sender, c.comboLocation, c.definition.color);
                        }

                        break;
                    }
                }
            }
        }
Beispiel #10
0
 private void OnMultiplierChange(GridScript grid, int m)
 {
     // Update UI
     GameUIScript.SetMultiplier(grid.player.index, m);
 }
Beispiel #11
0
 private void OnLevelChanged(GridScript g, int l)
 {
     // Update UI
     GameUIScript.SetSpeed(g.player.index, l);
 }
Beispiel #12
0
 private void OnScoreChanged(GridScript g, long score)
 {
     // Update UI
     GameUIScript.SetScore(g.player.index, score);
 }
Beispiel #13
0
        // Enemy effect

        public void SendTo(GridScript gridScript, Player sender)
        {
            Loom.RunCoroutine(AnimateSend(gridScript, sender));
        }
Beispiel #14
0
 public virtual bool CanUseOnOpponent(GridScript gridScript, Grid grid)
 {
     return(true);
 }
Beispiel #15
0
 private void OnPowerChargeChanged(GridScript g, PowerType power, float charge, int direction)
 {
     // Update UI
     GameUIScript.SetPowerCharge(g.player.index, charge, direction);
 }
        public static void Shake(GridScript grid, float duration, float force)
        {
            GridShakerScript shaker = grid.gameObject.AddOrGetComponent <GridShakerScript>();

            shaker.SetShake(duration, force);
        }
Beispiel #17
0
        public static void DisplayComboWidget(GridScript grid, int combo, int blocksCount, long score, BlockDefinition def,
                                              Vector2 loc, Vector2[] positions)
        {
            if (Instance == null)
            {
                return;
            }

            var go = Instantiate(Instance.scorePrefab.gameObject, grid.ui.transform, true);

            go.transform.position   = loc + RandomEx.GetVector2(-0.5f, 0.5f, -0.25f, 0.25f);
            go.transform.localScale = Vector3.one;

            var comboWidget = go.AddOrGetComponent <ComboTextWidget>();

            comboWidget.SetScore(score, def.color);

            ObjectiveWidget targetWidget = null;
            var             widgets      = GetWidgets(grid.player.index);

            widgets = widgets.Where(w => w != null).ToArray();

            // Combo
            foreach (var w in widgets)
            {
                if (w.Objective != null && w.Objective.GetObjectiveType() == ObjectiveStatType.TotalCombos)
                {
                    AnimateObjectiveUpdate(grid, w, loc);
                }
            }

            // Score
            foreach (var w in widgets)
            {
                if (w.Objective != null && w.Objective.GetObjectiveType() == ObjectiveStatType.Score)
                {
                    targetWidget = w;
                }
            }

            // 4 combo
            if (blocksCount == 4)
            {
                foreach (var w in widgets)
                {
                    if (w.Objective != null && w.Objective.GetObjectiveType() == ObjectiveStatType.Total4Combos)
                    {
                        AnimateObjectiveUpdate(grid, w, loc);
                    }
                }
            }
            // 5 combo
            else if (blocksCount == 5)
            {
                foreach (var w in widgets)
                {
                    if (w.Objective != null && w.Objective.GetObjectiveType() == ObjectiveStatType.Total5Combos)
                    {
                        AnimateObjectiveUpdate(grid, w, loc);
                    }
                }
            }
            // L combos
            else if (blocksCount > 5)
            {
                foreach (var w in widgets)
                {
                    if (w.Objective != null && w.Objective.GetObjectiveType() == ObjectiveStatType.TotalLCombos)
                    {
                        AnimateObjectiveUpdate(grid, w, loc);
                    }
                }
            }


            if (comboWidget != null)
            {
                AnimateComboScoreWidget(comboWidget, targetWidget, combo);
            }
        }