public Bitmap drawEntities(Bitmap image, List <Entity> entities) { FastPixel fp = new FastPixel(image); fp.rgbValues = new byte[160 * 128 * 4]; fp.Lock(); foreach (Entity selectedEntity in entities) { FastPixel src = new FastPixel(selectedEntity.sprite); src.rgbValues = new byte[16 * 16 * 4]; src.Lock(); int x = selectedEntity.xPos * 16; int y = selectedEntity.yPos * 16; if (selectedEntity.yPos < 8) { if (selectedEntity.xPos < 10) { for (int yy = 0; yy < 16; yy++) { for (int xx = 0; xx < 16; xx++) { try { if (src.GetPixel(xx, yy).A == 0) { continue; } fp.SetPixel(x + xx, y + yy, src.GetPixel(xx, yy)); } catch { System.Console.WriteLine("Out of bounds Y or X position."); break; } } } } } src.Unlock(true); } fp.Unlock(true); return(image); }
public Bitmap drawMap(Bitmap tiles, byte[] mapData) { Bitmap bmp = new Bitmap(160, 128); FastPixel fp = new FastPixel(bmp); FastPixel src = new FastPixel(tiles); fp.rgbValues = new byte[160 * 128 * 4]; src.rgbValues = new byte[256 * 256 * 4]; fp.Lock(); src.Lock(); for (int y = 0; y < 8; y++) { for (int x = 0; x < 10; x++) { byte v = mapData[x + (y * 10)]; for (int yy = 0; yy < 16; yy++) { for (int xx = 0; xx < 16; xx++) { fp.SetPixel(x * 16 + xx, y * 16 + yy, src.GetPixel((v % 16) * 16 + xx, (v / 16) * 16 + yy)); } } } } fp.Unlock(true); src.Unlock(true); return(bmp); }
public Bitmap DrawCollisions(Bitmap tiles, byte[] mapData, bool borders) { Bitmap b = new Bitmap(160, 128); FastPixel fp = new FastPixel(b); FastPixel src = new FastPixel(tiles); src.rgbValues = new byte[256 * 256 * 4]; fp.rgbValues = new byte[160 * 128 * 4]; fp.Lock(); src.Lock(); for (int y = 0; y < 8; y++) { for (int x = 0; x < 10; x++) { byte id = mapData[x + (y * 10)]; for (int yy = 0; yy < 16; yy++) { for (int xx = 0; xx < 16; xx++) { fp.SetPixel(x * 16 + xx, y * 16 + yy, src.GetPixel((id % 16) * 16 + xx, (id / 16) * 16 + yy)); } } } } fp.Unlock(true); src.Unlock(true); if (borders) { drawBorders(b); } return(b); }