1 /* 2000-08-13T14:36:17Z
3 * graphics manipulation crap
16 #if defined(TARGET_X11)
18 unsigned int frame; /* current frame */
19 unsigned int screen_x; /* current scroll position */
20 unsigned int screen_y;
22 static unsigned short screentiles[14][22]; /* tiles currently on screen */
24 static unsigned int colours[8];
25 static unsigned int colour_anim;
27 static void xdebug(char *msg)
30 XSync(display, False);
31 printf("EM DEBUG: %s\n", msg);
35 static void colour_shuffle(void)
39 for (i = 0; i < 8; i++)
42 for (i = 0; i < 8; i++)
44 Random = Random * 129 + 1;
45 j = (Random >> 10) & 7;
47 colours[i] = colours[j];
52 /* copy the entire screen to the window at the scroll position
54 * perhaps use mit-shm to speed this up
58 unsigned int x = screen_x % (22 * TILEX);
59 unsigned int y = screen_y % (14 * TILEY);
63 if (x < 2 * TILEX && y < 2 * TILEY)
65 BlitBitmap(screenBitmap, window, x, y,
66 20 * TILEX, 12 * TILEY, SX, SY);
68 else if (x < 2 * TILEX && y >= 2 * TILEY)
70 BlitBitmap(screenBitmap, window, x, y,
71 20 * TILEX, 14 * TILEY - y, SX, SY);
72 BlitBitmap(screenBitmap, window, x, 0,
73 20 * TILEX, y - 2 * TILEY, SX, SY + 14 * TILEY - y);
75 else if (x >= 2 * TILEX && y < 2 * TILEY)
77 BlitBitmap(screenBitmap, window, x, y,
78 22 * TILEX - x, 12 * TILEY, SX, SY);
79 BlitBitmap(screenBitmap, window, 0, y,
80 x - 2 * TILEX, 12 * TILEY, SX + 22 * TILEX - x, SY);
84 BlitBitmap(screenBitmap, window, x, y,
85 22 * TILEX - x, 14 * TILEY - y, SX, SY);
86 BlitBitmap(screenBitmap, window, 0, y,
87 x - 2 * TILEX, 14 * TILEY - y, SX + 22 * TILEX - x, SY);
88 BlitBitmap(screenBitmap, window, x, 0,
89 22 * TILEX - x, y - 2 * TILEY, SX, SY + 14 * TILEY - y);
90 BlitBitmap(screenBitmap, window, 0, 0,
91 x - 2 * TILEX, y - 2 * TILEY,
92 SX + 22 * TILEX - x, SY + 14 * TILEY - y);
95 BlitBitmap(scoreBitmap, window, 0, 0,
96 20 * TILEX, SCOREY, SX, SY + 12 * TILEY);
99 xdebug("blitscreen - done");
102 /* draw differences between game tiles and screen tiles
104 * implicitly handles scrolling and restoring background under the sprites
106 * perhaps use mit-shm to speed this up
108 static void animscreen(void)
110 unsigned int x, y, dx, dy;
112 unsigned int left = screen_x / TILEX;
113 unsigned int top = screen_y / TILEY;
115 xdebug("animscreen");
117 for (y = top; y < top + 14; y++)
120 for (x = left; x < left + 22; x++)
123 obj = map_obj[frame][Draw[y][x]];
125 if (screentiles[dy][dx] != obj)
127 screentiles[dy][dx] = obj;
128 BlitBitmap(objBitmap, screenBitmap,
129 (obj / 512) * TILEX, (obj % 512) * TILEY / 16,
130 TILEX, TILEY, dx * TILEX, dy * TILEY);
136 /* blit players to the screen
138 * handles transparency and movement
140 static void blitplayer(struct PLAYER *ply)
142 unsigned int x, y, dx, dy;
143 unsigned short obj, spr;
145 xdebug("blitplayer");
149 x = (frame * ply->oldx + (8 - frame) * ply->x) * TILEX / 8;
150 y = (frame * ply->oldy + (8 - frame) * ply->y) * TILEY / 8;
154 if ((unsigned int)(dx - screen_x) < (21 * TILEX - 1) &&
155 (unsigned int)(dy - screen_y) < (13 * TILEY - 1))
157 spr = map_spr[ply->num][frame][ply->anim];
165 obj = screentiles[y / TILEY][x / TILEX];
166 XCopyArea(display, objmaskBitmap, spriteBitmap, spriteGC,
167 (obj / 512) * TILEX, (obj % 512) * TILEY / 16, TILEX, TILEY,
168 -(x % TILEX), -(y % TILEY));
170 obj = screentiles[dy / TILEY][dx / TILEX];
171 XCopyArea(display, objmaskBitmap, spriteBitmap, spriteGC,
172 (obj / 512) * TILEX, (obj % 512) * TILEY / 16, TILEX, TILEY,
173 (22 * TILEX - x) % TILEX, (14 * TILEY - y) % TILEY);
175 else if (sprmaskBitmap)
177 XCopyArea(display, sprmaskBitmap, spriteBitmap, spriteGC,
178 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY, 0, 0);
182 XFillRectangle(display, spriteBitmap, spriteGC, 0, 0, TILEX, TILEY);
185 screentiles[y / TILEY][x / TILEX] = -1; /* mark screen as dirty */
186 screentiles[dy / TILEY][dx / TILEX] = -1;
193 SetClipMask(sprBitmap, sprBitmap->stored_clip_gc, spriteBitmap);
195 SetClipOrigin(sprBitmap, sprBitmap->stored_clip_gc, x, y);
196 BlitBitmapMasked(sprBitmap, screenBitmap,
197 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
200 SetClipOrigin(sprBitmap, sprBitmap->stored_clip_gc, x - 22 * TILEX, y);
201 BlitBitmapMasked(sprBitmap, screenBitmap,
202 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
205 SetClipOrigin(sprBitmap, sprBitmap->stored_clip_gc, x, y - 14 * TILEY);
206 BlitBitmapMasked(sprBitmap, screenBitmap,
207 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
210 SetClipMask(sprBitmap, sprBitmap->stored_clip_gc, None);
214 XSetClipMask(display, sprBitmap->stored_clip_gc, spriteBitmap);
216 XSetClipOrigin(display, sprBitmap->stored_clip_gc, x, y);
217 XCopyArea(display, sprBitmap->drawable, screenBitmap->drawable,
218 sprBitmap->stored_clip_gc,
219 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
222 XSetClipOrigin(display, sprBitmap->stored_clip_gc, x - 22 * TILEX, y);
223 XCopyArea(display, sprBitmap->drawable, screenBitmap->drawable,
224 sprBitmap->stored_clip_gc,
225 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
228 XSetClipOrigin(display, sprBitmap->stored_clip_gc, x, y - 14 * TILEY);
229 XCopyArea(display, sprBitmap->drawable, screenBitmap->drawable,
230 sprBitmap->stored_clip_gc,
231 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
234 XSetClipMask(display, sprBitmap->stored_clip_gc, None);
240 XSetClipMask(display, screenGC, spriteBitmap);
241 XSetClipOrigin(display, screenGC, x, y);
242 XCopyArea(display, sprPixmap, screenPixmap, screenGC,
243 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
245 XSetClipOrigin(display, screenGC, x - 22 * TILEX, y);
246 XCopyArea(display, sprPixmap, screenPixmap, screenGC,
247 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
249 XSetClipOrigin(display, screenGC, x, y - 14 * TILEY);
250 XCopyArea(display, sprPixmap, screenPixmap, screenGC,
251 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
253 XSetClipMask(display, screenGC, None);
260 void game_initscreen(void)
264 xdebug("game_initscreen");
270 for (y = 0; y < 14; y++)
271 for (x = 0; x < 22; x++)
272 screentiles[y][x] = -1;
280 ClearRectangle(scoreBitmap, 0, 0, 20 * TILEX, SCOREY);
281 BlitBitmap(botBitmap, scoreBitmap,
282 11 * SCOREX, colours[0] * SCOREY, 3 * SCOREX, SCOREY,
283 1 * SCOREX, 0); /* 0-63 time */
284 BlitBitmap(botBitmap, scoreBitmap,
285 18 * SCOREX, colours[0] * SCOREY, 6 * SCOREX, SCOREY,
286 15 * SCOREX, 0); /* 112-207 diamonds */
287 BlitBitmap(botBitmap, scoreBitmap,
288 14 * SCOREX, colours[0] * SCOREY, 4 * SCOREX, SCOREY,
289 32 * SCOREX, 0); /* 256-319 score */
292 void game_blitscore(void)
296 xdebug("game_blitscore");
298 i = (lev.time + 4) / 5;
299 BlitBitmap(botBitmap, scoreBitmap,
300 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
301 7 * SCOREX, 0); i /= 10;
302 BlitBitmap(botBitmap, scoreBitmap,
303 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
304 6 * SCOREX, 0); i /= 10;
305 BlitBitmap(botBitmap, scoreBitmap,
306 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
307 5 * SCOREX, 0); i /= 10;
308 BlitBitmap(botBitmap, scoreBitmap,
309 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
313 BlitBitmap(botBitmap, scoreBitmap,
314 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
315 39 * SCOREX, 0); i /= 10;
316 BlitBitmap(botBitmap, scoreBitmap,
317 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
318 38 * SCOREX, 0); i /= 10;
319 BlitBitmap(botBitmap, scoreBitmap,
320 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
321 37 * SCOREX, 0); i /= 10;
322 BlitBitmap(botBitmap, scoreBitmap,
323 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
328 BlitBitmap(botBitmap, scoreBitmap,
329 12 * SCOREX, 24 * SCOREY, 12 * SCOREX, SCOREY,
330 14 * SCOREX, 0); /* relax */
335 if (ply1.alive + ply2.alive >= lev.home && lev.required == 0)
337 BlitBitmap(botBitmap, scoreBitmap,
338 24 * SCOREX, colours[2] * SCOREY, 12 * SCOREX, SCOREY,
339 14 * SCOREX, 0); /* find the exit */
344 if (ply1.alive + ply2.alive < lev.home)
346 if (++colour_anim > 11)
351 BlitBitmap(botBitmap, scoreBitmap,
352 0, 24 * SCOREY, 12 * SCOREX, SCOREY,
353 14 * SCOREX, 0); /* forget it */
358 BlitBitmap(botBitmap, scoreBitmap,
359 18 * SCOREX, colours[0] * SCOREY, 6 * SCOREX, SCOREY,
360 15 * SCOREX, 0); /* diamonds */
364 BlitBitmap(botBitmap, scoreBitmap,
365 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
366 24 * SCOREX, 0); i /= 10;
367 BlitBitmap(botBitmap, scoreBitmap,
368 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
369 23 * SCOREX, 0); i /= 10;
370 BlitBitmap(botBitmap, scoreBitmap,
371 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
372 22 * SCOREX, 0); i /= 10;
373 BlitBitmap(botBitmap, scoreBitmap,
374 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
380 void game_animscreen(void)
384 xdebug("game_animscreen");
386 x = (frame * ply1.oldx + (8 - frame) * ply1.x) * TILEX / 8
388 y = (frame * ply1.oldy + (8 - frame) * ply1.y) * TILEY / 8
391 if (x > lev.width * TILEX)
392 x = lev.width * TILEX;
393 if (y > lev.height * TILEY)
394 y = lev.height * TILEY;
400 screen_x = x - 19 * TILEX;
401 screen_y = y - 11 * TILEY;
410 Random = Random * 129 + 1;
413 void title_initscreen(void)
415 xdebug("title_initscreen");
426 BlitBitmap(ttlBitmap, screenBitmap,
427 0, 0, 20 * TILEX, 12 * TILEY, 0, 0);
431 BlitBitmap(botBitmap, scoreBitmap,
432 0, colours[1] * SCOREY, 20 * TILEX, SCOREY, 0, 0);
434 SetClipOrigin(botBitmap, botBitmap->stored_clip_gc,
435 0, 0 - colours[0] * SCOREY);
438 BlitBitmapMasked(botBitmap, scoreBitmap,
439 0, colours[0] * SCOREY, 20 * TILEX, SCOREY, 0, 0);
443 XCopyArea(display, ttlPixmap, screenPixmap, screenGC,
444 0, 0, 20 * TILEX, 12 * TILEY, 0, 0);
448 XCopyArea(display, botPixmap, scorePixmap, scoreGC,
449 0, colours[1] * SCOREY, 20 * TILEX, SCOREY, 0, 0);
450 XSetClipMask(display, scoreGC, botmaskBitmap);
451 XSetClipOrigin(display, scoreGC, 0, 0 - colours[0] * SCOREY);
454 XCopyArea(display, botPixmap, scorePixmap, scoreGC,
455 0, colours[0] * SCOREY, 20 * TILEX, SCOREY, 0, 0);
458 XSetClipMask(display, scoreGC, None);
463 void title_blitscore(void)
465 unsigned int x, y, i;
467 xdebug("title_blitscore");
469 if (++colour_anim > 30)
472 i = colour_anim >= 16 ? 31 - colour_anim : colour_anim;
473 x = (i / 8 + 18) * 2 * SCOREX;
474 y = (i % 8 + 16) * SCOREY;
479 BlitBitmap(botBitmap, scoreBitmap,
480 32 * SCOREX, colours[1] * SCOREY, 2 * SCOREX, SCOREY,
483 SetClipOrigin(botBitmap, botBitmap->stored_clip_gc,
484 32 * SCOREX - x, 0 - y);
487 BlitBitmapMasked(botBitmap, scoreBitmap,
488 x, y, 2 * SCOREX, SCOREY, 32 * SCOREX, 0);
494 XCopyArea(display, botPixmap, scorePixmap, scoreGC,
495 32 * SCOREX, colours[1] * SCOREY, 2 * SCOREX, SCOREY,
497 XSetClipMask(display, scoreGC, botmaskBitmap);
498 XSetClipOrigin(display, scoreGC, 32 * SCOREX - x, 0 - y);
501 XCopyArea(display, botPixmap, scorePixmap, scoreGC,
502 x, y, 2 * SCOREX, SCOREY, 32 * SCOREX, 0);
505 XSetClipMask(display, scoreGC, None);
509 void title_blitants(unsigned int y)
511 static const char ants_dashes[2] = { 8, 7 };
513 xdebug("title_blitants");
515 XSetDashes(display, antsGC, colour_anim, ants_dashes, 2);
516 XDrawRectangle(display, screenPixmap, antsGC,
517 0, y * TILEY, 20 * TILEX - 1, TILEY - 1);
520 void title_animscreen(void)
525 Random = Random * 129 + 1;
528 static int ttl_map[] =
530 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
531 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
532 -1,0,-1,-1,-1,-1,-1,1,-1,-1,-1,-1,2,3,4,-1, /* !',-. */
533 5,6,7,8,9,10,11,12,13,14,15,-1,-1,-1,-1,16, /* 0123456789:? */
534 -1,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, /* ABCDEFGHIJKLMNO */
535 32,33,34,35,36,37,38,39,40,41,42,-1,-1,-1,-1,-1, /* PQRSTUVWXYZ */
536 -1,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, /* abcdefghijklmno */
537 32,33,34,35,36,37,38,39,40,41,42,-1,-1,-1,-1,-1 /* pqrstuvwxyz */
540 void title_string(unsigned int y, unsigned int left, unsigned int right,
546 xdebug("title_string");
552 x = (left + right - strlen(string) * MENUFONTX) / 2;
553 if (x < left || x >= right) x = left;
555 /* restore background graphic where text will be drawn */
556 BlitBitmap(ttlBitmap, screenBitmap,
557 left, y, right - left, MENUFONTY, left, y);
562 XSetClipMask(display, screenGC, ttlmaskBitmap);
565 for (i = 0; string[i] && x < right; i++)
567 int ch_pos, ch_x, ch_y;
569 ch_pos = ttl_map[string[i] & 127];
571 if (ch_pos == -1 || ch_pos > 22 * 2)
572 continue; /* no graphic for this character */
574 ch_x = (ch_pos % 22) * GFXMENUFONTX;
575 ch_y = (ch_pos / 22 + 12) * TILEY;
578 SetClipOrigin(ttlBitmap, ttlBitmap->stored_clip_gc,
581 BlitBitmapMasked(ttlBitmap, screenBitmap,
582 ch_x, ch_y, MENUFONTX, MENUFONTY, x, y);
585 XSetClipOrigin(display, screenGC, x - ch_x, y - ch_y);
587 XCopyArea(display, ttlPixmap, screenPixmap, screenGC,
588 ch_x, ch_y, MENUFONTX, MENUFONTY, x, y);
596 XSetClipMask(display, screenGC, None);