1 #include "src/lib/16_us.h"
\r
5 word WindowX,WindowY,WindowW,WindowH;
\r
7 static word far* clockw= (word far*) 0x046C; // 18.2hz clock
\r
9 // Control panel data
\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
18 #define TickBase 70 // 70Hz per tick - used as a base for timer 0
\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
29 USL_DrawPongScore(word k,word c, global_game_variables_t *gvar)
\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
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
45 //++++US_PrintUnsigned(c);
\r
49 USL_PlayPong(global_game_variables_t *gvar)
\r
51 boolean ball,killball,revdir,done,lastscore;
\r
60 word balltime,waittime;
\r
61 CursorInfo cursorinfo;
\r
62 word TimeCount = *clockw;
\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
75 waittime = TimeCount;
\r
77 IN_ReadCursor(&cursorinfo, gvar);
\r
78 if (((cursorinfo.x < 0) || IN_KeyDown(sc_LeftArrow)) && (kx > PaddleMinX))
\r
80 else if (((cursorinfo.x > 0) || IN_KeyDown(sc_RightArrow)) && (kx < PaddleMaxX))
\r
86 balltime = TimeCount + TickBase;
\r
91 if (ball && (cycle++ % 3))
\r
95 x += (US_RndT() & 1);
\r
97 if ((cx + 6 < x) && (cx < PaddleMaxX))
\r
99 else if ((cx + 6 > x) && (cx > PaddleMinX))
\r
105 VLB_Bar(BallMinX,BallMinY - 1,
\r
106 BallMaxX - BallMinX + 5,BallMaxY - BallMinY + 7,
\r
107 3/*BackColor*/, &gvar->video.ofs);
\r
109 VWB_DrawSprite(cx,CPaddleY,PADDLESPR);
\r
110 VWB_DrawSprite(kx,KPaddleY,PADDLESPR);
\r
112 modexputPixel(gvar->video.page, BallMinX, BallMinY, 3);
\r
114 modexputPixel(gvar->video.page, cx, CPaddleY, 3);
\r
115 modexputPixel(gvar->video.page, kx, KPaddleY, 3);
\r
120 (((bx + bdx) >> 2) > BallMaxX)
\r
121 || (((bx + bdx) >> 2) < BallMinX)
\r
124 //++++ SD__PlaySound(BALLBOUNCESND);
\r
129 if (((by + bdy) >> 2) > BallMaxY)
\r
134 //++++ SD__PlaySound(COMPSCOREDSND);
\r
135 USL_DrawPongScore(kscore,cscore, gvar);
\r
138 //++++ USL_CtlDialog("You lost!","Press any key",nil);
\r
143 else if (((by + bdy) >> 2) < BallMinY)
\r
148 //++++ SD__PlaySound(KEENSCOREDSND);
\r
149 USL_DrawPongScore(kscore,cscore, gvar);
\r
152 //++++ USL_CtlDialog("You won!","Press any key",nil);
\r
166 && ((y >= CPaddleY) && (y < CPaddleY + 3))
\r
167 && ((x >= (cx - 5)) && (x < (cx + 11)))
\r
172 //++++ SD__PlaySound(COMPPADDLESND);
\r
177 && ((y >= (KPaddleY - 3)) && (y < KPaddleY))
\r
178 && ((x >= (kx - 5)) && (x < (kx + 11)))
\r
181 if (((bdy >> 2) < 3) && !(--speedup))
\r
188 //++++ SD__PlaySound(KEENPADDLESND);
\r
193 bdx = ((x + 5 - rx) >> 1) - (1 << 2);
\r
199 //++++ VWB_DrawSprite(x,y,(x & 1)? BALL1PIXELTOTHERIGHTSPR : BALLSPR);
\r
201 else if (TimeCount >= balltime)
\r
204 bdx = 1 - (US_RndT() % 3);
\r
208 bx = (BallMinX + ((BallMaxX - BallMinX) / 2)) << 2;
\r
209 by = (BallMinY + ((BallMaxY - BallMinY) / 2)) << 2;
\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
220 USL_PongCustom(UserCall call,struct UserItem far *item)
\r
222 if (call != uic_SetupCard)
\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
234 ///////////////////////////////////////////////////////////////////////////
\r
236 // US_RndT - Returns the next 8-bit pseudo random number
\r
238 ///////////////////////////////////////////////////////////////////////////
\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