diff options
author | P. J. McDermott <pjm@nac.net> | 2013-05-20 16:51:12 (EDT) |
---|---|---|
committer | P. J. McDermott <pjm@nac.net> | 2013-05-20 16:51:12 (EDT) |
commit | 522f5dae6842a241149e4e466ff830a29d1cf73d (patch) | |
tree | b44122a947f73d9aa72a1a32006117c62c7f19a4 /src | |
parent | 96fd8d93c8b5cc62f4a62dd18ec9ae39e3075666 (diff) | |
download | cursespong-522f5dae6842a241149e4e466ff830a29d1cf73d.zip cursespong-522f5dae6842a241149e4e466ff830a29d1cf73d.tar.gz cursespong-522f5dae6842a241149e4e466ff830a29d1cf73d.tar.bz2 |
Limit paddle movement to game board.
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; + } } } } |