Exemple #1
0
    void generatePlanets()
    {
        LevelManager.Level level = levelManager.getLevel();

        this.planets = new List <GameObject>();
        spawnPlanet(level.numResourcePlanet, pCity);
        spawnPlanet(level.numBasePlanet, pBase);
        spawnPlanet(level.numBlackholePlanet, pBlackhole);

        Debug.Log("Instanted planets");
    }
    public static void Load(LevelManager.Level level, out XMLDataManager Level_Container)
    {
        XmlSerializer xml = new XmlSerializer(typeof(XMLDataManager));

        try
        {
            using (FileStream stream = new FileStream(level.LevelPath, FileMode.Open))
            {
                Level_Container = xml.Deserialize(stream) as XMLDataManager;
            }
        }
        catch (System.Exception)
        {
            Level_Container = new XMLDataManager();
        }
    }
 public void IncreaseLevel(int increaseTo = 1)
 {
     if (!inGame)
     {
         return;
     }
     levelIndex += increaseTo;
     if (LevelManager.levels.Count > levelIndex)
     {
         level = LevelManager.levels[levelIndex];
         ApplyLevelStats();
     }
     else
     {
         Debug.Log(name + " has already reached maximum level");
     }
 }
Exemple #4
0
    void ShowLevelMenu()
    {
        optionsShowing             = false;
        optionsButton.interactable = false;
        if (currentLevelButtons.Count > 0)
        {
            foreach (GameObject obj in currentLevelButtons)
            {
                Destroy(obj);
            }
            currentLevelButtons = new List <GameObject>();
        }
        optionsMenu.SetActive(false);
        loadLevelPanel.SetActive(true);
        GameObject levelsContainer = loadLevelPanel.transform.GetChild(1).transform.GetChild(0).transform.GetChild(0).gameObject;

        foreach (LevelManager.Level level in LevelManager.MyLevels)
        {
            GameObject newButton = Instantiate(levelButton);
            //levelsContainer.GetComponent<RectTransform>().sizeDelta += new Vector2(0, newButton.GetComponent<RectTransform>().sizeDelta.y);
            newButton.transform.SetParent(levelsContainer.transform);
            newButton.GetComponent <RectTransform>().localScale = new Vector3(1, 1, 1);
            Sprite screenshot = Sprite.Create(level.LevelPic, new Rect(0, 0, level.LevelPic.width, level.LevelPic.height), new Vector2());
            newButton.transform.GetChild(0).GetComponent <Image>().sprite = screenshot;
            newButton.GetComponentInChildren <Text>().text = level.LevelName;
            newButton.GetComponent <Button>().onClick.AddListener(delegate
            {
                levelToLoad = level;
                loadLevelPanel.SetActive(false);
                levelOptionsMenu.SetActive(true);
            });
            currentLevelButtons.Add(newButton);
        }
        if (currentLevelButtons.Count > 0)
        {
            RectTransform buttonTrans = currentLevelButtons[0].GetComponent <RectTransform>();
            float         scale       = Screen.height / Screen.width;
            float         ySize       = buttonTrans.sizeDelta.y * currentLevelButtons.Count;
            levelsContainer.GetComponent <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, ySize);
        }
    }
    public static void UserUploadToFirebase(LevelManager.Level level)
    {
        DatabaseReference data = FirebaseDatabase.DefaultInstance.GetReferenceFromUrl("https://blockquest-a1e16.firebaseio.com/");

        StorageReference levelFolder = root.Child(saveLoc);
        StorageReference userName    = levelFolder.Child(FormattedUserName);
        StorageReference userLevel   = userName.Child(level.LevelName);
        StorageReference levelFile   = userLevel.Child(level.LevelName + ".xml");
        StorageReference levelPic    = userLevel.Child(level.LevelName + ".png");

        levelFile.PutFileAsync(level.LevelPath);
        levelPic.PutBytesAsync(level.LevelPic.EncodeToPNG());

        Level newLevel = new Level(level.LevelName, levelFile.Path, levelPic.Path);

        Debug.Log(levelFile.Path);
        Debug.Log(levelPic.Path);

        data.Child(saveLoc).Child(FirebaseManager.FormattedUserName).Child(level.LevelName).Child("File_Path").SetValueAsync(newLevel.filePath);
        data.Child(saveLoc).Child(FirebaseManager.FormattedUserName).Child(level.LevelName).Child("Picture_Path").SetValueAsync(newLevel.picturePath);
    }
    public static void UploadFileToFirebase(LevelManager.Level level)
    {
        DatabaseReference data = FirebaseDatabase.DefaultInstance.GetReferenceFromUrl("https://blockquest-a1e16.firebaseio.com/");

        StorageReference levelFolder = root.Child(saveLoc);
        StorageReference userLevel   = levelFolder.Child(level.LevelName);
        StorageReference levelFile   = userLevel.Child(level.LevelName + ".xml");
        StorageReference levelPic    = userLevel.Child(level.LevelName + ".png");

        levelFile.PutFileAsync(level.LevelPath);
        levelPic.PutBytesAsync(level.LevelPic.EncodeToPNG());

        Level newLevel = new Level(level.LevelName, levelFile.Path, levelPic.Path);

        data.Child(saveLoc).Child(level.LevelName).Child("File_Path").SetValueAsync(newLevel.filePath);
        data.Child(saveLoc).Child(level.LevelName).Child("Picture_Path").SetValueAsync(newLevel.picturePath);
        if (saveLoc == "Default_Levels")
        {
            data.Child("Base_Level_Last_Changed").SetValueAsync(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
        }
    }
Exemple #7
0
    void LoadLevel(LevelManager.Level level)
    {
        if (currentGameObjects == null)
        {
            currentGameObjects = new List <GameObject>();
        }
        if (currentGameObjects.Count > 0)
        {
            foreach (GameObject obj in currentGameObjects)
            {
                Destroy(obj);
            }
            currentGameObjects.Clear();
        }
        XMLDataManager container;

        XMLDataLoaderSaver.Load(level, out container);
        foreach (XMLDataManager.Wall w in container.walls)
        {
            GameObject temp = Instantiate(wall, w.loc, new Quaternion());
            currentGameObjects.Add(temp);
        }
        foreach (XMLDataManager.Goal g in container.goals)
        {
            GameObject temp = Instantiate(goal, new Vector3(g.loc.x, .5f, g.loc.z), new Quaternion());
            currentGameObjects.Add(temp);
        }
        player.transform.position = container.player.loc + new Vector3(0, 2, 0);
        foreach (XMLDataManager.Bot b in container.bots)
        {
            GameObject temp = Instantiate(bot, b.location, new Quaternion());
            if (b.pPoints != null)
            {
                temp.GetComponent <BotScript>().patrolPoints = b.pPoints;
            }
            currentGameObjects.Add(temp);
        }
        goalNum = container.goals.Length;
        player.GetComponent <PlayerController>().RefreshSpawn(player.transform.position);
    }
    private void LoadLevel()
    {
        // Get the level configuration
        currentLevel = LevelManager.levels[GamePersistence.gameData.level - 1];
        // Reset values
        currentConnectorIndex = 0;
        // Set game properties
        cirlceColors    = currentLevel.colorsCount;
        connectorsCount = currentLevel.connectorsCount;
        rotationSpeed   = currentLevel.circleRotationSpeed;
        // Update the rotation's vector
        rotationVector.z = rotationSpeed;
        // Create connectors color count array
        connectorsColorCount = new int[cirlceColors];
        for (int i = 0; i < cirlceColors; i++)
        {
            connectorsColorCount[i] = 0;
        }

        // Setup current colors
        RefreshColors();
        // Calculate the connectors count per color
        maxConnectorsCountPerColor       = connectorsCount / cirlceColors;
        connectorsAllowedColorsBeyondMax = connectorsCount % cirlceColors;
        // Create connectors
        for (int i = 0; i < (connectorsCount > 3 ? 3 : connectorsCount); i++)
        {
            // Instantiate a new connector
            Image   newConnector = Instantiate(mainConnector, canvas.transform);
            Vector2 position     = new Vector2(CONNECTOR_POSITION.x, CONNECTOR_POSITION.y - DISTANCE_BETWEEN_CONNECTORS * i);
            // Generate a random color index
            int  colorIndex;
            bool allowBeyondMax = false;
            do
            {
                // Get random color index within the allowed range
                colorIndex = (int)Random.Range(0, cirlceColors);
                // Check colors beyond maximum allowed
                if (connectorsColorCount[colorIndex] >= maxConnectorsCountPerColor && connectorsAllowedColorsBeyondMax > 0)
                {
                    // Decrease the allowed colors beyond max count
                    connectorsAllowedColorsBeyondMax--;
                    allowBeyondMax = true;
                }
            } while (!allowBeyondMax && connectorsColorCount[colorIndex] >= maxConnectorsCountPerColor);

            // Increase the chosen color count
            connectorsColorCount[colorIndex]++;
            // Get the specified color
            Color color = currentColors[colorIndex];
            // Setup connector
            newConnector.rectTransform.anchoredPosition = position;
            newConnector.GetComponent <Connector>().Setup(rotationSpeed, color, colorIndex);
            // Add it to the connectors array
            connectors.Add(newConnector);
        }
        // Get the current connector instance
        currentConnector = (Image)connectors[currentConnectorIndex];
        currentConnectorIndex++;
        // Do we have static connectors ?
        if (currentLevel.hasStaticConnectors)
        {
            // Create static connectors
            for (int i = 0; i < currentLevel.staticConnectorsRotation.Length; i++)
            {
                // Instantiate a new connector
                Image newConnector = Instantiate(mainConnector, canvas.transform);
                // Setup connector
                newConnector.GetComponent <Connector>().SetupAsStatic(rotationSpeed, currentLevel.staticConnectorsRotation[i]);
                // Add it to the connectors array
                staticConnectors.Add(newConnector);
            }
        }
        // Set the default speed flag
        defaultSpeed             = true;
        timeSinceLastSpeedChange = 0f;
        timeSinceLastColorChange = 0f;
        // Toggle speed and color UI
        speedProgressBar.gameObject.SetActive(currentLevel.hasSpeedChange || currentLevel.increasingSpeed);
        speedText.gameObject.SetActive(currentLevel.hasSpeedChange || currentLevel.increasingSpeed);
        colorProgressBar.gameObject.SetActive(currentLevel.hasColorChange);
        colorText.gameObject.SetActive(currentLevel.hasColorChange);
        // Update speed text
        if (currentLevel.increasingSpeed)
        {
            speedText.text = "Speed\nIncreasing";
        }
    }
Exemple #9
0
    protected void OnGUI()
    {
        switch (state)
        {
        case MenuState.MAIN:
            GUI.Label(new Rect(screenCenter.x - titleWidth + titlePos.x / 2f, screenCenter.y - titleHeigth + titlePos.y, titleWidth, titleHeigth), "MAIN MENU");

            if (selected > 2)
            {
                selected = 0;
            }
            if (selected < 0)
            {
                selected = 2;
            }

            if (GUI.Button(new Rect(screenCenter.x - buttonWidth / 2f, screenCenter.y - buttonHeigth / 2f - buttonHeigth, buttonWidth, buttonHeigth), selected == 0 ? "--PLAY--" : "PLAY") || selected == 0 && selectedPress)
            {
                selected = 0;
                state    = MenuState.LEVEL_SCREEN;
            }

            if (GUI.Button(new Rect(screenCenter.x - buttonWidth / 2f, screenCenter.y - buttonHeigth / 2f, buttonWidth, buttonHeigth), selected == 1 ? "--OPTIONS--" : "OPTIONS") || selected == 1 && selectedPress)
            {
                selected = 0;
                state    = MenuState.OPTIONS;
            }

            if (GUI.Button(new Rect(screenCenter.x - buttonWidth / 2f, screenCenter.y - buttonHeigth / 2f + buttonHeigth, buttonWidth, buttonHeigth), selected == 2 ? "--ABOUT--" : "ABOUT") || selected == 2 && selectedPress)
            {
                selected = 0;
                state    = MenuState.ABOUT;
            }

            break;

        case MenuState.OPTIONS:

            if (selected > 0)
            {
                selected = 0;
            }
            if (selected < 0)
            {
                selected = 0;
            }

            GUI.Label(new Rect(screenCenter.x - titleWidth + titlePos.x / 2f, screenCenter.y - titleHeigth + titlePos.y, titleWidth, titleHeigth), "OPTIONS");
            if (GUI.Button(new Rect(screenCenter.x - buttonWidth / 2f, screenCenter.y - buttonHeigth / 2f + buttonHeigth, buttonWidth, buttonHeigth), selected == 0 ? "--BACK--" : "BACK") || selected == 0 && selectedPress)
            {
                selected = 0;
                state    = MenuState.MAIN;
            }

            break;

        case MenuState.ABOUT:

            if (selected > 0)
            {
                selected = 0;
            }
            if (selected < 0)
            {
                selected = 0;
            }

            GUI.Label(new Rect(screenCenter.x - titleWidth + titlePos.x / 2f, screenCenter.y - titleHeigth + titlePos.y, titleWidth, titleHeigth), "ABOUT");
            if (GUI.Button(new Rect(screenCenter.x - buttonWidth / 2f, screenCenter.y - buttonHeigth / 2f + buttonHeigth, buttonWidth, buttonHeigth), selected == 0 ? "--BACK--" : "BACK") || selected == 0 && selectedPress)
            {
                selected = 0;
                state    = MenuState.MAIN;
            }

            break;

        case MenuState.LEVEL_SCREEN:

            if (selected > LevelManager.Levels.Count)
            {
                selected = 0;
            }
            if (selected < 0)
            {
                selected = LevelManager.Levels.Count;
            }

            GUI.Label(new Rect(screenCenter.x - titleWidth + titlePos.x / 2f, screenCenter.y - titleHeigth + titlePos.y, titleWidth, titleHeigth), "LEVEL SCREEN");
            if (levelGrid == null)               // Initialize grid
            {
                levelGrid = new Grid(screenCenter.x - levelGridWidth / 2, screenCenter.y - levelGridHeigth / 2, levelGridWidth, levelGridHeigth, levelGridColloms, levelGridRows);
            }

            if (GUI.Button(new Rect(screenCenter.x - buttonWidth / 2f, screenCenter.y - buttonHeigth / 2f + buttonHeigth + 30f, buttonWidth, buttonHeigth), selected == 0 ? "--BACK--" : "BACK") || selected == 0 && selectedPress)
            {
                selected = 0;
                state    = MenuState.MAIN;
            }

            int i = 0;
            foreach (LevelManager.Level level in LevelManager.Levels)
            {
                Vector2 buttonPos = levelGrid.GetNodePostion(i);
                if (GUI.Button(new Rect(buttonPos.x - levelGridButtonWidth / 2f, buttonPos.y - levelGridButtonHeigth / 2f, levelGridButtonWidth, levelGridButtonHeigth), selected == i + 1 ? "--" + (i + 1).ToString() + "--" : (i + 1).ToString()) || selected == i + 1 && selectedPress)
                {
                    selectedLevel = level;
                    selected      = 0;
                    state         = MenuState.SELECTED_LEVEL;
                }
                GUI.Label(new Rect(buttonPos.x - levelGridTitleWidth / 2f, buttonPos.y + levelGridTitleHeigth / 2f + levelGridTitleHeigth, levelGridTitleWidth, levelGridTitleHeigth), level.levelName);
                i++;
            }

            break;

        case MenuState.SELECTED_LEVEL:

            if (selected > 1)
            {
                selected = 0;
            }
            if (selected < 0)
            {
                selected = 1;
            }

            GUI.Label(new Rect(screenCenter.x - titleWidth + titlePos.x / 2f, screenCenter.y - titleHeigth + titlePos.y, titleWidth, titleHeigth), "SELECTED LEVEL SCREEN");
            GUI.Label(new Rect(screenCenter.x - titleWidth + titlePos.x / 2f, screenCenter.y - 5f + titlePos.y, titleWidth, titleHeigth), selectedLevel.levelName);

            if (GUI.Button(new Rect(screenCenter.x, screenCenter.y, buttonWidth, buttonHeigth), selected == 1 ? "--PLAY--" : "PLAY") || selected == 1 && selectedPress)
            {
                LevelManager.LoadLevel(selectedLevel);
            }

            if (GUI.Button(new Rect(screenCenter.x - buttonWidth / 2f, screenCenter.y - buttonHeigth / 2f + buttonHeigth + 30f, buttonWidth, buttonHeigth), selected == 0 ? "--BACK--" : "BACK") || selected == 0 && selectedPress)
            {
                selected = 0;
                state    = MenuState.LEVEL_SCREEN;
            }
            break;
        }

        selectedPress = false;
    }
Exemple #10
0
 public void LoadLevel(LevelManager.Level level)
 {
     LevelManager.levelToLoad = level;
     SceneManager.LoadScene("MainGame");
 }