master
orange 12 years ago
parent 020aa6d120
commit aea9a53762

@ -13,19 +13,37 @@ void xy2rc(float x, float y, int *r, int *c) {
*r = MAX_R - ((y / MAX_Y) * MAX_R);
}
float lerp(float from, float to, float t) {
return from + t * (to-from);
}
float ball_x = 0.0;
float ball_y = 0.0;
float dir_x = +2.0;
float dir_y = +1.0;
float pad_l = 0.0;
float pad_r = 0.0;
void paint_ball() {
int r, c;
xy2rc(ball_x, ball_y, &r, &c);
mvaddch(r, c, ACS_DIAMOND);
}
void paint_paddles() {
int r, c;
xy2rc( 0, pad_l, &r, &c);
mvaddch(r, c, ACS_VLINE);
xy2rc(MAX_X, pad_r, &r, &c);
c--;
mvaddch(r, c, ACS_VLINE);
}
void paint() {
clear();
paint_paddles();
paint_ball();
refresh();
@ -46,6 +64,14 @@ int main() {
dir_y = -dir_y;
}
/* Awesome artificial intelligence working here. */
if (ball_x < 0.25f * MAX_X) {
pad_l = lerp(pad_l, ball_y, 0.3);
}
if (ball_x > 0.75f * MAX_X) {
pad_r = lerp(pad_r, ball_y, 0.3);
}
paint();
usleep(50000);
}

Loading…
Cancel
Save