Procg
Procg
#include <stdio.h>
#include <unistd.h> // For sleep() and usleep() functions
#include <stdlib.h> // For system("clear")
#include <termios.h> // For terminal input
#include <fcntl.h> // For non-blocking input
#define WIDTH 60
#define HEIGHT 30
tcgetattr(STDIN_FILENO, &oldt);
newt = oldt;
newt.c_lflag &= ~(ICANON | ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
oldf = fcntl(STDIN_FILENO, F_GETFL, 0);
fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK);
ch = getchar();
if (ch != EOF) {
ungetc(ch, stdin);
return 1;
}
return 0;
}
int main() {
int x, y; // Ball coordinates
int x_dir, y_dir; // Ball direction
char again;
do {
x = 0, y = 0;
x_dir = 1, y_dir = 1; // Ball direction: 1 for down/right, -1 for up/left
// Bounce horizontally
if (x <= 0 || x >= WIDTH - 1) {
x_dir *= -1; // Change direction
}
// Bounce vertically
if (y <= 0 || y >= HEIGHT - 1) {
y_dir *= -1; // Change direction
}
return 0;
}
OUTPUT:-