/// <summary> /// Copies a specified source area of the screen buffer to a specified destination area. /// Vacated character cells are filled with the specified character and color attributes. /// </summary> /// <param name="sourceLeft">Column position of the source area's top-left corner.</param> /// <param name="sourceTop">Row position of the source arean't top-left corner.</param> /// <param name="sourceWidth">Width, in character columns, of the source area.</param> /// <param name="sourceHeight">Height, in character rows, of the source area.</param> /// <param name="targetLeft">Column position of the target's top-left corner.</param> /// <param name="targetTop">Row position of the target's top-left corner.</param> /// <param name="sourceChar">Character with which to fill vacated character positions.</param> /// <param name="sourceForeColor">Foreground color to use for filling.</param> /// <param name="sourceBackColor">Background color to use for filling.</param> public void MoveBufferArea( int sourceLeft, int sourceTop, int sourceWidth, int sourceHeight, int targetLeft, int targetTop, char sourceChar, ConsoleColor sourceForeColor, ConsoleColor sourceBackColor ) { SmallRect sourceRect = new SmallRect((short)sourceLeft, (short)sourceTop, (short)(sourceLeft + sourceWidth - 1), (short)(sourceTop + sourceHeight - 1)); Coord dest = new Coord((short)targetLeft, (short)targetTop); ConsoleCharInfo cci = new ConsoleCharInfo(sourceChar, new ConsoleCharAttribute(sourceForeColor, sourceBackColor)); if (!WinCon.ScrollConsoleScreenBuffer(handle, sourceRect, null, dest, ref cci)) { throw new IOException("Error scrolling screen buffer", Marshal.GetLastWin32Error()); } }
/// <summary> /// Writes character and attribute information to a rectangular portion of the screen buffer. /// </summary> /// <param name="buff">The array that contains characters and attributes to be written.</param> /// <param name="buffX">Column position of the first character to be written from the array.</param> /// <param name="buffY">Row position of the first character to be written from the array.</param> /// <param name="left">Column position of the top-left corner of the screen buffer area where characters are to be written.</param> /// <param name="top">Row position of the top-left corner of the screen buffer area where characters are to be written.</param> /// <param name="right">Column position of the bottom-right corner of the screen buffer area where characters are to be written.</param> /// <param name="bottom">Row position of the bottom-right corner of the screen buffer area where characters are to be written.</param> public void WriteBlock(ConsoleCharInfo[,] buff, int buffX, int buffY, int left, int top, int right, int bottom) { if (disposed) { throw new ObjectDisposedException(this.ToString()); } Coord bufferSize = new Coord ((short)buff.GetLength(1), (short)buff.GetLength(0)); Coord bufferPos = new Coord((short)buffX, (short)buffY); SmallRect writeRegion = new SmallRect((short)left, (short)top, (short)right, (short)bottom); if (!WinCon.WriteConsoleOutput(handle, buff, bufferSize, bufferPos, writeRegion)) { throw new IOException("Write error.", Marshal.GetLastWin32Error()); } }
public void Draw(int x, int y, ConsoleCharInfo[,] hiddenBuffer) { for (int i = 0; i < Height; i++) { for (int j = 0; j < Width; j++) { if (!transparent[i, j]) { int r = y + i; int c = x + j; if (c >= 0 && c < 160 && r >= 0 && r < 50) { if ((c & 1) == 0) { hiddenBuffer[r, c >> 1].Foreground = image[i, j]; } else { hiddenBuffer[r, c >> 1].Background = image[i, j]; } } } } } }
public static extern bool ScrollConsoleScreenBuffer( IntPtr hConsoleOutput, [In][MarshalAs(UnmanagedType.LPStruct)] SmallRect lpScrollRectangle, [In][MarshalAs(UnmanagedType.LPStruct)] SmallRect lpClipRectangle, Coord dwDestinationOrigin, ref ConsoleCharInfo lpFill);
public static extern bool ScrollConsoleScreenBuffer( IntPtr hConsoleOutput, [In][MarshalAs(UnmanagedType.LPStruct)]SmallRect lpScrollRectangle, [In][MarshalAs(UnmanagedType.LPStruct)]SmallRect lpClipRectangle, Coord dwDestinationOrigin, ref ConsoleCharInfo lpFill);
public static void PrintLine( ConsoleCharInfo[,] hiddenBuffer, int x, int y, ConsoleColor foregroundColor, ConsoleColor backgroundColor, string text) { for (int i = 0; i < text.Length; i++) { int X = x + i; if (X >= 0 && X < 80) { hiddenBuffer[y, X].AsciiChar = (byte)text[i]; hiddenBuffer[y, X].Background = backgroundColor; hiddenBuffer[y, X].Foreground = foregroundColor; } } }
public static void PrintCentered(ConsoleCharInfo[,] hiddenBuffer, int y, ConsoleColor foregroundColor, ConsoleColor backgroundColor, string text) { PrintLine(hiddenBuffer, (80 - text.Length) / 2, y, foregroundColor, backgroundColor, text); }
public GameEngine(ConsoleCharInfo[,] hiddenBuffer, ConsoleInputBuffer inputBuffer) { this.hiddenBuffer = hiddenBuffer; this.inputBuffer = inputBuffer; playerX = (80 - shipSprite.Width) / 2; missileY = 49 - shipSprite.Height; for (int i = 0; i < 3; i++) { demons[i] = new Demon(); } }