Inheritance: MonoBehaviour
Ejemplo n.º 1
0
 public void DownAction(GridPlace gp)
 {
     if (!swiping && validPlace(gp)) {
         swiping = true;
         selected = gp;
         Utils.ScaleSiblings(selected, true);
     }
 }
Ejemplo n.º 2
0
 public void Deselect()
 {
     swiping = false;
     if (selected != null)
     {
         Utils.ScaleSiblings(selected, false);
     }
     selected = null;
 }
Ejemplo n.º 3
0
 public void DownAction(GridPlace gp)
 {
     if (!swiping && validPlace(gp))
     {
         swiping  = true;
         selected = gp;
         Utils.ScaleSiblings(selected, true);
     }
 }
Ejemplo n.º 4
0
    public void Destroy(GridPlace start)
    {
        destroyed = true;
        if (tutorialEnabled && !canDestroy)
            return;

        StartCoroutine(Utils.KillSiblings(start, KillCallback(start, colorSelector.Current())));
        AudioController.Instance.PlaySound ("chime1");
        DoMove();
    }
Ejemplo n.º 5
0
 static void FindSibs()
 {
     foreach (GameObject go in Selection.gameObjects)
     {
         GridPlace gp = go.GetComponent <GridPlace>();
         if (gp)
         {
             gp.DiscoverSiblings();
         }
     }
 }
Ejemplo n.º 6
0
 //Fill the connected siblings of the passed in GridPlace
 public static IEnumerator FillSiblings(GridPlace start, Color fillColor)
 {
     foreach (GridPlace[] ring in GetSiblings(start, check_busy(false), check_alive(true), check_color(start.hexaCube.hexColor)))
     {
         foreach (GridPlace gp in ring)
         {
             gp.hexaCube.Fill(fillColor);
         }
         yield return(new WaitForSeconds(0.1f));
     }
 }
Ejemplo n.º 7
0
 //Slow spawn all siblings of the passed in GridPlace
 public static IEnumerator SlowSpawnSiblings(GridPlace start)
 {
     foreach (GridPlace[] ring in GetSiblings(start))
     {
         foreach (GridPlace gp in ring)
         {
             gp.hexaCube.SlowSpawn();
         }
         yield return(new WaitForSeconds(.3f));
     }
 }
Ejemplo n.º 8
0
    public void Destroy(GridPlace start)
    {
        destroyed = true;
        if (tutorialEnabled && !canDestroy)
        {
            return;
        }

        StartCoroutine(Utils.KillSiblings(start, KillCallback(start, colorSelector.Current())));
        AudioController.Instance.PlaySound("chime1");
        DoMove();
    }
Ejemplo n.º 9
0
    //Generator that yields lists of GridPlaces by increasing depth from the origin
    //Returns the origin first, then a list of all it's siblings,
    //then all their siblings, etc.
    //The optional functions in the 'checks' list each take a GridPlace and return a bool
    //representing if the sibling is a valid addition to the output set.
    //All the checks must be true for the sibling to be added
    public static IEnumerable <GridPlace[]> GetSiblings(GridPlace parent, params Func <GridPlace, Boolean>[] checks)
    {
        Dictionary <GridPlace, int> seen  = new Dictionary <GridPlace, int>();
        Queue <GridPlace>           queue = new Queue <GridPlace>();

        if (!checks.All(fcn => fcn(parent)))
        {
            yield break;
        }

        int currDepth = -1;

        //Add the start node
        queue.Enqueue(parent);
        seen.Add(parent, 0);

        //BFS
        while (queue.Count > 0)
        {
            //Check the depth of the oldest item in the queue
            int depth = seen[queue.Peek()];
            if (depth > currDepth)
            {
                //If the depth is greater than the current depth it means that all
                //items of the previous depth have been removed from the queue
                //What's left will be all the items at currDepth + 1
                currDepth = depth;
                yield return(queue.ToArray());
            }

            //Take the oldest item out of the queue and add it's children the to the
            //queue at depth + 1 (if they haven't already been added)
            GridPlace        temp     = queue.Dequeue();
            List <GridPlace> siblings = temp.sibs.ExistingSibs();
            for (int i = 0; i < siblings.Count; i++)
            {
                //checks.All goes though the list of passed in checks (if any) and
                //executes the functions on the sibling
                //If all the functions return true, the sibling is added
                if (!seen.ContainsKey(siblings[i]) && checks.All(fcn => fcn(siblings[i])))
                {
                    seen.Add(siblings[i], depth + 1);
                    queue.Enqueue(siblings[i]);
                }
            }
        }
    }
Ejemplo n.º 10
0
    //Scale the siblings of the passed in GridPlace (to a depth of 2)
    public static void ScaleSiblings(GridPlace start, bool normalize)
    {
        int depth = 0;

        foreach (GridPlace[] ring in Utils.GetSiblings(start))
        {
            foreach (GridPlace gp in ring)
            {
                gp.Scale(depth, normalize);
            }
            if (depth > 2)
            {
                break;
            }
            depth++;
        }
    }
Ejemplo n.º 11
0
    //Kill the connected siblings of the passed in GridPlace
    //Call the callback with the current score
    public static IEnumerator KillSiblings(GridPlace start, Action <GridPlace, int> callback)
    {
        int count = 0;

        foreach (GridPlace[] ring in GetSiblings(start, check_busy(false), check_alive(true), check_color(start.hexaCube.hexColor)))
        {
            foreach (GridPlace gp in ring)
            {
                gp.hexaCube.Kill();

                count++;
                callback(gp, count);
            }
            yield return(new WaitForSeconds(0.1f));
        }
        callback(null, count);
    }
Ejemplo n.º 12
0
    //Return a callback for the current kill action
    public sys.Action <GridPlace, int> KillCallback(GridPlace start, Color color)
    {
        Color startColor = start.hexaCube.hexColor;

        return((gp, count) => {
            if (gp == null)
            {
                //Done counting, award score
                int levelBonus = 100 + (level - 1) * 10;
                int multiplier = startColor == color ? 2 : 1;
                int bonus = (int)(lastMoveScore * Mathf.Sqrt(count / (float)gridPlaces.Length));
                int earnedScore = ((bonus + count * levelBonus) / 10) * 10 * multiplier;

                lastMoveScore = earnedScore;

                score += earnedScore;
                UpdateUI(false);

                ObjectPoolManager.Instance.Pop("ScorePopup").GetComponent <ScorePopup>().Show(earnedScore, start.transform.position);

                //Clear all hexes in a single move
                if (count >= gridPlaces.Length)
                {
                    SocialManager.Instance.UnlockAchievement("total annihilation");
                }
            }
            else
            {
                if (count == 10)
                {
                    AudioController.Instance.PlaySound("chime2");
                }
                else if (count == 20)
                {
                    AudioController.Instance.PlaySound("chime3");
                }
                //Still counting, do animations and stuff
                //ObjectPoolManager.Instance.Pop("ScorePopup").GetComponent<ScorePopup>().Show(count, gp.transform.position);
            }
        });
    }
Ejemplo n.º 13
0
 static void AttachHexagonChild()
 {
     foreach (GameObject go in Selection.gameObjects)
     {
         GridPlace gp = go.GetComponent <GridPlace>();
         if (gp)
         {
             if (!gp.GetComponent <PolygonCollider2D>())
             {
                 if (gp.GetComponent <SphereCollider>())
                 {
                     DestroyImmediate(gp.GetComponent <SphereCollider>());
                 }
                 gp.gameObject.AddComponent <PolygonCollider2D>();
             }
             PolygonCollider2D hexCollider = (Resources.Load("PolygonCollider") as GameObject).GetComponent <PolygonCollider2D>();
             PolygonCollider2D newCol      = gp.GetComponent <PolygonCollider2D>();
             newCol.SetPath(0, hexCollider.points);
         }
     }
 }
Ejemplo n.º 14
0
    public void Flood(GridPlace start)
    {
        if (!start.busy)
        {
            flooded = true;
            if (tutorialEnabled && !canFlood)
            {
                return;
            }

            if (!tutorialEnabled && start.hexaCube.hexColor == colorSelector.Current())
            {
                //Don't let players make dumb moves (unless it's the tutorial)
                return;
            }

            lastMoveScore /= 4;             // halves your combo bonus

            StartCoroutine(Utils.FillSiblings(start, colorSelector.Current()));
            AudioController.Instance.PlaySound("fillchime");
            DoMove();
        }
    }
Ejemplo n.º 15
0
    void Start()
    {
        disabled = true;
        if (Application.loadedLevelName == "tutorial")
        {
            tutorialEnabled = true;
        }
        origin = transform.FindChild("Origin").GetComponent <GridPlace>();

        for (int i = 1; i < gridPlaces.Length; i++)
        {
            gridPlaces[i - 1] = transform.FindChild(i.ToString()).GetComponent <GridPlace>();
        }
        gridPlaces[gridPlaces.Length - 1] = origin;

        if (!tutorialEnabled)
        {
            FadeCam.Instance.FadeIn(() => { StartCoroutine(StartGame()); });
        }
        else
        {
            FadeCam.Instance.FadeIn(() => { StartCoroutine(Tutorial()); });
        }
    }
Ejemplo n.º 16
0
    IEnumerator NextLevel()
    {
        disabled = true;

        while (GridBusy())
        {
            yield return(new WaitForEndOfFrame());
        }

        //Calculate bonus points
        int scorePer = level * 200;

        score += moves.Remaining() * scorePer;

        //How many (if any) white hexes should be revived
        int revived = moves.Remaining();

        //Calculate how many white hexes to add
        int leftover = scoreBar.NumBlackHexes();

        //Setup next level
        moves.ResetMoves(scorePer);
        level++;
        startScore  = score;
        targetScore = score + level * 5000;

        UpdateUI(leftover != 0);

        bool gameover = false;

        if (revived != 0)
        {
            int target = deadPointer - revived;
            for (; deadPointer > target && deadPointer > 0; deadPointer--)
            {
                GridPlace newRevived = gridPlaces[deadPointer - 1];
                newRevived.hexaCube.Spawn();
                earnedback++;

                yield return(new WaitForSeconds(0.07f));
            }

            if (earnedback >= 20)
            {
                SocialManager.Instance.UnlockAchievement("phoenix down");
            }
        }

        else if (leftover != 0)
        {
            int target = deadPointer + leftover;
            for (; deadPointer < target && deadPointer < gridPlaces.Length; deadPointer++)
            {
                GridPlace newWhite = gridPlaces[deadPointer];
                newWhite.hexaCube.Despawn();
                yield return(new WaitForSeconds(0.07f));
            }
        }

        if (deadPointer > 23)
        {
            roundsdown++;

            if (roundsdown > 5)
            {
                SocialManager.Instance.UnlockAchievement("event horizon");
            }
        }
        else
        {
            roundsdown = 0;
        }

        //Only a single gridplace alive
        if (deadPointer == gridPlaces.Length - 1)
        {
            SocialManager.Instance.UnlockAchievement("last man standing");
        }

        if (deadPointer > gridPlaces.Length - 1)
        {
            gameover = true;
        }

        yield return(new WaitForSeconds(.7f));

        disabled = false;

        if (gameover)
        {
            GameOver();
        }
    }
Ejemplo n.º 17
0
 bool validPlace(GridPlace gp)
 {
     return(gp != null && !gp.busy && gp.hexaCube.alive);
 }
Ejemplo n.º 18
0
 bool validPlace(GridPlace gp)
 {
     return gp != null && !gp.busy && gp.hexaCube.alive;
 }
Ejemplo n.º 19
0
 void Start()
 {
     swiping  = false;
     selected = null;
 }
Ejemplo n.º 20
0
    //Return a callback for the current kill action
    public sys.Action<GridPlace, int> KillCallback(GridPlace start, Color color)
    {
        Color startColor = start.hexaCube.hexColor;
        return (gp, count) => {
            if (gp == null){
                //Done counting, award score
                int levelBonus = 100 + (level - 1) * 10;
                int multiplier = startColor == color ? 2 : 1;
                int bonus = (int)(lastMoveScore * Mathf.Sqrt(count/(float)gridPlaces.Length));
                int earnedScore = ((bonus + count * levelBonus)/10) * 10 * multiplier;

                lastMoveScore = earnedScore;

                score += earnedScore;
                UpdateUI(false);

                ObjectPoolManager.Instance.Pop("ScorePopup").GetComponent<ScorePopup>().Show(earnedScore, start.transform.position);

                //Clear all hexes in a single move
                if (count >= gridPlaces.Length){
                    SocialManager.Instance.UnlockAchievement("total annihilation");
                }
            }
            else{
                if (count == 10) {
                    AudioController.Instance.PlaySound ("chime2");
                }
                else if (count == 20) {
                    AudioController.Instance.PlaySound ("chime3");
                }
                //Still counting, do animations and stuff
                //ObjectPoolManager.Instance.Pop("ScorePopup").GetComponent<ScorePopup>().Show(count, gp.transform.position);
            }
        };
    }
Ejemplo n.º 21
0
    void Start()
    {
        disabled = true;
        if (Application.loadedLevelName == "tutorial")
            tutorialEnabled = true;
        origin = transform.FindChild("Origin").GetComponent<GridPlace>();

        for (int i = 1; i < gridPlaces.Length; i++) {
            gridPlaces[i-1] = transform.FindChild(i.ToString()).GetComponent<GridPlace>();
        }
        gridPlaces[gridPlaces.Length - 1] = origin;

        if (!tutorialEnabled)
            FadeCam.Instance.FadeIn(() => {StartCoroutine(StartGame());});
        else
            FadeCam.Instance.FadeIn(() => {StartCoroutine(Tutorial());});
    }
Ejemplo n.º 22
0
    public void Flood(GridPlace start)
    {
        if (!start.busy){
            flooded = true;
            if (tutorialEnabled && !canFlood)
                return;

            if (!tutorialEnabled && start.hexaCube.hexColor == colorSelector.Current()){
                //Don't let players make dumb moves (unless it's the tutorial)
                return;
            }

            lastMoveScore /= 4; // halves your combo bonus

            StartCoroutine(Utils.FillSiblings(start, colorSelector.Current()));
            AudioController.Instance.PlaySound ("fillchime");
            DoMove();
        }
    }