1 /* 2000-08-13T14:36:17Z
3 * graphics manipulation crap
15 unsigned int frame; /* current frame */
16 unsigned int screen_x; /* current scroll position */
17 unsigned int screen_y;
19 static unsigned short screentiles[14][22]; /* tiles currently on screen */
21 static unsigned int colours[8];
22 static unsigned int colour_anim;
24 void xdebug(char *msg)
27 XSync(display, False);
28 printf("EM DEBUG: %s\n", msg);
32 static void colour_shuffle(void)
35 for (i = 0; i < 8; i++) colours[i] = i;
36 for (i = 0; i < 8; i++) {
37 Random = Random * 129 + 1;
38 j = (Random >> 10) & 7;
40 colours[i] = colours[j];
45 /* copy the entire screen to the window at the scroll position
47 * perhaps use mit-shm to speed this up
51 unsigned int x = screen_x % (22 * TILEX);
52 unsigned int y = screen_y % (14 * TILEY);
57 printf("::: %d, %d [%d, %d]\n", x, y, TILEX, TILEY);
60 if (x < 2 * TILEX && y < 2 * TILEY) {
63 printf("!!! %ld, %ld, %ld, %ld\n",
64 display, screenPixmap, xwindow, screenGC);
67 XCopyArea(display, screenPixmap, xwindow, screenGC, x, y, 20 * TILEX, 12 * TILEY, 0, 0);
68 } else if (x < 2 * TILEX && y >= 2 * TILEY) {
69 XCopyArea(display, screenPixmap, xwindow, screenGC, x, y, 20 * TILEX, 14 * TILEY - y, 0, 0);
70 XCopyArea(display, screenPixmap, xwindow, screenGC, x, 0, 20 * TILEX, y - 2 * TILEY, 0, 14 * TILEY - y);
71 } else if (x >= 2 * TILEX && y < 2 * TILEY) {
72 XCopyArea(display, screenPixmap, xwindow, screenGC, x, y, 22 * TILEX - x, 12 * TILEY, 0, 0);
73 XCopyArea(display, screenPixmap, xwindow, screenGC, 0, y, x - 2 * TILEX, 12 * TILEY, 22 * TILEX - x, 0);
75 XCopyArea(display, screenPixmap, xwindow, screenGC, x, y, 22 * TILEX - x, 14 * TILEY - y, 0, 0);
76 XCopyArea(display, screenPixmap, xwindow, screenGC, 0, y, x - 2 * TILEX, 14 * TILEY - y, 22 * TILEX - x, 0);
77 XCopyArea(display, screenPixmap, xwindow, screenGC, x, 0, 22 * TILEX - x, y - 2 * TILEY, 0, 14 * TILEY - y);
78 XCopyArea(display, screenPixmap, xwindow, screenGC, 0, 0, x - 2 * TILEX, y - 2 * TILEY, 22 * TILEX - x, 14 * TILEY - y);
81 XCopyArea(display, scorePixmap, xwindow, scoreGC, 0, 0, 20 * TILEX, SCOREY, 0, 12 * TILEY);
84 xdebug("blitscreen - done");
87 /* draw differences between game tiles and screen tiles
89 * implicitly handles scrolling and restoring background under the sprites
91 * perhaps use mit-shm to speed this up
93 static void animscreen(void)
95 unsigned int x, y, dx, dy;
97 unsigned int left = screen_x / TILEX;
98 unsigned int top = screen_y / TILEY;
100 xdebug("animscreen");
102 for (y = top; y < top + 14; y++) {
104 for (x = left; x < left + 22; x++) {
106 obj = map_obj[frame][Draw[y][x]];
107 if (screentiles[dy][dx] != obj) {
108 screentiles[dy][dx] = obj;
109 XCopyArea(display, objPixmap, screenPixmap, screenGC, (obj / 512) * TILEX, (obj % 512) * TILEY / 16, TILEX, TILEY, dx * TILEX, dy * TILEY);
115 /* blit players to the screen
117 * handles transparency and movement
119 static void blitplayer(struct PLAYER *ply)
121 unsigned int x, y, dx, dy;
122 unsigned short obj, spr;
124 xdebug("blitplayer");
128 x = (frame * ply->oldx + (8 - frame) * ply->x) * TILEX / 8;
129 y = (frame * ply->oldy + (8 - frame) * ply->y) * TILEY / 8;
133 if ((unsigned int)(dx - screen_x) < (21 * TILEX - 1) &&
134 (unsigned int)(dy - screen_y) < (13 * TILEY - 1))
136 spr = map_spr[ply->num][frame][ply->anim];
144 obj = screentiles[y / TILEY][x / TILEX];
145 XCopyArea(display, objmaskBitmap, spriteBitmap, spriteGC,
146 (obj / 512) * TILEX, (obj % 512) * TILEY / 16, TILEX, TILEY,
147 -(x % TILEX), -(y % TILEY));
149 obj = screentiles[dy / TILEY][dx / TILEX];
150 XCopyArea(display, objmaskBitmap, spriteBitmap, spriteGC,
151 (obj / 512) * TILEX, (obj % 512) * TILEY / 16, TILEX, TILEY,
152 (22 * TILEX - x) % TILEX, (14 * TILEY - y) % TILEY);
154 else if (sprmaskBitmap)
156 XCopyArea(display, sprmaskBitmap, spriteBitmap, spriteGC,
157 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY, 0, 0);
161 XFillRectangle(display, spriteBitmap, spriteGC, 0, 0, TILEX, TILEY);
164 screentiles[y / TILEY][x / TILEX] = -1; /* mark screen as dirty */
165 screentiles[dy / TILEY][dx / TILEX] = -1;
167 XSetClipMask(display, screenGC, spriteBitmap);
168 XSetClipOrigin(display, screenGC, x, y);
169 XCopyArea(display, sprPixmap, screenPixmap, screenGC,
170 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
172 XSetClipOrigin(display, screenGC, x - 22 * TILEX, y);
173 XCopyArea(display, sprPixmap, screenPixmap, screenGC,
174 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
176 XSetClipOrigin(display, screenGC, x, y - 14 * TILEY);
177 XCopyArea(display, sprPixmap, screenPixmap, screenGC,
178 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
180 XSetClipMask(display, screenGC, None);
185 void game_initscreen(void)
189 xdebug("game_initscreen");
192 printf("--> M5.1: xwindow == %ld\n", xwindow);
200 printf("--> M5.2: &window == %ld\n", &window);
201 printf("--> M5.2: xwindow == %ld\n", xwindow);
202 printf("--> M5.2: &xwindow == %ld\n", &xwindow);
203 printf("--> M5.2: screen == %ld\n", screen);
204 printf("--> M5.2: &screentiles[0][0] == %ld\n", &screentiles[0][0]);
207 for (y = 0; y < 14; y++) {
208 for (x = 0; x < 22; x++) {
210 printf("--> M5.2.A: xwindow == %ld [%d,%d]\n", xwindow, x,y);
212 screentiles[y][x] = -1;
214 printf("--> M5.2.B: xwindow == %ld [%d,%d]\n", xwindow, x,y);
220 printf("--> M5.3: xwindow == %ld\n", xwindow);
230 printf("--> M5.4: xwindow == %ld\n", xwindow);
233 XFillRectangle(display, scorePixmap, scoreGC, 0, 0, 20 * TILEX, SCOREY);
234 XCopyArea(display, botPixmap, scorePixmap, scoreGC, 11 * SCOREX, colours[0] * SCOREY, 3 * SCOREX, SCOREY, 1 * SCOREX, 0); /* 0-63 time */
235 XCopyArea(display, botPixmap, scorePixmap, scoreGC, 18 * SCOREX, colours[0] * SCOREY, 6 * SCOREX, SCOREY, 15 * SCOREX, 0); /* 112-207 diamonds */
236 XCopyArea(display, botPixmap, scorePixmap, scoreGC, 14 * SCOREX, colours[0] * SCOREY, 4 * SCOREX, SCOREY, 32 * SCOREX, 0); /* 256-319 score */
239 printf("--> M5.X: xwindow == %ld\n", xwindow);
243 void game_blitscore(void)
247 xdebug("game_blitscore");
249 i = (lev.time + 4) / 5;
250 XCopyArea(display, botPixmap, scorePixmap, scoreGC, (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY, 7 * SCOREX, 0); i /= 10;
251 XCopyArea(display, botPixmap, scorePixmap, scoreGC, (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY, 6 * SCOREX, 0); i /= 10;
252 XCopyArea(display, botPixmap, scorePixmap, scoreGC, (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY, 5 * SCOREX, 0); i /= 10;
253 XCopyArea(display, botPixmap, scorePixmap, scoreGC, (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY, 4 * SCOREX, 0);
255 XCopyArea(display, botPixmap, scorePixmap, scoreGC, (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY, 39 * SCOREX, 0); i /= 10;
256 XCopyArea(display, botPixmap, scorePixmap, scoreGC, (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY, 38 * SCOREX, 0); i /= 10;
257 XCopyArea(display, botPixmap, scorePixmap, scoreGC, (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY, 37 * SCOREX, 0); i /= 10;
258 XCopyArea(display, botPixmap, scorePixmap, scoreGC, (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY, 36 * SCOREX, 0);
260 XCopyArea(display, botPixmap, scorePixmap, scoreGC, 12 * SCOREX, 24 * SCOREY, 12 * SCOREX, SCOREY, 14 * SCOREX, 0); /* relax */
263 if (ply1.alive + ply2.alive >= lev.home && lev.required == 0) {
264 XCopyArea(display, botPixmap, scorePixmap, scoreGC, 24 * SCOREX, colours[2] * SCOREY, 12 * SCOREX, SCOREY, 14 * SCOREX, 0); /* find the exit */
267 if (ply1.alive + ply2.alive < lev.home) {
268 if (++colour_anim > 11) colour_anim = 0;
269 if (colour_anim < 6) {
270 XCopyArea(display, botPixmap, scorePixmap, scoreGC, 0, 24 * SCOREY, 12 * SCOREX, SCOREY, 14 * SCOREX, 0); /* forget it */
273 XCopyArea(display, botPixmap, scorePixmap, scoreGC, 18 * SCOREX, colours[0] * SCOREY, 6 * SCOREX, SCOREY, 15 * SCOREX, 0); /* diamonds */
276 XCopyArea(display, botPixmap, scorePixmap, scoreGC, (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY, 24 * SCOREX, 0); i /= 10;
277 XCopyArea(display, botPixmap, scorePixmap, scoreGC, (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY, 23 * SCOREX, 0); i /= 10;
278 XCopyArea(display, botPixmap, scorePixmap, scoreGC, (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY, 22 * SCOREX, 0); i /= 10;
279 XCopyArea(display, botPixmap, scorePixmap, scoreGC, (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY, 21 * SCOREX, 0);
283 void game_animscreen(void)
287 xdebug("game_animscreen");
289 x = (frame * ply1.oldx + (8 - frame) * ply1.x) * TILEX / 8 + (19 * TILEX) / 2;
290 y = (frame * ply1.oldy + (8 - frame) * ply1.y) * TILEY / 8 + (11 * TILEY) / 2;
291 if (x > lev.width * TILEX) x = lev.width * TILEX;
292 if (y > lev.height * TILEY) y = lev.height * TILEY;
293 if (x < 20 * TILEX) x = 20 * TILEY;
294 if (y < 12 * TILEY) y = 12 * TILEY;
295 screen_x = x - 19 * TILEX;
296 screen_y = y - 11 * TILEY;
304 Random = Random * 129 + 1;
307 void title_initscreen(void)
309 xdebug("title_initscreen");
318 XCopyArea(display, ttlPixmap, screenPixmap, screenGC, 0, 0, 20 * TILEX, 12 * TILEY, 0, 0);
320 XCopyArea(display, botPixmap, scorePixmap, scoreGC, 0, colours[1] * SCOREY, 20 * TILEX, SCOREY, 0, 0);
321 XSetClipMask(display, scoreGC, botmaskBitmap);
322 XSetClipOrigin(display, scoreGC, 0, 0 - colours[0] * SCOREY);
324 XCopyArea(display, botPixmap, scorePixmap, scoreGC, 0, colours[0] * SCOREY, 20 * TILEX, SCOREY, 0, 0);
326 XSetClipMask(display, scoreGC, None);
330 void title_blitscore(void)
332 unsigned int x, y, i;
334 xdebug("title_blitscore");
336 if (++colour_anim > 30) colour_anim = 0;
337 i = colour_anim >= 16 ? 31 - colour_anim : colour_anim;
338 x = (i / 8 + 18) * 2 * SCOREX;
339 y = (i % 8 + 16) * SCOREY;
342 XCopyArea(display, botPixmap, scorePixmap, scoreGC, 32 * SCOREX, colours[1] * SCOREY, 2 * SCOREX, SCOREY, 32 * SCOREX, 0);
343 XSetClipMask(display, scoreGC, botmaskBitmap);
344 XSetClipOrigin(display, scoreGC, 32 * SCOREX - x, 0 - y);
346 XCopyArea(display, botPixmap, scorePixmap, scoreGC, x, y, 2 * SCOREX, SCOREY, 32 * SCOREX, 0);
348 XSetClipMask(display, scoreGC, None);
352 void title_blitants(unsigned int y)
354 static const char ants_dashes[2] = { 8, 7 };
356 xdebug("title_blitants");
358 XSetDashes(display, antsGC, colour_anim, ants_dashes, 2);
359 XDrawRectangle(display, screenPixmap, antsGC, 0, y * TILEY, 20 * TILEX - 1, TILEY - 1);
362 void title_animscreen(void)
367 Random = Random * 129 + 1;
370 void title_string(unsigned int y, unsigned int left, unsigned int right, char *string)
375 xdebug("title_string");
377 y *= TILEY; left *= SCOREX; right *= SCOREX;
378 x = (left + right - strlen(string) * 12) / 2;
379 if (x < left || x >= right) x = left;
381 XCopyArea(display, ttlPixmap, screenPixmap, screenGC, left, y, right - left, TILEY, left, y);
382 if (ttlmaskBitmap) XSetClipMask(display, screenGC, ttlmaskBitmap);
383 for (i = 0; string[i] && x < right; i++) {
384 unsigned short ch_pos, ch_x, ch_y;
385 ch_pos = map_ttl[string[i] & 127];
387 ch_x = (ch_pos % 320);
388 ch_y = (ch_pos / 320 + 12) * TILEY;
389 if (ttlmaskBitmap) XSetClipOrigin(display, screenGC, x - ch_x, y - ch_y);
390 XCopyArea(display, ttlPixmap, screenPixmap, screenGC, ch_x, ch_y, 12, TILEY, x, y);
394 XSetClipMask(display, screenGC, None);