]> 4ch.mooo.com Git - 16.git/blob - src/lib/16_us.c
going on vacation >.<
[16.git] / src / lib / 16_us.c
1 #include "src/lib/16_us.h"\r
2 \r
3 word px,py;\r
4 word PrintX,PrintY;\r
5 word WindowX,WindowY,WindowW,WindowH;\r
6 \r
7 static word far* clockw= (word far*) 0x046C; // 18.2hz clock\r
8 \r
9 //      Control panel data\r
10 \r
11 #define CtlPanelSX      74\r
12 #define CtlPanelSY      48\r
13 #define CtlPanelEX      234\r
14 #define CtlPanelEY      150\r
15 #define CtlPanelW       (CtlPanelEX - CtlPanelSX)\r
16 #define CtlPanelH       (CtlPanelEY - CtlPanelSY)\r
17 \r
18 #define TickBase        70              // 70Hz per tick - used as a base for timer 0\r
19 \r
20 #define PaddleMinX      (CtlPanelSX + 3)\r
21 #define PaddleMaxX      (CtlPanelEX - 15)\r
22 #define BallMinX                (CtlPanelSX + 2)\r
23 #define BallMinY                (CtlPanelSY + 12 + 2)\r
24 #define BallMaxX                (CtlPanelEX - 6)\r
25 #define BallMaxY                (CtlPanelEY - 13)\r
26 #define CPaddleY                (BallMinY + 4)\r
27 #define KPaddleY                (BallMaxY - 2)\r
28 void\r
29 USL_DrawPongScore(word k,word c, global_game_variables_t *gvar)\r
30 {\r
31         //++++fontcolor = HiliteColor;\r
32         PrintY = py = CtlPanelSY + 4;\r
33         px = CtlPanelSX + 6;\r
34         VLB_Bar(px,py,42,6,3/*BackColor*/, &gvar->video.ofs);\r
35         //++++USL_DrawString("YOU:");\r
36 //      modexprint(page_t *page, sword x, sword y, word t, boolean tlsw, word col, word bgcol, boolean sw, const byte *str)\r
37         modexprint(gvar->video.page, px, py, 1, 0, 4, 8, 1, "YOU:");\r
38         PrintX = px;\r
39         //++++US_PrintUnsigned(k);\r
40         px = CtlPanelSX + 108;\r
41         VLB_Bar(px,py,50,6,3/*BackColor*/, &gvar->video.ofs);\r
42         //++++USL_DrawString("COMP:");\r
43         modexprint(gvar->video.page, px, py, 1, 0, 4, 8, 1, "COMP:");\r
44         PrintX = px;\r
45         //++++US_PrintUnsigned(c);\r
46 }\r
47 \r
48 void\r
49 USL_PlayPong(global_game_variables_t *gvar)\r
50 {\r
51         boolean         ball,killball,revdir,done,lastscore;\r
52         word                    cycle,\r
53                                 x,y,\r
54                                 kx,cx,\r
55                                 rx,\r
56                                 bx,by,\r
57                                 kscore,cscore,\r
58                                 speedup;\r
59         int                     bdx,bdy;\r
60         word                    balltime,waittime;\r
61         CursorInfo              cursorinfo;\r
62         word TimeCount = *clockw;\r
63 \r
64         kx = cx = PaddleMinX + ((PaddleMaxX - PaddleMinX) / 2);\r
65         bx = by = bdx = bdy = 0;\r
66         kscore = cscore = 0;\r
67         USL_DrawPongScore(0,0, gvar);\r
68         cycle = 0;\r
69         revdir = false;\r
70         killball = true;\r
71         done = false;\r
72         lastscore = false;\r
73         do\r
74         {\r
75                 waittime = TimeCount;\r
76 \r
77                 IN_ReadCursor(&cursorinfo, gvar);\r
78                 if (((cursorinfo.x < 0) || IN_KeyDown(sc_LeftArrow)) && (kx > PaddleMinX))\r
79                         kx -= 2;\r
80                 else if (((cursorinfo.x > 0) || IN_KeyDown(sc_RightArrow)) && (kx < PaddleMaxX))\r
81                         kx += 2;\r
82 \r
83                 if (killball)\r
84                 {\r
85                         ball = false;\r
86                         balltime = TimeCount + TickBase;\r
87                         speedup = 10;\r
88                         killball = false;\r
89                 }\r
90 \r
91                 if (ball && (cycle++ % 3))\r
92                 {\r
93                         x = (bx >> 2);\r
94                         if (!(x & 1))\r
95                                 x += (US_RndT() & 1);\r
96 \r
97                         if ((cx + 6 < x) && (cx < PaddleMaxX))\r
98                                 cx += 1;\r
99                         else if ((cx + 6 > x) && (cx > PaddleMinX))\r
100                                 cx -= 1;\r
101                 }\r
102 \r
103 //++++\r
104 //#if 1\r
105                 VLB_Bar(BallMinX,BallMinY - 1,\r
106                                 BallMaxX - BallMinX + 5,BallMaxY - BallMinY + 7,\r
107                                 3/*BackColor*/, &gvar->video.ofs);\r
108 #if 0\r
109                 VWB_DrawSprite(cx,CPaddleY,PADDLESPR);\r
110                 VWB_DrawSprite(kx,KPaddleY,PADDLESPR);\r
111 \r
112                 modexputPixel(gvar->video.page, BallMinX, BallMinY, 3);\r
113 #endif\r
114                 modexputPixel(gvar->video.page, cx, CPaddleY, 3);\r
115                 modexputPixel(gvar->video.page, kx, KPaddleY, 3);\r
116                 if (ball)\r
117                 {\r
118                         if\r
119                         (\r
120                                 (((bx + bdx) >> 2) > BallMaxX)\r
121                         ||      (((bx + bdx) >> 2) < BallMinX)\r
122                         )\r
123                         {\r
124 //++++                          SD__PlaySound(BALLBOUNCESND);\r
125                                 bdx = -bdx;\r
126                         }\r
127                         bx += bdx;\r
128 \r
129                         if (((by + bdy) >> 2) > BallMaxY)\r
130                         {\r
131                                 killball = true;\r
132                                 lastscore = false;\r
133                                 cscore++;\r
134 //++++                          SD__PlaySound(COMPSCOREDSND);\r
135                                 USL_DrawPongScore(kscore,cscore, gvar);\r
136                                 if (cscore == 21)\r
137                                 {\r
138 //++++                                  USL_CtlDialog("You lost!","Press any key",nil);\r
139                                         done = true;\r
140                                         continue;\r
141                                 }\r
142                         }\r
143                         else if (((by + bdy) >> 2) < BallMinY)\r
144                         {\r
145                                 killball = true;\r
146                                 lastscore = true;\r
147                                 kscore++;\r
148 //++++                          SD__PlaySound(KEENSCOREDSND);\r
149                                 USL_DrawPongScore(kscore,cscore, gvar);\r
150                                 if (kscore == 21)\r
151                                 {\r
152 //++++                                  USL_CtlDialog("You won!","Press any key",nil);\r
153                                         done = true;\r
154                                         continue;\r
155                                 }\r
156                         }\r
157                         by += bdy;\r
158 \r
159                         x = bx >> 2;\r
160                         y = by >> 2;\r
161                         if (!killball)\r
162                         {\r
163                                 if\r
164                                 (\r
165                                         (bdy < 0)\r
166                                 &&      ((y >= CPaddleY) && (y < CPaddleY + 3))\r
167                                 &&      ((x >= (cx - 5)) && (x < (cx + 11)))\r
168                                 )\r
169                                 {\r
170                                         rx = cx;\r
171                                         revdir = true;\r
172 //++++                          SD__PlaySound(COMPPADDLESND);\r
173                                 }\r
174                                 else if\r
175                                 (\r
176                                         (bdy > 0)\r
177                                 &&      ((y >= (KPaddleY - 3)) && (y < KPaddleY))\r
178                                 &&      ((x >= (kx - 5)) && (x < (kx + 11)))\r
179                                 )\r
180                                 {\r
181                                         if (((bdy >> 2) < 3) && !(--speedup))\r
182                                         {\r
183                                                 bdy++;\r
184                                                 speedup = 10;\r
185                                         }\r
186                                         rx = kx;\r
187                                         revdir = true;\r
188 //++++                                  SD__PlaySound(KEENPADDLESND);\r
189                                 }\r
190                                 if (revdir)\r
191                                 {\r
192                                         bdy = -bdy;\r
193                                         bdx = ((x + 5 - rx) >> 1) - (1 << 2);\r
194                                         if (!bdx)\r
195                                                 bdx--;\r
196                                         revdir = false;\r
197                                 }\r
198                         }\r
199 //++++                  VWB_DrawSprite(x,y,(x & 1)? BALL1PIXELTOTHERIGHTSPR : BALLSPR);\r
200                 }\r
201                 else if (TimeCount >= balltime)\r
202                 {\r
203                         ball = true;\r
204                         bdx = 1 - (US_RndT() % 3);\r
205                         bdy = 2;\r
206                         if (lastscore)\r
207                                 bdy = -bdy;\r
208                         bx = (BallMinX + ((BallMaxX - BallMinX) / 2)) << 2;\r
209                         by = (BallMinY + ((BallMaxY - BallMinY) / 2)) << 2;\r
210                 }\r
211 //++++          VW_UpdateScreen();\r
212                 while (waittime == TimeCount){}\r
213                         //;       // DEBUG - do adaptiveness\r
214         } while ((gvar->in.inst->LastScan != sc_Escape) && !done);\r
215         IN_ClearKeysDown();\r
216 }\r
217 /*\r
218 #pragma argsused\r
219 static boolean\r
220 USL_PongCustom(UserCall call,struct UserItem far *item)\r
221 {\r
222         if (call != uic_SetupCard)\r
223                 return(false);\r
224 \r
225         //++++VWB_DrawPic(0,0,CP_MENUSCREENPIC);\r
226         //++++VWB_DrawPic(CtlPanelSX + 56,CtlPanelSY,CP_PADDLEWARPIC);\r
227         //++++VWB_Hlin(CtlPanelSX + 3,CtlPanelEX - 3,CtlPanelSY + 12,HiliteColor ^ BackColor);\r
228         //++++VWB_Hlin(CtlPanelSX + 3,CtlPanelEX - 3,CtlPanelEY - 7,HiliteColor ^ BackColor);\r
229         USL_PlayPong();\r
230 \r
231         return(true);\r
232 }\r
233 */\r
234 ///////////////////////////////////////////////////////////////////////////\r
235 //\r
236 // US_RndT - Returns the next 8-bit pseudo random number\r
237 //\r
238 ///////////////////////////////////////////////////////////////////////////\r
239 int US_RndT()\r
240 {\r
241         int rndindex = 0;\r
242 \r
243         byte rndtable[] = {\r
244         0,   8, 109, 220, 222, 241, 149, 107,  75, 248, 254, 140,  16,  66,\r
245         74,  21, 211,  47,  80, 242, 154,  27, 205, 128, 161,  89,  77,  36,\r
246         95, 110,  85,  48, 212, 140, 211, 249,  22,  79, 200,  50,  28, 188,\r
247         52, 140, 202, 120,  68, 145,  62,  70, 184, 190,  91, 197, 152, 224,\r
248         149, 104,  25, 178, 252, 182, 202, 182, 141, 197,   4,  81, 181, 242,\r
249         145,  42,  39, 227, 156, 198, 225, 193, 219,  93, 122, 175, 249,   0,\r
250         175, 143,  70, 239,  46, 246, 163,  53, 163, 109, 168, 135,   2, 235,\r
251         25,  92,  20, 145, 138,  77,  69, 166,  78, 176, 173, 212, 166, 113,\r
252         94, 161,  41,  50, 239,  49, 111, 164,  70,  60,   2,  37, 171,  75,\r
253         136, 156,  11,  56,  42, 146, 138, 229,  73, 146,  77,  61,  98, 196,\r
254         135, 106,  63, 197, 195,  86,  96, 203, 113, 101, 170, 247, 181, 113,\r
255         80, 250, 108,   7, 255, 237, 129, 226,  79, 107, 112, 166, 103, 241,\r
256         24, 223, 239, 120, 198,  58,  60,  82, 128,   3, 184,  66, 143, 224,\r
257         145, 224,  81, 206, 163,  45,  63,  90, 168, 114,  59,  33, 159,  95,\r
258         28, 139, 123,  98, 125, 196,  15,  70, 194, 253,  54,  14, 109, 226,\r
259         71,  17, 161,  93, 186,  87, 244, 138,  20,  52, 123, 251,  26,  36,\r
260         17,  46,  52, 231, 232,  76,  31, 221,  84,  37, 216, 165, 212, 106,\r
261         197, 242,  98,  43,  39, 175, 254, 145, 190,  84, 118, 222, 187, 136,\r
262         120, 163, 236, 249 };\r
263         rndindex = (rndindex+1)&0xff;\r
264         return rndtable[rndindex];\r
265 }\r