Example #1
0
 public Room(RoomJSONModel roomJSONModel)
 {
     floorTiles = new List <FloorTile>();
     wallTiles  = new List <WallTile>();
     JSONModelToObjects(roomJSONModel);
 }
Example #2
0
        private RoomJSONModel DeserialiseJSON(string strJSON)
        {
            RoomJSONModel roomJSONModel = JsonConvert.DeserializeObject <RoomJSONModel>(strJSON);

            return(roomJSONModel);
        }
Example #3
0
        public void JSONModelToObjects(RoomJSONModel roomJSONModel)
        {
            List <int[]> floorPosL = roomJSONModel.floorPositions;
            List <int[]> wallPosL  = roomJSONModel.wallPositions;

            foreach (var floorPos in floorPosL)
            {
                int mask = 0;
                if (PositionInList(floorPosL, floorPos, -1, 0))
                {
                    mask += 1;
                }
                if (PositionInList(floorPosL, floorPos, 0, -1))
                {
                    mask += 2;
                }
                if (PositionInList(floorPosL, floorPos, 0, 1))
                {
                    mask += 4;
                }
                if (PositionInList(floorPosL, floorPos, 1, 0))
                {
                    mask += 8;
                }
                floorTiles.Add(new FloorTile(new Vector2(floorPos.ElementAt(1) * Tile.tileSize, floorPos.ElementAt(0) * Tile.tileSize), mask));
            }
            foreach (var wallPos in wallPosL)
            {
                int  mask      = 0;
                bool left      = PositionInList(wallPosL, wallPos, 0, -1) || PositionInList(floorPosL, wallPos, 0, -1);
                bool right     = PositionInList(wallPosL, wallPos, 0, 1) || PositionInList(floorPosL, wallPos, 0, 1);
                bool up        = PositionInList(wallPosL, wallPos, -1, 0) || PositionInList(floorPosL, wallPos, -1, 0);
                bool down      = PositionInList(wallPosL, wallPos, 1, 0) || PositionInList(floorPosL, wallPos, 1, 0);
                bool upLeft    = PositionInList(wallPosL, wallPos, -1, -1) || PositionInList(floorPosL, wallPos, -1, -1);
                bool upRight   = PositionInList(wallPosL, wallPos, -1, 1) || PositionInList(floorPosL, wallPos, -1, 1);
                bool downLeft  = PositionInList(wallPosL, wallPos, 1, -1) || PositionInList(floorPosL, wallPos, 1, -1);
                bool downRight = PositionInList(wallPosL, wallPos, 1, 1) || PositionInList(floorPosL, wallPos, 1, 1);
                if (upLeft && left && up)
                {
                    mask += 1;
                }
                if (up)
                {
                    mask += 2;
                }
                if (upRight && right && up)
                {
                    mask += 4;
                }
                if (left)
                {
                    mask += 8;
                }
                if (right)
                {
                    mask += 16;
                }
                if (downLeft && left && down)
                {
                    mask += 32;
                }
                if (down)
                {
                    mask += 64;
                }
                if (downRight && right && down)
                {
                    mask += 128;
                }
                wallTiles.Add(new WallTile(new Vector2(wallPos.ElementAt(1) * Tile.tileSize, wallPos.ElementAt(0) * Tile.tileSize), maskRemap[mask]));
            }
        }