コード例 #1
0
ファイル: MINFile.cs プロジェクト: robinei/primevil
 public static MINFile Load(MPQArchive mpq, string path) {
     using (var f = mpq.Open(path)) {
         var data = new byte[f.Length];
         var len = f.Read(data, 0, (int)f.Length);
         Debug.Assert(len == f.Length);
         return new MINFile(path, data);
     }
 }
コード例 #2
0
ファイル: TownLevel.cs プロジェクト: robinei/primevil
        public static Level Load(MPQArchive mpq)
        {
            var palette = new byte[768];
            using (var f = mpq.Open("levels/towndata/town.pal")) {
                var len = f.Read(palette, 0, 768);
                Debug.Assert(len == palette.Length);
            }

            byte[] solData;
            using (var f = mpq.Open("levels/towndata/town.sol")) {
                solData = new byte[f.Length];
                var len = f.Read(solData, 0, (int)f.Length);
                Debug.Assert(len == f.Length);
            }

            var celFile = CELFile.Load(mpq, "levels/towndata/town.cel");
            var minFile = MINFile.Load(mpq, "levels/towndata/town.min");
            var tilFile = TILFile.Load(mpq, "levels/towndata/town.til");

            var dunNames = new string[] {
                "levels/towndata/sector1s.dun",
                "levels/towndata/sector2s.dun",
                "levels/towndata/sector3s.dun",
                "levels/towndata/sector4s.dun"
            };

            var sectors = new SectorTemplate[4];
            for (int i = 0; i < dunNames.Length; ++i) {
                var dunFile = DUNFile.Load(mpq, dunNames[i]);
                sectors[i] = new SectorTemplate(dunFile, tilFile, solData);
            }

            int mapWidth = sectors[0].Width + sectors[3].Width;
            int mapHeight = sectors[0].Height + sectors[3].Height;
            var map = new Map(mapWidth, mapHeight);

            map.PlaceSector(sectors[3], 0, 0);
            map.PlaceSector(sectors[2], 0, sectors[3].Height);
            map.PlaceSector(sectors[1], sectors[3].Width, 0);
            map.PlaceSector(sectors[0], sectors[3].Width, sectors[3].Height);

            var packer = new TextureAtlasPacker(2048);

            for (int i = 0; i < celFile.NumFrames; ++i) {
                var frame = celFile.GetFrame(i, palette);
                int rectId = packer.Insert(frame.Data, frame.Width, frame.Height, true);
                if (rectId < 0)
                    throw new Exception("atlas is full: " + i);
            }

            var atlas = packer.CreateAtlas();

            return new Level {
                Map = map,
                Tileset = atlas,
                PillarDefs = minFile
            };
        }
コード例 #3
0
ファイル: DUNFile.cs プロジェクト: robinei/primevil
 public static DUNFile Load(MPQArchive mpq, string path)
 {
     using (var f = mpq.Open(path)) {
         var data = new byte[f.Length];
         var len  = f.Read(data, 0, (int)f.Length);
         Debug.Assert(len == f.Length);
         return(new DUNFile(data));
     }
 }
コード例 #4
0
 public static CELFile Load(MPQArchive mpq, string path)
 {
     using (var f = mpq.Open(path)) {
         var data = new byte[f.Length];
         var len  = f.Read(data, 0, (int)f.Length);
         Debug.Assert(len == f.Length);
         bool isCL2 = path.EndsWith(".cl2");
         return(new CELFile(data, isCL2));
     }
 }
コード例 #5
0
ファイル: CELFile.cs プロジェクト: robinei/primevil
 public static CELFile Load(MPQArchive mpq, string path)
 {
     using (var f = mpq.Open(path)) {
         var data = new byte[f.Length];
         var len = f.Read(data, 0, (int)f.Length);
         Debug.Assert(len == f.Length);
         bool isCL2 = path.EndsWith(".cl2");
         return new CELFile(data, isCL2);
     }
 }
コード例 #6
0
ファイル: TextureAtlas.cs プロジェクト: robinei/primevil
 public static TextureAtlas Load(MPQArchive mpq, string path, byte[] palette = null)
 {
     if (palette == null)
         palette = DefaultPalette;
     var celFile = CELFile.Load(mpq, path);
     int sheetDim = 1024;
     while (true) {
       loop:
         var packer = new TextureAtlasPacker(sheetDim);
         for (int i = 0; i < celFile.NumFrames; ++i) {
             var frame = celFile.GetFrame(i, palette);
             int rectId = packer.Insert(frame.Data, frame.Width, frame.Height, true);
             if (rectId < 0) {
                 sheetDim *= 2;
                 goto loop;
             }
         }
         return packer.CreateAtlas();
     }
 }
コード例 #7
0
ファイル: MPQStream.cs プロジェクト: robinei/primevil
 internal MPQStream(MPQArchive archive, IDisposable handle)
 {
     this.archive = archive;
     this.handle  = handle;
 }
コード例 #8
0
ファイル: MPQStream.cs プロジェクト: robinei/primevil
 internal MPQStream(MPQArchive archive, IDisposable handle)
 {
     this.archive = archive;
     this.handle = handle;
 }
コード例 #9
0
ファイル: XnaGame.cs プロジェクト: robinei/primevil
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            var mpq = new MPQArchive("DIABDAT.MPQ");
            isoView.Level = TownLevel.Load(mpq);

            /*using (var wavStream = mpq.Open("music/dtowne.wav")) {
                var wavData = new byte[wavStream.Length];
                var wavLen = wavStream.Read(wavData, 0, (int)wavStream.Length);
                Debug.Assert(wavLen == wavStream.Length);
                music = new SoundEffect(wavData, 22050, AudioChannels.Stereo);
            }*/

            charAtlas = TextureAtlas.Load(mpq, PlayerGfx.GetAnimPath(
                PlayerGfx.Class.Warrior,
                PlayerGfx.Armor.Light,
                PlayerGfx.Weapon.MaceShield,
                PlayerGfx.State.StandingInTown));
            standingAnim = new Animation(new Sprite(charAtlas), 1.0f / 13);

            charAtlas = TextureAtlas.Load(mpq, PlayerGfx.GetAnimPath(
                PlayerGfx.Class.Warrior,
                PlayerGfx.Armor.Light,
                PlayerGfx.Weapon.MaceShield,
                PlayerGfx.State.WalkingInTown));
            walkingAnim = new Animation(new Sprite(charAtlas), 1.0f / 13);

            player = new Creature {
                Position = new CoordF(75.5f, 68.5f),
                CurrentAnimation = standingAnim
            };
            isoView.Level.Creatures.PushBack(player);
            isoView.Level.Map.PlaceCreature(player);
        }