Esempio n. 1
0
        // Parse an array of grid lines and depth, converting glyphs into objects in layers
        Level ParseLevel(IList <string> gridlines)
        {
            var width = gridlines.Max(g => g.Length);

            if (gridlines.Any(l => l.Length != width))
            {
                CompileWarn("short level line(s)");
            }
            var bgobjects = new List <int>();

            // create empty level of required size
            var level = Level.Create(width, gridlines.Count, _gamedef.LayerCount,
                                     (_gamedef.Levels.Count + 1).ToString());

            // parse each line of the grid
            for (int y = 0; y < gridlines.Count; y++)
            {
                var line = gridlines[y];
                if (line.Length < width)
                {
                    line += new string(line.Last(), width - line.Length);
                }

                // parse each column (which must be a glyph object or pile)
                // track any background objects seen
                for (int x = 0; x < line.Length; x++)
                {
                    foreach (var obj in ParseAggregate(line.Substring(x, 1)))
                    {
                        if (_gamedef.Background.Contains(obj))
                        {
                            bgobjects.Add(obj);
                        }
                        var layer = _gamedef.GetLayer(obj);
                        if (layer != 0)
                        {
                            level[x, y, layer] = obj;
                        }
                    }
                }
            }
            // now fill in the background
            for (int cellindex = 0; cellindex < level.Length; cellindex++)
            {
                // a tile with no background gets the lowest number found on the level
                if (!level.GetObjects(cellindex).Any(o => bgobjects.Contains(o)))
                {
                    var bgobj = (bgobjects.Count > 0) ? bgobjects.Min() : _gamedef.Background.Min();
                    level[cellindex, _gamedef.GetLayer(bgobj)] = bgobj;
                }
            }
            return(level);
        }
Esempio n. 2
0
        // create object at location
        internal bool CreateObject(int obj, int cellindex)
        {
            var layer = _gamedef.GetLayer(obj);

            if (_level[cellindex, layer] == obj)
            {
                return(false);
            }
            ClearLocation(cellindex, layer);
            SetCell(cellindex, layer, obj);
            return(true);
        }