private static Slice LoadSlice(BitStream stream) { var slice = new Slice(); slice.Header = ReadSliceHeader(stream); Trace("slice {0:X4} {1:X2} {2:X2} {3:X2} {4:X8} {5} {6} {7} {8}", slice.Header.Field8, slice.Header.X, slice.Header.Y, slice.Header.FieldC, slice.Header.Field14, slice.Header.FilthCount, slice.Header.EnemyCount, slice.Header.TileEdgeCount, slice.Header.FilthBlocks); // Trace(header.Kinds); if ((slice.Header.Kinds & 1) != 0) slice.Tiles = LoadTiles(stream); if ((slice.Header.Kinds & 2) != 0) slice.Filth = LoadFilth(stream); if ((slice.Header.Kinds & 8) != 0) slice.Props = LoadProps(stream); if ((slice.Header.Kinds & 4) != 0) slice.Entities = LoadEntities(stream); return slice; }
private bool DrawTiles(Graphics canvas, Slice slice, byte layer) { var tiles = slice.Tiles.Where(t => t.Layer == layer).ToArray(); if (tiles.Length == 0) return false; var attrs = new ImageAttributes(); //attrs.SetColorMatrix(MakeFogMatrix(layer)); foreach (var tile in tiles) DrawTileCenter(canvas, tile, tileShapes[tile.Shape], attrs); foreach (var tile in tiles) DrawTileBottomEdge(canvas, tile, tileShapes[tile.Shape], attrs); foreach (var tile in tiles) DrawTileLeftEdge(canvas, tile, tileShapes[tile.Shape], attrs); foreach (var tile in tiles) DrawTileRightEdge(canvas, tile, tileShapes[tile.Shape], attrs); foreach (var tile in tiles) DrawTileTopEdge(canvas, tile, tileShapes[tile.Shape], attrs); return true; }
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); }
private bool DrawProps(Graphics canvas, Block block, Slice slice, int layer) { var drewAnything = false; // foreach (var prop in slice.Props) { // if (prop.LayerGroup == layer) { // DrawProp(canvas, block, slice, prop); // drewAnything = true; // } // } // TODO: this is garbage; optimize this foreach (var b in level.Blocks) foreach (var s in b.Slices) foreach (var p in s.Props) if (p.LayerGroup == layer) { DrawProp(canvas, block, slice, p); drewAnything = true; } return drewAnything; }
private void DrawFilth(Graphics canvas, Slice slice, Filth filth) { var tile = slice.Tiles.First(t => t.Layer == 19 && t.X == filth.X && t.Y == filth.Y); var shape = tileShapes[tile.Shape]; DrawFilth(canvas, tile, shape.Bottom, (filth.Edges >> 4) & 0xf, (filth.EndCaps >> 2) & 0x3); DrawFilth(canvas, tile, shape.Left, (filth.Edges >> 8) & 0xf, (filth.EndCaps >> 4) & 0x3); DrawFilth(canvas, tile, shape.Right, (filth.Edges >> 12) & 0xf, (filth.EndCaps >> 6) & 0x3); DrawFilth(canvas, tile, shape.Top, (filth.Edges >> 0) & 0xf, (filth.EndCaps >> 0) & 0x3); }