I am writing a small libary to draw "graphics" to a console to make writing console games easier, but whenever a frame is renedered, it is very slow I am new to c#, however I have been coding for 8 months.
I have optimized it as much as I can but I have had no succsess(keep in mind i'm writing this on an ASUS 2016 laptop)
So here is the code:
Console.Title = "Pyrite";
int winWidth = Console.BufferWidth;
int winHeight = Console.BufferHeight / 190;
char[,] screen = new char[winWidth, winHeight];
ConsoleColor[,] screenColours = new ConsoleColor[winWidth, winHeight];
for(int j = 0; j < screen.GetLength(1); j += 1){
for(int i = 0; i < screen.GetLength(0); i += 1){
screenColours[i, j] = ConsoleColor.Green;
screen[i, j] = '■';
}
}
void drawPixel(int x, int y, char character, ConsoleColor colour){
screenColours[x, y] = colour;
screen[x, y] = character;
}
void drawRect(int x, int y, int width, int height, char character, bool outlineOnly, ConsoleColor colour){
if(!outlineOnly){
for(int j = 0; j < height + 1; j += 1){
for(int i = 0; i < width + 1; i += 1){
drawPixel(i + x, j + y, character, colour);
}
}
}else{
for(int i = 0; i < width + 1; i += 1){
drawPixel(x + i, y, character, colour);
}
for(int i = 0; i < width + 1; i += 1){
drawPixel(x + i, y + height, character, colour);
}
for(int i = 0; i < height + 1; i += 1){
drawPixel(x, y + i, character, colour);
}
for(int i = 0; i < height + 1; i += 1){
drawPixel(x + width, y + i, character, colour);
}
}
}
void draw(){
for(int j = 0; j < screen.GetLength(1); j += 1){
for(int i = 0; i < screen.GetLength(0); i += 1){
Console.ForegroundColor = screenColours[i, j];
Console.Write(screen[i, j]);
}
}
}
while(true){
drawPixel(20, 20, '■', ConsoleColor.Cyan);
drawRect(0, 0, 25, 15, '■', true, ConsoleColor.DarkMagenta);
draw();
Console.Clear();
Console.ResetColor();
}
Console.ReadKey();