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;
188 XSetClipMask(display, screenGC, spriteBitmap);
189 XSetClipOrigin(display, screenGC, x, y);
190 XCopyArea(display, sprPixmap, screenPixmap, screenGC,
191 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
193 XSetClipOrigin(display, screenGC, x - 22 * TILEX, y);
194 XCopyArea(display, sprPixmap, screenPixmap, screenGC,
195 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
197 XSetClipOrigin(display, screenGC, x, y - 14 * TILEY);
198 XCopyArea(display, sprPixmap, screenPixmap, screenGC,
199 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
201 XSetClipMask(display, screenGC, None);
206 void game_initscreen(void)
210 xdebug("game_initscreen");
216 for (y = 0; y < 14; y++)
217 for (x = 0; x < 22; x++)
218 screentiles[y][x] = -1;
226 ClearRectangle(scoreBitmap, 0, 0, 20 * TILEX, SCOREY);
227 BlitBitmap(botBitmap, scoreBitmap,
228 11 * SCOREX, colours[0] * SCOREY, 3 * SCOREX, SCOREY,
229 1 * SCOREX, 0); /* 0-63 time */
230 BlitBitmap(botBitmap, scoreBitmap,
231 18 * SCOREX, colours[0] * SCOREY, 6 * SCOREX, SCOREY,
232 15 * SCOREX, 0); /* 112-207 diamonds */
233 BlitBitmap(botBitmap, scoreBitmap,
234 14 * SCOREX, colours[0] * SCOREY, 4 * SCOREX, SCOREY,
235 32 * SCOREX, 0); /* 256-319 score */
238 void game_blitscore(void)
242 xdebug("game_blitscore");
244 i = (lev.time + 4) / 5;
245 BlitBitmap(botBitmap, scoreBitmap,
246 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
247 7 * SCOREX, 0); i /= 10;
248 BlitBitmap(botBitmap, scoreBitmap,
249 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
250 6 * SCOREX, 0); i /= 10;
251 BlitBitmap(botBitmap, scoreBitmap,
252 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
253 5 * SCOREX, 0); i /= 10;
254 BlitBitmap(botBitmap, scoreBitmap,
255 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
259 BlitBitmap(botBitmap, scoreBitmap,
260 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
261 39 * SCOREX, 0); i /= 10;
262 BlitBitmap(botBitmap, scoreBitmap,
263 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
264 38 * SCOREX, 0); i /= 10;
265 BlitBitmap(botBitmap, scoreBitmap,
266 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
267 37 * SCOREX, 0); i /= 10;
268 BlitBitmap(botBitmap, scoreBitmap,
269 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
274 BlitBitmap(botBitmap, scoreBitmap,
275 12 * SCOREX, 24 * SCOREY, 12 * SCOREX, SCOREY,
276 14 * SCOREX, 0); /* relax */
281 if (ply1.alive + ply2.alive >= lev.home && lev.required == 0)
283 BlitBitmap(botBitmap, scoreBitmap,
284 24 * SCOREX, colours[2] * SCOREY, 12 * SCOREX, SCOREY,
285 14 * SCOREX, 0); /* find the exit */
290 if (ply1.alive + ply2.alive < lev.home)
292 if (++colour_anim > 11)
297 BlitBitmap(botBitmap, scoreBitmap,
298 0, 24 * SCOREY, 12 * SCOREX, SCOREY,
299 14 * SCOREX, 0); /* forget it */
304 BlitBitmap(botBitmap, scoreBitmap,
305 18 * SCOREX, colours[0] * SCOREY, 6 * SCOREX, SCOREY,
306 15 * SCOREX, 0); /* diamonds */
310 BlitBitmap(botBitmap, scoreBitmap,
311 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
312 24 * SCOREX, 0); i /= 10;
313 BlitBitmap(botBitmap, scoreBitmap,
314 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
315 23 * SCOREX, 0); i /= 10;
316 BlitBitmap(botBitmap, scoreBitmap,
317 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
318 22 * SCOREX, 0); i /= 10;
319 BlitBitmap(botBitmap, scoreBitmap,
320 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
326 void game_animscreen(void)
330 xdebug("game_animscreen");
332 x = (frame * ply1.oldx + (8 - frame) * ply1.x) * TILEX / 8
334 y = (frame * ply1.oldy + (8 - frame) * ply1.y) * TILEY / 8
337 if (x > lev.width * TILEX)
338 x = lev.width * TILEX;
339 if (y > lev.height * TILEY)
340 y = lev.height * TILEY;
346 screen_x = x - 19 * TILEX;
347 screen_y = y - 11 * TILEY;
356 Random = Random * 129 + 1;
359 void title_initscreen(void)
361 xdebug("title_initscreen");
370 XCopyArea(display, ttlPixmap, screenPixmap, screenGC,
371 0, 0, 20 * TILEX, 12 * TILEY, 0, 0);
375 XCopyArea(display, botPixmap, scorePixmap, scoreGC,
376 0, colours[1] * SCOREY, 20 * TILEX, SCOREY, 0, 0);
377 XSetClipMask(display, scoreGC, botmaskBitmap);
378 XSetClipOrigin(display, scoreGC, 0, 0 - colours[0] * SCOREY);
381 XCopyArea(display, botPixmap, scorePixmap, scoreGC,
382 0, colours[0] * SCOREY, 20 * TILEX, SCOREY, 0, 0);
385 XSetClipMask(display, scoreGC, None);
388 void title_blitscore(void)
390 unsigned int x, y, i;
392 xdebug("title_blitscore");
394 if (++colour_anim > 30)
397 i = colour_anim >= 16 ? 31 - colour_anim : colour_anim;
398 x = (i / 8 + 18) * 2 * SCOREX;
399 y = (i % 8 + 16) * SCOREY;
403 XCopyArea(display, botPixmap, scorePixmap, scoreGC,
404 32 * SCOREX, colours[1] * SCOREY, 2 * SCOREX, SCOREY,
406 XSetClipMask(display, scoreGC, botmaskBitmap);
407 XSetClipOrigin(display, scoreGC, 32 * SCOREX - x, 0 - y);
410 XCopyArea(display, botPixmap, scorePixmap, scoreGC,
411 x, y, 2 * SCOREX, SCOREY, 32 * SCOREX, 0);
414 XSetClipMask(display, scoreGC, None);
417 void title_blitants(unsigned int y)
419 static const char ants_dashes[2] = { 8, 7 };
421 xdebug("title_blitants");
423 XSetDashes(display, antsGC, colour_anim, ants_dashes, 2);
424 XDrawRectangle(display, screenPixmap, antsGC,
425 0, y * TILEY, 20 * TILEX - 1, TILEY - 1);
428 void title_animscreen(void)
433 Random = Random * 129 + 1;
436 static int ttl_map[] =
438 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
439 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
440 -1,0,-1,-1,-1,-1,-1,1,-1,-1,-1,-1,2,3,4,-1, /* !',-. */
441 5,6,7,8,9,10,11,12,13,14,15,-1,-1,-1,-1,16, /* 0123456789:? */
442 -1,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, /* ABCDEFGHIJKLMNO */
443 32,33,34,35,36,37,38,39,40,41,42,-1,-1,-1,-1,-1, /* PQRSTUVWXYZ */
444 -1,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, /* abcdefghijklmno */
445 32,33,34,35,36,37,38,39,40,41,42,-1,-1,-1,-1,-1 /* pqrstuvwxyz */
448 void title_string(unsigned int y, unsigned int left, unsigned int right,
454 xdebug("title_string");
460 x = (left + right - strlen(string) * MENUFONTX) / 2;
461 if (x < left || x >= right) x = left;
463 /* restore background graphic where text will be drawn */
464 BlitBitmap(ttlBitmap, screenBitmap,
465 left, y, right - left, MENUFONTY, left, y);
470 XSetClipMask(display, screenGC, ttlmaskBitmap);
473 for (i = 0; string[i] && x < right; i++)
475 int ch_pos, ch_x, ch_y;
477 ch_pos = ttl_map[string[i] & 127];
479 if (ch_pos == -1 || ch_pos > 22 * 2)
480 continue; /* no graphic for this character */
482 ch_x = (ch_pos % 22) * GFXMENUFONTX;
483 ch_y = (ch_pos / 22 + 12) * TILEY;
486 SetClipOrigin(ttlBitmap, ttlBitmap->stored_clip_gc,
489 BlitBitmapMasked(ttlBitmap, screenBitmap,
490 ch_x, ch_y, MENUFONTX, MENUFONTY, x, y);
493 XSetClipOrigin(display, screenGC, x - ch_x, y - ch_y);
495 XCopyArea(display, ttlPixmap, screenPixmap, screenGC,
496 ch_x, ch_y, MENUFONTX, MENUFONTY, x, y);
504 XSetClipMask(display, screenGC, None);