示例#1
0
        private void LoadTemplateFile(string path)
        {
            // Reset the lighting
            GameManager.Game.Penumbra.Lights.Clear();
            GameManager.Game.Player.InitLighting();
            GameManager.Game.Penumbra.Hulls.Clear();
            ((MainGameScreen)GameManager.Game.GameScreen).InitLighting();

            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.Load(path);

            foreach (XmlNode tile in xmlDocument["world"]["tiles"])
            {
                // Add a tile to the colidable tiles layer
                Tile fTile = ParseTile(tile);

                fTile.TileInfo.Tile = fTile;
                WorldTemplate.ParseTemplateTag(fTile);
                this.Tiles.Add(fTile);
            }
            foreach (XmlNode tile in xmlDocument["world"]["floorTiles"])
            {
                // Add a tile to the floor layer
                this.FloorTiles.Add(ParseTile(tile));
            }
            foreach (XmlNode tile in xmlDocument["world"]["decor"])
            {
                //Custom entitity tiles
                if (tile["textureKey"].InnerText == "torch")
                {
                    // Torch

                    Torch torch = new Torch();
                    torch.X = int.Parse(tile["position"]["x"].InnerText) * 64;
                    torch.Y = int.Parse(tile["position"]["y"].InnerText) * 64;
                    Entity.Add(torch);
                    GameManager.Game.Penumbra.Lights.Add(new PointLight
                    {
                        Position     = new Vector2(torch.X + 32, torch.Y + 32),
                        Scale        = new Vector2(600),
                        ShadowType   = ShadowType.Illuminated,
                        CastsShadows = true,
                        Intensity    = 0.5f
                    });
                }
                else
                {
                    // Normal entity-tile
                    Tile fTile = ParseTile(tile);
                    this.Decor.Add(fTile);
                }
            }
            foreach (XmlNode tile in xmlDocument["world"]["entitys"])
            {
                if (GlobalAssets.EntityTextures[tile["textureKey"].InnerText].IsTile)
                {
                    TileEntity fTile = new TileEntity(new Frame(GlobalAssets.EntityTextures[tile["textureKey"].InnerText].Texture));
                    fTile.X             = int.Parse(tile["position"]["x"].InnerText) * 64;
                    fTile.Y             = int.Parse(tile["position"]["y"].InnerText) * 64;
                    fTile.Texture       = GlobalAssets.EntityTextures[tile["textureKey"].InnerText].Texture;
                    fTile.Size          = GlobalAssets.EntityTextures[tile["textureKey"].InnerText].Size;
                    fTile.EntityTexture = GlobalAssets.EntityTextures[tile["textureKey"].InnerText];
                    fTile.Colidable     = GlobalAssets.EntityTextures[tile["textureKey"].InnerText].Colidable;
                    this.Entity.Add(fTile);

                    fTile.AfterAdd();
                }
                else
                {
                    switch (tile["textureKey"].InnerText.TrimEnd('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'))
                    {
                    case "corphafon":
                        Corphafon fTile = new Corphafon();
                        fTile.X             = int.Parse(tile["position"]["x"].InnerText) * 64;
                        fTile.Y             = int.Parse(tile["position"]["y"].InnerText) * 64;
                        fTile.Texture       = GlobalAssets.EntityTextures[tile["textureKey"].InnerText].Texture;
                        fTile.Size          = GlobalAssets.EntityTextures[tile["textureKey"].InnerText].Size;
                        fTile.EntityTexture = GlobalAssets.EntityTextures[tile["textureKey"].InnerText];
                        fTile.Texture       = fTile.EntityTexture.Texture;
                        this.Entity.Add(fTile);
                        fTile.AfterAdd();
                        break;
                    }
                }
            }
        }