blob: 4bf90fa963f17600e42dac08c168e85d7f422155 (
plain)
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
45
46
47
48
49
50
51
52
|
#include <curses.h>
#include "paddle.h"
#include "board.h"
void
update_paddle(struct paddle *pad)
{
int min;
int max;
pad->pos += pad->speed * pad->dir;
if (pad->type == PADDLE_TYPE_H) {
min = 3;
max = BOARD_WIDTH - 2;
} else {
min = 2;
max = BOARD_HEIGHT - 2;
}
if (pad->pos < min + pad->size / 2) pad->pos = min + pad->size / 2;
if (pad->pos > max - pad->size / 2) pad->pos = max - pad->size / 2;
}
void
draw_paddle(struct paddle *pad)
{
int off;
int pos;
off = pad->pos;
off -= pad->size / 2;
if (pad->type == PADDLE_TYPE_H) {
for (pos = 0; pos < BOARD_WIDTH - 1; ++pos) {
mvprintw(pad->track, pos, " ");
}
for (pos = 0; pos < pad->size; ++pos) {
attr_on(WA_REVERSE, NULL);
mvprintw(pad->track, off + pos, " ");
attr_off(WA_REVERSE, NULL);
}
} else {
for (pos = 0; pos < BOARD_HEIGHT - 1; ++pos) {
mvprintw(pos, pad->track, " ");
}
for (pos = 0; pos < pad->size; ++pos) {
attr_on(WA_REVERSE, NULL);
mvprintw(off + pos, pad->track, " ");
attr_off(WA_REVERSE, NULL);
}
}
}
|