Inheritance: MonoBehaviour
Beispiel #1
0
    public void SaveMap(string savefilepath)
    {
        //string savefilepath = StandaloneFileBrowser.SaveFilePanel("Save the map", "", "New Map", extenstionSave);
        //string savefilepath = EditorUtility.SaveFilePanel("Save the map", Application.dataPath + "/Levels", "New Map", "xml");
        List <SerializableTile> temp = new List <SerializableTile>();

        foreach (CombinedTile item in levelTiles)
        {
            SerializableTile tempTile = new SerializableTile(item.Tile.Index, item.Tile.Name, item.Tile.Rotation, item.Tile.Layer, item.Tile.X, item.Tile.Y, item.Tile.Dimensions, item.Tile.Category);
            temp.Add(tempTile);
        }
        CompleteLevel cl = new CompleteLevel(new MapInfo(mapname, levelWidth, levelHeight), temp);

        FileStream fStream = File.Create(savefilepath);

        //Serialize to xml
        DataContractSerializer bf       = new DataContractSerializer(cl.GetType());
        MemoryStream           streamer = new MemoryStream();

        //Serialize the file
        bf.WriteObject(streamer, cl);
        streamer.Seek(0, SeekOrigin.Begin);

        //Save to disk
        fStream.Write(streamer.GetBuffer(), 0, streamer.GetBuffer().Length);

        // Close the file to prevent any corruptions
        fStream.Close();

        string result = XElement.Parse(Encoding.ASCII.GetString(streamer.GetBuffer()).Replace("\0", "")).ToString();

        Debug.Log("Saved level. Saved tiles: " + temp.Count + " Serialized Result: " + result);
    }
    // Use this for initialization
    void Start()
    {
        // Find canvas, "gameobject" with "picasso"
        canvas = GameObject.FindWithTag("picasso");
        // Restart at the beginning so 0
        position = start;
        newpos   = start;
        // Get the length of the array from the GM
        GM = GameManagerObject.GetComponent <GameManager>();
        // Get the checkvalid function from the CompleteLevel Script
        CompleteLevelController = GameObject.FindWithTag("mutate");
        CLC = CompleteLevelController.GetComponent <CompleteLevel> ();
        // Finding the level number to find the length of the level
        LevelCounterConstant = GameObject.FindWithTag("constant");
        LCS         = LevelCounterConstant.GetComponent <LevelCountScript> ();
        levelnumber = LCS.levelnumber;
        levellength = GM.LController.ldata [levelnumber].leveldesign.Length;
        Debug.Log(levellength + " is the MC levellength");

        // Instantiate the character
        startcharacter(GM.LController.ldata[levelnumber].mainstartindex);


        // To get the checkvalid function
        // valid = CLC.checkvalid (newpos);
    }
    // Moves the character without the
    public void safemovement(int amount, int position, GameObject character)
    {
        if (character == null)
        {
            Debug.Log("NULL Character");
        }
        Vector2 newPosition = (Vector2)(character.transform.position) + new Vector2(1, 1) * amount;

        Debug.Log(newPosition + " is the new vector2 pos");
        // Find the CLC obj
        CompleteLevelController = GameObject.FindGameObjectWithTag("mutate");
        CLC = CompleteLevelController.GetComponent <CompleteLevel> ();
        // If the levellength is 9, it cannot be past 8
        int ll = CLC.levelm.Length - 1;

        // Check if the overflow of the array rotation occurs
        if ((newPosition.x >= ll) || (newPosition.y >= ll))
        {
            newPosition = new Vector2(0, 0);
            Debug.Log(newPosition + " is the new vector2 pos, because of overflow");
            character.transform.position = newPosition;
            // Check if the underflow of the array rotation occurs
        }
        else if ((newPosition.x < 0) || (newPosition.y < 0))
        {
            newPosition = new Vector2(1, 1) * levellength;
            Debug.Log(newPosition + " is the new vector2 pos, because of underflow");
            character.transform.position = newPosition;
        }
        character.transform.position = newPosition;
    }
Beispiel #4
0
    void LoadMap(string path)
    {
        try
        {
            if (File.Exists(path))
            {
                FileStream fStream = File.Open(path, FileMode.Open, System.IO.FileAccess.Read);

                //Deserialize from xml
                DataContractSerializer serializer = new DataContractSerializer(typeof(CompleteLevel), null, 1000, false, true, null);
                CompleteLevel          cl         = serializer.ReadObject(fStream) as CompleteLevel;
                fStream.Close();

                List <SerializableTile> temp = cl.MapTiles;
                foreach (SerializableTile item in temp)
                {
                    Tile tempTile = new Tile(item.Index, levelLoader.tileIndexer[item.Index].Obj, item.Name, item.Rotation, item.Layer, item.X, item.Y, item.Dimensions, item.Category);
                    levelTiles.Add(new CombinedTile(tempTile, null));
                }

                levelLoader.LoadLevel(levelTiles);

                Debug.Log("Loaded " + path);
            }
        }
        catch (System.Exception ex)
        {
            Debug.Log("Failure during loading the level. Error: " + ex);
            ReturnToMenu("Failure during loading the level. Error: " + ex);
        }
    }
Beispiel #5
0
    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag("Player") && firsttime)
        {
            firsttime = false;

            //decrement pages left
            cl = levelCompletedTrigger.GetComponent <CompleteLevel> ();
            cl.pagesGot++;
            canvas.SendMessage("RenderPaper", gameObject.GetComponent <SpriteRenderer>().sprite);
            Destroy(gameObject);
        }
    }
Beispiel #6
0
    public void levelComplete()
    {
        DimmerScript.RoomToGoTo = 1;
        GameObject.Find("Leaver").GetComponent <DimmerScript>().Begin();

        if (CheckLevelCompletion(currentLevel))
        {
            CompleteLevel.AllCompletedOnce = true;
        }

        Levels[currentLevel] = true;

        CompleteLevel.Save();
    }
Beispiel #7
0
    public void LoadMap(string loadfilepath)
    {
        try
        {
            //string loadfilepath = StandaloneFileBrowser.OpenFilePanel("Load a map", "", extensionOpen, false)[0];
            //string loadfilepath = EditorUtility.OpenFilePanel("Load a map", Application.dataPath + "/Levels", "xml");
            Debug.Log("Loading level: " + loadfilepath);

            if (File.Exists(loadfilepath))
            {
                FileStream fStream = File.Open(loadfilepath, FileMode.Open, System.IO.FileAccess.Read);

                //Deserialize from xml
                DataContractSerializer serializer = new DataContractSerializer(typeof(CompleteLevel), null, 1000, false, true, null);
                CompleteLevel          cl         = serializer.ReadObject(fStream) as CompleteLevel;
                fStream.Close();

                SetMapName(cl.MapInfo.MapName);
                ChangeLevelWidth(cl.MapInfo.MapWidth.ToString());
                ChangeLevelHeight(cl.MapInfo.MapHeight.ToString());
                ApplySettings();
                ClearLevelTiles();
                List <SerializableTile> temp = cl.MapTiles;
                foreach (SerializableTile item in temp)
                {
                    Tile tempTile = new Tile(item.Index, levelLoader.tileIndexer[item.Index].Obj, item.Name, item.Rotation, item.Layer, item.X, item.Y, item.Dimensions, item.Category);
                    levelTiles.Add(new CombinedTile(tempTile, null));
                }

                levelLoader.LoadLevel(levelTiles);
                ChangeLayer("0");

                Debug.Log("Loaded " + loadfilepath);
            }
        }
        catch (System.Exception ex)
        {
            Debug.Log("Failure during loading the level. Error: " + ex);
        }
    }
Beispiel #8
0
 private void EndLevel(Character unit)
 {
     level = FindObjectOfType <CompleteLevel>();
     level.Completed();
 }