I am trying to make s imple game using only console graphics but for some reason even when I use putc()
instead of printf()
it is stille extremely slow averaging 14 FPS even though all I am doing is displayinga bunch of @ sighns.
code:
#include <stdio.h>
#include <time.h>
#include <windows.h>
const int sizeX = 20;
const int sizeY = 20;
int grid[20][20];
void draw_screen() {
system("cls");
int y, x;
for (y = 0; y < sizeY; y++) {
for (x = 0; x < sizeX; x++) {
if (grid[y][x] == 0) {
putc('@', stdout);
}
}
putc('\n', stdout);
}
}
int main(void) {
int x, y;
float frameTime, FPS;
while (1) {
clock_t start = clock();
draw_screen();
clock_t stop = clock();
frameTime = (float)(stop - start) / CLOCKS_PER_SEC;
FPS = 1.0 / frameTime;
printf("FPS: %f\n", FPS);
}
}