public Object(Reader reader)
        {
            cur_id++;
            id = cur_id;

            // Object type, 1 byte, unsigned
            type = reader.ReadByte();
            // Object subtype, 1 byte, unsigned
            subtype = reader.ReadByte();

            // X Position, 2 bytes, big-endian, signed
            xPos  = (short)(reader.ReadSByte() << 8);
            xPos |= (short)reader.ReadByte();

            // Y Position, 2 bytes, big-endian, signed
            yPos  = (short)(reader.ReadSByte() << 8);
            yPos |= (short)reader.ReadByte();

            Console.WriteLine(id + " Obj Values: Type: " + type + ", Subtype: " + subtype + ", Xpos = " + xPos + ", Ypos = " + yPos);
        }
Example #2
0
        public Level(Reader reader)
        {
            Title = reader.ReadRSDKString();
            Console.WriteLine(Title);
            byte[] buffer = new byte[5];
            reader.Read(displayBytes, 0, 5); //Waste 5 bytes, I don't care about them right now.
            //The first 4 bytes are loaded into StageSystem.ActiveTileLayers. 5th byte is tLayerMidPoint.
            //If you want to know the values then look at the values for "DisplayBytes"
            reader.Read(buffer, 0, 2); //Read size

            width = 0; height = 0;


            // Map width in 128 pixel units
            // In RSDKv2, it's one byte long
            width  = buffer[0];
            height = buffer[1];

            MapLayout = new ushort[height][];
            for (int i = 0; i < height; i++)
            {
                MapLayout[i] = new ushort[width];
            }

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    // 128x128 Block number is 16-bit
                    // Big-Endian in RSDKv2 and RSDKv3
                    reader.Read(buffer, 0, 2); //Read size
                    MapLayout[y][x] = (ushort)(buffer[1] + (buffer[0] << 8));
                }
            }


            // Read number of object types, Only RSDKv2 and RSDKv3 support this feature
            int ObjTypeCount = reader.ReadByte();

            for (int n = 0; n < ObjTypeCount; n++)
            {
                string name = reader.ReadRSDKString();

                objectTypeNames.Add(name);
                Console.WriteLine(name);
            }
            // Read object data

            int ObjCount = 0;

            // 2 bytes, big-endian, unsigned
            ObjCount  = reader.ReadByte() << 8;
            ObjCount |= reader.ReadByte();

            int obj_type    = 0;
            int obj_subtype = 0;
            int obj_xPos    = 0;
            int obj_yPos    = 0;

            for (int n = 0; n < ObjCount; n++)
            {
                // Object type, 1 byte, unsigned
                obj_type = reader.ReadByte();
                // Object subtype, 1 byte, unsigned
                obj_subtype = reader.ReadByte();

                // X Position, 2 bytes, big-endian, signed
                obj_xPos  = reader.ReadSByte() << 8;
                obj_xPos |= reader.ReadByte();

                // Y Position, 2 bytes, big-endian, signed
                obj_yPos  = reader.ReadSByte() << 8;
                obj_yPos |= reader.ReadByte();

                // Add object
                objects.Add(new Object(obj_type, obj_subtype, obj_xPos, obj_yPos));
            }
            reader.Close();
        }