1 /* 2000-08-13T14:36:17Z
3 * graphics manipulation crap
11 unsigned int frame; /* current screen frame */
12 unsigned int screen_x; /* current scroll position */
13 unsigned int screen_y;
15 /* tiles currently on screen */
16 static unsigned short screentiles[MAX_BUF_YSIZE][MAX_BUF_XSIZE];
19 /* copy the entire screen to the window at the scroll position
21 * perhaps use mit-shm to speed this up
26 unsigned int x = screen_x % (MAX_BUF_XSIZE * TILEX);
27 unsigned int y = screen_y % (MAX_BUF_YSIZE * TILEY);
29 if (x < 2 * TILEX && y < 2 * TILEY)
31 BlitBitmap(screenBitmap, window, x, y,
32 SCR_FIELDX * TILEX, SCR_FIELDY * TILEY, SX, SY);
34 else if (x < 2 * TILEX && y >= 2 * TILEY)
36 BlitBitmap(screenBitmap, window, x, y,
37 SCR_FIELDX * TILEX, MAX_BUF_YSIZE * TILEY - y,
39 BlitBitmap(screenBitmap, window, x, 0,
40 SCR_FIELDX * TILEX, y - 2 * TILEY,
41 SX, SY + MAX_BUF_YSIZE * TILEY - y);
43 else if (x >= 2 * TILEX && y < 2 * TILEY)
45 BlitBitmap(screenBitmap, window, x, y,
46 MAX_BUF_XSIZE * TILEX - x, SCR_FIELDY * TILEY,
48 BlitBitmap(screenBitmap, window, 0, y,
49 x - 2 * TILEX, SCR_FIELDY * TILEY,
50 SX + MAX_BUF_XSIZE * TILEX - x, SY);
54 BlitBitmap(screenBitmap, window, x, y,
55 MAX_BUF_XSIZE * TILEX - x, MAX_BUF_YSIZE * TILEY - y,
57 BlitBitmap(screenBitmap, window, 0, y,
58 x - 2 * TILEX, MAX_BUF_YSIZE * TILEY - y,
59 SX + MAX_BUF_XSIZE * TILEX - x, SY);
60 BlitBitmap(screenBitmap, window, x, 0,
61 MAX_BUF_XSIZE * TILEX - x, y - 2 * TILEY,
62 SX, SY + MAX_BUF_YSIZE * TILEY - y);
63 BlitBitmap(screenBitmap, window, 0, 0,
64 x - 2 * TILEX, y - 2 * TILEY,
65 SX + MAX_BUF_XSIZE * TILEX - x, SY + MAX_BUF_YSIZE * TILEY - y);
70 /* draw differences between game tiles and screen tiles
72 * implicitly handles scrolling and restoring background under the sprites
74 * perhaps use mit-shm to speed this up
77 static void animscreen(void)
79 unsigned int x, y, dx, dy;
81 unsigned int left = screen_x / TILEX;
82 unsigned int top = screen_y / TILEY;
84 for (y = top; y < top + MAX_BUF_YSIZE; y++)
86 dy = y % MAX_BUF_YSIZE;
88 for (x = left; x < left + MAX_BUF_XSIZE; x++)
90 dx = x % MAX_BUF_XSIZE;
91 obj = map_obj[frame][Draw[y][x]];
93 if (screentiles[dy][dx] != obj)
95 screentiles[dy][dx] = obj;
96 BlitBitmap(objBitmap, screenBitmap,
97 (obj / 512) * TILEX, (obj % 512) * TILEY / 16,
98 TILEX, TILEY, dx * TILEX, dy * TILEY);
105 /* blit players to the screen
107 * handles transparency and movement
110 static void blitplayer(struct PLAYER *ply)
112 unsigned int x, y, dx, dy;
113 unsigned short obj, spr;
114 int src_x, src_y, dest_x, dest_y;
119 x = (frame * ply->oldx + (8 - frame) * ply->x) * TILEX / 8;
120 y = (frame * ply->oldy + (8 - frame) * ply->y) * TILEY / 8;
124 if ((unsigned int)(dx - screen_x) < ((MAX_BUF_XSIZE - 1) * TILEX - 1) &&
125 (unsigned int)(dy - screen_y) < ((MAX_BUF_YSIZE - 1) * TILEY - 1))
127 spr = map_spr[ply->num][frame][ply->anim];
128 x %= MAX_BUF_XSIZE * TILEX;
129 y %= MAX_BUF_YSIZE * TILEY;
130 dx %= MAX_BUF_XSIZE * TILEX;
131 dy %= MAX_BUF_YSIZE * TILEY;
134 /* draw the player to current location */
135 BlitBitmap(sprBitmap, screenBitmap,
136 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
138 /* draw the player to opposite wrap-around column */
139 BlitBitmap(sprBitmap, screenBitmap,
140 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
141 x - MAX_BUF_XSIZE * TILEX, y),
142 /* draw the player to opposite wrap-around row */
143 BlitBitmap(sprBitmap, screenBitmap,
144 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
145 x, y - MAX_BUF_YSIZE * TILEY);
147 /* draw the field the player is moving from (masked over the player) */
148 obj = screentiles[y / TILEY][x / TILEX];
149 src_x = (obj / 512) * TILEX;
150 src_y = (obj % 512) * TILEY / 16;
151 dest_x = (x / TILEX) * TILEX;
152 dest_y = (y / TILEY) * TILEY;
154 SetClipOrigin(objBitmap, objBitmap->stored_clip_gc,
155 dest_x - src_x, dest_y - src_y);
156 BlitBitmapMasked(objBitmap, screenBitmap,
157 src_x, src_y, TILEX, TILEY, dest_x, dest_y);
159 /* draw the field the player is moving to (masked over the player) */
160 obj = screentiles[dy / TILEY][dx / TILEX];
161 src_x = (obj / 512) * TILEX;
162 src_y = (obj % 512) * TILEY / 16;
163 dest_x = (dx / TILEX) * TILEX;
164 dest_y = (dy / TILEY) * TILEY;
166 SetClipOrigin(objBitmap, objBitmap->stored_clip_gc,
167 dest_x - src_x, dest_y - src_y);
168 BlitBitmapMasked(objBitmap, screenBitmap,
169 src_x, src_y, TILEX, TILEY, dest_x, dest_y);
175 obj = screentiles[y / TILEY][x / TILEX];
176 XCopyArea(display, objmaskBitmap, spriteBitmap, spriteGC,
177 (obj / 512) * TILEX, (obj % 512) * TILEY / 16, TILEX, TILEY,
178 -(x % TILEX), -(y % TILEY));
180 obj = screentiles[dy / TILEY][dx / TILEX];
181 XCopyArea(display, objmaskBitmap, spriteBitmap, spriteGC,
182 (obj / 512) * TILEX, (obj % 512) * TILEY / 16, TILEX, TILEY,
183 (MAX_BUF_XSIZE * TILEX - x) % TILEX,
184 (MAX_BUF_YSIZE * TILEY - y) % TILEY);
186 else if (sprmaskBitmap)
188 XCopyArea(display, sprmaskBitmap, spriteBitmap, spriteGC,
189 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY, 0, 0);
193 XFillRectangle(display, spriteBitmap, spriteGC, 0, 0, TILEX, TILEY);
196 SetClipMask(sprBitmap, sprBitmap->stored_clip_gc, spriteBitmap);
198 SetClipOrigin(sprBitmap, sprBitmap->stored_clip_gc, x, y);
199 BlitBitmapMasked(sprBitmap, screenBitmap,
200 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
203 SetClipOrigin(sprBitmap, sprBitmap->stored_clip_gc,
204 x - MAX_BUF_XSIZE * TILEX, y);
205 BlitBitmapMasked(sprBitmap, screenBitmap,
206 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
207 x - MAX_BUF_XSIZE * TILEX, y);
209 SetClipOrigin(sprBitmap, sprBitmap->stored_clip_gc,
210 x, y - MAX_BUF_YSIZE * TILEY);
211 BlitBitmapMasked(sprBitmap, screenBitmap,
212 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
213 x, y - MAX_BUF_YSIZE * TILEY);
215 SetClipMask(sprBitmap, sprBitmap->stored_clip_gc, None);
218 screentiles[y / TILEY][x / TILEX] = -1; /* mark screen as dirty */
219 screentiles[dy / TILEY][dx / TILEX] = -1;
223 void game_initscreen(void)
231 for (y = 0; y < MAX_BUF_YSIZE; y++)
232 for (x = 0; x < MAX_BUF_XSIZE; x++)
233 screentiles[y][x] = -1;
235 DrawGameDoorValues_EM(lev.required, ply1.dynamite, lev.score,
236 DISPLAY_TIME(lev.time + 4));
239 void game_animscreen(void)
243 x = (frame * ply1.oldx + (8 - frame) * ply1.x) * TILEX / 8
244 + ((SCR_FIELDX - 1) * TILEX) / 2;
245 y = (frame * ply1.oldy + (8 - frame) * ply1.y) * TILEY / 8
246 + ((SCR_FIELDY - 1) * TILEY) / 2;
248 if (x > lev.width * TILEX)
249 x = lev.width * TILEX;
250 if (y > lev.height * TILEY)
251 y = lev.height * TILEY;
253 if (x < SCR_FIELDX * TILEX)
254 x = SCR_FIELDX * TILEY;
255 if (y < SCR_FIELDY * TILEY)
256 y = SCR_FIELDY * TILEY;
258 screen_x = x - (SCR_FIELDX - 1) * TILEX;
259 screen_y = y - (SCR_FIELDY - 1) * TILEY;