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 if (em_game_status == EM_GAME_STATUS_PLAY && SCR_FIELDY < 17)
115 BlitBitmap(scoreBitmap, window, 0, 0, SCR_FIELDX * TILEX, SCOREY,
116 SX, SY + SCR_FIELDY * TILEY);
117 ClearRectangle(window, SX, SY + SCR_FIELDY * TILEY + SCOREY,
118 SCR_FIELDX * TILEX, (17 - SCR_FIELDY) * TILEY - SCOREY);
123 xdebug("blitscreen - done");
127 /* draw differences between game tiles and screen tiles
129 * implicitly handles scrolling and restoring background under the sprites
131 * perhaps use mit-shm to speed this up
134 static void animscreen(void)
136 unsigned int x, y, dx, dy;
138 unsigned int left = screen_x / TILEX;
139 unsigned int top = screen_y / TILEY;
141 xdebug("animscreen");
143 for (y = top; y < top + MAX_BUF_YSIZE; y++)
145 dy = y % MAX_BUF_YSIZE;
146 for (x = left; x < left + MAX_BUF_XSIZE; x++)
148 dx = x % MAX_BUF_XSIZE;
149 obj = map_obj[frame][Draw[y][x]];
151 if (screentiles[dy][dx] != obj)
153 screentiles[dy][dx] = obj;
154 BlitBitmap(objBitmap, screenBitmap,
155 (obj / 512) * TILEX, (obj % 512) * TILEY / 16,
156 TILEX, TILEY, dx * TILEX, dy * TILEY);
163 /* blit players to the screen
165 * handles transparency and movement
168 static void blitplayer(struct PLAYER *ply)
170 unsigned int x, y, dx, dy;
171 unsigned short obj, spr;
173 xdebug("blitplayer");
177 x = (frame * ply->oldx + (8 - frame) * ply->x) * TILEX / 8;
178 y = (frame * ply->oldy + (8 - frame) * ply->y) * TILEY / 8;
182 if ((unsigned int)(dx - screen_x) < ((MAX_BUF_XSIZE - 1) * TILEX - 1) &&
183 (unsigned int)(dy - screen_y) < ((MAX_BUF_YSIZE - 1) * TILEY - 1))
185 spr = map_spr[ply->num][frame][ply->anim];
186 x %= MAX_BUF_XSIZE * TILEX;
187 y %= MAX_BUF_YSIZE * TILEY;
188 dx %= MAX_BUF_XSIZE * TILEX;
189 dy %= MAX_BUF_YSIZE * TILEY;
193 obj = screentiles[y / TILEY][x / TILEX];
194 XCopyArea(display, objmaskBitmap, spriteBitmap, spriteGC,
195 (obj / 512) * TILEX, (obj % 512) * TILEY / 16, TILEX, TILEY,
196 -(x % TILEX), -(y % TILEY));
198 obj = screentiles[dy / TILEY][dx / TILEX];
199 XCopyArea(display, objmaskBitmap, spriteBitmap, spriteGC,
200 (obj / 512) * TILEX, (obj % 512) * TILEY / 16, TILEX, TILEY,
201 (MAX_BUF_XSIZE * TILEX - x) % TILEX,
202 (MAX_BUF_YSIZE * TILEY - y) % TILEY);
204 else if (sprmaskBitmap)
206 XCopyArea(display, sprmaskBitmap, spriteBitmap, spriteGC,
207 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY, 0, 0);
211 XFillRectangle(display, spriteBitmap, spriteGC, 0, 0, TILEX, TILEY);
214 screentiles[y / TILEY][x / TILEX] = -1; /* mark screen as dirty */
215 screentiles[dy / TILEY][dx / TILEX] = -1;
222 SetClipMask(sprBitmap, sprBitmap->stored_clip_gc, spriteBitmap);
224 SetClipOrigin(sprBitmap, sprBitmap->stored_clip_gc, x, y);
225 BlitBitmapMasked(sprBitmap, screenBitmap,
226 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
229 SetClipOrigin(sprBitmap, sprBitmap->stored_clip_gc,
230 x - MAX_BUF_XSIZE * TILEX, y);
231 BlitBitmapMasked(sprBitmap, screenBitmap,
232 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
233 x - MAX_BUF_XSIZE * TILEX, y);
235 SetClipOrigin(sprBitmap, sprBitmap->stored_clip_gc,
236 x, y - MAX_BUF_YSIZE * TILEY);
237 BlitBitmapMasked(sprBitmap, screenBitmap,
238 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
239 x, y - MAX_BUF_YSIZE * TILEY);
241 SetClipMask(sprBitmap, sprBitmap->stored_clip_gc, None);
245 XSetClipMask(display, sprBitmap->stored_clip_gc, spriteBitmap);
247 XSetClipOrigin(display, sprBitmap->stored_clip_gc, x, y);
248 XCopyArea(display, sprBitmap->drawable, screenBitmap->drawable,
249 sprBitmap->stored_clip_gc,
250 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
253 XSetClipOrigin(display, sprBitmap->stored_clip_gc,
254 x - MAX_BUF_XSIZE * TILEX, y);
255 XCopyArea(display, sprBitmap->drawable, screenBitmap->drawable,
256 sprBitmap->stored_clip_gc,
257 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
258 x - MAX_BUF_XSIZE * TILEX, y);
260 XSetClipOrigin(display, sprBitmap->stored_clip_gc,
261 x, y - MAX_BUF_YSIZE * TILEY);
262 XCopyArea(display, sprBitmap->drawable, screenBitmap->drawable,
263 sprBitmap->stored_clip_gc,
264 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
265 x, y - MAX_BUF_YSIZE * TILEY);
267 XSetClipMask(display, sprBitmap->stored_clip_gc, None);
273 XSetClipMask(display, screenGC, spriteBitmap);
274 XSetClipOrigin(display, screenGC, x, y);
275 XCopyArea(display, sprPixmap, screenPixmap, screenGC,
276 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
278 XSetClipOrigin(display, screenGC, x - MAX_BUF_XSIZE * TILEX, y);
279 XCopyArea(display, sprPixmap, screenPixmap, screenGC,
280 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
281 x - MAX_BUF_XSIZE * TILEX, y);
282 XSetClipOrigin(display, screenGC, x, y - MAX_BUF_YSIZE * TILEY);
283 XCopyArea(display, sprPixmap, screenPixmap, screenGC,
284 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
285 x, y - MAX_BUF_YSIZE * TILEY);
286 XSetClipMask(display, screenGC, None);
294 /* draw static text for time, gems and score counter */
296 void game_initscreen(void)
300 xdebug("game_initscreen");
306 for (y = 0; y < MAX_BUF_YSIZE; y++)
307 for (x = 0; x < MAX_BUF_XSIZE; x++)
308 screentiles[y][x] = -1;
316 ClearRectangle(scoreBitmap, 0, 0, SCR_FIELDX * TILEX, SCOREY);
317 BlitBitmap(botBitmap, scoreBitmap,
318 11 * SCOREX, colours[0] * SCOREY, 3 * SCOREX, SCOREY,
319 1 * SCOREX, 0); /* 0-63 time */
320 BlitBitmap(botBitmap, scoreBitmap,
321 18 * SCOREX, colours[0] * SCOREY, 6 * SCOREX, SCOREY,
322 11 * SCOREX, 0); /* 112-207 diamonds */
323 BlitBitmap(botBitmap, scoreBitmap,
324 14 * SCOREX, colours[0] * SCOREY, 4 * SCOREX, SCOREY,
325 24 * SCOREX, 0); /* 256-319 score */
329 /* draw current values for time, gems and score counter */
331 void game_blitscore(void)
335 xdebug("game_blitscore");
337 DrawGameDoorValues_EM(lev.required, ply1.dynamite, lev.score,
340 i = (lev.time + 4) / 5;
341 BlitBitmap(botBitmap, scoreBitmap,
342 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
345 BlitBitmap(botBitmap, scoreBitmap,
346 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
349 BlitBitmap(botBitmap, scoreBitmap,
350 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
353 BlitBitmap(botBitmap, scoreBitmap,
354 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
358 BlitBitmap(botBitmap, scoreBitmap,
359 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
362 BlitBitmap(botBitmap, scoreBitmap,
363 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
366 BlitBitmap(botBitmap, scoreBitmap,
367 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
370 BlitBitmap(botBitmap, scoreBitmap,
371 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
376 BlitBitmap(botBitmap, scoreBitmap,
377 12 * SCOREX, 24 * SCOREY, 12 * SCOREX, SCOREY,
378 14 * SCOREX, 0); /* relax */
383 if (ply1.alive + ply2.alive >= lev.home && lev.required == 0)
385 BlitBitmap(botBitmap, scoreBitmap,
386 24 * SCOREX, colours[2] * SCOREY, 12 * SCOREX, SCOREY,
387 14 * SCOREX, 0); /* find the exit */
392 if (ply1.alive + ply2.alive < lev.home)
394 if (++colour_anim > 11)
399 BlitBitmap(botBitmap, scoreBitmap,
400 0, 24 * SCOREY, 12 * SCOREX, SCOREY,
401 14 * SCOREX, 0); /* forget it */
406 BlitBitmap(botBitmap, scoreBitmap,
407 18 * SCOREX, colours[0] * SCOREY, 6 * SCOREX, SCOREY,
408 15 * SCOREX, 0); /* diamonds */
412 BlitBitmap(botBitmap, scoreBitmap,
413 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
416 BlitBitmap(botBitmap, scoreBitmap,
417 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
420 BlitBitmap(botBitmap, scoreBitmap,
421 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
424 BlitBitmap(botBitmap, scoreBitmap,
425 (i % 10) * SCOREX, colours[1] * SCOREY, SCOREX, SCOREY,
431 void game_animscreen(void)
435 xdebug("game_animscreen");
437 x = (frame * ply1.oldx + (8 - frame) * ply1.x) * TILEX / 8
438 + ((SCR_FIELDX - 1) * TILEX) / 2;
439 y = (frame * ply1.oldy + (8 - frame) * ply1.y) * TILEY / 8
440 + ((SCR_FIELDY - 1) * TILEY) / 2;
442 if (x > lev.width * TILEX)
443 x = lev.width * TILEX;
444 if (y > lev.height * TILEY)
445 y = lev.height * TILEY;
447 if (x < SCR_FIELDX * TILEX)
448 x = SCR_FIELDX * TILEY;
449 if (y < SCR_FIELDY * TILEY)
450 y = SCR_FIELDY * TILEY;
452 screen_x = x - (SCR_FIELDX - 1) * TILEX;
453 screen_y = y - (SCR_FIELDY - 1) * TILEY;
462 Random = Random * 129 + 1;
466 /* draw main menu background and copyright note */
468 void title_initscreen(void)
470 xdebug("title_initscreen");
481 /* draw title screen on menu background */
483 BlitBitmap(ttlBitmap, screenBitmap, ORIG_MENU_SX, ORIG_MENU_SY,
484 SCR_MENUX * TILEX, SCR_MENUY * TILEY, 0, 0);
486 /* draw copyright note at footer */
490 BlitBitmap(botBitmap, scoreBitmap, 0, colours[1] * SCOREY,
491 SCR_MENUX * TILEX, SCOREY, 0, 0);
493 SetClipOrigin(botBitmap, botBitmap->stored_clip_gc,
494 0, 0 - colours[0] * SCOREY);
497 BlitBitmapMasked(botBitmap, scoreBitmap, 0, colours[0] * SCOREY,
498 SCR_MENUX * TILEX, SCOREY, 0, 0);
502 XCopyArea(display, ttlPixmap, screenPixmap, screenGC,
503 0, 0, SCR_MENUX * TILEX, SCR_MENUY * TILEY, 0, 0);
507 XCopyArea(display, botPixmap, scorePixmap, scoreGC,
508 0, colours[1] * SCOREY, SCR_MENUX * TILEX, SCOREY, 0, 0);
509 XSetClipMask(display, scoreGC, botmaskBitmap);
510 XSetClipOrigin(display, scoreGC, 0, 0 - colours[0] * SCOREY);
513 XCopyArea(display, botPixmap, scorePixmap, scoreGC,
514 0, colours[0] * SCOREY, SCR_MENUX * TILEX, SCOREY, 0, 0);
517 XSetClipMask(display, scoreGC, None);
523 /* draw bouncing ball on main menu footer */
525 void title_blitscore(void)
527 unsigned int x, y, i;
529 xdebug("title_blitscore");
531 if (++colour_anim > 30)
534 i = colour_anim >= 16 ? 31 - colour_anim : colour_anim;
535 x = (i / 8 + 18) * 2 * SCOREX;
536 y = (i % 8 + 16) * SCOREY;
541 BlitBitmap(botBitmap, scoreBitmap,
542 32 * SCOREX, colours[1] * SCOREY, 2 * SCOREX, SCOREY,
545 SetClipOrigin(botBitmap, botBitmap->stored_clip_gc,
546 32 * SCOREX - x, 0 - y);
549 BlitBitmapMasked(botBitmap, scoreBitmap,
550 x, y, 2 * SCOREX, SCOREY, 32 * SCOREX, 0);
556 XCopyArea(display, botPixmap, scorePixmap, scoreGC,
557 32 * SCOREX, colours[1] * SCOREY, 2 * SCOREX, SCOREY,
559 XSetClipMask(display, scoreGC, botmaskBitmap);
560 XSetClipOrigin(display, scoreGC, 32 * SCOREX - x, 0 - y);
563 XCopyArea(display, botPixmap, scorePixmap, scoreGC,
564 x, y, 2 * SCOREX, SCOREY, 32 * SCOREX, 0);
567 XSetClipMask(display, scoreGC, None);
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);