Esempio n. 1
0
        public Level(LevelInfo levelInfo, GraphicsDevice graphicsDevice)
        {
            LevelInfo     = levelInfo;
            LevelRenderer = new LevelRenderer();

            DayCycleTexture = TextureHandler.LoadTexture(graphicsDevice, "C:\\GitHub\\Maps\\YourRoom\\textures\\daycycle.png");
            SetLastColor();

            var entities = new List <EntityInfo>();

            foreach (var structure in LevelInfo.Structures)
            {
                var directory = LevelInfo.DirectoryLocation;
                if (!Path.HasExtension(structure.Map))
                {
                    structure.Map += ".dat";
                }
                var structurePath = Path.Combine(directory, structure.Map);
                var file          = File.ReadAllText(structurePath);

                // Little hack
                var structureData = LevelLoader.Load(file, structurePath);
                foreach (var entityInfo in structureData.Entities)
                {
                    entityInfo.Parent = levelInfo;

                    entityInfo.Position += structure.Offset;

                    var rot = Entity.GetRotationFromVector(entityInfo.Rotation) + (structure.Rotation == -1 ? 0 : structure.Rotation);
                    while (rot > 3)
                    {
                        rot -= 4;
                    }
                    entityInfo.Rotation = Entity.GetRotationFromInteger(rot);
                }

                entities.AddRange(structureData.Entities);
            }

            var combined = LevelInfo.Entities.Concat(entities).ToList();

            foreach (var entity in combined)
            {
                entity.Shader = GetDaytimeColor(true);
                Models.Add(BaseModel.GetModelByEntityInfo(entity, graphicsDevice));
            }

            LevelRenderer.HandleModels(Models);
            LevelRenderer.Setup(graphicsDevice);
            //BaseModel.SetupStatic(graphicsDevice);
        }
        public FontFile(GraphicsDevice graphicsDevice, string fontPath)
        {
            using (var stream = File.Open(fontPath, FileMode.Open, FileAccess.Read))
                using (var textReader = new StreamReader(stream))
                    XmlFontData = (XmlFontFile) new XmlSerializer(typeof(XmlFontFile)).Deserialize(textReader);

            Textures = new Texture2D[XmlFontData.Pages.Count];
            foreach (var fontPage in XmlFontData.Pages)
            {
                var texturePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Content", "Fonts", fontPage.File);
                Textures[fontPage.ID] = TextureHandler.LoadTexture(graphicsDevice, texturePath);
            }

            foreach (var glyph in XmlFontData.Chars)
            {
                GlyphMap.Add((char)glyph.ID, glyph);
            }
        }