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); }
void loadPattern() { //DEBUG int totalMet = 0; foreach (KeyValuePair <Vector2, List <Meteor> > entry in meteorMap) { totalMet += entry.Value.Count; } Debug.Log("Number of meteors before pattern: " + totalMet); //DEBUG patternIndex++; MeteorPattern patternToLoad = currentPatternList[patternIndex]; Vector2[] positions = patternToLoad.initialPos.ToArray(); float[] fallTime = patternToLoad.timeToFall.ToArray(); Shape[] shapes = patternToLoad.meteorShape.ToArray(); float[] startTime = patternToLoad.timeToStart.ToArray(); int size = positions.Length; Debug.Log("Adding " + size + " meteors as pattern"); patternEndTime = patternToLoad.initTime; patternInitTime = patternToLoad.endTime; for (int i = 0; i < size; i++) { GameObject newMeteor = Instantiate(meteorPrefab, new Vector3(100.0f, 100.0f, 100.0f), Quaternion.identity);//Instance Meteor meteorRef = newMeteor.GetComponent <Meteor>(); if (meteorMap[positions[i]] != null) { meteorMap[positions[i]].Add(meteorRef); } else { Debug.Log("Emptied meteormap on position:" + positions[i]); meteorMap.Add(positions[i], new List <Meteor>()); meteorMap[positions[i]].Add(meteorRef); } //Debug.Log("Ok "+positionToHit); //registerHitShapeOnCells(hashMap[positionToHit], newShape); meteorRef.Initialize(hashMap[positions[i]], fallTime[i], startTime[i], patternToLoad.warningTime, _gameController, shapes[i]); if (!tutorialEnded) { meteorRef.setMakeHoles(true); } } //DEBUG totalMet = 0; foreach (KeyValuePair <Vector2, List <Meteor> > entry in meteorMap) { totalMet += entry.Value.Count; } Debug.Log("Number of meteors after pattern: " + totalMet); //DEBUG }
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); } }
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); } }
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 }); }
public MeteorPattern[] getDefaultPattern() { MeteorPattern[] pattern = new MeteorPattern[0] { }; return(pattern); }