MeteorPattern getPatternFromCSV(string path, string typeString)
    {
        MeteorPattern newPattern = new MeteorPattern();

        string[] metaLines = { };
        if (!path.Contains("jar"))
        {
            metaLines = File.ReadAllLines(GetStreamingAssetsPath() + "/Patterns/METADATA.csv");
        }
        else
        {
            WWW request = new WWW(GetStreamingAssetsPath() + "/Patterns/METADATA.csv");
            while (!request.isDone)
            {
            }
            metaLines = request.text.Split('\n');
        }
        foreach (string line in metaLines)
        {
            string[] fields = line.Split(';');
            if (fields[0] == typeString)
            {
                newPattern.warningTime = float.Parse(fields[1]);
                newPattern.initTime    = float.Parse(fields[2]);
                newPattern.endTime     = float.Parse(fields[3]);
            }
        }
        MeteorShapeGenerator shapeGenerator = new MeteorShapeGenerator();

        string[] lines = { };
        if (!path.Contains("jar"))
        {
            lines = File.ReadAllLines(path);
        }
        else
        {
            WWW request = new WWW(path);
            while (!request.isDone)
            {
            }
            lines = request.text.Split('\n');
        }
        newPattern.initialPos  = new List <Vector2>();
        newPattern.timeToFall  = new List <float>();
        newPattern.timeToStart = new List <float>();
        newPattern.meteorShape = new List <Shape>();
        foreach (string line in lines)
        {
            string[] fields = line.Split(';');
            if (fields[0].Length > 1)
            {
                fields[0] = fields[0].Substring(fields[0].Length - 1);
            }
            newPattern.initialPos.Add(new Vector2(int.Parse(fields[0]), int.Parse(fields[1])));
            newPattern.timeToFall.Add(float.Parse(fields[2]));
            newPattern.timeToStart.Add(0.0f);
            newPattern.meteorShape.Add(shapeGenerator.generateSquareShape(int.Parse(fields[3])));
        }
        return(newPattern);
    }
Пример #2
0
 public bool waitForUserInteraction()
 {
     if (playerGrid.getPosition() == abacus.getPosition())
     {
         if (locale == "ES")
         {
             tutText.text = "¡Evita perder todos tus objetos!";
         }
         else
         {
             tutText.text = "Avoid losing all your objects!";
         }
         pointArrow.finishAnimation();
         MeteorShapeGenerator shapeGenerator = new MeteorShapeGenerator();
         MeteorPattern        pattern        = new MeteorPattern();
         pattern.initialPos = new List <Vector2>()
         {
             new Vector2(0.0f, 0.0f), new Vector2(3.0f, 3.0f), telescope.getPosition()
         };
         pattern.initTime    = 0.0f;
         pattern.timeToStart = new List <float>()
         {
             0.0f, 0.0f, 0.0f
         };
         pattern.timeToFall = new List <float>()
         {
             5.0f, 8.0f, 6.0f
         };
         pattern.warningTime = 3.0f;
         pattern.endTime     = 0.0f;
         pattern.meteorShape = new List <Shape>()
         {
             shapeGenerator.generateSquareShape(2), shapeGenerator.generateSquareShape(1), shapeGenerator.generateSquareShape(1)
         };
         loadMeteorMap(new MeteorPattern[1] {
             pattern
         });
         return(true);
     }
     else
     {
         return(false);
     }
 }
Пример #3
0
 public bool waitForUserInteraction()
 {
     if (playerGrid.getPosition() == telescope.getPosition())
     {
         if (locale == "ES")
         {
             tutText.text = "Salva tus objetos. ¡Cuidado, un meteorito! (Sálvalo arrastrando)";
         }
         else
         {
             tutText.text = "Keep your objects away from danger. Look out! \nA meteor! (Swipe to move) ";
         }
         pointArrow.finishAnimation();
         MeteorShapeGenerator shapeGenerator = new MeteorShapeGenerator();
         MeteorPattern        pattern        = new MeteorPattern();
         pattern.initialPos = new List <Vector2>()
         {
             telescope.getPosition()
         };
         pattern.initTime    = 0.0f;
         pattern.timeToStart = new List <float>()
         {
             0.0f
         };
         pattern.timeToFall = new List <float>()
         {
             5.0f
         };
         pattern.warningTime = 5.0f;
         pattern.endTime     = 0.0f;
         pattern.meteorShape = new List <Shape>()
         {
             shapeGenerator.generateSquareShape(1)
         };
         loadMeteorMap(new MeteorPattern[1] {
             pattern
         });
         slideArrow.initiateAnimation(Camera.main.ScreenToWorldPoint(gameObject.GetComponent <GameController>().getScreenPositionFromGrid(telescope.getPosition())), Camera.main.ScreenToWorldPoint(gameObject.GetComponent <GameController>().getScreenPositionFromGrid(new Vector2(3.0f, 2.0f))));
         return(true);
     }
     else
     {
         return(false);
     }
 }
Пример #4
0
    public void setUpSection()
    {
        gameObject.GetComponent <LevelManager>().resetMeteorMap();
        Meteor[] meteors = FindObjectsOfType <Meteor>();
        foreach (Meteor met in meteors)
        {
            Destroy(met.gameObject);
        }
        gameObject.GetComponent <GameController>().resetGridColor();

        GridObject[] objects = FindObjectsOfType <GridObject>();

        foreach (GridObject element in objects)
        {
            if (element.gameObject.GetComponent <BasicObject>() != null)
            {
                element.gameObject.GetComponent <SpriteRenderer>().enabled = false;
                element.gameObject.GetComponent <BasicObject>().setDestroyed(true);
            }
            element.setParentCell(null);
        }

        gameObject.GetComponent <GameController>().setInitialObjects(true);

        foreach (GridObject element in objects)
        {
            if (element.gameObject.GetComponent <BasicObject>() != null)
            {
                element.gameObject.GetComponent <SpriteRenderer>().enabled = false;
                element.gameObject.GetComponent <BasicObject>().setDestroyed(true);
                element.setParentCell(null);
            }
        }

        focusPanel.SetActive(true);

        telescope.gameObject.GetComponent <SpriteRenderer>().enabled = true;
        telescope.gameObject.GetComponent <BasicObject>().setDestroyed(false);
        telescope.attachToPreviousCell();
        abacus.gameObject.GetComponent <SpriteRenderer>().enabled = true;
        abacus.gameObject.GetComponent <BasicObject>().setDestroyed(false);
        abacus.attachToPreviousCell();

        focusPanel.GetComponent <FocusPanel>().InitializeFocus(telescope.GetComponent <GridObject>().getParentCell().getScreenPosition());

        //pointArrow.initiateAnimation(Camera.main.ScreenToWorldPoint(telescope.GetComponent<GridObject>().getParentCell().getScreenPosition()));
        if (locale == "ES")
        {
            tutText.text = "Algunos meteoritos dañan el suelo. ¡Ten cuidado donde pisas!";
        }
        else
        {
            tutText.text = "Some meteors can destroy the floor. Mind your step!";
        }
        initialHolePtg = gameObject.GetComponent <GameController>().holePercentageChance;
        gameObject.GetComponent <GameController>().setHolePercentage(1.1f);

        MeteorShapeGenerator shapeGenerator = new MeteorShapeGenerator();
        MeteorPattern        pattern        = new MeteorPattern();

        pattern.initialPos = new List <Vector2>()
        {
            telescope.getPosition(), new Vector2(4.0f, 0.0f), new Vector2(5.0f, 1.0f), new Vector2(4.0f, 1.0f)
        };
        pattern.initTime    = 0.0f;
        pattern.timeToStart = new List <float>()
        {
            0.0f, 0.0f, 0.0f, 0.0f
        };
        pattern.timeToFall = new List <float>()
        {
            6.0f, 4.0f, 4.0f, 4.0f
        };
        pattern.warningTime = 1.0f;
        pattern.endTime     = 0.0f;
        pattern.meteorShape = new List <Shape>()
        {
            shapeGenerator.generateSquareShape(1), shapeGenerator.generateSquareShape(1), shapeGenerator.generateSquareShape(1), shapeGenerator.generateSquareShape(1)
        };
        loadMeteorMap(new MeteorPattern[1] {
            pattern
        });
    }
    IEnumerator GenerateMeteors()
    {
        while (true)
        {
            yield return(null);

            while (spawning && !Utils.freezed) //Safely stop this coroutine
            {
                float xRelativePositionHit = Mathf.Floor(UnityEngine.Random.Range(-1.0f * (float)gridWidth * (1.0f - currentLuck), (float)gridWidth) * (1.0f - currentLuck));
                float yRelativePositionHit = Mathf.Floor(UnityEngine.Random.Range(-1.0f * (float)gridHeight * (1.0f - currentLuck), (float)gridHeight) * (1.0f - currentLuck));
                float xPositionToHit       = centralPoint.x + xRelativePositionHit;
                float yPositionToHit       = centralPoint.y + yRelativePositionHit;
                if (xPositionToHit < 0.0f)
                {
                    xPositionToHit = 0.0f;
                }
                else if (xPositionToHit > gridWidth - 1)
                {
                    xPositionToHit = gridWidth - 1;
                }

                if (yPositionToHit < 0.0f)
                {
                    yPositionToHit = 0.0f;
                }
                else if (yPositionToHit > gridHeight - 1)
                {
                    yPositionToHit = gridHeight - 1;
                }

                Vector2 positionToHit = new Vector2(xPositionToHit, yPositionToHit);
                Shape   newShape      = generator.generateSquareShape(UnityEngine.Random.Range(1, 4)); // TO DO: Change
                float   timeToFall    = UnityEngine.Random.Range(FallMin, FallMax);
                float   timeToStart   = UnityEngine.Random.Range(StartMin, StartMax);
                if (spawning)
                {
                    GameObject newMeteor = Instantiate(meteorPrefab, new Vector3(100.0f, 100.0f, 100.0f), Quaternion.identity);//Instance
                    Meteor     meteorRef = newMeteor.GetComponent <Meteor>();
                    meteorMap[positionToHit].Add(meteorRef);
                    //Debug.Log("Ok "+positionToHit);
                    //registerHitShapeOnCells(hashMap[positionToHit], newShape);
                    meteorRef.Initialize(hashMap[positionToHit], timeToFall, timeToStart, warningTime, _gameController, newShape);
                    meteorRef.setMakeHoles(true);
                    //Debug.Log("Spawned Meteor to hit " + positionToHit + " starting in " + timeToStart + " and hitting in " + timeToFall);
                }
                else
                {
                    Debug.Log("Added from random routine");
                }
                yield return(new WaitForSeconds(spawnRate / timeDifficulty)); //TO DO: Change
            }
            while (patternMode && !Utils.freezed)
            {
                yield return(new WaitForSeconds(patternInitTime));

                if (patternMode)
                {
                    loadPattern();
                }
                if (patternIndex == currentPatternList.Length - 1)
                {
                    patternMode = false;
                    if (tutorialEnded)
                    {
                        spawning = true;
                    }
                    Debug.Log("SPAWNING");
                }
                else
                {
                    break;
                }
                yield return(new WaitForSeconds(patternEndTime));
            }
            while (!patternMode && !spawning || Utils.freezed)
            {
                if (tutorialEnded)
                {
                    spawning = true;
                }
                yield return(new WaitForSeconds(spawnRate / timeDifficulty));;
            }
        }
    }