diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/game.c | 30 |
1 files changed, 22 insertions, 8 deletions
@@ -56,6 +56,8 @@ static void input(struct game *g) { int c; + struct paddle *pad; + int dir; timeout(0); for (;;) { @@ -65,17 +67,29 @@ input(struct game *g) } else if (c == ERR) { break; } else if (c == KEY_LEFT) { - g->players[0]->paddle_h.pos -= - g->players[0]->paddle_h.speed; + pad = &g->players[0]->paddle_h; + dir = -1; + if (pad->pos > pad->size / 2 + 2) { + pad->pos += pad->speed * dir; + } } else if (c == KEY_RIGHT) { - g->players[0]->paddle_h.pos += - g->players[0]->paddle_h.speed; + pad = &g->players[0]->paddle_h; + dir = 1; + if (pad->pos < 78 - pad->size / 2) { + pad->pos += pad->speed * dir; + } } else if (c == KEY_UP) { - g->players[0]->paddle_v.pos -= - g->players[0]->paddle_v.speed; + pad = &g->players[0]->paddle_v; + dir = -1; + if (pad->pos > pad->size / 2 + 2) { + pad->pos += pad->speed * dir; + } } else if (c == KEY_DOWN) { - g->players[0]->paddle_v.pos += - g->players[0]->paddle_v.speed; + pad = &g->players[0]->paddle_v; + dir = 1; + if (pad->pos < 23 - pad->size / 2) { + pad->pos += pad->speed * dir; + } } } } |