1 /* 2000-08-13T14:36:17Z
3 * graphics manipulation crap
16 #if defined(TARGET_X11)
18 extern void DrawGameDoorValues_EM(int, int, int, int);
20 unsigned int frame; /* current frame */
21 unsigned int screen_x; /* current scroll position */
22 unsigned int screen_y;
24 /* tiles currently on screen */
25 static unsigned short screentiles[MAX_BUF_YSIZE][MAX_BUF_XSIZE];
27 static unsigned int colours[8];
28 static unsigned int colour_anim;
30 static void xdebug(char *msg)
33 XSync(display, False);
34 printf("EM DEBUG: %s\n", msg);
38 static void colour_shuffle(void)
42 for (i = 0; i < 8; i++)
45 for (i = 0; i < 8; i++)
47 Random = Random * 129 + 1;
48 j = (Random >> 10) & 7;
50 colours[i] = colours[j];
56 /* copy the entire screen to the window at the scroll position
58 * perhaps use mit-shm to speed this up
63 unsigned int x = screen_x % (MAX_BUF_XSIZE * TILEX);
64 unsigned int y = screen_y % (MAX_BUF_YSIZE * TILEY);
68 if (em_game_status == EM_GAME_STATUS_MENU)
70 ClearRectangle(screenBitmap, 0, SCR_MENUY * TILEY,
71 SCR_FIELDX * TILEX, (17 - SCR_MENUY) * TILEY);
72 BlitBitmap(scoreBitmap, screenBitmap, 0, 0, SCR_MENUX * TILEX, SCOREY,
73 0, SCR_MENUY * TILEY);
76 if (x < 2 * TILEX && y < 2 * TILEY)
78 BlitBitmap(screenBitmap, window, x, y,
79 SCR_FIELDX * TILEX, SCR_FIELDY * TILEY, SX, SY);
81 else if (x < 2 * TILEX && y >= 2 * TILEY)
83 BlitBitmap(screenBitmap, window, x, y,
84 SCR_FIELDX * TILEX, MAX_BUF_YSIZE * TILEY - y,
86 BlitBitmap(screenBitmap, window, x, 0,
87 SCR_FIELDX * TILEX, y - 2 * TILEY,
88 SX, SY + MAX_BUF_YSIZE * TILEY - y);
90 else if (x >= 2 * TILEX && y < 2 * TILEY)
92 BlitBitmap(screenBitmap, window, x, y,
93 MAX_BUF_XSIZE * TILEX - x, SCR_FIELDY * TILEY,
95 BlitBitmap(screenBitmap, window, 0, y,
96 x - 2 * TILEX, SCR_FIELDY * TILEY,
97 SX + MAX_BUF_XSIZE * TILEX - x, SY);
101 BlitBitmap(screenBitmap, window, x, y,
102 MAX_BUF_XSIZE * TILEX - x, MAX_BUF_YSIZE * TILEY - y,
104 BlitBitmap(screenBitmap, window, 0, y,
105 x - 2 * TILEX, MAX_BUF_YSIZE * TILEY - y,
106 SX + MAX_BUF_XSIZE * TILEX - x, SY);
107 BlitBitmap(screenBitmap, window, x, 0,
108 MAX_BUF_XSIZE * TILEX - x, y - 2 * TILEY,
109 SX, SY + MAX_BUF_YSIZE * TILEY - y);
110 BlitBitmap(screenBitmap, window, 0, 0,
111 x - 2 * TILEX, y - 2 * TILEY,
112 SX + MAX_BUF_XSIZE * TILEX - x, SY + MAX_BUF_YSIZE * TILEY - y);
115 if (em_game_status == EM_GAME_STATUS_PLAY && SCR_FIELDY < 17)
117 BlitBitmap(scoreBitmap, window, 0, 0, SCR_FIELDX * TILEX, SCOREY,
118 SX, SY + SCR_FIELDY * TILEY);
119 ClearRectangle(window, SX, SY + SCR_FIELDY * TILEY + SCOREY,
120 SCR_FIELDX * TILEX, (17 - SCR_FIELDY) * TILEY - SCOREY);
125 xdebug("blitscreen - done");
129 /* draw differences between game tiles and screen tiles
131 * implicitly handles scrolling and restoring background under the sprites
133 * perhaps use mit-shm to speed this up
136 static void animscreen(void)
138 unsigned int x, y, dx, dy;
140 unsigned int left = screen_x / TILEX;
141 unsigned int top = screen_y / TILEY;
143 xdebug("animscreen");
145 for (y = top; y < top + MAX_BUF_YSIZE; y++)
147 dy = y % MAX_BUF_YSIZE;
148 for (x = left; x < left + MAX_BUF_XSIZE; x++)
150 dx = x % MAX_BUF_XSIZE;
151 obj = map_obj[frame][Draw[y][x]];
153 if (screentiles[dy][dx] != obj)
155 screentiles[dy][dx] = obj;
156 BlitBitmap(objBitmap, screenBitmap,
157 (obj / 512) * TILEX, (obj % 512) * TILEY / 16,
158 TILEX, TILEY, dx * TILEX, dy * TILEY);
165 /* blit players to the screen
167 * handles transparency and movement
170 static void blitplayer(struct PLAYER *ply)
172 unsigned int x, y, dx, dy;
173 unsigned short obj, spr;
175 xdebug("blitplayer");
179 x = (frame * ply->oldx + (8 - frame) * ply->x) * TILEX / 8;
180 y = (frame * ply->oldy + (8 - frame) * ply->y) * TILEY / 8;
184 if ((unsigned int)(dx - screen_x) < ((MAX_BUF_XSIZE - 1) * TILEX - 1) &&
185 (unsigned int)(dy - screen_y) < ((MAX_BUF_YSIZE - 1) * TILEY - 1))
187 spr = map_spr[ply->num][frame][ply->anim];
188 x %= MAX_BUF_XSIZE * TILEX;
189 y %= MAX_BUF_YSIZE * TILEY;
190 dx %= MAX_BUF_XSIZE * TILEX;
191 dy %= MAX_BUF_YSIZE * TILEY;
195 obj = screentiles[y / TILEY][x / TILEX];
196 XCopyArea(display, objmaskBitmap, spriteBitmap, spriteGC,
197 (obj / 512) * TILEX, (obj % 512) * TILEY / 16, TILEX, TILEY,
198 -(x % TILEX), -(y % TILEY));
200 obj = screentiles[dy / TILEY][dx / TILEX];
201 XCopyArea(display, objmaskBitmap, spriteBitmap, spriteGC,
202 (obj / 512) * TILEX, (obj % 512) * TILEY / 16, TILEX, TILEY,
203 (MAX_BUF_XSIZE * TILEX - x) % TILEX,
204 (MAX_BUF_YSIZE * TILEY - y) % TILEY);
206 else if (sprmaskBitmap)
208 XCopyArea(display, sprmaskBitmap, spriteBitmap, spriteGC,
209 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY, 0, 0);
213 XFillRectangle(display, spriteBitmap, spriteGC, 0, 0, TILEX, TILEY);
216 screentiles[y / TILEY][x / TILEX] = -1; /* mark screen as dirty */
217 screentiles[dy / TILEY][dx / TILEX] = -1;
224 SetClipMask(sprBitmap, sprBitmap->stored_clip_gc, spriteBitmap);
226 SetClipOrigin(sprBitmap, sprBitmap->stored_clip_gc, x, y);
227 BlitBitmapMasked(sprBitmap, screenBitmap,
228 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
231 SetClipOrigin(sprBitmap, sprBitmap->stored_clip_gc,
232 x - MAX_BUF_XSIZE * TILEX, y);
233 BlitBitmapMasked(sprBitmap, screenBitmap,
234 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
235 x - MAX_BUF_XSIZE * TILEX, y);
237 SetClipOrigin(sprBitmap, sprBitmap->stored_clip_gc,
238 x, y - MAX_BUF_YSIZE * TILEY);
239 BlitBitmapMasked(sprBitmap, screenBitmap,
240 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
241 x, y - MAX_BUF_YSIZE * TILEY);
243 SetClipMask(sprBitmap, sprBitmap->stored_clip_gc, None);
247 XSetClipMask(display, sprBitmap->stored_clip_gc, spriteBitmap);
249 XSetClipOrigin(display, sprBitmap->stored_clip_gc, x, y);
250 XCopyArea(display, sprBitmap->drawable, screenBitmap->drawable,
251 sprBitmap->stored_clip_gc,
252 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
255 XSetClipOrigin(display, sprBitmap->stored_clip_gc,
256 x - MAX_BUF_XSIZE * TILEX, y);
257 XCopyArea(display, sprBitmap->drawable, screenBitmap->drawable,
258 sprBitmap->stored_clip_gc,
259 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
260 x - MAX_BUF_XSIZE * TILEX, y);
262 XSetClipOrigin(display, sprBitmap->stored_clip_gc,
263 x, y - MAX_BUF_YSIZE * TILEY);
264 XCopyArea(display, sprBitmap->drawable, screenBitmap->drawable,
265 sprBitmap->stored_clip_gc,
266 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
267 x, y - MAX_BUF_YSIZE * TILEY);
269 XSetClipMask(display, sprBitmap->stored_clip_gc, None);
275 XSetClipMask(display, screenGC, spriteBitmap);
276 XSetClipOrigin(display, screenGC, x, y);
277 XCopyArea(display, sprPixmap, screenPixmap, screenGC,
278 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
280 XSetClipOrigin(display, screenGC, x - MAX_BUF_XSIZE * TILEX, y);
281 XCopyArea(display, sprPixmap, screenPixmap, screenGC,
282 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
283 x - MAX_BUF_XSIZE * TILEX, y);
284 XSetClipOrigin(display, screenGC, x, y - MAX_BUF_YSIZE * TILEY);
285 XCopyArea(display, sprPixmap, screenPixmap, screenGC,
286 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
287 x, y - MAX_BUF_YSIZE * TILEY);
288 XSetClipMask(display, screenGC, None);
296 /* draw static text for time, gems and score counter */
298 void game_initscreen(void)
302 xdebug("game_initscreen");
308 for (y = 0; y < MAX_BUF_YSIZE; y++)
309 for (x = 0; x < MAX_BUF_XSIZE; x++)
310 screentiles[y][x] = -1;
318 ClearRectangle(scoreBitmap, 0, 0, SCR_FIELDX * TILEX, SCOREY);
319 BlitBitmap(botBitmap, scoreBitmap,
320 11 * SCOREX, colours[0] * SCOREY, 3 * SCOREX, SCOREY,
321 1 * SCOREX, 0); /* 0-63 time */
322 BlitBitmap(botBitmap, scoreBitmap,
323 18 * SCOREX, colours[0] * SCOREY, 6 * SCOREX, SCOREY,
324 11 * SCOREX, 0); /* 112-207 diamonds */
325 BlitBitmap(botBitmap, scoreBitmap,
326 14 * SCOREX, colours[0] * SCOREY, 4 * SCOREX, SCOREY,
327 24 * SCOREX, 0); /* 256-319 score */
331 /* draw current values for time, gems and score counter */
333 void game_blitscore(void)
337 xdebug("game_blitscore");
339 DrawGameDoorValues_EM(lev.required, ply1.dynamite, lev.score,
342 i = (lev.time + 4) / 5;
343 BlitBitmap(botBitmap, scoreBitmap,
344 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
347 BlitBitmap(botBitmap, scoreBitmap,
348 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
351 BlitBitmap(botBitmap, scoreBitmap,
352 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
355 BlitBitmap(botBitmap, scoreBitmap,
356 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
360 BlitBitmap(botBitmap, scoreBitmap,
361 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
364 BlitBitmap(botBitmap, scoreBitmap,
365 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
368 BlitBitmap(botBitmap, scoreBitmap,
369 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
372 BlitBitmap(botBitmap, scoreBitmap,
373 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
378 BlitBitmap(botBitmap, scoreBitmap,
379 12 * SCOREX, 24 * SCOREY, 12 * SCOREX, SCOREY,
380 14 * SCOREX, 0); /* relax */
385 if (ply1.alive + ply2.alive >= lev.home && lev.required == 0)
387 BlitBitmap(botBitmap, scoreBitmap,
388 24 * SCOREX, colours[2] * SCOREY, 12 * SCOREX, SCOREY,
389 14 * SCOREX, 0); /* find the exit */
394 if (ply1.alive + ply2.alive < lev.home)
396 if (++colour_anim > 11)
401 BlitBitmap(botBitmap, scoreBitmap,
402 0, 24 * SCOREY, 12 * SCOREX, SCOREY,
403 14 * SCOREX, 0); /* forget it */
408 BlitBitmap(botBitmap, scoreBitmap,
409 18 * SCOREX, colours[0] * SCOREY, 6 * SCOREX, SCOREY,
410 15 * SCOREX, 0); /* diamonds */
414 BlitBitmap(botBitmap, scoreBitmap,
415 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
418 BlitBitmap(botBitmap, scoreBitmap,
419 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
422 BlitBitmap(botBitmap, scoreBitmap,
423 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
426 BlitBitmap(botBitmap, scoreBitmap,
427 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
433 void game_animscreen(void)
437 xdebug("game_animscreen");
439 x = (frame * ply1.oldx + (8 - frame) * ply1.x) * TILEX / 8
440 + ((SCR_FIELDX - 1) * TILEX) / 2;
441 y = (frame * ply1.oldy + (8 - frame) * ply1.y) * TILEY / 8
442 + ((SCR_FIELDY - 1) * TILEY) / 2;
444 if (x > lev.width * TILEX)
445 x = lev.width * TILEX;
446 if (y > lev.height * TILEY)
447 y = lev.height * TILEY;
449 if (x < SCR_FIELDX * TILEX)
450 x = SCR_FIELDX * TILEY;
451 if (y < SCR_FIELDY * TILEY)
452 y = SCR_FIELDY * TILEY;
454 screen_x = x - (SCR_FIELDX - 1) * TILEX;
455 screen_y = y - (SCR_FIELDY - 1) * TILEY;
464 Random = Random * 129 + 1;
468 /* draw main menu background and copyright note */
470 void title_initscreen(void)
472 xdebug("title_initscreen");
483 /* draw title screen on menu background */
485 BlitBitmap(ttlBitmap, screenBitmap, ORIG_MENU_SX, ORIG_MENU_SY,
486 SCR_MENUX * TILEX, SCR_MENUY * TILEY, 0, 0);
488 /* draw copyright note at footer */
492 BlitBitmap(botBitmap, scoreBitmap, 0, colours[1] * SCOREY,
493 SCR_MENUX * TILEX, SCOREY, 0, 0);
495 SetClipOrigin(botBitmap, botBitmap->stored_clip_gc,
496 0, 0 - colours[0] * SCOREY);
499 BlitBitmapMasked(botBitmap, scoreBitmap, 0, colours[0] * SCOREY,
500 SCR_MENUX * TILEX, SCOREY, 0, 0);
504 XCopyArea(display, ttlPixmap, screenPixmap, screenGC,
505 0, 0, SCR_MENUX * TILEX, SCR_MENUY * TILEY, 0, 0);
509 XCopyArea(display, botPixmap, scorePixmap, scoreGC,
510 0, colours[1] * SCOREY, SCR_MENUX * TILEX, SCOREY, 0, 0);
511 XSetClipMask(display, scoreGC, botmaskBitmap);
512 XSetClipOrigin(display, scoreGC, 0, 0 - colours[0] * SCOREY);
515 XCopyArea(display, botPixmap, scorePixmap, scoreGC,
516 0, colours[0] * SCOREY, SCR_MENUX * TILEX, SCOREY, 0, 0);
519 XSetClipMask(display, scoreGC, None);
525 /* draw bouncing ball on main menu footer */
527 void title_blitscore(void)
529 unsigned int x, y, i;
531 xdebug("title_blitscore");
533 if (++colour_anim > 30)
536 i = colour_anim >= 16 ? 31 - colour_anim : colour_anim;
537 x = (i / 8 + 18) * 2 * SCOREX;
538 y = (i % 8 + 16) * SCOREY;
543 BlitBitmap(botBitmap, scoreBitmap,
544 32 * SCOREX, colours[1] * SCOREY, 2 * SCOREX, SCOREY,
547 SetClipOrigin(botBitmap, botBitmap->stored_clip_gc,
548 32 * SCOREX - x, 0 - y);
551 BlitBitmapMasked(botBitmap, scoreBitmap,
552 x, y, 2 * SCOREX, SCOREY, 32 * SCOREX, 0);
558 XCopyArea(display, botPixmap, scorePixmap, scoreGC,
559 32 * SCOREX, colours[1] * SCOREY, 2 * SCOREX, SCOREY,
561 XSetClipMask(display, scoreGC, botmaskBitmap);
562 XSetClipOrigin(display, scoreGC, 32 * SCOREX - x, 0 - y);
565 XCopyArea(display, botPixmap, scorePixmap, scoreGC,
566 x, y, 2 * SCOREX, SCOREY, 32 * SCOREX, 0);
569 XSetClipMask(display, scoreGC, None);
573 void title_blitants(unsigned int y)
575 static const char ants_dashes[2] = { 8, 7 };
577 xdebug("title_blitants");
579 XSetDashes(display, antsGC, colour_anim, ants_dashes, 2);
580 XDrawRectangle(display, screenPixmap, antsGC,
581 0, y * TILEY, SCR_MENUX * TILEX - 1, TILEY - 1);
584 void title_animscreen(void)
589 Random = Random * 129 + 1;
592 static int ttl_map[] =
594 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
595 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
596 -1,0,-1,-1,-1,-1,-1,1,-1,-1,-1,-1,2,3,4,-1, /* !',-. */
597 5,6,7,8,9,10,11,12,13,14,15,-1,-1,-1,-1,16, /* 0123456789:? */
598 -1,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, /* ABCDEFGHIJKLMNO */
599 32,33,34,35,36,37,38,39,40,41,42,-1,-1,-1,-1,-1, /* PQRSTUVWXYZ */
600 -1,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, /* abcdefghijklmno */
601 32,33,34,35,36,37,38,39,40,41,42,-1,-1,-1,-1,-1 /* pqrstuvwxyz */
604 void title_string(unsigned int y, unsigned int left, unsigned int right,
610 xdebug("title_string");
616 x = (left + right - strlen(string) * MENUFONTX) / 2;
617 if (x < left || x >= right)
620 /* restore background graphic where text will be drawn */
621 BlitBitmap(ttlBitmap, screenBitmap, ORIG_MENU_SX + left, ORIG_MENU_SY + y,
622 right - left, MENUFONTY, left, y);
627 XSetClipMask(display, screenGC, ttlmaskBitmap);
630 for (i = 0; string[i] && x < right; i++)
632 int ch_pos, ch_x, ch_y;
634 ch_pos = ttl_map[string[i] & 127];
636 if (ch_pos == -1 || ch_pos > 22 * 2)
637 continue; /* no graphic for this character */
639 ch_x = (ch_pos % 22) * GFXMENUFONTX;
640 ch_y = (ch_pos / 22 + 12) * TILEY;
643 SetClipOrigin(ttlBitmap, ttlBitmap->stored_clip_gc,
644 x - ORIG_MENU_SX - ch_x, y - ORIG_MENU_SY - ch_y);
646 BlitBitmapMasked(ttlBitmap, screenBitmap, ch_x, ch_y, MENUFONTX, MENUFONTY,
647 x - ORIG_MENU_SX, y - ORIG_MENU_SY);
650 XSetClipOrigin(display, screenGC, x - ch_x, y - ch_y);
652 XCopyArea(display, ttlPixmap, screenPixmap, screenGC,
653 ch_x, ch_y, MENUFONTX, MENUFONTY, x, y);
661 XSetClipMask(display, screenGC, None);