I'm working on a simple pong clone for the terminal and need a way to delay the printing of a 'frame'.
I have a two dimensional array
screen[ROWS][COLUMNS]
and a function that prints the screen
void printScreen() {
int i = 0;
int j;
while(i < ROWS) {
j = 0;
while(j < COLUMNS) {
printf("%c", screen[i][j]);
j++;
}
i++;
}
}
It seems that when I do
printScreen();
usleep(1000000);
printScreen();
it will sleep
the execution during printScreen()
.
Any tips for doing this type of animation on the terminal would be much appreciated. Maybe I'm doing this completely wrong. How is it done with ASCII movies like this?
EDIT I'm going with ncurses. Thank you both for the suggestion.
On Ubuntu sudo aptitude install libncurses5-dev
and compile with -lncurses
.