Esempio n. 1
0
    public void spawnConsumables(GameDataSerializable data)
    {
        cleanLevelBeforeSpawn();
        initVariables(data.level);

        spawnConsumablesOf(data);
    }
Esempio n. 2
0
 /* Load level */
 private void spawnConsumablesOf(GameDataSerializable data)
 {
     spawnGrapes(data.grapePositions);
     spawnPumpkins(data.pumpkinPositions);
     spawnEnergies(data.energyPositions);
     spawnHearts(data.heartPositions);
 }
Esempio n. 3
0
    public static GameDataSerializable loadGameDataAt(paths pathEnum)
    {
        if (pathEnum == paths.cell1)
        {
            path = path_cell1;
        }
        if (pathEnum == paths.cell2)
        {
            path = path_cell2;
        }
        if (pathEnum == paths.cell3)
        {
            path = path_cell3;
        }

        if (File.Exists(path))
        {
            BinaryFormatter formatter = new BinaryFormatter();
            FileStream      stream    = new FileStream(path, FileMode.Open);

            GameDataSerializable data = formatter.Deserialize(stream) as GameDataSerializable;
            stream.Close();

            return(data);
        }
        else
        {
            //Debug.LogError("Save file not found in path: " + path);
            return(null);
        }
    }
Esempio n. 4
0
    public void loadGame(SaveLoad.paths path)
    {
        SceneManager.LoadScene(2);

        data = SaveLoad.loadGameDataAt(path);
        this.currentLevel = data.level;
    }
Esempio n. 5
0
 public static GameDataSerializable[] loadAllGameData()
 {
     GameDataSerializable[] data = new GameDataSerializable[3];
     data[0] = loadGameDataAt(paths.cell1);
     data[1] = loadGameDataAt(paths.cell2);
     data[2] = loadGameDataAt(paths.cell3);
     return(data);
 }
Esempio n. 6
0
    public static void SavePlayerData(GameData gameData)
    {
        //Formatter converts a class into a stream, FileStream writes the stream to file
        BinaryFormatter      formatter = new BinaryFormatter();
        FileStream           stream    = new FileStream(SavePath, FileMode.Create);
        GameDataSerializable data      = GameDataSerializable.ConvertGameDataToSerializable(gameData);

        formatter.Serialize(stream, data);
        stream.Close();
    }
    public static void ConvertToGameData(GameDataSerializable data, GameData gameData)
    {
        //gameData.playerLevel = data.playerLevel;
        //gameData.playerHealth = data.playerHealth;

        //Vector3 pos = new Vector3(
        //    data.playerPosition[0],
        //    data.playerPosition[1],
        //    data.playerPosition[2]);
        //gameData.playerPosition = pos;
    }
Esempio n. 8
0
    public static GameDataSerializable ConvertGameDataToSerializable(GameData gameData)
    {
        GameDataSerializable data = new GameDataSerializable();

        data.playerLevel  = gameData.playerLevel;
        data.playerHealth = gameData.playerHealth;

        data.playerPosition    = new float[3];
        data.playerPosition[0] = gameData.playerPosition.x;
        data.playerPosition[1] = gameData.playerPosition.y;
        data.playerPosition[2] = gameData.playerPosition.z;

        return(data);
    }
Esempio n. 9
0
 private void setCellData(GameObject cell, GameDataSerializable data)
 {
     if (data != null)
     {
         cell.transform.GetChild(2).GetChild(0).gameObject.GetComponent <Text>().text = "Last updated: " + data.date;
         cell.transform.GetChild(2).GetChild(1).gameObject.GetComponent <Text>().text = "Score: " + data.calories.ToString();
         cell.transform.GetChild(2).GetChild(2).gameObject.GetComponent <Text>().text = "Level: " + data.level.ToString();
         cell.transform.GetChild(2).GetChild(3).gameObject.GetComponent <Text>().text = "Hearts: " + data.hearts.ToString();
     }
     else
     {
         cell.transform.GetChild(2).GetChild(0).gameObject.GetComponent <Text>().text = "[Empty cell]";
         cell.transform.GetChild(2).GetChild(1).gameObject.GetComponent <Text>().text = "";
         cell.transform.GetChild(2).GetChild(2).gameObject.GetComponent <Text>().text = "";
         cell.transform.GetChild(2).GetChild(3).gameObject.GetComponent <Text>().text = "";
     }
 }
Esempio n. 10
0
    public static bool TryLoadPlayerData(GameData gameData)
    {
        if (HasSaveFile())
        {
            BinaryFormatter formatter = new BinaryFormatter();
            FileStream      stream    = new FileStream(SavePath, FileMode.Open);

            GameDataSerializable data = formatter.Deserialize(stream) as GameDataSerializable;
            stream.Close();

            GameDataSerializable.ConvertToGameData(data, gameData);
            return(true);
        }
        else
        {
            Debug.LogError("Save file does not exist, using default.");
            return(false);
        }
    }
Esempio n. 11
0
    private void OnLevelWasLoaded(int level)
    {
        /*          Menu and login scene        */
        if (SceneManager.GetActiveScene().buildIndex < 2)
        {
            return;
        }

        /*     We load the map only if we are in Game Scene             */
        if (data != null)
        {
            GameController.instance.startLevel(data);
            data = null;
        }
        else
        {
            GameController.instance.startLevel(this.currentLevel);
        }
    }
Esempio n. 12
0
    public List <IEnemy> spawnEnemies(GameDataSerializable data)
    {
        cleanLevelBeforeSpawn();

        List <IEnemy> listOfEnemies = new List <IEnemy>();

        float[][] bunnyPositions = data.bunnyPositions, impPositions = data.impPositions;
        for (int i = 0; i < impPositions.Length; i++)
        {
            listOfEnemies.Add(Instantiate(impPrefab, new Vector3(impPositions[i][0], impPositions[i][1], impPositions[i][2]), Quaternion.identity).GetComponent <IEnemy>());
        }

        for (int i = 0; i < bunnyPositions.Length; i++)
        {
            listOfEnemies.Add(Instantiate(bunnyPrefab, new Vector3(bunnyPositions[i][0], bunnyPositions[i][1], bunnyPositions[i][2]), Quaternion.identity).GetComponent <IEnemy>());
        }

        return(listOfEnemies);
    }
Esempio n. 13
0
    public static void saveGameDataAt(GameDataSerializable data, paths pathEnum)
    {
        if (pathEnum == paths.cell1)
        {
            path = path_cell1;
        }
        if (pathEnum == paths.cell2)
        {
            path = path_cell2;
        }
        if (pathEnum == paths.cell3)
        {
            path = path_cell3;
        }

        BinaryFormatter formatter = new BinaryFormatter();
        FileStream      stream    = new FileStream(path, FileMode.Create);

        formatter.Serialize(stream, data);
        stream.Close();
    }