public Bytemap GetLetter(char character, byte colour) { if (!_characters.ContainsKey(character)) { return(new Bytemap(7, 7)); } bool[,] pixels = _characters[character]; Bytemap output = new Bytemap(pixels.GetLength(0), pixels.GetLength(1)); for (int yy = 0; yy < pixels.GetLength(1); yy++) { for (int xx = 0; xx < pixels.GetLength(0); xx++) { output[xx, yy] = (byte)(pixels[xx, yy] ? colour : 0); } } return(output); }
public static IBitmap UnitsToPicture(this ITile tile) { if (tile == null || tile.Units.Length == 0 || (tile.Units.Length == 1 && tile.Units[0] == Game.MovingUnit)) { return(null); } IUnit[] units = tile.Units.OrderBy(x => (tile.IsOcean && x.Class == UnitClass.Water) ? 1 : 0).Where(x => x != Game.MovingUnit).ToArray(); if (units.Length == 0) { return(null); } bool stack = (units.Length > 1); IUnit unit = units.First(); if (tile.IsOcean) { unit = units.FirstOrDefault(x => x.Class == UnitClass.Water) ?? units.FirstOrDefault(x => !(x.Class == UnitClass.Land && x.Sentry)); } if (Game.Started && Game.ActiveUnit != null && !Game.ActiveUnit.Moving && Game.ActiveUnit.X == tile.X && Game.ActiveUnit.Y == tile.Y) { unit = Game.ActiveUnit; } if (unit == null) { return(null); } IBitmap output = new Picture(16, 16, Palette); Bytemap unitPicture = unit.ToBitmap(); if (tile.City == null) { output.AddLayer(unitPicture); } if (stack || tile.City != null) { output.AddLayer(unitPicture, -1, -1); } return(output); }
private static void DrawCoastSegments(ref Bytemap output, Direction land) { if (!Resources.Exists("TER257")) { return; } Bytemap pic = Resources["TER257"].Bitmap; if (land.And(North)) { int xw = land.And(West) ? 80 : land.And(NorthWest) ? 96 : 64; int xe = land.And(East) ? 88 : land.And(NorthEast) ? 56 : 24; output.AddLayer(pic[xw, 176, 8, 8], 0, 0); output.AddLayer(pic[xe, 176, 8, 8], 8, 0); } if (land.And(East)) { int xn = land.And(North) ? 88 : land.And(NorthEast) ? 104 : 72; int xs = land.And(South) ? 88 : land.And(SouthEast) ? 56 : 24; output.AddLayer(pic[xn, 176, 8, 8], 8, 0); output.AddLayer(pic[xs, 184, 8, 8], 8, 8); } if (land.And(South)) { int xw = land.And(West) ? 80 : land.And(SouthWest) ? 48 : 16; int xe = land.And(East) ? 88 : land.And(SouthEast) ? 104 : 72; output.AddLayer(pic[xw, 184, 8, 8], 0, 8); output.AddLayer(pic[xe, 184, 8, 8], 8, 8); } if (land.And(West)) { int xn = land.And(North) ? 80 : land.And(NorthWest) ? 48 : 16; int xs = land.And(South) ? 80 : land.And(SouthWest) ? 96 : 64; output.AddLayer(pic[xn, 176, 8, 8], 0, 0); output.AddLayer(pic[xs, 184, 8, 8], 0, 8); } }
/// <summary> /// Read the 4-bit image into a 2D byte array. /// </summary> /// <param name="index">Current file reading index.</param> private void ReadPictureX1(ref int index) { uint length = BitConverter.ToUInt16(_bytes, index); index += 2; int width = BitConverter.ToUInt16(_bytes, index); index += 2; int height = BitConverter.ToUInt16(_bytes, index); index += 2; _picture16?.Dispose(); _picture16 = new Bytemap(width, height); byte[] image = DecodePicture(ref index, length); int c = 0; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { _picture16[x++, y] = (byte)(image[c] & 0x0F); _picture16[x, y] = (byte)((image[c++] & 0xF0) >> 4); } } }
public static Bytemap MatchColours(this IBitmap input, Palette palette, int startIndex, int length) { Dictionary <int, int> matches = new Dictionary <int, int>(); Colour[] pal = input.Palette.Entries.ToArray(); Colour[] cmp = palette.Entries.ToArray(); for (int i = 0; i < pal.Length; i++) { if (pal[i].A == 0) { matches.Add(i, 0); continue; } int entry = 0; int mx = 768; for (int j = startIndex; j < cmp.Length && j < (startIndex + length); j++) { int total = Math.Abs((int)pal[i].R - cmp[j].R) + Math.Abs((int)pal[i].G - cmp[j].G) + Math.Abs((int)pal[i].B - cmp[j].B); if (total >= mx) { continue; } entry = j; mx = total; } matches.Add(i, entry); } Bytemap output = new Bytemap(input.Width(), input.Height()); for (int yy = 0; yy < input.Height(); yy++) { for (int xx = 0; xx < input.Height(); xx++) { output[xx, yy] = (byte)matches[input.Bitmap[xx, yy]]; } } return(output); }
private void LoadMap(Bytemap bitmap) { _tiles = new ITile[WIDTH, HEIGHT]; for (int x = 0; x < WIDTH; x++) { for (int y = 0; y < HEIGHT; y++) { ITile tile; bool special = TileIsSpecial(x, y); switch (bitmap[x, y]) { case 2: tile = new Forest(x, y, special); break; case 3: tile = new Swamp(x, y, special); break; case 6: tile = new Plains(x, y, special); break; case 7: tile = new Tundra(x, y, special); break; case 9: tile = new River(x, y); break; case 10: tile = new Grassland(x, y); break; case 11: tile = new Jungle(x, y, special); break; case 12: tile = new Hills(x, y, special); break; case 13: tile = new Mountains(x, y, special); break; case 14: tile = new Desert(x, y, special); break; case 15: tile = new Arctic(x, y, special); break; default: tile = new Ocean(x, y, special); break; } _tiles[x, y] = tile; } } }
/// <summary> /// Generate a 4-bit image from the 8-bit image and colourtable. /// </summary> /// <param name="colourTable">Colour table that was generated</param> private void ConvertPictureX0(byte[,] colourTable) { if (colourTable == null) { return; } int width = _picture256.Width; int height = _picture256.Height; _picture16?.Dispose(); _picture16 = new Bytemap(width, height); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { byte col256 = _picture256[x, y]; _picture16[x, y] = colourTable[col256, (y + x) % 2]; } } }
public static IBitmap Tile(this IBitmap bitmap, Bytemap layer, int left = 0, int top = 0, int width = -1, int height = -1) { if (layer == null) { return(bitmap); } if (width == -1) { width = bitmap.Width() - left; } if (height == -1) { height = bitmap.Height() - top; } for (int yy = 0; yy < height; yy++) { if (top + yy >= bitmap.Height()) { break; } if (bitmap.OutBoundY(top + yy)) { continue; } for (int xx = 0; xx < width; xx++) { if (left + xx >= bitmap.Width()) { break; } if (layer[xx % layer.Width, yy % layer.Height] == 0 || bitmap.OutBoundX(left + xx)) { continue; } bitmap.Bitmap[left + xx, top + yy] = layer[xx % layer.Width, yy % layer.Height]; } } return(bitmap); }
public Bytemap Fog(Direction direction) { Bytemap output = new Bytemap(16, 16); switch (direction) { case Direction.West: output.AddLayer(new Bytemap(3, 16).FromByteArray(GenerateNoise(0, 28, 29, 30, 31).Take(3 * 16).ToArray()), 0, 0); break; case Direction.South: output.AddLayer(new Bytemap(16, 3).FromByteArray(GenerateNoise(28, 0, 29, 30, 31).Take(16 * 3).ToArray()), 0, 13); break; case Direction.East: output.AddLayer(new Bytemap(3, 16).FromByteArray(GenerateNoise(28, 29, 0, 30, 31).Take(3 * 16).ToArray()), 13, 0); break; case Direction.North: output.AddLayer(new Bytemap(16, 3).FromByteArray(GenerateNoise(28, 29, 30, 0, 31).Take(16 * 3).ToArray()), 0, 0); break; } return(output); }
private Tuple <DirectBitmap, SimpleDatum> getData(COLORTYPE ct, int nWid, int nHt, int nOffset, int nDownsample, byte[] rg, bool bPreprocess, bool bGetAction, bool bForceGray) { int nChannels = (bPreprocess || bForceGray) ? 1 : 3; int nSize = Math.Min(nWid, nHt); int nDsSize = nSize / nDownsample; int nX = 0; int nY = 0; bool bY = false; bool bX = false; if (m_bmpRaw != null && (m_bmpRaw.Width != nWid || m_bmpRaw.Height != nHt)) { m_bmpRaw.Dispose(); m_bmpRaw = null; } if (m_bmpActionRaw != null && (m_bmpActionRaw.Width != nDsSize || m_bmpActionRaw.Height != nDsSize)) { m_bmpActionRaw.Dispose(); m_bmpActionRaw = null; } if (m_bmpRaw == null) { m_bmpRaw = new DirectBitmap(nWid, nHt); } if (m_bmpActionRaw == null) { m_bmpActionRaw = new DirectBitmap(nDsSize, nDsSize); } DirectBitmap bmp = m_bmpRaw; Valuemap dataV = null; Bytemap dataB = null; if (bGetAction) { if (m_bPreprocess) { dataV = new Valuemap(nChannels, nDsSize, nDsSize); } else { dataB = new Bytemap(nChannels, nDsSize, nDsSize); } } for (int y = 0; y < nHt; y++) { if (y % nDownsample == 0 && y > nOffset && y < nOffset + nSize) { bY = true; } else { bY = false; } for (int x = 0; x < nWid; x++) { int nIdx = (y * nWid) + x; int nR = rg[nIdx]; int nG = nR; int nB = nR; if (x % nDownsample == 0) { bX = true; } else { bX = false; } if (ct == COLORTYPE.CT_COLOR) { nG = rg[nIdx + (nWid * nHt * 1)]; nB = rg[nIdx + (nWid * nHt * 2)]; } Color clr = Color.FromArgb(nR, nG, nB); bmp.SetPixel(x, y, clr); if (bForceGray) { int nClr = (nR + nG + nB) / 3; clr = Color.FromArgb(nClr, nClr, nClr); } if (bY && bX && (dataB != null || dataV != null)) { if (bPreprocess) { if (nR != 144 && nR != 109 && nR != 0) { dataV.SetPixel(nX, nY, 1.0); } } else { dataB.SetPixel(nX, nY, clr); } nX++; } } if (bY) { nX = 0; nY++; } } SimpleDatum sd = null; if (m_bPreprocess) { if (dataV != null) { sd = new SimpleDatum(dataV); } } else { if (dataB != null) { sd = new SimpleDatum(dataB); } } return(new Tuple <DirectBitmap, SimpleDatum>(bmp, sd)); }
protected override bool HasUpdate(uint gameTick) { if (HasMenu) { return(false); } if (_difficulty == -1) { MenuDifficulty(); } else if (_competition == -1) { MenuCompetition(); } else if (_tribe == -1) { MenuTribe(); } else if (_leaderName == null) { InputLeaderName(); } else if (!_done) { if (_showIntroText) { return(false); } ICivilization civ = _tribesAvailable[_tribe]; Game.CreateGame(_difficulty, _competition, civ, _leaderName, _tribeName, _tribeNamePlural); this.Clear(15); DrawBorder(Common.Random.Next(2)); this.AddLayer(DifficultyPicture, OffsetX + 134, OffsetY + 20); int yy = OffsetY + 81; foreach (string textLine in TextFile.Instance.GetGameText("KING/INIT")) { string line = textLine.Replace("$RPLC1", Human.LeaderName).Replace("$US", Human.TribeNamePlural).Replace("^", ""); this.DrawText(line, 0, 5, OffsetX + 88, yy); yy += 8; Log(line); } StringBuilder sb = new StringBuilder(); int i = 0; foreach (IAdvance advance in Human.Advances.OrderBy(a => a.Id)) { sb.Append($"{advance.Name}, "); i++; if (i % 2 == 0) { sb.Append("|"); } } sb.Append("and Roads."); foreach (string line in sb.ToString().Split('|')) { this.DrawText(line, 0, 5, OffsetX + 88, yy); Log(line); yy += 8; } PlaySound(Human.Civilization.Tune); _showIntroText = true; return(true); } else if (HandleScreenFadeOut()) { return(true); } else { Destroy(); GamePlay gamePlay = new GamePlay(); Common.AddScreen(gamePlay); IUnit startUnit = Game.GetUnits().First(x => Game.Human == x.Owner); gamePlay.CenterOnPoint(startUnit.X, startUnit.Y); if (Game.InstantAdvice) { GameTask.Enqueue(Show.InterfaceHelp); GameTask.Enqueue(Message.Help("--- Civilization Note ---", TextFile.Instance.GetGameText("HELP/FIRSTMOVE"))); } return(true); } if (_tribe != -1 && _tribeName == null) { DrawInputBox("Name of your Tribe..."); return(true); } // Draw background Bitmap = new Bytemap(Width, Height); if (_difficulty == -1) { this.AddLayer(_background, OffsetX, OffsetY); } else { if (_tribe == -1) { this.AddLayer(_background[140, 0, 180, 200], OffsetX + 140, OffsetY); } int pictureStack = (_competition <= 0) ? 1 : _competition; for (int i = pictureStack; i > 0; i--) { this.AddLayer(DifficultyPicture, OffsetX + 22 + (i * 2), OffsetY + 100 + (i * 3)); } if (_tribe != -1 && _leaderName == null) { this.DrawText(_tribeNamePlural, 6, 15, OffsetX + 47, OffsetY + 92, TextAlign.Center); DrawInputBox("Your Name..."); } } return(true); }
internal Sprite(Bytemap bitmap) { Bitmap = bitmap; }
public static IBitmap Tile(this IBitmap bitmap, Bytemap layer, Point point, Size size) => Tile(bitmap, layer, point.X, point.Y, size.Width, size.Height);
public void Resize(int width) { Bitmap = new Bytemap(width, 97); _update = true; }
private void Resize(int width, int height) { Bitmap = new Bytemap(width, height); OnResize?.Invoke(this, new ResizeEventArgs(width, height)); }
public ushort SaveMap(string filename) { Log($"Map: Saving {filename} - Random seed: {_terrainMasterWord}"); using (Bytemap bitmap = Resources["SP299"].Bitmap) { // Save terrainlayer for (int x = 0; x < WIDTH; x++) { for (int y = 0; y < HEIGHT; y++) { byte b; switch (_tiles[x, y].Type) { case Terrain.Forest: b = 2; break; case Terrain.Swamp: b = 3; break; case Terrain.Plains: b = 6; break; case Terrain.Tundra: b = 7; break; case Terrain.River: b = 9; break; case Terrain.Grassland1: case Terrain.Grassland2: b = 10; break; case Terrain.Jungle: b = 11; break; case Terrain.Hills: b = 12; break; case Terrain.Mountains: b = 13; break; case Terrain.Desert: b = 14; break; case Terrain.Arctic: b = 15; break; default: b = 1; break; // Ocean } bitmap[x, y] = b; } } // Save improvement layer for (int x = 0; x < WIDTH; x++) { for (int y = 0; y < HEIGHT; y++) { byte b = 0; if (_tiles[x, y].City != null) { b |= 0x01; } if (_tiles[x, y].Irrigation) { b |= 0x02; } if (_tiles[x, y].Mine) { b |= 0x04; } if (_tiles[x, y].Road) { b |= 0x08; } bitmap[x, y + (HEIGHT * 2)] = b; bitmap[x + (WIDTH * 1), y + (HEIGHT * 2)] = b; // Visibility layer } } // Save improvement layer 2 for (int x = 0; x < WIDTH; x++) { for (int y = 0; y < HEIGHT; y++) { byte b = 0; if (_tiles[x, y].RailRoad) { b |= 0x01; } bitmap[x, y + (HEIGHT * 3)] = b; bitmap[x + (WIDTH * 1), y + (HEIGHT * 3)] = b; // Visibility layer } } // Save explored layer for (int x = 0; x < WIDTH; x++) { for (int y = 0; y < HEIGHT; y++) { bitmap[x + (WIDTH * 2), y] = _tiles[x, y].Visited; } } using (Picture picture = new Picture(bitmap, Resources["SP299"].Palette)) { PicFile picFile = new PicFile(picture) { HasPalette256 = false }; using (BinaryWriter bw = new BinaryWriter(File.Open(filename, FileMode.Create))) { bw.Write(picFile.GetBytes()); } return((ushort)_terrainMasterWord); } } }
public PicFile(string filename) { filename = GetFilename(filename); // generate an exception if the file is not found if (RuntimeHandler.Runtime.Settings.Free || !File.Exists(filename)) { if (!File.Exists(filename)) { Log($"File not found: {filename.ToUpper()}.PIC"); } HasPalette16 = true; HasPalette256 = true; _palette256 = Common.GetPalette256; _picture16 = new Bytemap(320, 200); _picture256 = new Bytemap(320, 200); for (int yy = 0; yy < 200; yy++) { for (int xx = 0; xx < 320; xx++) { _picture16[xx, yy] = 1; _picture256[xx, yy] = 1; } } return; } // read all bytes into a byte array using (FileStream fs = new FileStream(filename, FileMode.Open)) { _bytes = new byte[fs.Length]; fs.Read(_bytes, 0, _bytes.Length); } int index = 0; while (index < (_bytes.Length - 1)) { uint magicCode = BitConverter.ToUInt16(_bytes, index); index += 2; switch (magicCode) { case 0x3045: _colourTable = ReadColourTable(ref index); HasPalette16 = true; break; case 0x304D: ReadColourPalette(ref index); HasPalette256 = true; break; case 0x3058: ReadPictureX0(ref index); ConvertPictureX0(_colourTable); HasPicture256 = true; break; case 0x3158: ReadPictureX1(ref index); HasPicture16 = true; break; } } Log($"Loaded {filename}"); }
protected Texture CreateTexture(Palette palette, Bytemap bytemap) => new Texture(_renderer, palette, bytemap);
//for editing public override void ConvertChrToMem(Byte[] data, int addr, Bytemap bytemap, int px, int py) { for (int i = 0; i < base.CharHeight; i++) { int index = (i * 16) + addr; int pointAddress = bytemap.GetPointAddress(px, py + i); byte num1 = 0; byte num2 = 0; byte num3 = 0; byte num4 = 0; for (int j = 0; j < 8; j++) { byte num9 = (byte)(bytemap.Data[pointAddress++]); byte num20 = (byte)(num9 & 1); byte num21 = (byte)((num9 >> 1) & 1); byte num22 = (byte)((num9 >> 2) & 1); byte num23 = (byte)((num9 >> 3) & 1); num1 = (byte)(num1 | ((byte)(num20 << (7 - j)))); num2 = (byte)(num2 | ((byte)(num21 << (7 - j)))); num3 = (byte)(num3 | ((byte)(num22 << (7 - j)))); num4 = (byte)(num4 | ((byte)(num23 << (7 - j)))); } byte num5 = 0; byte num6 = 0; byte num7 = 0; byte num8 = 0; for (int k = 0; k < 8; k++) { byte num10 = (byte)(bytemap.Data[pointAddress++]); byte num25 = (byte)(num10 & 1); byte num26 = (byte)((num10 >> 1) & 1); byte num27 = (byte)((num10 >> 2) & 1); byte num28 = (byte)((num10 >> 3) & 1); num5 = (byte)(num5 | ((byte)(num25 << (7 - k)))); num6 = (byte)(num6 | ((byte)(num26 << (7 - k)))); num7 = (byte)(num7 | ((byte)(num27 << (7 - k)))); num8 = (byte)(num8 | ((byte)(num28 << (7 - k)))); } byte num1a = 0; byte num2a = 0; byte num3a = 0; byte num4a = 0; for (int j = 0; j < 8; j++) { byte num9 = (byte)(bytemap.Data[pointAddress++]); byte num20 = (byte)(num9 & 1); byte num21 = (byte)((num9 >> 1) & 1); byte num22 = (byte)((num9 >> 2) & 1); byte num23 = (byte)((num9 >> 3) & 1); num1a = (byte)(num1a | ((byte)(num20 << (7 - j)))); num2a = (byte)(num2a | ((byte)(num21 << (7 - j)))); num3a = (byte)(num3a | ((byte)(num22 << (7 - j)))); num4a = (byte)(num4a | ((byte)(num23 << (7 - j)))); } byte num5a = 0; byte num6a = 0; byte num7a = 0; byte num8a = 0; for (int k = 0; k < 8; k++) { byte num10 = (byte)(bytemap.Data[pointAddress++]); byte num25 = (byte)(num10 & 1); byte num26 = (byte)((num10 >> 1) & 1); byte num27 = (byte)((num10 >> 2) & 1); byte num28 = (byte)((num10 >> 3) & 1); num5a = (byte)(num5a | ((byte)(num25 << (7 - k)))); num6a = (byte)(num6a | ((byte)(num26 << (7 - k)))); num7a = (byte)(num7a | ((byte)(num27 << (7 - k)))); num8a = (byte)(num8a | ((byte)(num28 << (7 - k)))); } data[index] = num5; data[index + 1] = num1; data[index + 2] = num6; data[index + 3] = num2; data[index + 4] = num7; data[index + 5] = num3; data[index + 6] = num8; data[index + 7] = num4; data[index + 8] = num5a; data[index + 9] = num1a; data[index + 10] = num6a; data[index + 11] = num2a; data[index + 12] = num7a; data[index + 13] = num3a; data[index + 14] = num8a; data[index + 15] = num4a; } }
internal void Resize(int width) { Bitmap = new Bytemap(width, 38); _update = true; }
/// <param name="data">Data</param> /// <param name="addr">Data address</param> /// <param name="bytemap">Bytemap</param> /// <param name="px">Bytemap position X</param> /// <param name="py">Bytemap position Y</param> public override void ConvertMemToChr(Byte[] data, int addr, Bytemap bytemap, int px, int py) { // Convert the 4bpp linear, mixed columns data: /* ----------------------- LR LR LR LR LR LR LR LR * data 1 x8 (columns 5,4) 54 54 54 54 54 54 54 54 * data 2 x8 (columns 7,6) 76 76 76 76 76 76 76 76 * data 3 x8 (columns 1,0) 10 10 10 10 10 10 10 10 * data 4 x8 (columns 3,2) 32 32 32 32 32 32 32 32 */ // one row of fix data consists of reading the bytes of: // data 3, data 4, data 1, and data 2, in that order. // dat1 dat2 dat3 dat4 // 0x00,0x08,0x10,0x18 <- tile 1/8 (y=0) // 0x01,0x09,0x11,0x19 <- tile 2/8 (y=1) // 0x02,0x0A,0x12,0x1A <- tile 3/8 (y=2) // 0x03,0x0B,0x13,0x1B <- tile 4/8 (y=3) // 0x04,0x0C,0x14,0x1C <- tile 5/8 (y=4) // 0x05,0x0D,0x15,0x1D <- tile 6/8 (y=5) // 0x06,0x0E,0x16,0x1E <- tile 7/8 (y=6) // 0x07,0x0F,0x17,0x1F <- tile 8/8 (y=7) for (int x = 0; x < CharWidth; x++) { // each group of bytes defines a column. for (int y = 0; y < CharHeight; y++) { // decode this tile. int tileAddr = addr; // set base address byte pixByte = 0x00; // the base address for this pixel depends on the X and Y values. switch (x) { case 0: // column 0: ColDataOffsets[0], data 3, mask 0x0F tileAddr = addr + ColDataOffsets[0] + y; pixByte = (byte)(data[tileAddr] & 0x0F); break; case 1: // column 1: ColDataOffsets[0], data 3, mask 0xF0 tileAddr = addr + ColDataOffsets[0] + y; pixByte = (byte)((data[tileAddr] & 0xF0) >> 4); break; case 2: // column 2: ColDataOffsets[1], data 4, mask 0x0F tileAddr = addr + ColDataOffsets[1] + y; pixByte = (byte)(data[tileAddr] & 0x0F); break; case 3: // column 3: ColDataOffsets[1], data 4, mask 0xF0 tileAddr = addr + ColDataOffsets[1] + y; pixByte = (byte)((data[tileAddr] & 0xF0) >> 4); break; case 4: // column 4: ColDataOffsets[2], data 1, mask 0x0F tileAddr = addr + ColDataOffsets[2] + y; pixByte = (byte)(data[tileAddr] & 0x0F); break; case 5: // column 5: ColDataOffsets[2], data 1, mask 0xF0 tileAddr = addr + ColDataOffsets[2] + y; pixByte = (byte)((data[tileAddr] & 0xF0) >> 4); break; case 6: // column 6: ColDataOffsets[3], data 2, mask 0x0F tileAddr = addr + ColDataOffsets[3] + y; pixByte = (byte)(data[tileAddr] & 0x0F); break; case 7: // column 7: ColDataOffsets[3], data 2, mask 0xF0 tileAddr = addr + ColDataOffsets[3] + y; pixByte = (byte)((data[tileAddr] & 0xF0) >> 4); break; } Point p = base.GetAdvancePixelPoint(px + x, py + y); int bytemapAddr = bytemap.GetPointAddress(p.X, p.Y); bytemap.Data[bytemapAddr] = pixByte; } } }
protected override bool HasUpdate(uint gameTick) { if (!(_update || _fullRedraw)) { return(false); } if (Game.MovingUnit == null && (gameTick % 2 == 1)) { return(false); } Player renderPlayer = Settings.RevealWorld ? null : Human; IUnit activeUnit = ActiveUnit; if (Game.MovingUnit != null && !_fullRedraw) { IUnit movingUnit = Game.MovingUnit; ITile tile = movingUnit.Tile; int dx = GetX(tile); int dy = GetY(tile); if (dx < _tilesX && dy < _tilesY) { dx *= 16; dy *= 16; MoveUnit movement = movingUnit.Movement; this.FillRectangle(dx - 16, dy - 16, 48, 48, 5) .AddLayer(Map[movingUnit.X - 1, movingUnit.Y - 1, 3, 3].ToBitmap(player: renderPlayer), dx - 16, dy - 16, dispose: true); Bytemap unitPicture = movingUnit.ToBitmap(); this.AddLayer(unitPicture, dx + movement.X, dy + movement.Y); if (movingUnit is IBoardable && tile.Units.Any(u => u.Class == UnitClass.Land && (tile.City == null || (tile.City != null && u.Sentry)))) { this.AddLayer(unitPicture, dx + movement.X - 1, dy + movement.Y - 1); } return(true); } } else if (_fullRedraw) { _fullRedraw = false; this.Clear(5) .AddLayer(Tiles.ToBitmap(player: renderPlayer), dispose: true); } if (activeUnit != null && Game.CurrentPlayer == Human && !GameTask.Any()) { ITile tile = activeUnit.Tile; int dx = GetX(tile); int dy = GetY(tile); if (dx < _tilesX && dy < _tilesY) { dx *= 16; dy *= 16; // blink status TileSettings setting = ((gameTick % 4) < 2) ? TileSettings.BlinkOn : TileSettings.BlinkOff; this.AddLayer(tile.ToBitmap(setting), dx, dy, dispose: true); DrawHelperArrows(dx, dy); } return(true); } _update = false; return(true); }
protected BaseScreen(int width, int height, MouseCursor cursor = MouseCursor.None) { _cursor = cursor; Bitmap = new Bytemap(width, height); }
public Picture(Bytemap bytemap, Palette palette) { _originalColours = palette.Copy(); _palette = palette.Copy(); _bitmap = Bytemap.Copy(bytemap); }
public static IBitmap Tile(this IBitmap bitmap, Bytemap layer, Rectangle rectangle) => Tile(bitmap, layer, rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
public void Clear() { _bitmap?.Dispose(); _bitmap = null; }
public GifFile(IBitmap bitmap) { _palette = bitmap.Palette; _pixels = bitmap.Bitmap; }
public Bytemap GetUnit(UnitType type) { Bytemap output = new Bytemap(16, 16).FromByteArray(GenerateUnit().ToArray()); char text = ' '; switch (type) { case UnitType.Settlers: output.AddLayer(new Bytemap(10, 10).FromByteArray( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 0, 0, 5, 15, 15, 8, 15, 15, 8, 7, 5, 0, 5, 15, 15, 8, 15, 15, 8, 7, 5, 0, 5, 15, 15, 15, 15, 15, 8, 7, 5, 0, 0, 5, 6, 6, 15, 15, 6, 6, 5, 0, 0, 6, 8, 0, 6, 6, 8, 0, 6, 0, 0, 6, 0, 0, 6, 6, 0, 0, 6, 0, 0, 0, 6, 6, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ), 3, 3); break; case UnitType.Militia: output.AddLayer(new Bytemap(10, 10).FromByteArray( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 4, 14, 14, 14, 4, 0, 7, 0, 0, 0, 14, 14, 14, 14, 14, 0, 7, 7, 0, 0, 14, 9, 14, 9, 14, 0, 7, 7, 0, 0, 14, 14, 14, 14, 14, 0, 0, 7, 0, 0, 14, 8, 8, 8, 14, 0, 6, 6, 0, 0, 5, 14, 14, 14, 5, 0, 5, 5, 0, 5, 5, 5, 5, 5, 5, 5, 5, 0 ), 3, 3); break; case UnitType.Phalanx: output.AddLayer(new Bytemap(10, 10).FromByteArray( 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8, 8, 0, 0, 0, 0, 0, 8, 14, 14, 14, 7, 8, 0, 0, 0, 0, 5, 5, 5, 14, 7, 7, 0, 0, 0, 5, 15, 8, 8, 5, 7, 6, 0, 0, 0, 5, 15, 7, 8, 5, 6, 0, 0, 0, 0, 5, 15, 7, 8, 5, 6, 0, 0, 0, 0, 5, 15, 7, 8, 5, 6, 0, 0, 0, 0, 0, 5, 15, 5, 0, 6, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0 ), 3, 3); break; case UnitType.Legion: text = 'L'; break; case UnitType.Musketeers: text = 'M'; break; case UnitType.Riflemen: text = 'R'; break; case UnitType.Cavalry: text = 'c'; break; case UnitType.Knights: text = 'K'; break; case UnitType.Catapult: text = 'C'; break; case UnitType.Cannon: text = 'X'; break; case UnitType.Chariot: text = 'W'; break; case UnitType.Armor: text = 'a'; break; case UnitType.MechInf: text = 'I'; break; case UnitType.Artillery: text = 'A'; break; case UnitType.Fighter: text = 'F'; break; case UnitType.Bomber: text = 'B'; break; case UnitType.Trireme: text = 'T'; break; case UnitType.Sail: text = 's'; break; case UnitType.Frigate: text = 'f'; break; case UnitType.Ironclad: text = 'i'; break; case UnitType.Cruiser: text = 'Y'; break; case UnitType.Battleship: text = 'Z'; break; case UnitType.Submarine: text = 'U'; break; case UnitType.Carrier: text = 'G'; break; case UnitType.Transport: text = 'H'; break; case UnitType.Nuclear: text = 'N'; break; case UnitType.Diplomat: text = 'D'; break; case UnitType.Caravan: text = 't'; break; } if (text != ' ') { output.AddLayer( new Picture(16, 16) .DrawText(text.ToString(), 0, 8, 8, 5, TextAlign.Center) .DrawText(text.ToString(), 0, 7, 8, 4, TextAlign.Center) .Bitmap); } return(output); }
public static IBitmap AddLayer(this IBitmap bitmap, Bytemap layer, Point point, bool dispose = false) => AddLayer(bitmap, layer, point.X, point.Y, dispose);
public Picture(byte[,] bytes, Palette palette) { _originalColours = palette.Copy(); _palette = palette.Copy(); _bitmap = new Bytemap(bytes); }