예제 #1
0
    void Start()
    {
        _rooms = new List <RoomData>();

        using (SnapshotImporter importer = new SnapshotImporter(snapshotFile))
        {
            int offset = 45056;

            for (int i = 0; i < 20; i++)
            {
                // Move to the offset
                importer.Seek(offset);

                // Import Room
                ImportRoom(importer, IsSpecialRoom(i));

                // Move to the next room
                offset += 1024;
            }

            importer.Seek(33280);
            for (int i = 0; i < 8; i++)
            {
                byte[] sprite = importer.ReadBytes(32);
                _sprites.Add(sprite);
            }
        }

        IsReady = true;
    }
예제 #2
0
    // Start is called before the first frame update
    void Start()
    {
        _rooms = new List <RoomData>();

        using (SnapshotImporter importer = new SnapshotImporter(snapshotFile))
        {
            int offset = 45056;

            for (int i = 0; i < 20; i++)
            {
                importer.Seek(offset);

                ImportRoom(importer, IsSpecialRoom(i));

                offset += 1024;
            }

            importer.Seek(33280); // 33280-33535 - sprites for Miner Willy
            for (int i = 0; i < 8; i++)
            {
                byte[] sprite = importer.ReadBytes(32);
                _sprites.Add(sprite);
            }
        }

        IsReady = true;
    }
예제 #3
0
    void ImportRoom(SnapshotImporter importer, bool hasSpecialGraphic)
    {
        RoomData data = new RoomData();

        // Read in the screen attributes
        byte[] buf = importer.ReadBytes(512);
        int    i   = 0;

        //string s = "";

        for (int y = 0; y < 16; y++)
        {
            for (int x = 0; x < 32; x++)
            {
                //s += " " + buf[i];
                data.Attributes[i] = buf[i];
                i++;
            }
            //s += "\r\n";
        }

        //print(s);

        // Read in the room name
        data.RoomName = importer.ReadString(32);

        // Read in the block graphics
        for (i = 0; i < 8; i++)
        {
            // Read in the first byte that represents the attribute
            byte   attr      = importer.Read();
            byte[] blockData = importer.ReadBytes(8);
            data.Blocks[attr] = new BlockData(blockData, (BlockType)i);
        }

        // Read Miner Willy's start position

        // TODO: Read 1 byte for y-offset
        importer.Read();
        // TODO: Read 1 byte for sprite willy starts at
        importer.Read();
        // TODO: Read 1 byte for direction facing
        importer.Read();
        // TODO: Read 1 byte, should always be 0
        importer.Read();

        short     rawMWPos = importer.ReadShort();
        CellPoint startPos = new CellPoint(rawMWPos.GetX(), rawMWPos.GetY());

        data.MinerWillyStart = startPos;
        importer.Read(); // Should always be zero??

        // TODO: Conveyor belt (4 bytes for the conveyor belt)
        data.ConveyorDirection = (ConveyorDirection)importer.Read();
        importer.ReadBytes(3);

        data.BorderColour = importer.Read();

        bool addKey = true;

        for (var j = 0; j < 5; j++)
        {
            byte attr = importer.Read();
            //if (attr == 255) addKey = false;
            //if (attr == 0) addKey = false;

            byte      secondGfxBuf = importer.Read();
            short     keyPosRaw    = importer.ReadShort();
            CellPoint keyPos       = new CellPoint(keyPosRaw.GetX(), keyPosRaw.GetY());

            // read dummy byte
            int dummy = importer.Read();

            if (addKey)
            {
                data.RoomKeys.Add(new RoomKey(attr, keyPos));
            }

            addKey = true;
        }

        /*
         * Offset 628 is set at 0 in all Manic Miner rooms. Its counterpart in the runtime work area
         * (see Appendix F) "is used to decide whether or not all the items have yet been collected;
         * just before the items are displayed it is set to zero, then when an uncollected item is
         * displayed, it is changed to the attribute of that item. Thus, after printing items, if
         * this byte is still zero then all items must have been collected." [Garry Lancaster]
         *
         *  Offset 654 is always set at 255.
         */
        byte d1 = importer.Read();
        byte d2 = importer.Read();

        // PORTAL
        byte portalColour = importer.Read();

        byte[] portalShape = importer.ReadBytes(32);

        short portalPosRaw = importer.ReadShort();

        importer.ReadShort(); // Bit of a fudge, because we're gonna ignore the SECOND short...

        data.AddPortal(portalColour, portalShape, portalPosRaw.GetX(), portalPosRaw.GetY());

        data.KeyShape = importer.ReadBytes(8);

        byte airFirst  = importer.Read();
        byte airSize   = (byte)((airFirst - 32) - 4);
        byte airPixels = importer.Read();

        data.AirSupply = new AirSupply()
        {
            Length = airSize, Tip = airPixels
        };

        // Horizontal guardians
        for (int h = 0; h < 4; h++)
        {
            // TODO: Check this logic because we are getting black areas top left

            HorizontalGuardian hg = new HorizontalGuardian();
            hg.Attribute = importer.Read();
            var pos = importer.ReadShort();
            hg.StartX = pos.GetX();
            hg.StartY = pos.GetY();
            importer.Read(); // ignore this byte
            hg.StartFrame = importer.Read();
            hg.Left       = importer.Read() & 0x1f;
            hg.Right      = importer.Read() & 0x1f;

            if (hg.Attribute != 255)
            {
                data.HorizontalGuardians.Add(hg);
            }
        }

        importer.ReadBytes(3); // Always 255, and 0 and 0 Offset 730 is a terminator which is always set at 255, and Offsets 731 and 732 are 0 for all Manic Miner rooms.

        if (hasSpecialGraphic)
        {
            importer.ReadBytes(3); // ignore offsets 733, 734 and 736

            byte[] specialGraphic = importer.ReadBytes(32);
            data.SpecialGraphics.Add(specialGraphic);
        }
        else
        {
            // TODO: Vertical guardians
            for (int h = 0; h < 4; h++)
            {
                HorizontalGuardian hg = new HorizontalGuardian();
                hg.Attribute = importer.Read();
                var pos = importer.ReadShort();
                hg.StartX = pos.GetX();
                hg.StartY = pos.GetY();
                importer.Read(); // ignore this byte
                hg.StartFrame = importer.Read();
                hg.Left       = importer.Read() & 0x1f;
                hg.Right      = importer.Read() & 0x1f;

                if (hg.Attribute != 0)
                {
                    // TODO: NEED TO ADD TO VERTICAL GUARDIANS
                    //data.HorizontalGuardians.Add(hg);
                }
            }
        }

        for (int sp = 0; sp < 8; sp++)
        {
            byte[] shape = importer.ReadBytes(32);
            data.GuardianGraphics.Add(shape);
        }

        _rooms.Add(data);
    }
예제 #4
0
    void ImportRoom(SnapshotImporter importer, bool hasSpecialGraphics)
    {
        //throw new NotImplementedException();

        RoomData data = new RoomData();

        /*
         * for(int y=0; y<16; y++)
         * {
         *  for(int x=0; x<32; x++)
         *  {
         *      data.SetAttr(x, y, importer.Read());
         *  }
         * }
         */

        byte[] buf = importer.ReadBytes(512);
        int    ii  = 0;

        for (int y = 0; y < 16; y++)
        {
            for (int x = 0; x < 32; x++)
            {
                //data.SetAttr(x, y, buf[i]);
                data.Attributes[ii] = buf[ii];
                ii++;
            }
        }

        data.RoomName = importer.ReadString(32);

        for (int i = 0; i < 8; i++)
        {
            byte attr = importer.Read();

            ////SpriteTexture tex = new SpriteTexture(8, 8, Vector2.zero);
            //SpriteTexture tex = new SpriteTexture(8, 8, new Vector2(0,1));
            //tex.Clear(new Color(0,0,0,0));
            //for(int y=0; y<8; y++)
            //{
            //    tex.SetLine(y, importer.Read());
            //}

            //data.Blocks[attr] = tex.Apply();

            byte[] blockData = importer.ReadBytes(8);
            data.Blocks[attr] = new BlockData(blockData, (BlockType)i);

            // for debug only

            /*
             * GameObject go = new GameObject();
             * go.transform.position = new Vector3(i*8, _rooms.Count*8, 0);
             * var sr = go.AddComponent<SpriteRenderer>();
             * sr.sprite = data.Blocks[attr];
             */
            // /for debug only
        }

        importer.Read(); // y-offset
        importer.Read(); // starts at
        importer.Read(); // direction facing
        importer.Read(); // always 0

        // start position
        short     startPos = importer.ReadShort();
        CellPoint pos      = new CellPoint(startPos.GetX(), startPos.GetY());

        data.StartPoint = pos;

        importer.Read(); // always 0 ???

        //importer.ReadBytes(4); // (623-626) conveyor belt
        data.ConveyorDirection = (ConveyorDirection)importer.Read();
        importer.ReadBytes(3);

        data.BorderColour = importer.Read(); // border color

        // positions of the items (keys)
        bool addKey = true;

        for (int j = 0; j < 5; j++)
        {
            addKey = true; // reset value (set default)

            byte attr = importer.Read();
            //if (attr == 255) continue;
            //if (attr == 0) continue;
            //if (attr == 255) addKey = false;
            //if (attr == 0) addKey = false;

            byte      secondGfxBuf = importer.Read();
            short     keyPosRaw    = importer.ReadShort();
            CellPoint keyPos       = new CellPoint(keyPosRaw.GetX(), keyPosRaw.GetY());

            importer.Read(); // dummy byte

            if (addKey)
            {
                data.RoomKeys.Add(new RoomKey(attr, keyPos));
            }
        }

        importer.Read(); // dummy
        importer.Read(); // dummy always =255

        // PORTAL
        byte portalColour = importer.Read();               // 655

        byte[] portalShape       = importer.ReadBytes(32); // 656-687 (=687-656+1)
        short  portalPositionRaw = importer.ReadShort();   // 688-691

        importer.ReadShort();                              // skip short
        data.AddPortal(portalColour, portalShape, portalPositionRaw.GetX(), portalPositionRaw.GetY());
        // /PORTAL

        data.KeyShape = importer.ReadBytes(8); // ITEMS (keys) shape

        byte airFirst = importer.Read();
        byte airSize  = (byte)(airFirst - 32 - 4);
        byte airPixel = importer.Read();

        data.AirSupply = new AirSupply()
        {
            Length = airSize, Tip = airPixel
        };

        // GUARDIANS
        // horizontal guardians(offset 702-732)
        for (int i = 0; i < 4; i++)
        {
            // todo: check black square in room 1
            GuardianHorizontal gh = new GuardianHorizontal();
            gh.Attribute = importer.Read();
            var pos_tmp = importer.ReadShort();
            gh.StartX = pos_tmp.GetX();
            gh.StartY = pos_tmp.GetY();
            //gh.StartPoint = new CellPoint(pos_tmp.GetX(), pos_tmp.GetY());
            importer.Read(); // ignore
            gh.StartFrame = importer.Read();
            gh.Left       = importer.Read() & 0x1f;
            gh.Right      = importer.Read() & 0x1f;

            if (gh.Attribute != 255)
            {
                data.HorizontalGuardians.Add(gh);
            }
        }

        importer.ReadBytes(3); // offset 730 - 255, 731-0, 732-0

        if (hasSpecialGraphics)
        {
            importer.ReadBytes(3); // ignore offset 733, 734, 735

            // SPECIAL GRAPHICS (offset 736-767)
            byte[] specialGraphic = importer.ReadBytes(32);
            data.SpecialGraphics.Add(specialGraphic);
            // /SPECIAL GRAPHICS
        }
        else
        {
            // vertical guardians(offset 702-732)
            for (int i = 0; i < 4; i++)
            {
                GuardianHorizontal gh = new GuardianHorizontal();
                gh.Attribute = importer.Read();
                var pos_tmp = importer.ReadShort();
                gh.StartX = pos_tmp.GetX();
                gh.StartY = pos_tmp.GetY();
                //gh.StartPoint = new CellPoint(pos_tmp.GetX(), pos_tmp.GetY());
                importer.Read(); // ignore
                gh.StartFrame = importer.Read();
                gh.Left       = importer.Read() & 0x1f;
                gh.Right      = importer.Read() & 0x1f;

                if (gh.Attribute != 255)
                {
                    //data.VerticalGuardians.Add(gh);
                }
            }
        }
        // /GUARDIANS

        // GUARDIAN GRAPHICS (offset 768-1023)
        for (int i = 0; i < 8; i++)
        {
            byte[] shape = importer.ReadBytes(32);
            data.GuardianGraphics.Add(shape);
        }
        // /GUARDIAN GRAPHICS


        _rooms.Add(data);
    }