private Vector3 ToWorldPos(int x, int y, int z, int level, float pitch) { return(new Vector3((x / 16f) * 3f, (z * pitch / 16f) * 3f + ((level - 1) * 2.95f * 3f) + blueprint.GetAltitude(x / 16, y / 16) * 3, (y / 16f) * 3f)); }
public override void Draw(GraphicsDevice device, WorldState world) { if (ArchZBuffers == null) { ArchZBuffers = TextureGenerator.GetWallZBuffer(device); } var pxOffset = world.WorldSpace.GetScreenOffset(); var floorContent = Content.Content.Get().WorldFloors; Rectangle db; if (DrawBound == null) { db = new Rectangle(0, 0, blueprint.Width, blueprint.Height); } else { db = DrawBound.Value; } for (sbyte level = 1; level <= world.Level; level++) { for (short y = (short)db.Top; y < db.Bottom; y++) { //ill decide on a reasonable system for components when it's finished ok pls :( for (short x = (short)db.Left; x < db.Right; x++) { var comp = blueprint.GetFloor(x, y, level); if (comp.Pattern != 0) { ushort room = (ushort)blueprint.RoomMap[level - 1][x + y * blueprint.Width]; var tilePosition = new Vector3(x, y, (level - 1) * 2.95f + blueprint.GetAltitude(x, y)); world._2D.OffsetPixel(world.WorldSpace.GetScreenFromTile(tilePosition)); world._2D.OffsetTile(tilePosition); if (comp.Pattern > 65533) { //determine adjacent pool tiles int poolAdj = 0; for (int i = 0; i < PoolDirections.Length; i++) { var testTile = new Point(x, y) + PoolDirections[i]; if ((testTile.X <= 0 || testTile.X >= blueprint.Width - 1) || (testTile.Y <= 0 || testTile.Y >= blueprint.Height - 1) || blueprint.GetFloor((short)testTile.X, (short)testTile.Y, level).Pattern == comp.Pattern) { poolAdj |= 1 << i; } } var adj = RotatePoolSegs((PoolSegments)poolAdj, (int)world.Rotation); //get and draw the base tile int spriteNum = 0; if ((adj & PoolSegments.TopRight) > 0) { spriteNum |= 1; } if ((adj & PoolSegments.TopLeft) > 0) { spriteNum |= 2; } if ((adj & PoolSegments.BottomLeft) > 0) { spriteNum |= 4; } if ((adj & PoolSegments.BottomRight) > 0) { spriteNum |= 8; } var _Sprite = world._2D.NewSprite(_2DBatchRenderMode.Z_BUFFER); SPR2 sprite = null; int baseSPR; int frameNum = 0; switch (world.Zoom) { case WorldZoom.Far: baseSPR = (comp.Pattern == 65535) ? 0x400 : 0x800; frameNum = (comp.Pattern == 65535) ? 0 : 2; sprite = floorContent.GetGlobalSPR((ushort)(baseSPR + spriteNum)); _Sprite.DestRect = FLOORDEST_FAR; _Sprite.Depth = ArchZBuffers[14]; break; case WorldZoom.Medium: baseSPR = (comp.Pattern == 65535) ? 0x410 : 0x800; frameNum = (comp.Pattern == 65535) ? 0 : 1; sprite = floorContent.GetGlobalSPR((ushort)(baseSPR + spriteNum)); _Sprite.DestRect = FLOORDEST_MED; _Sprite.Depth = ArchZBuffers[13]; break; case WorldZoom.Near: baseSPR = (comp.Pattern == 65535) ? 0x420 : 0x800; sprite = floorContent.GetGlobalSPR((ushort)(baseSPR + spriteNum)); _Sprite.DestRect = FLOORDEST_NEAR; _Sprite.Depth = ArchZBuffers[12]; break; } _Sprite.Pixel = world._2D.GetTexture(sprite.Frames[frameNum]); _Sprite.SrcRect = new Microsoft.Xna.Framework.Rectangle(0, 0, _Sprite.Pixel.Width, _Sprite.Pixel.Height); _Sprite.Room = room; _Sprite.Floor = level; world._2D.Draw(_Sprite); //draw any corners on top if (comp.Pattern == 65535) { PoolSegments[] CornerChecks = { (PoolSegments.TopLeft | PoolSegments.TopRight), (PoolSegments.TopLeft | PoolSegments.BottomLeft), (PoolSegments.BottomLeft | PoolSegments.BottomRight), (PoolSegments.TopRight | PoolSegments.BottomRight) }; if ((adj & CornerChecks[0]) == CornerChecks[0] && (adj & PoolSegments.Top) == 0) { //top corner var tcS = world._2D.NewSprite(_2DBatchRenderMode.Z_BUFFER); //base sprite position on base tile sprite = floorContent.GetGlobalSPR((ushort)(0x430 + ((int)world.Zoom - 1) * 4)); tcS.Pixel = world._2D.GetTexture(sprite.Frames[0]); tcS.DestRect = new Rectangle(_Sprite.DestRect.Center.X - tcS.Pixel.Width / 2, _Sprite.DestRect.Y, tcS.Pixel.Width, tcS.Pixel.Height); tcS.SrcRect = new Microsoft.Xna.Framework.Rectangle(0, 0, tcS.Pixel.Width, tcS.Pixel.Height); tcS.Depth = ArchZBuffers[21 + (3 - (int)world.Zoom)]; tcS.Room = room; tcS.Floor = level; world._2D.Draw(tcS); } if ((adj & CornerChecks[1]) == CornerChecks[1] && (adj & PoolSegments.Left) == 0) { //left corner var tcS = world._2D.NewSprite(_2DBatchRenderMode.Z_BUFFER); //base sprite position on base tile sprite = floorContent.GetGlobalSPR((ushort)(0x431 + ((int)world.Zoom - 1) * 4)); tcS.Pixel = world._2D.GetTexture(sprite.Frames[0]); tcS.DestRect = new Rectangle(_Sprite.DestRect.X, _Sprite.DestRect.Center.Y + 1 - tcS.Pixel.Height / 2, tcS.Pixel.Width, tcS.Pixel.Height); tcS.SrcRect = new Microsoft.Xna.Framework.Rectangle(0, 0, tcS.Pixel.Width, tcS.Pixel.Height); tcS.Depth = ArchZBuffers[24 + (3 - (int)world.Zoom)]; tcS.Room = room; tcS.Floor = level; world._2D.Draw(tcS); } if ((adj & CornerChecks[2]) == CornerChecks[2] && (adj & PoolSegments.Bottom) == 0) { //bottom corner var tcS = world._2D.NewSprite(_2DBatchRenderMode.Z_BUFFER); //base sprite position on base tile sprite = floorContent.GetGlobalSPR((ushort)(0x432 + ((int)world.Zoom - 1) * 4)); tcS.Pixel = world._2D.GetTexture(sprite.Frames[0]); tcS.DestRect = new Rectangle(_Sprite.DestRect.Center.X - tcS.Pixel.Width / 2, _Sprite.DestRect.Bottom - tcS.Pixel.Height, tcS.Pixel.Width, tcS.Pixel.Height); tcS.SrcRect = new Microsoft.Xna.Framework.Rectangle(0, 0, tcS.Pixel.Width, tcS.Pixel.Height); tcS.Depth = ArchZBuffers[27 + (3 - (int)world.Zoom)]; tcS.Room = room; tcS.Floor = level; world._2D.Draw(tcS); } if ((adj & CornerChecks[3]) == CornerChecks[3] && (adj & PoolSegments.Right) == 0) { //right corner var tcS = world._2D.NewSprite(_2DBatchRenderMode.Z_BUFFER); //base sprite position on base tile sprite = floorContent.GetGlobalSPR((ushort)(0x433 + ((int)world.Zoom - 1) * 4)); tcS.Pixel = world._2D.GetTexture(sprite.Frames[0]); tcS.DestRect = new Rectangle(_Sprite.DestRect.Right - tcS.Pixel.Width, _Sprite.DestRect.Center.Y + 1 - tcS.Pixel.Height / 2, tcS.Pixel.Width, tcS.Pixel.Height); tcS.SrcRect = new Microsoft.Xna.Framework.Rectangle(0, 0, tcS.Pixel.Width, tcS.Pixel.Height); tcS.Depth = ArchZBuffers[24 + (3 - (int)world.Zoom)]; tcS.Room = room; tcS.Floor = level; world._2D.Draw(tcS); } } } else { var floor = GetFloorSprite(floorContent.Get(comp.Pattern), 0, world); floor.Room = room; floor.Floor = level; if (floor.Pixel != null) { world._2D.Draw(floor); } } } else if (world.BuildMode > 1 && level > 1 && blueprint.Supported[level - 2][y * blueprint.Height + x]) { var tilePosition = new Vector3(x, y, (level - 1) * 2.95f + blueprint.GetAltitude(x, y)); world._2D.OffsetPixel(world.WorldSpace.GetScreenFromTile(tilePosition)); world._2D.OffsetTile(tilePosition); var floor = GetAirSprite(world); floor.Room = 65535; floor.Floor = level; if (floor.Pixel != null) { world._2D.Draw(floor); } } } } } }