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 /* tiles currently on screen */
23 static unsigned short screentiles[MAX_BUF_YSIZE][MAX_BUF_XSIZE];
25 static unsigned int colours[8];
26 static unsigned int colour_anim;
28 static void xdebug(char *msg)
31 XSync(display, False);
32 printf("EM DEBUG: %s\n", msg);
36 static void colour_shuffle(void)
40 for (i = 0; i < 8; i++)
43 for (i = 0; i < 8; i++)
45 Random = Random * 129 + 1;
46 j = (Random >> 10) & 7;
48 colours[i] = colours[j];
54 /* copy the entire screen to the window at the scroll position
56 * perhaps use mit-shm to speed this up
61 unsigned int x = screen_x % (MAX_BUF_XSIZE * TILEX);
62 unsigned int y = screen_y % (MAX_BUF_YSIZE * TILEY);
66 if (em_game_status == EM_GAME_STATUS_MENU)
68 ClearRectangle(screenBitmap, 0, SCR_MENUY * TILEY,
69 SCR_FIELDX * TILEX, (17 - SCR_MENUY) * TILEY);
70 BlitBitmap(scoreBitmap, screenBitmap, 0, 0, SCR_MENUX * TILEX, SCOREY,
71 0, SCR_MENUY * TILEY);
74 if (x < 2 * TILEX && y < 2 * TILEY)
76 BlitBitmap(screenBitmap, window, x, y,
77 SCR_FIELDX * TILEX, SCR_FIELDY * TILEY, SX, SY);
79 else if (x < 2 * TILEX && y >= 2 * TILEY)
81 BlitBitmap(screenBitmap, window, x, y,
82 SCR_FIELDX * TILEX, MAX_BUF_YSIZE * TILEY - y,
84 BlitBitmap(screenBitmap, window, x, 0,
85 SCR_FIELDX * TILEX, y - 2 * TILEY,
86 SX, SY + MAX_BUF_YSIZE * TILEY - y);
88 else if (x >= 2 * TILEX && y < 2 * TILEY)
90 BlitBitmap(screenBitmap, window, x, y,
91 MAX_BUF_XSIZE * TILEX - x, SCR_FIELDY * TILEY,
93 BlitBitmap(screenBitmap, window, 0, y,
94 x - 2 * TILEX, SCR_FIELDY * TILEY,
95 SX + MAX_BUF_XSIZE * TILEX - x, SY);
99 BlitBitmap(screenBitmap, window, x, y,
100 MAX_BUF_XSIZE * TILEX - x, MAX_BUF_YSIZE * TILEY - y,
102 BlitBitmap(screenBitmap, window, 0, y,
103 x - 2 * TILEX, MAX_BUF_YSIZE * TILEY - y,
104 SX + MAX_BUF_XSIZE * TILEX - x, SY);
105 BlitBitmap(screenBitmap, window, x, 0,
106 MAX_BUF_XSIZE * TILEX - x, y - 2 * TILEY,
107 SX, SY + MAX_BUF_YSIZE * TILEY - y);
108 BlitBitmap(screenBitmap, window, 0, 0,
109 x - 2 * TILEX, y - 2 * TILEY,
110 SX + MAX_BUF_XSIZE * TILEX - x, SY + MAX_BUF_YSIZE * TILEY - y);
113 /* draw either the main menu footer or the in-game time/gems/score values */
115 if (em_game_status == EM_GAME_STATUS_PLAY)
116 BlitBitmap(scoreBitmap, window, 0, 0, SCR_FIELDX * TILEX, SCOREY,
117 SX, SY + SCR_FIELDY * TILEY - SCOREY);
121 xdebug("blitscreen - done");
125 /* draw differences between game tiles and screen tiles
127 * implicitly handles scrolling and restoring background under the sprites
129 * perhaps use mit-shm to speed this up
132 static void animscreen(void)
134 unsigned int x, y, dx, dy;
136 unsigned int left = screen_x / TILEX;
137 unsigned int top = screen_y / TILEY;
139 xdebug("animscreen");
141 for (y = top; y < top + MAX_BUF_YSIZE; y++)
143 dy = y % MAX_BUF_YSIZE;
144 for (x = left; x < left + MAX_BUF_XSIZE; x++)
146 dx = x % MAX_BUF_XSIZE;
147 obj = map_obj[frame][Draw[y][x]];
149 if (screentiles[dy][dx] != obj)
151 screentiles[dy][dx] = obj;
152 BlitBitmap(objBitmap, screenBitmap,
153 (obj / 512) * TILEX, (obj % 512) * TILEY / 16,
154 TILEX, TILEY, dx * TILEX, dy * TILEY);
161 /* blit players to the screen
163 * handles transparency and movement
166 static void blitplayer(struct PLAYER *ply)
168 unsigned int x, y, dx, dy;
169 unsigned short obj, spr;
171 xdebug("blitplayer");
175 x = (frame * ply->oldx + (8 - frame) * ply->x) * TILEX / 8;
176 y = (frame * ply->oldy + (8 - frame) * ply->y) * TILEY / 8;
180 if ((unsigned int)(dx - screen_x) < ((MAX_BUF_XSIZE - 1) * TILEX - 1) &&
181 (unsigned int)(dy - screen_y) < ((MAX_BUF_YSIZE - 1) * TILEY - 1))
183 spr = map_spr[ply->num][frame][ply->anim];
184 x %= MAX_BUF_XSIZE * TILEX;
185 y %= MAX_BUF_YSIZE * TILEY;
186 dx %= MAX_BUF_XSIZE * TILEX;
187 dy %= MAX_BUF_YSIZE * TILEY;
191 obj = screentiles[y / TILEY][x / TILEX];
192 XCopyArea(display, objmaskBitmap, spriteBitmap, spriteGC,
193 (obj / 512) * TILEX, (obj % 512) * TILEY / 16, TILEX, TILEY,
194 -(x % TILEX), -(y % TILEY));
196 obj = screentiles[dy / TILEY][dx / TILEX];
197 XCopyArea(display, objmaskBitmap, spriteBitmap, spriteGC,
198 (obj / 512) * TILEX, (obj % 512) * TILEY / 16, TILEX, TILEY,
199 (MAX_BUF_XSIZE * TILEX - x) % TILEX,
200 (MAX_BUF_YSIZE * TILEY - y) % TILEY);
202 else if (sprmaskBitmap)
204 XCopyArea(display, sprmaskBitmap, spriteBitmap, spriteGC,
205 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY, 0, 0);
209 XFillRectangle(display, spriteBitmap, spriteGC, 0, 0, TILEX, TILEY);
212 screentiles[y / TILEY][x / TILEX] = -1; /* mark screen as dirty */
213 screentiles[dy / TILEY][dx / TILEX] = -1;
220 SetClipMask(sprBitmap, sprBitmap->stored_clip_gc, spriteBitmap);
222 SetClipOrigin(sprBitmap, sprBitmap->stored_clip_gc, x, y);
223 BlitBitmapMasked(sprBitmap, screenBitmap,
224 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
227 SetClipOrigin(sprBitmap, sprBitmap->stored_clip_gc,
228 x - MAX_BUF_XSIZE * TILEX, y);
229 BlitBitmapMasked(sprBitmap, screenBitmap,
230 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
231 x - MAX_BUF_XSIZE * TILEX, y);
233 SetClipOrigin(sprBitmap, sprBitmap->stored_clip_gc,
234 x, y - MAX_BUF_YSIZE * TILEY);
235 BlitBitmapMasked(sprBitmap, screenBitmap,
236 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
237 x, y - MAX_BUF_YSIZE * TILEY);
239 SetClipMask(sprBitmap, sprBitmap->stored_clip_gc, None);
243 XSetClipMask(display, sprBitmap->stored_clip_gc, spriteBitmap);
245 XSetClipOrigin(display, sprBitmap->stored_clip_gc, x, y);
246 XCopyArea(display, sprBitmap->drawable, screenBitmap->drawable,
247 sprBitmap->stored_clip_gc,
248 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
251 XSetClipOrigin(display, sprBitmap->stored_clip_gc,
252 x - MAX_BUF_XSIZE * TILEX, y);
253 XCopyArea(display, sprBitmap->drawable, screenBitmap->drawable,
254 sprBitmap->stored_clip_gc,
255 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
256 x - MAX_BUF_XSIZE * TILEX, y);
258 XSetClipOrigin(display, sprBitmap->stored_clip_gc,
259 x, y - MAX_BUF_YSIZE * TILEY);
260 XCopyArea(display, sprBitmap->drawable, screenBitmap->drawable,
261 sprBitmap->stored_clip_gc,
262 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
263 x, y - MAX_BUF_YSIZE * TILEY);
265 XSetClipMask(display, sprBitmap->stored_clip_gc, None);
271 XSetClipMask(display, screenGC, spriteBitmap);
272 XSetClipOrigin(display, screenGC, x, y);
273 XCopyArea(display, sprPixmap, screenPixmap, screenGC,
274 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
276 XSetClipOrigin(display, screenGC, x - MAX_BUF_XSIZE * TILEX, y);
277 XCopyArea(display, sprPixmap, screenPixmap, screenGC,
278 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
279 x - MAX_BUF_XSIZE * TILEX, y);
280 XSetClipOrigin(display, screenGC, x, y - MAX_BUF_YSIZE * TILEY);
281 XCopyArea(display, sprPixmap, screenPixmap, screenGC,
282 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
283 x, y - MAX_BUF_YSIZE * TILEY);
284 XSetClipMask(display, screenGC, None);
292 /* draw static text for time, gems and score counter */
294 void game_initscreen(void)
298 xdebug("game_initscreen");
304 for (y = 0; y < MAX_BUF_YSIZE; y++)
305 for (x = 0; x < MAX_BUF_XSIZE; x++)
306 screentiles[y][x] = -1;
314 ClearRectangle(scoreBitmap, 0, 0, SCR_FIELDX * TILEX, SCOREY);
315 BlitBitmap(botBitmap, scoreBitmap,
316 11 * SCOREX, colours[0] * SCOREY, 3 * SCOREX, SCOREY,
317 1 * SCOREX, 0); /* 0-63 time */
318 BlitBitmap(botBitmap, scoreBitmap,
319 18 * SCOREX, colours[0] * SCOREY, 6 * SCOREX, SCOREY,
320 11 * SCOREX, 0); /* 112-207 diamonds */
321 BlitBitmap(botBitmap, scoreBitmap,
322 14 * SCOREX, colours[0] * SCOREY, 4 * SCOREX, SCOREY,
323 24 * SCOREX, 0); /* 256-319 score */
327 /* draw current values for time, gems and score counter */
329 void game_blitscore(void)
333 xdebug("game_blitscore");
335 i = (lev.time + 4) / 5;
336 BlitBitmap(botBitmap, scoreBitmap,
337 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
338 7 * SCOREX, 0); i /= 10;
339 BlitBitmap(botBitmap, scoreBitmap,
340 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
341 6 * SCOREX, 0); i /= 10;
342 BlitBitmap(botBitmap, scoreBitmap,
343 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
344 5 * SCOREX, 0); i /= 10;
345 BlitBitmap(botBitmap, scoreBitmap,
346 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
350 BlitBitmap(botBitmap, scoreBitmap,
351 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
352 31 * SCOREX, 0); i /= 10;
353 BlitBitmap(botBitmap, scoreBitmap,
354 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
355 30 * SCOREX, 0); i /= 10;
356 BlitBitmap(botBitmap, scoreBitmap,
357 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
358 29 * SCOREX, 0); i /= 10;
359 BlitBitmap(botBitmap, scoreBitmap,
360 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
365 BlitBitmap(botBitmap, scoreBitmap,
366 12 * SCOREX, 24 * SCOREY, 12 * SCOREX, SCOREY,
367 14 * SCOREX, 0); /* relax */
372 if (ply1.alive + ply2.alive >= lev.home && lev.required == 0)
374 BlitBitmap(botBitmap, scoreBitmap,
375 24 * SCOREX, colours[2] * SCOREY, 12 * SCOREX, SCOREY,
376 14 * SCOREX, 0); /* find the exit */
381 if (ply1.alive + ply2.alive < lev.home)
383 if (++colour_anim > 11)
388 BlitBitmap(botBitmap, scoreBitmap,
389 0, 24 * SCOREY, 12 * SCOREX, SCOREY,
390 14 * SCOREX, 0); /* forget it */
395 BlitBitmap(botBitmap, scoreBitmap,
396 18 * SCOREX, colours[0] * SCOREY, 6 * SCOREX, SCOREY,
397 15 * SCOREX, 0); /* diamonds */
401 BlitBitmap(botBitmap, scoreBitmap,
402 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
405 BlitBitmap(botBitmap, scoreBitmap,
406 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
409 BlitBitmap(botBitmap, scoreBitmap,
410 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
413 BlitBitmap(botBitmap, scoreBitmap,
414 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
420 void game_animscreen(void)
424 xdebug("game_animscreen");
426 x = (frame * ply1.oldx + (8 - frame) * ply1.x) * TILEX / 8
427 + ((SCR_FIELDX - 1) * TILEX) / 2;
428 y = (frame * ply1.oldy + (8 - frame) * ply1.y) * TILEY / 8
429 + ((SCR_FIELDY - 1) * TILEY) / 2;
431 if (x > lev.width * TILEX)
432 x = lev.width * TILEX;
433 if (y > lev.height * TILEY)
434 y = lev.height * TILEY;
436 if (x < SCR_FIELDX * TILEX)
437 x = SCR_FIELDX * TILEY;
438 if (y < SCR_FIELDY * TILEY)
439 y = SCR_FIELDY * TILEY;
441 screen_x = x - (SCR_FIELDX - 1) * TILEX;
442 screen_y = y - (SCR_FIELDY - 1) * TILEY;
451 Random = Random * 129 + 1;
455 /* draw main menu background and copyright note */
457 void title_initscreen(void)
459 xdebug("title_initscreen");
470 /* draw title screen on menu background */
472 BlitBitmap(ttlBitmap, screenBitmap, ORIG_MENU_SX, ORIG_MENU_SY,
473 SCR_MENUX * TILEX, SCR_MENUY * TILEY, 0, 0);
475 /* draw copyright note at footer */
479 BlitBitmap(botBitmap, scoreBitmap, 0, colours[1] * SCOREY,
480 SCR_MENUX * TILEX, SCOREY, 0, 0);
482 SetClipOrigin(botBitmap, botBitmap->stored_clip_gc,
483 0, 0 - colours[0] * SCOREY);
486 BlitBitmapMasked(botBitmap, scoreBitmap, 0, colours[0] * SCOREY,
487 SCR_MENUX * TILEX, SCOREY, 0, 0);
491 XCopyArea(display, ttlPixmap, screenPixmap, screenGC,
492 0, 0, SCR_MENUX * TILEX, SCR_MENUY * TILEY, 0, 0);
496 XCopyArea(display, botPixmap, scorePixmap, scoreGC,
497 0, colours[1] * SCOREY, SCR_MENUX * TILEX, SCOREY, 0, 0);
498 XSetClipMask(display, scoreGC, botmaskBitmap);
499 XSetClipOrigin(display, scoreGC, 0, 0 - colours[0] * SCOREY);
502 XCopyArea(display, botPixmap, scorePixmap, scoreGC,
503 0, colours[0] * SCOREY, SCR_MENUX * TILEX, SCOREY, 0, 0);
506 XSetClipMask(display, scoreGC, None);
512 /* draw bouncing ball on main menu footer */
514 void title_blitscore(void)
516 unsigned int x, y, i;
518 xdebug("title_blitscore");
520 if (++colour_anim > 30)
523 i = colour_anim >= 16 ? 31 - colour_anim : colour_anim;
524 x = (i / 8 + 18) * 2 * SCOREX;
525 y = (i % 8 + 16) * SCOREY;
530 BlitBitmap(botBitmap, scoreBitmap,
531 32 * SCOREX, colours[1] * SCOREY, 2 * SCOREX, SCOREY,
534 SetClipOrigin(botBitmap, botBitmap->stored_clip_gc,
535 32 * SCOREX - x, 0 - y);
538 BlitBitmapMasked(botBitmap, scoreBitmap,
539 x, y, 2 * SCOREX, SCOREY, 32 * SCOREX, 0);
545 XCopyArea(display, botPixmap, scorePixmap, scoreGC,
546 32 * SCOREX, colours[1] * SCOREY, 2 * SCOREX, SCOREY,
548 XSetClipMask(display, scoreGC, botmaskBitmap);
549 XSetClipOrigin(display, scoreGC, 32 * SCOREX - x, 0 - y);
552 XCopyArea(display, botPixmap, scorePixmap, scoreGC,
553 x, y, 2 * SCOREX, SCOREY, 32 * SCOREX, 0);
556 XSetClipMask(display, scoreGC, None);
560 void title_blitants(unsigned int y)
562 static const char ants_dashes[2] = { 8, 7 };
564 xdebug("title_blitants");
566 XSetDashes(display, antsGC, colour_anim, ants_dashes, 2);
567 XDrawRectangle(display, screenPixmap, antsGC,
568 0, y * TILEY, SCR_MENUX * TILEX - 1, TILEY - 1);
571 void title_animscreen(void)
576 Random = Random * 129 + 1;
579 static int ttl_map[] =
581 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
582 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
583 -1,0,-1,-1,-1,-1,-1,1,-1,-1,-1,-1,2,3,4,-1, /* !',-. */
584 5,6,7,8,9,10,11,12,13,14,15,-1,-1,-1,-1,16, /* 0123456789:? */
585 -1,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, /* ABCDEFGHIJKLMNO */
586 32,33,34,35,36,37,38,39,40,41,42,-1,-1,-1,-1,-1, /* PQRSTUVWXYZ */
587 -1,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, /* abcdefghijklmno */
588 32,33,34,35,36,37,38,39,40,41,42,-1,-1,-1,-1,-1 /* pqrstuvwxyz */
591 void title_string(unsigned int y, unsigned int left, unsigned int right,
597 xdebug("title_string");
603 x = (left + right - strlen(string) * MENUFONTX) / 2;
604 if (x < left || x >= right)
607 /* restore background graphic where text will be drawn */
608 BlitBitmap(ttlBitmap, screenBitmap, ORIG_MENU_SX + left, ORIG_MENU_SY + y,
609 right - left, MENUFONTY, left, y);
614 XSetClipMask(display, screenGC, ttlmaskBitmap);
617 for (i = 0; string[i] && x < right; i++)
619 int ch_pos, ch_x, ch_y;
621 ch_pos = ttl_map[string[i] & 127];
623 if (ch_pos == -1 || ch_pos > 22 * 2)
624 continue; /* no graphic for this character */
626 ch_x = (ch_pos % 22) * GFXMENUFONTX;
627 ch_y = (ch_pos / 22 + 12) * TILEY;
630 SetClipOrigin(ttlBitmap, ttlBitmap->stored_clip_gc,
631 x - ORIG_MENU_SX - ch_x, y - ORIG_MENU_SY - ch_y);
633 BlitBitmapMasked(ttlBitmap, screenBitmap, ch_x, ch_y, MENUFONTX, MENUFONTY,
634 x - ORIG_MENU_SX, y - ORIG_MENU_SY);
637 XSetClipOrigin(display, screenGC, x - ch_x, y - ch_y);
639 XCopyArea(display, ttlPixmap, screenPixmap, screenGC,
640 ch_x, ch_y, MENUFONTX, MENUFONTY, x, y);
648 XSetClipMask(display, screenGC, None);