예제 #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);
        }