-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathbounce.c
More file actions
44 lines (36 loc) · 689 Bytes
/
bounce.c
File metadata and controls
44 lines (36 loc) · 689 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <curses.h>
#include "delayms.h"
struct ball {
int y, x;
int vy, vx;
};
void oneFrame(struct ball *b, int ymin, int ymax, int xmin, int xmax)
{
if (b->y <= ymin || b->y >= ymax) b->vy *= -1;
if (b->x <= xmin || b->x >= xmax) b->vx *= -1;
b->y += b->vy;
b->x += b->vx;
}
int main(int argc, char *argv[])
{
int ymax, xmax;
initscr();
cbreak();
noecho();
curs_set(0);
getmaxyx(stdscr, ymax, xmax);
mvprintw(0, 0, "Press Ctrl+C to stop...");
refresh();
delayms(1000);
clear();
struct ball b = {1, 1, 1, 1};
for (;;) {
mvaddch(b.y, b.x, 'O');
refresh();
delayms(50);
mvaddch(b.y, b.x, ' ');
oneFrame(&b, 0, ymax, 0, xmax);
}
endwin();
return 0;
}