コード例 #1
0
        private void btnNewMap_Click(object sender, EventArgs e)
        {
            Map m = new Map(30, 20);
            m.Name = "NewMap";
            m.Tileset = CurrentTileset;

            Project.Maps.Add(m);

            LoadMapList();
        }
コード例 #2
0
        public static void TrimMap(Map map, int width, int height)
        {
            map.Width = width;
            map.Height = height;

            var newCollisionLayer = new MapCollisionLayer(width, height);

            for (int y = 0; y < newCollisionLayer.Height; y++)
            {
                for (int x = 0; x < newCollisionLayer.Width; x++)
                {
                    var tile = new Vector2(x, y);

                    CollisionValues value = map.CollisionLayer.Width > tile.X && map.CollisionLayer.Height > tile.Y
                        ? map.CollisionLayer.GetCollisionValue(tile)
                        : CollisionValues.Passable;

                    newCollisionLayer.SetCollisionValue(tile, value);
                }
            }

            map.CollisionLayer = newCollisionLayer;

            for (int i = 0; i < map.Layers.Count; i++)
            {
                var newLayer = new MapLayer(width, height);

                newLayer.Id = map.Layers[i].Id;

                for (int y = 0; y < newLayer.Height; y++)
                    for (int x = 0; x < newLayer.Width; x++)
                    {
                        var tile = new Vector2(x, y);
                        if (map.Layers[i].Width > x && map.Layers[i].Height > y)
                        {
                            newLayer.SetTexture(tile, map.Layers[i].Map[y, x]);
                        }
                    }

                map.Layers[i] = newLayer;
            }
        }
コード例 #3
0
        private void LoadMap(Map map)
        {
            CurrentMap = map;

            if (map.Tileset != null)
            {
                lbxTilesets.SelectedIndex = Project.Tilesets.FindIndex(x => x.Id == map.Tileset.Id);
            }

            // Setup map interface information
            mapControl.Width = CurrentMap.WidthInPixels;
            mapControl.Height = CurrentMap.HeightInPixels;
            txtMapName.Text = CurrentMap.Name;
            nudCurrentMapHeight.Value = CurrentMap.Height;
            nudCurrentMapWidth.Value = CurrentMap.Width;

            Objects = new List<GameObject>();

            // Get already loaded sprites for map content
            foreach (var obj in CurrentMap.MapObjects)
            {
                obj.Animation = Project.MapObjects.FirstOrDefault(o => o.Id == obj.Id)?.Animation;
            }
            foreach (var enemy in CurrentMap.MapEnemies)
            {
                enemy.CharSprite = Project.Enemies.FirstOrDefault(e => e.Id == enemy.Id)?.CharSprite;
            }
            foreach (var npc in CurrentMap.MapNpcs)
            {
                npc.CharSprite = Project.Npcs.FirstOrDefault(n => n.Id == npc.Id)?.CharSprite;
            }

            // Load layers dropdown
            CbbLayersUpdate();

            // Update map size information
            RefreshMapSize();
        }