Exemple #1
0
 public void ToggleDebugMode()
 {
     if (debugUI.activeInHierarchy)
     {
         debugUI.SetActive(false);
         for (int i = 0; i < debugUI.transform.childCount; ++i)
         {
             MPTWeightButton weightButton = debugUI.transform.GetChild(i).GetComponent <MPTWeightButton>();
             MPTShape        shape        = MPTSpawner.Instance.spawnables[i].GetComponent <MPTShape>();
             shape.weight = weightButton.GetWeight();
             Destroy(debugUI.transform.GetChild(i).gameObject);
         }
     }
     else
     {
         debugUI.SetActive(true);
         for (int i = 0; i < MPTSpawner.Instance.spawnables.Count; ++i)
         {
             GameObject      go           = MPTSpawner.Instance.spawnables[i];
             MPTShape        shape        = go.GetComponent <MPTShape>();
             GameObject      debugWeight  = GameObject.Instantiate(debugWeightModel);
             MPTWeightButton weightButton = debugWeight.GetComponent <MPTWeightButton>();
             weightButton.SetWeight(shape.weight);
             weightButton.SetName(go.name);
             debugWeight.transform.SetParent(debugUI.transform, false);
             RectTransform tr     = (RectTransform)debugWeight.transform;
             float         height = tr.offsetMax.y - tr.offsetMin.y;
             (debugWeight.transform as RectTransform).offsetMin = new Vector2(0.0f, -height * i);
             (debugWeight.transform as RectTransform).offsetMax = new Vector2(0.0f, -height * (i + 1));
         }
     }
 }
 public override void ShapeRegistered(MPTShape shape)
 {
     if (targetShape == null && shape.name == spawnableShape)
     {
         shape.shapeTryDrop += ShapeTriedDrop;
     }
 }
Exemple #3
0
 public bool BlockadeDropAtSpot(MPTShape shape, Vector2 spot)
 {
     if (currentTuto)
     {
         return(currentTuto.BlockadeDropAtSpot(shape, spot));
     }
     return(true);
 }
Exemple #4
0
 public bool BlockadeDragPiece(MPTShape shape)
 {
     if (currentTuto)
     {
         return(currentTuto.BlockadeDragPiece(shape));
     }
     return(true);
 }
 public override bool BlockadeDropAtSpot(MPTShape shape, Vector2 spot)
 {
     if (targetShape != null)
     {
         return(shape.gameObject == targetShape && spot == droppableSpot);
     }
     return(shape.name == spawnableShape && spot == droppableSpot);
 }
 public override bool BlockadeDragPiece(MPTShape shape)
 {
     if (targetShape != null)
     {
         return(shape.gameObject == targetShape);
     }
     return(shape.name == spawnableShape && shape.hasBeenDropped == false);
 }
Exemple #7
0
 private void ShapeTryDrop(MPTShape obj)
 {
     if (coroutine != null)
     {
         StopCoroutine(coroutine);
     }
     coroutine = StartCoroutine(SetDirtySoon());
 }
Exemple #8
0
 public void UnregisterShape(MPTShape newShape)
 {
     if (shapeUnregistered != null)
     {
         shapeUnregistered(newShape);
     }
     listOfShapes.Remove(newShape);
 }
Exemple #9
0
 public void RegisterShape(MPTShape newShape)
 {
     if (shapeRegistered != null)
     {
         shapeRegistered(newShape);
     }
     listOfShapes.Add(newShape);
 }
    public void ShapeTriedDrop(MPTShape draggable)
    {
        MPTShape shape = draggable.gameObject.GetComponent <MPTShape>();

        if (shape != null && shape.canDrop)
        {
            End();
        }
    }
 public virtual void ShapeRegistered(MPTShape shape)
 {
     if (targetShape == null && shape.name == spawnableShape)
     {
         targetShape = shape.gameObject;
         shapesSubscribed.Add(shape);
         shape.shapeTryDrop += ShapeTriedDrop;
     }
 }
Exemple #12
0
 public void ShapeConsumed(MPTShape shape, int multiplier)
 {
     score += multiplier * shape.points;
     if (score > currentTopScore)
     {
         currentTopScore = score;
     }
     UpdateScoreText();
 }
Exemple #13
0
    public void Loose()
    {
        Resume();
        isPaused = true;
        int shapeId = MPTShapeManager.Instance.listOfShapes.Count - 1;

        while (shapeId >= 0)
        {
            MPTShape shape = MPTShapeManager.Instance.listOfShapes[shapeId];
            if (shape.hasBeenDropped)
            {
                shape.Consume(1, false);
                MPTSquareDoneAnimation anim = shape.gameObject.AddComponent <MPTSquareDoneAnimation>();
                anim.targetScale   = Vector3.zero;
                anim.animationTime = 1.0f;
            }
            --shapeId;
        }
        MPTQuickSave.Instance.Erase();
        StartCoroutine(ShowLooseScreenIn(4.0f));
    }
Exemple #14
0
 public void SetNextShape(MPTShape shapeToKeep)
 {
     shapeToKeep.draggable.enabled = true;
     for (int spawnId = 0; spawnId < spawnedShapes.Length; ++spawnId)
     {
         if (spawnedShapes[spawnId] == null)
         {
             shapeToKeep.gameObject.transform.SetParent(spawnPoints[spawnId].transform);
             MPTKeepShapeAnimation anim = shapeToKeep.gameObject.AddComponent <MPTKeepShapeAnimation>();
             anim.animationTime  = 1.0f;
             anim.targetPosition = shapeToKeep.gameObject.transform.parent.position;
             anim.targetScale    = shapeToKeep.initialScale / 2.0f;
             //shapeToKeep.gameObject.transform.localPosition = new Vector3(0.0f, 0.0f, 0.0f);
             shapeToKeep.gameObject.GetComponent <MPTShape>().Init();
             shapeToKeep.draggable.additionalColliders.Clear();
             shapeToKeep.draggable.additionalColliders.Add(spawnPoints[spawnId].GetComponent <Collider2D>());
             shapeToKeep.draggable.initialPos = shapeToKeep.gameObject.transform.parent.position;
             spawnedShapes[spawnId]           = shapeToKeep.gameObject;
             return;
         }
     }
 }
Exemple #15
0
    public void QuickLoad()
    {
        isLoading = true;
        string[] lines = File.ReadAllLines(FILE_PATH);
        MPTGameManager.Instance.score = int.Parse(lines[0]);
        MPTGameManager.Instance.UpdateScoreText();

        for (int lineId = 1; lineId < lines.Length; ++lineId)
        {
            string[] split = lines[lineId].Split(':');
            if (split.Length < 4)
            {
                continue;
            }

            string  shapeName = split[0];
            Vector3 pos       = new Vector3(float.Parse(split[1]), float.Parse(split[2]), float.Parse(split[3]));
            int     points    = int.Parse(split[4]);

            GameObject newShapeGo = MPTSpawner.Instance.CreateShapeInQueue(MPTSpawner.Instance.spawnablesDict[shapeName]);


            MPTShape newShape = newShapeGo.GetComponent <MPTShape>();
            newShape.points = points;
            newShape.UpdateColor();

            if (pos.y != MPTSpawner.Instance.spawnPoints[0].transform.position.y)
            {
                newShapeGo.transform.position = pos;
                MPTDraggable draggable = newShapeGo.GetComponent <MPTDraggable>();
                draggable.initialPos          = new Vector3(-1000.0f, -1000.0f, 0.0f);
                newShape.canDrop              = true;
                newShape.transform.localScale = newShape.initialScale;
                newShape.AfterDrop();
            }
        }
        MPTSpawner.Instance.UpdateDropWarning();
        isLoading = false;
    }
 public override void ShapeUnregistered(MPTShape shape)
 {
     shape.shapeTryDrop -= ShapeTriedDrop;
 }
 public override bool BlockadeDragPiece(MPTShape shape)
 {
     return(false);
 }
Exemple #18
0
 public virtual bool BlockadeDropAtSpot(MPTShape shape, Vector2 spot)
 {
     return(true);
 }
Exemple #19
0
 public virtual bool BlockadeDragPiece(MPTShape shape)
 {
     return(true);
 }
 public override bool BlockadeDropAtSpot(MPTShape shape, Vector2 spot)
 {
     return(false);
 }
Exemple #21
0
 private void ShapeRegistered(MPTShape shape)
 {
     shape.shapeTryDrop += ShapeTryDrop;
 }
Exemple #22
0
    public void ShapeDropped(MPTShape shape)
    {
        float xStart = transform.position.x - width / 2.0f + 0.5f;
        float yStart = transform.position.y + height / 2.0f - 0.25f;

        int miniTrianglesCount = 0;

        for (int shapeX = 0; shapeX < width; ++shapeX)
        {
            for (int shapeY = 0; shapeY < height * 2; ++shapeY)
            {
                if (shapesTab[shapeY, shapeX] == shape)
                {
                    shapesTab[shapeY, shapeX] = null;
                }
            }
        }

        for (int shapeX = 0; shapeX < width; ++shapeX)
        {
            for (int shapeY = 0; shapeY < height * 2; ++shapeY)
            {
                Vector2 point = new Vector2(xStart + shapeX, yStart - shapeY * 0.5f);
                if (shape.polygonCollider.OverlapPoint(point))
                {
                    shapesTab[shapeY, shapeX] = shape;
                    ++miniTrianglesCount;
                }
            }
        }

        shape.miniTrianglesCount = miniTrianglesCount;

        if (MPTQuickSave.Instance.IsLoading)
        {
            return;
        }

        List <List <MPTShape> > squares = new List <List <MPTShape> >();

        for (int xNW = 0; xNW < width; ++xNW)
        {
            for (int yNW = 0; yNW < height; ++yNW)
            {
                for (int squareWidth = 1; squareWidth < width - xNW + 1; ++squareWidth)
                {
                    for (int squareHeight = 1; squareHeight < height - yNW + 1; ++squareHeight)
                    {
                        bool brokenSquare = false;
                        Dictionary <MPTShape, int> shapeToCount = new Dictionary <MPTShape, int>();
                        for (int squareX = 0; squareX < squareWidth; ++squareX)
                        {
                            for (int squareY = 0; squareY < squareHeight; ++squareY)
                            {
                                Vector2 miniSquarePos = new Vector2(xNW + squareX, yNW + squareY);
                                if (shapesTab[(int)miniSquarePos.y * 2, (int)miniSquarePos.x] == null || shapesTab[(int)miniSquarePos.y * 2 + 1, (int)miniSquarePos.x] == null)
                                {
                                    brokenSquare = true;
                                    break;
                                }
                                else
                                {
                                    MPTShape shape1 = shapesTab[(int)miniSquarePos.y * 2, (int)miniSquarePos.x];
                                    MPTShape shape2 = shapesTab[(int)miniSquarePos.y * 2 + 1, (int)miniSquarePos.x];

                                    if (shapeToCount.ContainsKey(shape1))
                                    {
                                        shapeToCount[shape1] = shapeToCount[shape1] + 1;
                                    }
                                    else
                                    {
                                        shapeToCount.Add(shape1, 1);
                                    }

                                    if (shapeToCount.ContainsKey(shape2))
                                    {
                                        shapeToCount[shape2] = shapeToCount[shape2] + 1;
                                    }
                                    else
                                    {
                                        shapeToCount.Add(shape2, 1);
                                    }
                                }
                            }
                            if (brokenSquare)
                            {
                                break;
                            }
                        }
                        if (brokenSquare)
                        {
                            continue;
                        }
                        if (shapeToCount.Count < 3)
                        {
                            continue;
                        }
                        squares.Add(new List <MPTShape>());
                        foreach (KeyValuePair <MPTShape, int> kvp in shapeToCount)
                        {
                            if (kvp.Key.miniTrianglesCount != kvp.Value)
                            {
                                brokenSquare = true;
                                break;
                            }
                            else
                            {
                                squares[squares.Count - 1].Add(kvp.Key);
                            }
                        }
                        if (brokenSquare)
                        {
                            squares.RemoveAt(squares.Count - 1);
                        }
                    }
                }
            }
        }

        List <MPTShape> finalSquare = new List <MPTShape>();

        foreach (List <MPTShape> square in squares)
        {
            if (square.Count > finalSquare.Count)
            {
                finalSquare = square;
            }
        }
        if (finalSquare.Count >= 3)
        {
            MPTSpawner.Instance.SquareDone();
        }
        else
        {
            MPTSpawner.Instance.SpawnNew();
            return;
        }


        int shapeToKeep = Random.Range(0, finalSquare.Count);

        int multiplier        = finalSquare.Count;
        int highestMultiplier = 0;

        /*
         * foreach (MPTShape currentShape in finalSquare)
         * {
         *  multiplier += currentShape.multiplier;
         *  highestMultiplier = Mathf.Max(highestMultiplier, currentShape.multiplier);
         * }*/

        int shapeToKeepPosition = shapeToKeep;

        /*shapeToKeep = -1;
         *
         * int multipliedShape = Random.Range(0, MPTSpawner.Instance.spawnedShapes.Length);
         *
         * MPTSpawner.Instance.spawnedShapes[multipliedShape].GetComponent<MPTShape>().multiplier = highestMultiplier + 1;
         * GameObject spawnTextMultiplier = Instantiate<GameObject>(spawnText);
         * spawnTextMultiplier.GetComponent<TextMesh>().text = "x " + (highestMultiplier + 2);
         * spawnTextMultiplier.transform.position = MPTSpawner.Instance.spawnedShapes[multipliedShape].transform.position + Vector3.back;*/
        if (MPTInteractiveTutoManager.Instance.GetKeepableShape() != "")
        {
            foreach (MPTShape currentShape in finalSquare)
            {
                bool shouldKeepThisShape = currentShape.name == MPTInteractiveTutoManager.Instance.GetKeepableShape();
                currentShape.Consume(multiplier, shouldKeepThisShape);

                if (shouldKeepThisShape)
                {
                    MPTSpawner.Instance.SetNextShape(currentShape);
                    currentShape.SetMultiplier(highestMultiplier + 1);
                    currentShape.points = multiplier;
                    currentShape.UpdateColor();
                }
                else
                {
                    MPTSquareDoneAnimation anim = currentShape.gameObject.AddComponent <MPTSquareDoneAnimation>();
                    anim.targetPosition = finalSquare[shapeToKeepPosition].transform.position + Vector3.forward;
                    anim.targetScale    = Vector3.zero;
                    anim.animationTime  = 1.0f;
                }
                --shapeToKeep;
            }
        }
        else
        {
            foreach (MPTShape currentShape in finalSquare)
            {
                bool shouldKeepThisShape = shapeToKeep == 0;
                currentShape.Consume(multiplier, shouldKeepThisShape);

                if (shouldKeepThisShape)
                {
                    MPTSpawner.Instance.SetNextShape(currentShape);
                    currentShape.SetMultiplier(highestMultiplier + 1);
                    currentShape.points = multiplier;
                    currentShape.UpdateColor();
                }
                else
                {
                    MPTSquareDoneAnimation anim = currentShape.gameObject.AddComponent <MPTSquareDoneAnimation>();
                    anim.targetPosition = finalSquare[shapeToKeepPosition].transform.position + Vector3.forward;
                    anim.targetScale    = Vector3.zero;
                    anim.animationTime  = 1.0f;
                }
                --shapeToKeep;
            }
        }

        int multiplierColorId = Mathf.Clamp(multiplier - 1, 0, MPTGameManager.Instance.multiplierColors.Count - 1);

        GameObject amazingPrefabToSpawn = null;

        for (int amazingPrefabId = 0; amazingPrefabId < finalSquare.Count && amazingPrefabId < MPTGameManager.Instance.amazingPrefabs.Count; ++amazingPrefabId)
        {
            if (MPTGameManager.Instance.amazingPrefabs[amazingPrefabId] != null)
            {
                amazingPrefabToSpawn = MPTGameManager.Instance.amazingPrefabs[amazingPrefabId];
            }
        }
        if (amazingPrefabToSpawn != null)
        {
            GameObject amazingPrefab = (GameObject)Instantiate(amazingPrefabToSpawn, new Vector3(transform.position.x, transform.position.y, finalSquare[0].transform.position.z - 2), Quaternion.identity);
            TextMesh   textMesh      = amazingPrefab.GetComponentInChildren <TextMesh>();
            textMesh.color = MPTGameManager.Instance.multiplierColors[multiplierColorId];
            textMesh.text  = string.Format(textMesh.text, multiplier);
        }
    }
 public virtual void ShapeUnregistered(MPTShape shape)
 {
     shape.shapeTryDrop -= ShapeTriedDrop;
 }