private void Render() { foreach (GameObject gameObject in gameObjects) { Vector2Int position = gameObject.Position; buffer2D[position.X, position.Y] = gameObject.Sprite; } buffer2D.Swap(); Console.SetCursorPosition(0, 0); for (int y = 0; y < YMAX; y++) { for (int x = 0; x < XMAX; x++) { char sprite = buffer2D[x, y]; if (sprite != default) { Console.Write(sprite); } else { Console.Write(' '); } } Console.WriteLine(); } // Note for this rendering solution: // - This approach does not work for colored characters. // - It does not consider the z-buffer, so it's not possible to // define when game objects should appear in front or behind // others. // - It's very inefficient and will probably not work when there's // too many game objects. // See https://github.com/fakenmc/CoreGameEngine/ for possible // solutions and ideas. }
// Perform rendering private void Render() { // Swap buffers in the double buffer buffer2D.Swap(); // Set cursor position to top of the console Console.SetCursorPosition(0, 0); // Render information in the double buffer for (int y = 0; y < buffer2D.YDim; y++) { for (int x = 0; x < buffer2D.XDim; x++) { if (buffer2D[x, y] == default) { Console.Write(' '); } else { Console.Write(buffer2D[x, y]); } } Console.WriteLine(); } // Render frame number (just for debugging purposes) Console.Write($"Frame: {frame++}\n"); // Note: // This approach does not work for colored characters. // See https://github.com/fakenmc/CoreGameEngine/ for a // possible solution. }