Ejemplo n.º 1
0
 private static List<Prop> LoadProps(BitStream stream)
 {
     var ret = new List<Prop>();
     var buf = new byte[4];
     stream.Read(buf, 16);
     var count = Util.MakeU16(buf);
     for (var i = 0; i < count; ++i) {
         stream.Read(buf, 32);
         var something = Util.MakeI32(buf);
         if (something >= 0) {
             var prop = new Prop();
             prop.Field4 = something;
             stream.Read(buf, 8);
             prop.LayerGroup = buf[0];
             stream.Read(buf, 8);
             prop.LayerSub = buf[0];
             prop.X = stream.ReadFloat(28, 4);
             prop.Y = stream.ReadFloat(28, 4);
             stream.Read(buf, 16);
             prop.Rotation = (float) (Util.MakeU16(buf) / 65536.0 * 2 * Math.PI);
             stream.Read(buf, 1);
             prop.FlipHorz = buf[0] == 0;  // buf[0] != 0 ? 1 : -1;
             stream.Read(buf, 1);
             prop.FlipVert = buf[0] == 0;  // buf[0] != 0 ? 1 : -1;
             stream.Read(buf, 8);
             prop.PropSet = buf[0];
             stream.Read(buf, 12);
             prop.PropGroup = Util.MakeU16(buf);
             stream.Read(buf, 12);
             prop.PropIndex = Util.MakeU16(buf);
             stream.Read(buf, 8);
             prop.Palette = buf[0];
             Trace("prop {0:N} {1:N} {2:N} {3:X8} {4:X8} {5:X2} {6:X4} {7:X4} {8:X2} {9:X2} {10:X2}",
                 prop.X, prop.Y, prop.Rotation, prop.FlipHorz, prop.FlipVert, prop.PropSet, prop.PropGroup, prop.PropIndex, prop.Palette, prop.LayerGroup, prop.LayerSub);
             ret.Add(prop);
         } else
             throw new NotImplementedException();
     }
     return ret;
 }
Ejemplo n.º 2
0
        private void DrawProp(Graphics canvas, Block block, Slice slice, Prop prop)
        {
            //Console.WriteLine("{0} {1} {2}", prop.PropGroup, prop.Y, y);
            var sprite = sprites.LoadProp(prop.PropSet, prop.PropGroup, prop.PropIndex, prop.Palette);
            if (sprite == null)
                return;

            var dstRect = new Rectangle((int) prop.X, (int) prop.Y, sprite.Hitbox.Width, sprite.Hitbox.Height);

            // no idea what the deal with this is. it isn't perfect, but it's at least closer than just using the raw numbers, usually…
            // no idea what significance the constants have.
            dstRect.Y += (dstRect.Y / 232) * 32;
            dstRect.X -= (dstRect.X / 286) * 32;

            if (prop.LayerGroup <= 5) {
                dstRect.X = (int) (dstRect.X * (0.05 * prop.LayerGroup));  // multiply the position by the layer's parallax
                dstRect.Y = (int) (dstRect.Y * (0.05 * prop.LayerGroup));
                dstRect.Width *= 2;
                dstRect.Height *= 2;
            }

            if (prop.FlipHorz)
            //                dstRect = new Rectangle(dstRect.Left                 - sprite.Hitbox.Left, dstRect.Top, -dstRect.Width, dstRect.Height);
            //                dstRect = new Rectangle(dstRect.Left - dstRect.Width - sprite.Hitbox.Left, dstRect.Top, -dstRect.Width, dstRect.Height);
            //                dstRect = new Rectangle(dstRect.Left                 - sprite.Hitbox.Left - sprite.Hitbox.Right, dstRect.Top, -dstRect.Width, dstRect.Height);
            //                dstRect = new Rectangle(dstRect.Left - dstRect.Width - sprite.Hitbox.Left - sprite.Hitbox.Right, dstRect.Top, -dstRect.Width, dstRect.Height);
            //                dstRect = new Rectangle(dstRect.Left                , dstRect.Top, -dstRect.Width, dstRect.Height);
            //                dstRect = new Rectangle(dstRect.Left + dstRect.Width, dstRect.Top, -dstRect.Width, dstRect.Height);
            //                dstRect = new Rectangle(dstRect.Left                 - sprite.Hitbox.Left, dstRect.Top, -dstRect.Width, dstRect.Height);
            //                dstRect = new Rectangle(dstRect.Left + dstRect.Width - sprite.Hitbox.Left, dstRect.Top, -dstRect.Width, dstRect.Height);
            //                dstRect = new Rectangle(dstRect.Left                 - sprite.Hitbox.Right, dstRect.Top, -dstRect.Width, dstRect.Height);
            //                dstRect = new Rectangle(dstRect.Left + dstRect.Width - sprite.Hitbox.Right, dstRect.Top, -dstRect.Width, dstRect.Height);
            //                dstRect = new Rectangle(dstRect.Left                 - sprite.Hitbox.Left - sprite.Hitbox.Right, dstRect.Top, -dstRect.Width, dstRect.Height);
                dstRect = new Rectangle(dstRect.Right - sprite.Hitbox.Left - sprite.Hitbox.Right, dstRect.Top, -dstRect.Width, dstRect.Height);
            if (prop.FlipVert)
                dstRect = new Rectangle(dstRect.Left, dstRect.Bottom - sprite.Hitbox.Top - sprite.Hitbox.Bottom, dstRect.Width, -dstRect.Height);

            //var attrs = new ImageAttributes();
            //attrs.SetColorMatrix(MakeFogMatrix(prop.LayerGroup));

            dstRect.X += sprite.Hitbox.Left;
            dstRect.Y += sprite.Hitbox.Top;
            dstRect.X -= (block.X * App.SlicesPerBlock + slice.Header.X) * App.PixelsPerSlice;
            dstRect.Y -= (block.Y * App.SlicesPerBlock + slice.Header.Y) * App.PixelsPerSlice;
            dstRect.X += sliceOverdraw;
            dstRect.Y += sliceOverdraw;
            canvas.DrawImage(sprite.Image, dstRect, 0, 0, sprite.Hitbox.Width, sprite.Hitbox.Height, GraphicsUnit.Pixel);
        }