Пример #1
0
        public void DrawRoom(BitsyGame.Room room, IRenderSurface context)
        {
            var pal = _env.GetRoomPalette(room.Id);

            context.FillSurface(_env.GetCurrentPalette().Colors[0]);

            for (int i = 0; i < room.Tilemap.GetLength(0); i++)
            {
                for (int j = 0; j < room.Tilemap.GetLength(1); j++)
                {
                    string id = room.Tilemap[i, j];
                    if (id != BitsyGame.ID_DEFAULT)
                    {
                        BitsyGame.Tile tile;
                        if (_env.Tiles.TryGetValue(id, out tile))
                        {
                            this.DrawTile(tile.DrawId, tile.Anim.FrameIndex, i, j, pal.Colors[tile.Color], context);
                        }
                        else
                        {
                            id = BitsyGame.ID_DEFAULT;
                            room.Tilemap[i, j] = id;
                        }
                    }
                }
            }

            for (int i = 0; i < room.Items.Count; i++)
            {
                BitsyGame.Item item;
                if (_env.Items.TryGetValue(room.Items[i].Id, out item))
                {
                    this.DrawTile(item.DrawId, item.Anim.FrameIndex, room.Items[i].x, room.Items[i].y, pal.Colors[item.Color], context);
                }
            }

            foreach (var spr in _env.Sprites.Values)
            {
                if (spr.RoomId == room.Id)
                {
                    this.DrawTile(spr.DrawId, spr.Anim.FrameIndex, spr.x, spr.y, pal.Colors[spr.Color], context);
                }
            }
        }
Пример #2
0
        private void ParseRoom(TextReader reader, string header)
        {
            var room = new BitsyGame.Room()
            {
                Id    = GetLineArg(header, 1),
                Walls = Utils.Empty <string>()
            };
            List <BitsyGame.Loc>  items   = new List <BitsyGame.Loc>();
            List <BitsyGame.Loc>  endings = new List <BitsyGame.Loc>();
            List <BitsyGame.Exit> exits   = new List <BitsyGame.Exit>();

            string line;

            switch ((RoomFormats)_flags[FLAG_ROOMFORMAT])
            {
            case RoomFormats.Space:
            {
                room.Tilemap = new string[BitsyGame.MAPSIZE, BitsyGame.MAPSIZE];
                for (int i = 0; i < BitsyGame.MAPSIZE; i++)
                {
                    line = reader.ReadLineSafe();
                    for (int j = 0; j < BitsyGame.MAPSIZE; j++)
                    {
                        room.Tilemap[i, j] = line[j].ToString();
                    }
                }
            }
            break;

            case RoomFormats.Comma:
            {
                room.Tilemap = new string[BitsyGame.MAPSIZE, BitsyGame.MAPSIZE];
                for (int j = 0; j < BitsyGame.MAPSIZE; j++)
                {
                    var lines = reader.ReadLineSafe().Split(',');
                    for (int i = 0; i < BitsyGame.MAPSIZE; i++)
                    {
                        room.Tilemap[i, j] = lines[i];
                    }
                }
            }
            break;
            }

            while (!string.IsNullOrEmpty(line = reader.ReadLineSafe()))
            {
                switch (GetLineArg(line, 0))
                {
                case "NAME":
                    room.Name = line.Substring(5);
                    break;

                case "SPR":
                {
                    string   sid = GetLineArg(line, 1);
                    string[] args;
                    if (sid.IndexOf(',') < 0 && (args = line.Split(' ')).Length >= 3)
                    {
                        var coords = args[2].Split(',');
                        this._spriteStartLocations[sid] = new BitsyGame.Loc()
                        {
                            Id = room.Id,
                            x  = int.Parse(coords[0]),
                            y  = int.Parse(coords[1])
                        };
                    }
                    else if ((RoomFormats)_flags[FLAG_ROOMFORMAT] == RoomFormats.Space)
                    {
                        var arr = sid.Split(',');
                        for (int i = 0; i < BitsyGame.MAPSIZE; i++)
                        {
                            foreach (var s in arr)
                            {
                                int j = Utils.IndexOfInRow(room.Tilemap, i, s);
                                if (j >= 0)
                                {
                                    room.Tilemap[i, j]            = "0";
                                    this._spriteStartLocations[s] = new BitsyGame.Loc()
                                    {
                                        Id = room.Id,
                                        x  = j,
                                        y  = i
                                    };
                                }
                            }
                        }
                    }
                }
                break;

                case "ITM":
                {
                    var coords = GetLineArg(line, 2).Split(',');
                    items.Add(new BitsyGame.Loc()
                        {
                            Id = GetLineArg(line, 1),
                            x  = int.Parse(coords[0]),
                            y  = int.Parse(coords[1])
                        });
                }
                break;

                case "WAL":
                    room.Walls = GetLineArg(line, 1).Split(',');
                    break;

                case "EXT":
                {
                    var args       = line.Split(' ');
                    var exitCoords = args[1].Split(',');
                    var destCoords = args[3].Split(',');
                    exits.Add(new BitsyGame.Exit()
                        {
                            x           = int.Parse(exitCoords[0]),
                            y           = int.Parse(exitCoords[1]),
                            Destination = new BitsyGame.Loc()
                            {
                                Id = args[2],
                                x  = int.Parse(destCoords[0]),
                                y  = int.Parse(destCoords[1])
                            }
                        });
                }
                break;

                case "END":
                {
                    var coords = GetLineArg(line, 2).Split(',');
                    endings.Add(new BitsyGame.Loc()
                        {
                            Id = GetLineArg(line, 1),
                            x  = int.Parse(coords[0]),
                            y  = int.Parse(coords[1])
                        });
                }
                break;

                case "PAL":
                    room.Palette = GetLineArg(line, 1);
                    break;
                }
            }

            if (string.IsNullOrEmpty(room.Id))
            {
                return;
            }
            room.Items   = items;
            room.Endings = endings.ToArray();
            room.Exits   = exits.ToArray();
            _environment.Rooms[room.Id] = room;
            if (!string.IsNullOrEmpty(room.Name))
            {
                _environment.Names.rooms[room.Name] = room.Id;
            }
        }