예제 #1
0
    public Map(string json, float allScale)
    {
        // JSON load
        JSONMap temp = JsonUtility.FromJson <JSONMap>(json);

        // Set up variables
        ID         = temp.id;
        Ratio      = temp.ratio;
        Resolution = temp.resolution;

        if (Ratio >= 1f)
        {
            HScale = Ratio * allScale;
            VScale = allScale;
        }
        else
        {
            HScale = allScale;
            VScale = allScale / Ratio;
        }

        Offset = new Vector3(-HScale / 2, 0, VScale / 2);

        Lines = temp.lines.Select(l => new Line(l, this)).ToArray();
    }
예제 #2
0
        // Devuelve un mapa creado a partir del Json especificado
        static public Map GetMapFromJson(TextAsset levelFile)
        {
            Map    m    = new Map();
            string json = levelFile.text; // String con el texto en formato Json

            JSONMap jsonMap = JsonUtility.FromJson <JSONMap>(json);

            m.InitMap(jsonMap);

            return(m);
        }
예제 #3
0
 // Inicializa los atributos del mapa a partir de un JSONMap
 public void InitMap(JSONMap m)
 {
     width  = m.c;
     height = m.r;
     start  = new MapPosition(m.s.x, m.s.y);
     goal   = new MapPosition(m.f.x, m.f.y);
     foreach (var hPos in m.h)
     {
         hints.Add(new MapPosition(hPos.x, hPos.y));
     }
     foreach (var iPos in m.i)
     {
         ice.Add(new MapPosition(iPos.x, iPos.y));
     }
     foreach (var wall in m.w)
     {
         walls.Add(new MapWall(new MapPosition(wall.o.x, wall.o.y), new MapPosition(wall.d.x, wall.d.y)));
     }
 }
예제 #4
0
    public static Map FromJson(string json)
    {
        JSONMap jsonMap = JSONMap.CreateFromJSON(json);

        int rows = jsonMap.r;
        int cols = jsonMap.c;

        Map map = new Map();

        // inicializo los arrays
        map.hints = new float[jsonMap.h.Count, 2];
        map.tiles = new tileInfo[rows, cols];

        // crear el map y asignar los valores por defecto
        for (int i = 0; i < rows; i++)
        {
            for (int j = 0; j < cols; j++)
            {
                tileInfo t;
                t.ice           = false;
                t.type          = TILETYPE.IDLE;
                t.upWall        = false;
                t.downWall      = false;
                t.leftWall      = false;
                t.rightWall     = false;
                map.tiles[i, j] = t;
            }
        }

        // asignamos los valores leidos del JSONMap
        // casilla inicio
        map.tiles[(int)jsonMap.s.y, (int)jsonMap.s.x].type = TILETYPE.START;
        // casilla final
        map.tiles[(int)jsonMap.f.y, (int)jsonMap.f.x].type = TILETYPE.GOAL;

        foreach (JSONWall wall in jsonMap.w)
        {
            int xOrigen  = (int)wall.o.x;
            int yOrigen  = (int)wall.o.y;
            int xDestino = (int)wall.d.x;
            int yDestino = (int)wall.d.y;

            if (xOrigen != xDestino)
            {
                if (yOrigen == rows)
                {
                    //map.tiles[yOrigen - 1, xOrigen].upWall = true;
                    if (xOrigen == cols)
                    {
                        map.tiles[yOrigen - 1, xOrigen - 1].upWall = true;
                    }
                    else
                    {
                        map.tiles[yOrigen - 1, xOrigen].upWall = true;
                    }
                }
                else
                {
                    //map.tiles[yOrigen, xOrigen].downWall = true;
                    if (xOrigen == cols)
                    {
                        map.tiles[yOrigen, xOrigen - 1].downWall = true;
                    }
                    else
                    {
                        map.tiles[yOrigen, xOrigen].downWall = true;
                    }
                    // para ponerle el muro a la casilla anterior (pepa dice en una clase que solo hace falta poner uno)
                    if (--yOrigen > -1)
                    {
                        //map.tiles[yOrigen, xOrigen].upWall = true;
                        if (xOrigen == cols)
                        {
                            map.tiles[yOrigen, xOrigen - 1].upWall = true;
                        }
                        else
                        {
                            map.tiles[yOrigen, xOrigen].upWall = true;
                        }
                    }
                }
            }
            else
            {
                if (xDestino == cols)
                {
                    //map.tiles[yDestino, xDestino - 1].rightWall = true;
                    if (yDestino == rows)
                    {
                        map.tiles[yDestino - 1, xDestino - 1].rightWall = true;
                    }
                    else
                    {
                        map.tiles[yDestino, xDestino - 1].rightWall = true;
                    }
                }
                else
                {
                    //map.tiles[yDestino, xDestino].leftWall = true;
                    if (yDestino == rows)
                    {
                        map.tiles[yDestino - 1, xDestino].leftWall = true;
                    }
                    else
                    {
                        map.tiles[yDestino, xDestino].leftWall = true;
                    }
                    // para ponerle el muro a la casilla anterior (pepa dice en una clase que solo hace falta poner uno)
                    if (--xDestino > -1)
                    {
                        //map.tiles[yDestino, xDestino].rightWall = true;
                        if (yDestino == rows)
                        {
                            map.tiles[yDestino - 1, xDestino].rightWall = true;
                        }
                        else
                        {
                            map.tiles[yDestino, xDestino].rightWall = true;
                        }
                    }
                }
            }
        }

        // asignamos el hielo
        foreach (JSONPoint ice in jsonMap.i)
        {
            map.tiles[(int)ice.y, (int)ice.x].ice = true;
        }

        // asignamos las pistas
        int n = 0;

        foreach (JSONPoint hint in jsonMap.h)
        {
            map.hints[n, 0] = hint.x;
            map.hints[n, 1] = hint.y;
            n++;
        }

        return(map);
    }
예제 #5
0
 /// <summary>
 /// Maps a IJSONValue object onto another object
 /// </summary>
 /// <typeparam name="T">The type of object to map the IJSONValue onto</typeparam>
 /// <param name="toMap">The IJSONValue to map onto the object</param>
 /// <returns>An instance of the object containing the JSON information</returns>
 public static T Map <T>(IJSONValue toMap)
 {
     return((T)JSONMap.MapValue(typeof(T), toMap));
 }