//initializes the page and sets the palette public unsafe void Initialize(XConsole.PALETTE palette, bool _cursor = false) { Initialize(_cursor); XConsole.CONSOLE_SCREEN_BUFFER_INFO_EX sbi = new XConsole.CONSOLE_SCREEN_BUFFER_INFO_EX(); sbi.cbSize = sizeof(XConsole.CONSOLE_SCREEN_BUFFER_INFO_EX); IntPtr sbiptr = new IntPtr(&sbi); XConsole.GetConsoleScreenBufferInfoEx(Handle, sbiptr); for (int n = 0; n < XConsole.PALETTE_SIZE; n++) { sbi.Palette[n] = new XConsole.RGBXConverter(palette.rgbx[n]).UINT; } XConsole.SetConsoleScreenBufferInfoEx(Handle, sbiptr); }
static unsafe void Main(string[] args) { //create custom palette XConsole.PALETTE pal = new XConsole.PALETTE(); pal.rgbx[1] = new XConsole.RGBX(35, 1, 5); pal.rgbx[2] = new XConsole.RGBX(60, 7, 3); pal.rgbx[3] = new XConsole.RGBX(100, 22, 2); pal.rgbx[4] = new XConsole.RGBX(143, 44, 0); pal.rgbx[5] = new XConsole.RGBX(181, 61, 1); pal.rgbx[6] = new XConsole.RGBX(224, 60, 0); pal.rgbx[7] = new XConsole.RGBX(200, 60, 80); pal.rgbx[8] = new XConsole.RGBX(170, 60, 130); pal.rgbx[9] = new XConsole.RGBX(150, 78, 155); pal.rgbx[10] = new XConsole.RGBX(118, 95, 188); pal.rgbx[11] = new XConsole.RGBX(100, 170, 200); pal.rgbx[12] = new XConsole.RGBX(157, 227, 236); pal.rgbx[13] = new XConsole.RGBX(0x7F, 0x7F, 0x7F); pal.rgbx[14] = new XConsole.RGBX(0x3F, 0x0, 0x0); pal.rgbx[15] = new XConsole.RGBX(0x0, 0xFF, 0x0); //create a crutch and set the console title and console's window size Window.Initialize(129, 59, "XConsole", pal); //a pair of styles Style s = new Style(1, 4, true); Style s2 = new Style(0, 13, true); //separate surface ans viewport Surface simpletext = new Surface(new XConsole.SMALL_COORD(64, 40)); Viewport simpletextvp = new Viewport(new XConsole.SMALL_RECT(80, 27, 115, 45)); //write text till the surface is filled //the text wraps and has different colors for (int n = 0; n < 100; n++) { s.color = (byte)(n); simpletext.Write(XConsole.EncodeASCII(" HELLO WORLD " + n.ToString()), s); } //three percentage scales PercentScale ps = new PercentScale(10, 50, 100); PercentScale ps2 = new PercentScale(10, 52, 100); PercentScale ps3 = new PercentScale(10, 54, 100); //fire effect Fire fire = new Fire(5, 0, 72, 48); //sprite with 4 frames Sprite bm = new Sprite(80, 3, 35, 20, 4); for (int l = 0; l < 4; l++) { for (int n = 0; n < 40; n++) { for (int i = 0; i < bm.surface.size.x; i++) { bm.SetPixel(i, n + l * 40, (byte)((l * 3) + 6)); bm.SetPixel(0, 0 + l * 40, 13); bm.SetPixel(34, 39 + l * 40, 13); } } } int unknown = 0; int frame = 0; float k = 0; //the cycle do { Window.Clear(); //clear the screen with black Window.Draw(ps); Window.Draw(ps2); Window.Draw(ps3); Window.Draw(fire); bm.SetFrame(frame >> 4); //sets a frame Window.Draw(bm); Window.Draw(simpletextvp, simpletext); Thread.Sleep(10); //relaxes the system, prevent the screen flashing //updates the elements ps.Update(k, s2); ps2.Update((int)(100 - k), 100, s2); ps3.Update(ref unknown, s2); fire.Update(2000); if (k < 100) { k += 0.1f; } else { k = 0; } if (frame++ == 64) { frame = 0; } } while (!Console.KeyAvailable); Console.ReadKey(); }
public static int Initialize(int width, int height, string lpConsoleTitle = "XConsole", XConsole.PALETTE palette = null, bool cursor = false) { XConsole.SetConsoleTitle(lpConsoleTitle); Console.SetWindowSize(width, height); Console.SetBufferSize(width, height); if (palette != null) { page.Initialize(palette, cursor); } else { page.Initialize(cursor); } bgroundsurface = new Surface(new XConsole.SMALL_COORD(width, height)); bgroundsurface.Clear(XConsole.DEFAULT_STYLE); page.Active(); bgroundviewport = new Viewport(new XConsole.SMALL_RECT(0, 0, width, height)); return(XConsole.GetLastError()); }