예제 #1
0
    public void FocusCameraAndRunInterpreter(XBuildData XBD, ref GameObject root)
    {
        CameraScript cs = root.AddComponent<CameraScript>();
        cs.mainCamera = mainCamera;

        //start the interpreter script
        Interpreter iscript = interpreterObject.GetComponent<Interpreter>();
        iscript.Root = root.GetComponent<RootScript>();

        iscript.start_code = XBD.startCode;
        iscript.update_code = XBD.updateCode;

        iscript.Run();
    }
예제 #2
0
    public XBuildData LoadXBuildData(string id, string name, string date, string json, string img, string start, string update)
    {
        XBuildData XBD;

        if(json != null)
        {
            if (!(json.Equals ("null", System.StringComparison.InvariantCulture)) && !(json.Equals ("", System.StringComparison.InvariantCulture))) {
                XDebug.Log ("Parsing xbuild " + name + " with data of length " + json.Length);

                JSONNode arr = JSON.Parse (json);

                JSONArray ja_names = arr [0].AsArray;
                JSONArray ja_types = arr [1].AsArray;
                float center_x = arr [2].AsFloat;
                float center_y = arr [3].AsFloat;

                string[,] names = new string[ja_names.Count, ja_names [0].Count];
                int[,] types = new int[ja_names.Count, ja_names [0].Count];

                for (int i = 0; i < ja_names.Count; i++) {
                    for (int j = 0; j < ja_names[0].Count; j++) {
                        names [i, j] = arr [0] [i] [j].Value;
                        types [i, j] = arr [1] [i] [j].AsInt;
                    }
                }
                //XDebug.Log (ja_names.Count + " " + ja_names [0].Count + " (" + ja_names [0] [0].Value + ") (" + ja_names [0] [1].Value + ") (" + ja_names [0] [2].Value + ")");
                //XDebug.Log (names.GetLength (0) + " " + names.GetLength (1));
                XBD = new XBuildData (types, names, new Vector2 (center_x, center_y));
            } else {
                XBD = new XBuildData (null, null, new Vector2 (0, 0));
            }
        } else {
            XDebug.Log ("Parsing xbuild " + name + " with no data");
            XBD = new XBuildData (null, null, new Vector2 (0, 0));
        }

        XBD.name = name;
        XBD.date = date;
        XBD.image = img;
        XBD.startCode = start;
        XBD.updateCode = update;
        XBD.db_id = id;
        return XBD;
    }
예제 #3
0
    protected override void RunScript()
    {
        //Make the success Screen invivisble
        //successOverlay.active = false;

        //CreateBlock((int)BlockType.NormalRed, 2, 2, 0);

        //Test Data
        //int[,] data = new int[,] { { 2, 1, 1, 1, 2}, { 1, 0, 2, 0, 1}, { 1, 2, 2, 2, 1 },
        //{ 1, 0, 2, 0, 1}, { 2, 2, 3, 2, 2}};
        /*int[,] data = new int[,] {
            { 3, 1, 0, 0, 0},
            { 0, 2, 1, 0, 0},
            { 1, 1, 1, 4, 0},
            { 2, 2, 2, 2, 5},
            { 1, 1, 1, 4, 0},
            { 0, 2, 1, 0, 0},
            { 3, 1, 0, 0, 0}
        };
        //names = new Dictionary<Vector2, string>();
        //names.Add(new Vector2(2, 0), "rocket1");
        names = new string[7, 7];
        names[0, 0] = "rocket1";
        names[6, 0] = "rocket2";
        names[2, 3] = "missiletype11";
        names[4, 3] = "missiletype12";
        names[3, 4] = "radar1";*/

        try{
            DataPassingScript dps = GameObject.Find ("XBuildData").GetComponent<DataPassingScript> ();
            XBD = dps.XBD;
            Debug.Log ("BOS Data " + dps.XBD.db_id);
            Debug.Log ("BOS StartCode " + dps.XBD.startCode);
        } catch (NullReferenceException e) {
            DefaultXBD();
        }
        names = XBD.names;

        //XDebug.Log (XBD.names);
        //
        if (XBD.types == null || XBD.names == null || XBD.center == null) {
            XDebug.Log(BLOCK_OBJECT_SCRIPT_TAG, "Empty XBuild \nTypes: " + XBD.types
                   + "\nNames: " + XBD.names
                   + "\nCenter: " + XBD.center);
            return;
        }

        Vector3 location = new Vector3(X, Y, Z);
        XDebug.Verbose ("Creating player XBuild at location: " + location);
        if (XBD.names != null && XBD.types != null) {
            GameObject root = CreateXBuild (XBD.name, location, XBD.center, XBD.types);
            if (!GarageMode) {
                Rigidbody RBroot = root.GetComponent<Rigidbody> ();
                RBroot.mass = root.transform.childCount;
            }
            XBD.name = XBD.names [(int)XBD.center.y, (int)XBD.center.x];

            //root XBuild must be attaced to camera

            if (!GarageMode)
                FocusCameraAndRunInterpreter (XBD, ref root);
        } else {
            XDebug.Log ("Empty xbuild, no data and type matrixes");
            XBD.name = "Empty Slot";
        }
    }
예제 #4
0
    void DefaultXBD()
    {
        Debug.Log ("Data passing script had no data, creating default debuging XBuild");
        /*int[,] data = new int[,] {
            { 3, 0, 1, 2, 1, 0, 3 },
            { 1, 2, 1, 2, 1, 2, 1 },
            { 0, 1, 1, 2, 1, 1, 0 },
            { 0, 0, 4, 2, 4, 0, 0 },
            { 0, 0, 0, 5, 0, 0, 0 }
        };
        names = new string[7, 7];
        names[0, 0] = "rocketgarage0";
        names[0, 6] = "rocketgarage1";
        names[3, 2] = "missilegarage2";
        names[3, 4] = "missilegarage3";
        names[4, 3] = "radar1";
        Vector2 center = new Vector2(3, 2);*/
        int[,] data = new int[,]{
            { 3, 0, 3 },
            { 4, 1, 4 }
        };
        names = new string[,]{
            { "RocketGarage0", "", "RocketGarage1" },
            { "MissileGarage2", "BasicGarage5", "MissileGarage3" }
        };

        Vector2 center = new Vector2(1, 1);
        XBD = new XBuildData (data, names, center);
    }
예제 #5
0
    XBuildData GetXBuildData(Dictionary<Vector3, GraphNode<GarageBlock>> map)
    {
        if (map == null) {
            XDebug.Verbose(XBUILD_PARSE_SCRIPT_TAG, "Empty Map");
            return new XBuildData(null, null, new Vector2(0,0));
        }

        XDebug.Verbose("Making matrix");
        float GX = 0, GY = 0, LX = 0, LY = 0;
        //GraphNode<GarageBlock> BoundGX = null, BoundGY = null, BoundLX = null, BoundGY = null;
        //find largest x and y
        foreach(KeyValuePair<Vector3, GraphNode<GarageBlock>> pair in map)
        {
            Vector3 pos = pair.Key;
            if(GX < pos.x)
            {
                GX = pos.x;
                //BoundGX = pair.Value
            }
            if(GY < pos.y)
            {
                GY = pos.y;
                //BoundGY = pair.Value
            }
            if(LX > pos.x)
            {
                LX = pos.x;
                //BoundLX = pair.Value
            }
            if(LY > pos.y)
            {
                LY = pos.y;
                //BoundLY = pair.Value
            }
        }
        XDebug.Verbose(XBUILD_PARSE_SCRIPT_TAG, "Bounds " + GX + " " + GY + " " + LX + " " + LY);

        //int crossingX = (Math.Sign (GX) != Math.Sign (LX) || GX == 0f || LX == 0f) ? 1 : 0;
        //int crossingY = (Math.Sign (GY) != Math.Sign (LY) || GY == 0f || LY == 0f) ? 1 : 0;
        int xlen = (int)(GX - LX + 1f);
        int ylen = (int)(GY - LY + 1f);
        GarageBlock[,] matrix = new GarageBlock[ylen,xlen];
        int[,] typeMatrix = new int[ylen,xlen];
        string[,] nameMatrix = new string[ylen,xlen];

        //calculate offset
        //set the block with the largest value
        int offsetX = (int) LX;
        int offsetY = (int) LY;

        int centerX = (int)xlen / 2;
        int centerY = (int)ylen / 2;

        XDebug.Verbose(XBUILD_PARSE_SCRIPT_TAG, "Offset x,y " + offsetX + ", " + offsetY);
        double least = double.MaxValue;
        Vector2 center = new Vector2 ();
        for (int y = ylen - 1; y >= 0; y--) {
            for(int x = 0; x < xlen; x++)
            {
                //is there a block at this coord
                int cX = x + offsetX;
                int cY = y + offsetY;
                GraphNode<GarageBlock> node= null;
                XDebug.Verbose("Serching " + cX + "," + cY + " for " + x + ", " + y);
                if(map.TryGetValue(new Vector3(cX, cY, 0), out node))
                {
                    matrix[y,x] = node.Value;
                    typeMatrix[y,x] = (int) node.Value.type;
                    nameMatrix[y,x] = node.Value.name;

                    if(typeMatrix[y,x] == 1 || typeMatrix[y,x] == 2)
                    {
                        double dist = Math.Pow((Math.Pow((double)(centerX - x), 2d) + Math.Pow((double)(centerY - y), 2d)), 0.5);
                        if(dist < least)
                        {
                            least = dist;
                            center = new Vector2(x,y);
                        }
                    }
                    //update center
                }
            }
        }

        XBuildData XBD = new XBuildData (typeMatrix, nameMatrix, center);

        //update the name

        //get the name of the xbuild anything with no blocks is named Empty Slot
        if (XBD.names != null) {
            XBD.name = XBD.names [(int)center.y, (int)center.x];
        } else {
            XBD.name = "Empty Slot";
        }

        return XBD;
    }