Example #1
0
        public string MapDecodeGlyphFont(MapContent content)
        {
            switch (content)
            {
            case MapContent.ClearSpace: return(" ");

            case MapContent.InvalidSpace: return("X");

            case MapContent.PrincessSpace: return("P");

            case MapContent.ExitSpace: return("E");

            case MapContent.LootSpace: return("$");

            case MapContent.PuzzleSpace: return("?");

            case MapContent.MonsterSpace: return("M");

            case MapContent.WeaponSpace: return("w");

            case MapContent.FoodSpace: return("f");

            default:
            {
                return(".");
            }
            }
        }
Example #2
0
        private void EnsureContent(IDrsProviderFixture fixture, string[] holderNames, string
                                   [] keyNames, string[] valueNames)
        {
            int holderCount = holderNames.Length;

            EnsureInstanceCount(fixture, typeof(MapHolder), holderCount);
            // After dropping generating uuid for collection, it does not
            //  make sense to count collection because collection is never reused
            // ensureInstanceCount(provider, Map.class, holderCount);
            int         i         = 0;
            IEnumerator objectSet = fixture.Provider().GetStoredObjects(typeof(MapHolder)).GetEnumerator
                                        ();

            while (objectSet.MoveNext())
            {
                MapHolder lh = (MapHolder)objectSet.Current;
                Assert.AreEqual(holderNames[i], lh.GetName());
                IDictionary Map = lh.GetMap();
                for (int j = 0; j < keyNames.Length; j++)
                {
                    MapContent mc   = (MapContent)Map[keyNames[j]];
                    string     name = mc.GetName();
                    Assert.AreEqual(valueNames[j], name);
                }
            }
        }
Example #3
0
 public MapItemClass(MapContent map, int x, int y)
 {
     xCoord     = x;
     yCoord     = y;
     mapContent = map;
     Name       = "";
 }
        public void InitsMapWhenReady()
        {
            using (var client1 = InitClient())
                using (var client2 = InitClient())
                {
                    MapContent map = null;
                    var        gameStartedCount  = 0;
                    var        mapGeneratedCount = 0;

                    client1.MapGeneratedSignal.AddListener((received) => { mapGeneratedCount++; map = received; });
                    client1.GameStartedSignal.AddListener(() => gameStartedCount++);
                    client1.StartDispatchingEvents();

                    client2.MapGeneratedSignal.AddListener((_) => mapGeneratedCount++);
                    client2.GameStartedSignal.AddListener(() => gameStartedCount++);
                    client2.StartDispatchingEvents();

                    client1.SendReady();
                    client2.SendReady();

                    Thread.Sleep(500);
                    Assert.AreEqual(2, mapGeneratedCount);
                    Assert.NotNull(map?.Map);

                    client1.SendRendered();
                    client2.SendRendered();
                    Thread.Sleep(500);
                    Assert.AreEqual(2, gameStartedCount);
                }
        }
Example #5
0
        /// <summary>Default constructor creates a map from a .tmx file and creates any associated tileset textures by using the passed renderer.
        /// </summary>
        /// <param name="filePath">Path to the .tmx file to load</param>
        /// <param name="renderer">Renderer object used to load tileset textures</param>
        public TiledMap(string filePath, Renderer renderer, string contentRoot = "")
        {
            MapContent mapContent = new MapContent(filePath, renderer, contentRoot);

            TileWidth  = mapContent.TileWidth;
            TileHeight = mapContent.TileHeight;

            Width  = mapContent.Width * TileWidth;
            Height = mapContent.Height * TileHeight;

            foreach (LayerContent layer in mapContent.Layers)
            {
                if (layer is TileLayerContent)
                {
                    TileLayerContent tileLayerContent = layer as TileLayerContent;
                    TileLayer        tileLayer        = new TileLayer(tileLayerContent.Width, tileLayerContent.Height);

                    for (int i = 0; i < tileLayerContent.Data.Length; i++)
                    {
                        // strip out the flipped flags from the map editor to get the real tile index
                        uint tileID = tileLayerContent.Data[i];
                        uint flippedHorizontallyFlag = 0x80000000;
                        uint flippedVerticallyFlag   = 0x40000000;
                        int  tileIndex = (int)(tileID & ~(flippedVerticallyFlag | flippedHorizontallyFlag));

                        Tile tile = CreateTile(tileIndex, mapContent.TileSets);

                        tileLayer.AddTile(tile);
                    }

                    tileLayers.Add(tileLayer);
                }
                else if (layer is ObjectLayerContent)
                {
                    ObjectLayerContent objectLayerContent = layer as ObjectLayerContent;

                    bool isCollidable = false;
                    if (objectLayerContent.Name == "Collidables")
                    {
                        isCollidable = true;
                    }

                    MapObjectLayer mapObjectLayer = new MapObjectLayer(objectLayerContent.Name);

                    foreach (ObjectContent objectContent in objectLayerContent.MapObjects)
                    {
                        MapObject mapObject = new MapObject(objectContent.Name, objectContent.Bounds, isCollidable, mapContent.Orientation);
                        mapObjectLayer.AddMapObject(mapObject);
                    }

                    mapObjectLayers.Add(mapObjectLayer);
                }
            }

            CalculateTilePositions(mapContent.Orientation);
        }
Example #6
0
        private void StoreMapToProviderA()
        {
            MapHolder  mh  = new MapHolder("h1");
            MapContent mc1 = new MapContent("c1");
            MapContent mc2 = new MapContent("c2");

            mh.Put("key1", mc1);
            mh.Put("key2", mc2);
            A().Provider().StoreNew(mh);
            A().Provider().Commit();
            EnsureContent(A(), new string[] { "h1" }, new string[] { "key1", "key2" }, new string
                          [] { "c1", "c2" });
        }
Example #7
0
        private void AddElementInProviderA()
        {
            MapHolder mh = (MapHolder)GetOneInstance(A(), typeof(MapHolder));

            mh.SetName("h3");
            MapContent mc3 = new MapContent("co3");

            A().Provider().StoreNew(mc3);
            mh.GetMap()["key3"] = mc3;
            A().Provider().Update(mh.GetMap());
            A().Provider().Update(mh);
            A().Provider().Commit();
            EnsureContent(A(), new string[] { "h3" }, new string[] { "key1", "key2", "key3" }
                          , new string[] { "co1", "co2", "co3" });
        }
Example #8
0
        /// <summary
        /// >Default constructor creates a map from a .tmx file and creates any associated tileset textures by using the passed renderer.
        /// </summary>
        /// <param name="filePath">Path to the .tmx file to load</param>
        /// <param name="renderer">Renderer object used to load tileset textures</param>
        public TiledMap(string filePath, IRenderer renderer, string contentRoot = "")
        {
            MapContent mapContent = new MapContent(filePath, renderer, contentRoot);

            TileWidth  = mapContent.TileWidth;
            TileHeight = mapContent.TileHeight;

            PixelWidth  = mapContent.Width * TileWidth;
            PixelHeight = mapContent.Height * TileHeight;

            HorizontalTileCount = mapContent.Width;
            VerticalTileCount   = mapContent.Height;

            CreateLayers(mapContent);
        }
Example #9
0
        /// <summary>
        /// Create empty map cells based on tile counts in the Tiled Map TMX. For example, a tile map of 15x15 tiles will be translated into
        /// 15x15 map cells. These map cells are then later populated with 0-N tiles, 0-4 dead zones, and 0-4 path nodes.
        /// </summary>
        /// <param name="mapContent">Map contentManager.</param>
        private void CreateMapCells(MapContent mapContent)
        {
            if (mapContent == null)
            {
                throw new ArgumentNullException("mapContent");
            }

            for (int y = 0; y < mapContent.Height; y++)
            {
                for (int x = 0; x < mapContent.Width; x++)
                {
                    MapCell mapCell = new MapCell(CoordinateHelper.WorldGridCellWidth, CoordinateHelper.WorldGridCellHeight);
                    mapCell.WorldGridIndex = new Point(x, y);
                    mapCells.Add(mapCell);
                }
            }
        }
Example #10
0
        private void ModifyInProviderB()
        {
            MapHolder mh = (MapHolder)GetOneInstance(B(), typeof(MapHolder));

            mh.SetName("h2");
            MapContent mc1 = (MapContent)mh.GetMap()["key1"];
            MapContent mc2 = (MapContent)mh.GetMap()["key2"];

            mc1.SetName("co1");
            mc2.SetName("co2");
            B().Provider().Update(mc1);
            B().Provider().Update(mc2);
            B().Provider().Update(mh.GetMap());
            B().Provider().Update(mh);
            B().Provider().Commit();
            EnsureContent(B(), new string[] { "h2" }, new string[] { "key1", "key2" }, new string
                          [] { "co1", "co2" });
        }
Example #11
0
        /// <summary>
        /// Create tile layers and object layers based on what we find in the Tiled Map TMX file.
        /// </summary>
        /// <param name="mapContent">Map contentManager.</param>
        private void CreateLayers(MapContent mapContent)
        {
            if (mapContent == null)
            {
                throw new ArgumentNullException("mapContent");
            }

            foreach (LayerContent layerContent in mapContent.Layers)
            {
                if (layerContent is TileLayerContent)
                {
                    TileLayer tileLayer = CreateTileLayer(layerContent, mapContent.TileSets);
                    tileLayers.Add(tileLayer);
                }
                else if (layerContent is ObjectLayerContent)
                {
                    MapObjectLayer mapObjectLayer = CreateObjectLayer(layerContent, mapContent.Orientation);
                    mapObjectLayers.Add(mapObjectLayer);
                }
            }
        }
Example #12
0
        /// <summary
        /// >Default constructor creates a map from a .tmx file and creates any associated tileset textures by using the passed renderer.
        /// </summary>
        /// <param name="filePath">Path to the .tmx file to load</param>
        /// <param name="renderer">Renderer object used to load tileset textures</param>
        public TiledMap(string filePath, Renderer renderer, AgentFactory agentFactory, string contentRoot = "")
        {
            this.agentFactory = agentFactory;

            MapContent mapContent = new MapContent(filePath, renderer, contentRoot);

            TileWidth  = mapContent.TileWidth;
            TileHeight = mapContent.TileHeight;

            PixelWidth  = mapContent.Width * TileWidth;
            PixelHeight = mapContent.Height * TileHeight;

            HorizontalTileCount = mapContent.Width;
            VerticalTileCount   = mapContent.Height;

            CreateLayers(mapContent);
            CalculateTilePositions(mapContent.Orientation);
            CalculatePathNodeNeighbors();
            CreateMapCells(mapContent);
            InitializeMapCells();
        }
Example #13
0
        private async void Window_Activated(object sender, EventArgs e)
        {
            if (loaded)
            {
                return;
            }



            JsonObject data = JsonObject.Load(new StreamReader(@"Maps\TestMap.json").ReadToEnd());

            this.Cmd.Focus();

            MapContent map = JsonConvert.Deserialize <MapContent>(data);

            MapView.Load(map);



            //GameObject Test = new Map.Object.GameObject("Test" ,new MapPosition() { X = 0 ,Y = 0 });

            //MapView.AddGameObject(Test);

            await MapView.DisplayScreen();

            await MapView[5, 5].Focus();

            System.Windows.Forms.Application.DoEvents();

            Thread.Sleep(2000);

            LoadGrid.Visibility = Visibility.Collapsed;
            Title = "逮丸の物語 - " + map.Name;

            loaded = true;
        }