Rev 2479 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2479 | Rev 4515 | ||
---|---|---|---|
Line 34... | Line 34... | ||
34 | * |
34 | * |
35 | * @(#)shapes.c 8.1 (Berkeley) 5/31/93 |
35 | * @(#)shapes.c 8.1 (Berkeley) 5/31/93 |
36 | */ |
36 | */ |
37 | 37 | ||
38 | /** @addtogroup tetris |
38 | /** @addtogroup tetris |
39 | * @{ |
39 | * @{ |
40 | */ |
40 | */ |
41 | /** @file |
41 | /** @file |
42 | */ |
42 | */ |
43 | 43 | ||
44 | /* |
44 | /* |
Line 48... | Line 48... | ||
48 | */ |
48 | */ |
49 | 49 | ||
50 | #include <unistd.h> |
50 | #include <unistd.h> |
51 | #include "tetris.h" |
51 | #include "tetris.h" |
52 | 52 | ||
53 | #define TL -B_COLS-1 /* top left */ |
53 | #define TL (-B_COLS - 1) /* top left */ |
54 | #define TC -B_COLS /* top center */ |
54 | #define TC (-B_COLS) /* top center */ |
55 | #define TR -B_COLS+1 /* top right */ |
55 | #define TR (-B_COLS + 1) /* top right */ |
56 | #define ML -1 /* middle left */ |
56 | #define ML -1 /* middle left */ |
57 | #define MR 1 /* middle right */ |
57 | #define MR 1 /* middle right */ |
58 | #define BL B_COLS-1 /* bottom left */ |
58 | #define BL (B_COLS - 1) /* bottom left */ |
59 | #define BC B_COLS /* bottom center */ |
59 | #define BC B_COLS /* bottom center */ |
60 | #define BR B_COLS+1 /* bottom right */ |
60 | #define BR (B_COLS + 1) /* bottom right */ |
61 | 61 | ||
62 | const struct shape shapes[] = { |
62 | const struct shape shapes[] = { |
63 | /* 0*/ { 7, 7, { TL, TC, MR } }, |
63 | /* 0 */ { 7, 7, { TL, TC, MR }, 0xff042d}, |
64 | /* 1*/ { 8, 8, { TC, TR, ML } }, |
64 | /* 1 */ { 8, 8, { TC, TR, ML }, 0xff9304}, |
65 | /* 2*/ { 9, 11, { ML, MR, BC } }, |
65 | /* 2 */ { 9, 11, { ML, MR, BC }, 0xbeff04}, |
66 | /* 3*/ { 3, 3, { TL, TC, ML } }, |
66 | /* 3 */ { 3, 3, { TL, TC, ML }, 0x63ff04}, |
67 | /* 4*/ { 12, 14, { ML, BL, MR } }, |
67 | /* 4 */ { 12, 14, { ML, BL, MR }, 0xce04ff}, |
68 | /* 5*/ { 15, 17, { ML, BR, MR } }, |
68 | /* 5 */ { 15, 17, { ML, BR, MR }, 0xff04cf}, |
69 | /* 6*/ { 18, 18, { ML, MR, 2 } }, /* sticks out */ |
69 | /* 6 */ { 18, 18, { ML, MR, 2 }, 0x7604ff}, /* sticks out */ |
70 | /* 7*/ { 0, 0, { TC, ML, BL } }, |
70 | /* 7 */ { 0, 0, { TC, ML, BL }, 0xff042d}, |
71 | /* 8*/ { 1, 1, { TC, MR, BR } }, |
71 | /* 8 */ { 1, 1, { TC, MR, BR }, 0xff9304}, |
72 | /* 9*/ { 10, 2, { TC, MR, BC } }, |
72 | /* 9 */ { 10, 2, { TC, MR, BC }, 0xbeff04}, |
73 | /*10*/ { 11, 9, { TC, ML, MR } }, |
73 | /* 10 */ { 11, 9, { TC, ML, MR }, 0xbeff04}, |
74 | /*11*/ { 2, 10, { TC, ML, BC } }, |
74 | /* 11 */ { 2, 10, { TC, ML, BC }, 0xbeff04}, |
75 | /*12*/ { 13, 4, { TC, BC, BR } }, |
75 | /* 12 */ { 13, 4, { TC, BC, BR }, 0xce04ff}, |
76 | /*13*/ { 14, 12, { TR, ML, MR } }, |
76 | /* 13 */ { 14, 12, { TR, ML, MR }, 0xce04ff}, |
77 | /*14*/ { 4, 13, { TL, TC, BC } }, |
77 | /* 14 */ { 4, 13, { TL, TC, BC }, 0xce04ff}, |
78 | /*15*/ { 16, 5, { TR, TC, BC } }, |
78 | /* 15 */ { 16, 5, { TR, TC, BC }, 0xff04cf}, |
79 | /*16*/ { 17, 15, { TL, MR, ML } }, |
79 | /* 16 */ { 17, 15, { TL, MR, ML }, 0xff04cf}, |
80 | /*17*/ { 5, 16, { TC, BC, BL } }, |
80 | /* 17 */ { 5, 16, { TC, BC, BL }, 0xff04cf}, |
81 | /*18*/ { 6, 6, { TC, BC, 2*B_COLS } }/* sticks out */ |
81 | /* 18 */ { 6, 6, { TC, BC, 2 * B_COLS }, 0x7604ff} /* sticks out */ |
82 | }; |
82 | }; |
83 | 83 | ||
84 | /* |
84 | /* |
85 | * Return true iff the given shape fits in the given position, |
85 | * Return true iff the given shape fits in the given position, |
86 | * taking the current board into account. |
86 | * taking the current board into account. |
87 | */ |
87 | */ |
88 | int |
- | |
89 | fits_in(const struct shape *shape, int pos) |
88 | int fits_in(const struct shape *shape, int pos) |
90 | { |
89 | { |
91 | int *o = shape->off; |
90 | int *o = shape->off; |
92 | 91 | ||
93 | if (board[pos] || board[pos + *o++] || board[pos + *o++] || |
92 | if ((board[pos]) || (board[pos + *o++]) || (board[pos + *o++]) || |
94 | board[pos + *o]) |
93 | (board[pos + *o])) |
95 | return 0; |
94 | return 0; |
- | 95 | ||
96 | return 1; |
96 | return 1; |
97 | } |
97 | } |
98 | 98 | ||
99 | /* |
99 | /* |
100 | * Write the given shape into the current board, turning it on |
100 | * Write the given shape into the current board, turning it on |
101 | * if `onoff' is 1, and off if `onoff' is 0. |
101 | * if `onoff' is 1, and off if `onoff' is 0. |
102 | */ |
102 | */ |
103 | void |
- | |
104 | place(const struct shape *shape, int pos, int onoff) |
103 | void place(const struct shape *shape, int pos, int onoff) |
105 | { |
104 | { |
106 | int *o = shape->off; |
105 | int *o = shape->off; |
107 | 106 | ||
108 | board[pos] = onoff; |
107 | board[pos] = onoff ? shape->color : 0x000000; |
109 | board[pos + *o++] = onoff; |
108 | board[pos + *o++] = onoff ? shape->color : 0x000000; |
110 | board[pos + *o++] = onoff; |
109 | board[pos + *o++] = onoff ? shape->color : 0x000000; |
111 | board[pos + *o] = onoff; |
110 | board[pos + *o] = onoff ? shape->color : 0x000000; |
112 | } |
111 | } |
113 | 112 | ||
114 | /** @} |
113 | /** @} |
115 | */ |
114 | */ |
116 | - |