Example #1
0
        private static Player MakeWorldAndPlayer(params Rectangle[] immovables)
        {
            var world       = new World();
            var map         = new TiledMap("TestMap", Room.NumTilesWidth, Room.NumTilesHeight, Room.TileWidth, Room.TileHeight, TiledMapTileDrawOrder.RightDown, TiledMapOrientation.Orthogonal);
            var bottomLayer = new TiledMapTileLayer(Dungeon.BottomLayerName, Room.NumTilesWidth, Room.NumTilesHeight, Room.TileWidth, Room.TileHeight);

            for (int y = 0; y < bottomLayer.Height; ++y)
            {
                for (int x = 0; x < bottomLayer.Width; ++x)
                {
                    bottomLayer.SetTile((ushort)x, (ushort)y, 1);
                }
            }
            map.AddLayer(bottomLayer);
            var collidables = new TiledMapRectangleObject[immovables.Length];
            int i           = 0;

            foreach (Rectangle immovable in immovables)
            {
                // Note: Object IDs for Tiled maps start at 1, not 0.
                collidables[i] = new TiledMapRectangleObject(i + 1, "collidable" + (i + 1), new Size2(immovable.Width, immovable.Height), new Vector2(immovable.X, immovable.Y));
                ++i;
            }
            var collisionLayer = new TiledMapObjectLayer(Dungeon.CollisionLayerName, collidables);

            map.AddLayer(collisionLayer);
            var dungeon = new Dungeon(world, map, null);

            world.Dungeons.Add(dungeon);
            var player = new Player(dungeon, new Point(Room.Width / 2, Room.Height / 2), Direction.Down);

            world.Player = player;
            return(player);
        }
Example #2
0
        public Location FormLocation(Random random, ref ILocationGenerator.CellType[,] map)
        {
            uint width  = (uint)map.GetLength(0);
            uint height = (uint)map.GetLength(1);

            var location = new Location(width, height);

            var tiles = Storage.Content.Load <TiledMapTileset>("maps/dungeon_tiles");

            var floors = new TiledMapTileLayer("floors", (int)width, (int)height, 64, 32, new Vector2(0, -32));

            location.TiledMap.AddLayer(floors);

            var walls = new TiledMapTileLayer("walls", (int)width, (int)height, 64, 32, new Vector2(0, -32));

            location.TiledMap.AddLayer(walls);

            location.TiledMap.AddTileset(tiles, 1);

            for (ushort x = 1; x < width; x++)
            {
                for (ushort y = 1; y < height; y++)
                {
                    floors.SetTile(x, y, (uint)(location.TiledMap.GetTilesetFirstGlobalIdentifier(tiles) + 74));
                }
            }

            for (ushort x = 0; x < width; x++)
            {
                for (ushort y = 0; y < height; y++)
                {
                    if (map[x, y] == ILocationGenerator.CellType.Wall)
                    {
                        walls.SetTile(x, y,
                                      (uint)(location.TiledMap.GetTilesetFirstGlobalIdentifier(tiles) + 32));
                        location.SetWall(x, y);
                    }
                }
            }

            return(location);
        }