1
2 #include "xchomp.h"
3
4 /*
5 * This file contains the code which implements the title screen
6 * for the game.
7 */
8
demo_seq()9 void demo_seq()
10 {
11 int i, xx, yy, direction, ascent, descent, len;
12 XCharStruct chars;
13 char string[50], c_buf;
14 XEvent event;
15 Bool done = False;
16 long sc;
17 XComposeStatus status;
18
19 /* clear the entire window and the map */
20 XFillRectangle(display, window, clearGC, 0, 0, WIN_WIDTH,
21 WIN_HEIGHT + GHOST_SIZE + 2);
22 XFillRectangle(display, map, clearGC, 0, 0, WIN_WIDTH,
23 WIN_HEIGHT + GHOST_SIZE + 2);
24
25 /* draw the marble background */
26 XSetFillStyle(display, fullcopyGC, FillStippled);
27 XFillRectangle(display, map, fullcopyGC, 0, 0, WIN_WIDTH,
28 WIN_HEIGHT + GHOST_SIZE + 2);
29 XCopyArea(display, map, window, fullcopyGC, 0, 0,
30 WIN_WIDTH, WIN_HEIGHT + GHOST_SIZE + 2, 0, 0);
31 XSetFillStyle(display, fullcopyGC, FillSolid);
32
33 /* draw the big title (on the map) */
34 XSetFillStyle(display, orGC, FillStippled);
35 xx = (WIN_WIDTH - (48 * 5 - 10)) / 2;
36 yy = 25;
37 for (i = 0; i < 5; i++) {
38 XSetClipMask(display, orGC, demo_mask[i]);
39 XSetClipMask(display, fullcopyGC, demo_mask[i]);
40 XSetClipOrigin(display, orGC, xx + 8, yy + 8);
41 XSetClipOrigin(display, fullcopyGC, xx, yy);
42 XFillRectangle(display, map, orGC, xx + 8, yy + 8, 48, 48);
43 XCopyPlane(display, demo_map[i], map, fullcopyGC, 0, 0,
44 48, 48, xx, yy, 1);
45 xx += (i ? 48 : 42); /* compensate for the 'c' cut-off */
46 }
47 XSetFillStyle(display, orGC, FillSolid);
48 XSetClipMask(display, orGC, None);
49 XSetClipMask(display, fullcopyGC, None);
50 XSetClipOrigin(display, orGC, 0, 0);
51 XSetClipOrigin(display, fullcopyGC, 0, 0);
52
53 /* programmer credits */
54 xx = (WIN_WIDTH - CREDIT_WIDTH) / 2;
55 yy = 89;
56 XSetFillStyle(display, orGC, FillStippled);
57 XFillRectangle(display, map, orGC, xx + 8, yy + 8,
58 CREDIT_WIDTH, CREDIT_HEIGHT);
59 XCopyPlane(display, credit, map, fullcopyGC, 0, 0,
60 CREDIT_WIDTH, CREDIT_HEIGHT, xx, yy, 1);
61 XSetFillStyle(display, orGC, FillSolid);
62
63 /* draw the first demo panel */
64 xx = (WIN_WIDTH - DEMOBOX_WIDTH) / 2;
65 yy = 126;
66 XSetFillStyle(display, orGC, FillStippled);
67 XFillRectangle(display, map, orGC, xx + 8, yy + 8,
68 DEMOBOX_WIDTH, DEMOBOX_HEIGHT);
69 XCopyPlane(display, demobox, map, fullcopyGC, 0, 0,
70 DEMOBOX_WIDTH, DEMOBOX_HEIGHT, xx, yy, 1);
71 XSetFillStyle(display, orGC, FillSolid);
72
73 /* draw the second demo panel */
74 XQueryTextExtents(display, font, " ", 1, &direction, &ascent,
75 &descent, &chars);
76 xx = WIN_WIDTH / 4;
77 yy = WIN_HEIGHT - 2 * GHOST_SIZE - descent - ascent - 20;
78 XSetFillStyle(display, orGC, FillStippled);
79 XFillRectangle(display, map, orGC, xx + 8, yy + 8,
80 WIN_WIDTH / 2, 4 * GHOST_SIZE);
81 XFillRectangle(display, map, clearGC, xx, yy,
82 WIN_WIDTH / 2, 4 * GHOST_SIZE);
83 XDrawRectangle(display, map, fullcopyGC, xx, yy,
84 WIN_WIDTH / 2, 4 * GHOST_SIZE);
85 XSetFillStyle(display, orGC, FillSolid);
86
87 /* draw the high score */
88 strcpy(string, "High Score: 000000");
89 sc = high_score;
90 for (i = 5; i >= 0; i--) {
91 string[12 + i] = '0' + (sc % 10);
92 sc /= 10;
93 }
94 len = strlen(string);
95 XQueryTextExtents(display, font, string, len, &direction, &ascent,
96 &descent, &chars);
97 xx = (WIN_WIDTH - chars.width) / 2;
98 yy = WIN_HEIGHT - 2 * GHOST_SIZE - descent - 10;
99 XDrawImageString(display, map, fullcopyGC, xx, yy, string, len);
100
101 /* draw some text */
102 strcpy(string, "Press \'Q\' To Quit");
103 len = strlen(string);
104 XQueryTextExtents(display, font, string, len, &direction, &ascent,
105 &descent, &chars);
106 xx = (WIN_WIDTH - chars.width) / 2;
107 yy = WIN_HEIGHT - GHOST_SIZE - descent - 10;
108 XDrawImageString(display, map, fullcopyGC, xx, yy, string, len);
109
110 /* draw some more text */
111 strcpy(string, "Any Other Key To Begin");
112 len = strlen(string);
113 XQueryTextExtents(display, font, string, len, &direction, &ascent,
114 &descent, &chars);
115 xx = (WIN_WIDTH - chars.width) / 2;
116 yy = WIN_HEIGHT - descent - 10;
117 XDrawImageString(display, map, fullcopyGC, xx, yy, string, len);
118
119 /* now copy the whole thing to the screen */
120 XCopyArea(display, map, window, fullcopyGC, 0, 0,
121 WIN_WIDTH, WIN_HEIGHT + GHOST_SIZE + 2, 0, 0);
122 XSync(display, True);
123
124 /* wait until the user hits a key */
125 while (!done) {
126 XNextEvent(display, &event);
127 if (event.xany.window != window) continue;
128 switch (event.type) {
129 case KeyPress:
130 XLookupString((XKeyEvent *) &event, &c_buf, 1, &last_key, &status);
131 if ((last_key == XK_q) || (last_key == XK_Q))
132 do_exit();
133 XFillRectangle(display, window, clearGC, 0, 0, WIN_WIDTH,
134 WIN_HEIGHT + GHOST_SIZE + 2);
135 XSync(display, True);
136 done = True;
137 break;
138 case Expose:
139 XCopyArea(display, map, window, fullcopyGC, 0, 0,
140 WIN_WIDTH, WIN_HEIGHT + GHOST_SIZE + 2, 0, 0);
141 break;
142 default: break;
143 }
144 }
145 }
146
147