Exemple #1
0
    public SaveData GetSaveData()
    {
        SaveData data = new SaveData();

        SaveUnit main    = new SaveUnit();
        SaveUnit support = new SaveUnit();
        SaveUnit bad     = new SaveUnit();

        main.name    = "main";
        support.name = "support";
        bad.name     = "bad";

        main.tag    = "Player";
        support.tag = "Player";
        bad.tag     = "Enemy";

        if (mainGuy != null && mainGuy.GetComponent <Unit>().Health > 0)
        {
            main.x = mainGuy.transform.position.x;
            main.y = mainGuy.transform.position.y;
            main.z = mainGuy.transform.position.z;

            main.f_x = mainGuy.transform.forward.x;
            main.f_y = mainGuy.transform.forward.y;
            main.f_z = mainGuy.transform.forward.z;

            main.health = mainGuy.GetComponent <Unit>().Health;
        }
        data.main = main;

        if (supportGuy != null && supportGuy.GetComponent <Unit>().Health > 0)
        {
            support.x = supportGuy.transform.position.x;
            support.y = supportGuy.transform.position.y;
            support.z = supportGuy.transform.position.z;

            support.f_x = supportGuy.transform.forward.x;
            support.f_y = supportGuy.transform.forward.y;
            support.f_z = supportGuy.transform.forward.z;

            support.health = supportGuy.GetComponent <Unit>().Health;
        }
        data.support = support;

        if (supportGuy != null && supportGuy.GetComponent <Unit>().Health > 0)
        {
            bad.x = badGuy.transform.position.x;
            bad.y = badGuy.transform.position.y;
            bad.z = badGuy.transform.position.z;

            bad.f_x = badGuy.transform.forward.x;
            bad.f_y = badGuy.transform.forward.y;
            bad.f_z = badGuy.transform.forward.z;

            bad.health = badGuy.GetComponent <Unit>().Health;
        }
        data.bad = bad;

        return(data);
    }
Exemple #2
0
    public SaveUnit[] EntriesToSaveUnits(List<SetupManager.UnitEntry> entries)
    {
        SaveUnit[] newUnits = new SaveUnit[entries.Count];
        for (int i = 0; i < entries.Count; i++)
        {
            SetupManager.UnitEntry entry = entries[i];
            List<float> stats = new List<float>{ entry.unitID, entry.unitScript.hp, entry.unitScript.damage,
                entry.unitScript.attack_speed, entry.unitScript.range, entry.unitScript.move_speed};
            newUnits[i] = new SaveUnit(stats, entry.unitPos);
        }

        return newUnits;
    }
Exemple #3
0
    public void SaveLevel(bool toTheTemporarySlot)
    {
        if (!toTheTemporarySlot)
        {
            currentSlot = saveSlot;
        }
        else
        {
            currentSlot = 0;
        }
        SaveUnit.SaveLevel(this, lu, currentSlot, "/Levels/Editor/");

        string levelSaved = LocalizationManager.instance.GetLocalizedValue("editor_level_saved");

        mt.DisplayMessage(levelSaved + " " + currentSlot.ToString() + "!", 2.5f);

        isSaved = true;
    }
Exemple #4
0
    /// <summary>
    /// Loads previously saved state of the game and replaces current one
    /// Uses 'slotToLoad' variable to identify the file from which to load
    /// </summary>
    public void LoadLevel(string path, int levelNumber)
    {
        LevelData ld = SaveUnit.LoadLevel(levelNumber, path);

        if (path == "/Levels/Editor/")
        {
            GameDataManager.instance.generalData.selectedRocket = -1;
        }

        for (int x = 0; x < gridSize.x; x++)
        {
            for (int y = 0; y < gridSize.y; y++)
            {
                if (!lu.grid[x, y].IsEmpty())
                {
                    gu.DestroyGem(x, y, lu.grid[x, y].Gem.Color, false);
                }
            }
        }

        gridSize.x = ld.gridSizeX;
        gridSize.y = ld.gridSizeY;

        randomizeColors  = ld.randomizeColors;
        colorsAvailable  = ld.colorVector.Length;
        permittedBonuses = ld.availableBonuses;

        ComputeGemColors();
        ComputeGemSizes();

        winCondition   = ld.winCondition;
        timeAvailable  = ld.timeAvailable;
        movesAvailable = ld.movesAvailable;
        scoreToWin     = ld.scoreToWin;

        gu.UpdateDataAfterLoading();
        lu.UpdateDataAfterLoading();

        gu.RecreateGrid((int)gridSize.x, (int)gridSize.y);

        int[] gemColors = ld.gemColors;
        if (randomizeColors)
        {
            for (int i = 0; i < gemColors.Length; i++)
            {
                gemColors[i] = colorVector[IndexOf(ld.gemColors[i], ld.colorVector)];
            }
        }

        lu.grid = new Cell[(int)gridSize.x, (int)gridSize.y];
        for (int x = 0; x < (int)gridSize.x; x++)
        {
            for (int y = 0; y < (int)gridSize.y; y++)
            {
                if (ld.gemColors[x * (int)gridSize.y + y] != -1)
                {
                    lu.grid[x, y] = new Cell(new Vector2(x, y))
                    {
                        Gem = new Gem
                        {
                            Color = gemColors[x * (int)gridSize.y + y],
                            Bonus = ld.gemBonuses[x * (int)gridSize.y + y]
                        }
                    };
                    gu.SpawnGem((int)lu.grid[x, y].Position.x, (int)lu.grid[x, y].Position.y, lu.grid[x, y].Gem.Color, lu.grid[x, y].Gem.Bonus);
                }
                else
                {
                    lu.grid[x, y] = new Cell(new Vector2(x, y));
                    lu.grid[x, y].SetEmpty();
                }
            }
        }

        sequenceSize  = ld.sequenceSize;
        maximumEnergy = ld.maximumEnergy;

        int rocketId = GameDataManager.instance.generalData.selectedRocket;

        if (rocketId != -1)
        {
            maximumEnergy = GameDataManager.instance.rocketData[rocketId].maxEnergy;
        }
        lu.suboptimalMoves = maximumEnergy;
        gu.RecreateEnergyBar(maximumEnergy);

        spawnNewGems = ld.spawnNewGems;
        spawnEnergy  = ld.spawnEnergy;

        winCondition   = ld.winCondition;
        timeAvailable  = ld.timeAvailable;
        scoreToWin     = ld.scoreToWin;
        movesAvailable = ld.movesAvailable;

        lu.ComputeResourceColors();
    }
Exemple #5
0
    // Loads previously saved state of the game and replaces current one
    // Uses 'currentSlot' variable to identify the file from which to load
    public void LoadLevel()
    {
        currentSlot = loadSlot;
        saveSlot    = loadSlot;

        LevelData ld = SaveUnit.LoadLevel(currentSlot, "/Levels/Editor/");

        if (ld == null)
        {
            string slot  = LocalizationManager.instance.GetLocalizedValue("editor_slot_lable");
            string empty = LocalizationManager.instance.GetLocalizedValue("editor_empty_slot");
            mt.DisplayMessage(slot + " " + currentSlot.ToString() + " " + empty + "!", 2.0f);
        }
        else
        {
            for (int x = 0; x < gridSize.x; x++)
            {
                for (int y = 0; y < gridSize.y; y++)
                {
                    if (!lu.grid[x, y].IsEmpty())
                    {
                        gu.DestroyGem(x, y, lu.grid[x, y].Gem.Color);
                    }
                }
            }

            winCondition   = ld.winCondition;
            timeAvailable  = ld.timeAvailable;
            movesAvailable = ld.movesAvailable;
            scoreToWin     = ld.scoreToWin;

            colorsAvailable  = ld.colorVector.Length;
            permittedBonuses = ld.availableBonuses;

            sequenceSize  = ld.sequenceSize;
            maximumEnergy = ld.maximumEnergy;

            spawnNewGems    = ld.spawnNewGems;
            spawnEnergy     = ld.spawnEnergy;
            randomizeColors = ld.randomizeColors;

            colorVector = ld.colorVector;

            gridSize.x = ld.gridSizeX;
            gridSize.y = ld.gridSizeY;

            ComputeGemSizes();

            lu.UpdateDataAfterLoading();
            gu.UpdateDataAfterLoading();

            gu.RecreateGrid((int)gridSize.x, (int)gridSize.y);

            lu.grid = new Cell[(int)gridSize.x, (int)gridSize.y];
            for (int x = 0; x < (int)gridSize.x; x++)
            {
                for (int y = 0; y < (int)gridSize.y; y++)
                {
                    if (ld.gemColors[x * (int)gridSize.y + y] != -1)
                    {
                        lu.grid[x, y] = new Cell(new Vector2(x, y))
                        {
                            Gem = new Gem
                            {
                                Color = ld.gemColors[x * (int)gridSize.y + y],
                                Bonus = ld.gemBonuses[x * (int)gridSize.y + y]
                            }
                        };
                        gu.SpawnGem((int)lu.grid[x, y].Position.x, (int)lu.grid[x, y].Position.y, lu.grid[x, y].Gem.Color, lu.grid[x, y].Gem.Bonus);
                    }
                    else
                    {
                        lu.grid[x, y] = new Cell(new Vector2(x, y));
                        lu.grid[x, y].SetEmpty();
                    }
                }
            }
        }

        isSaved = true;
    }