1 // ============================================================================
2 // Mirror Magic -- McDuffin's Revenge
3 // ----------------------------------------------------------------------------
4 // (c) 1994-2017 by Artsoft Entertainment
7 // https://www.artsoft.org/
8 // ----------------------------------------------------------------------------
10 // ============================================================================
20 void SetDrawtoField_MM(int mode)
22 int full_xsize = lev_fieldx * TILESIZE_VAR;
23 int full_ysize = lev_fieldy * TILESIZE_VAR;
25 // distance (delta) from screen border (SX/SY) to centered level playfield
26 dSX = (full_xsize < SXSIZE ? (SXSIZE - full_xsize) / 2 : 0);
27 dSY = (full_ysize < SYSIZE ? (SYSIZE - full_ysize) / 2 : 0);
29 // for convenience, absolute screen position to centered level playfield
32 cSX2 = SX + dSX + 2; // including playfield border
33 cSY2 = SY + dSY + 2; // including playfield border
35 if (mode == DRAW_TO_BACKBUFFER)
41 SetTileCursorSXSY(cSX, cSY);
44 void ClearWindow(void)
46 ClearRectangle(backbuffer, REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
48 SetDrawtoField(DRAW_TO_BACKBUFFER);
49 SetDrawtoField_MM(DRAW_TO_BACKBUFFER);
51 redraw_mask |= REDRAW_FIELD;
54 void DrawGraphicAnimation_MM(int x, int y, int graphic, int frame)
59 getGraphicSource(graphic, frame, &bitmap, &src_x, &src_y);
61 BlitBitmap(bitmap, drawto_field, src_x, src_y, TILEX, TILEY,
62 cFX + x * TILEX, cFY + y * TILEY);
65 void DrawGraphic_MM(int x, int y, int graphic)
68 if (!IN_SCR_FIELD(x,y))
70 Debug("game:mm:DrawGraphic_MM", "x = %d, y = %d, graphic = %d",
72 Debug("game:mm:DrawGraphic_MM", "This should never happen!");
78 DrawGraphicExt_MM(drawto_field, cFX + x * TILEX, cFY + y * TILEY, graphic);
83 void DrawGraphicExt_MM(DrawBuffer *d, int x, int y, int graphic)
88 getGraphicSource(graphic, 0, &bitmap, &src_x, &src_y);
90 BlitBitmap(bitmap, d, src_x, src_y, TILEX, TILEY, x, y);
93 void DrawGraphicThruMask_MM(int x, int y, int graphic)
96 if (!IN_SCR_FIELD(x,y))
98 Debug("game:mm:DrawGraphicThruMask_MM", "x = %d,y = %d, graphic = %d",
100 Debug("game:mm:DrawGraphicThruMask_MM", "This should never happen!");
106 DrawGraphicThruMaskExt_MM(drawto_field, cFX + x * TILEX, cFY + y * TILEY,
112 void DrawGraphicThruMaskExt_MM(DrawBuffer *d, int dest_x, int dest_y,
118 if (graphic == IMG_EMPTY)
121 getGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
123 BlitBitmapMasked(src_bitmap, d, src_x, src_y, TILEX, TILEY, dest_x, dest_y);
126 void DrawMiniGraphic_MM(int x, int y, int graphic)
128 DrawMiniGraphicExt_MM(drawto, cSX + x * MINI_TILEX, cSY + y * MINI_TILEY,
131 MarkTileDirty(x / 2, y / 2);
135 static void getMicroGraphicSource(int graphic, Bitmap **bitmap, int *x, int *y)
137 getSizedGraphicSource(graphic, 0, TILESIZE / 4, bitmap, x, y);
141 void DrawMiniGraphicExt_MM(DrawBuffer *d, int x, int y, int graphic)
146 getMiniGraphicSource(graphic, &bitmap, &src_x, &src_y);
148 BlitBitmap(bitmap, d, src_x, src_y, MINI_TILEX, MINI_TILEY, x, y);
151 void DrawGraphicShifted_MM(int x,int y, int dx,int dy, int graphic,
152 int cut_mode, int mask_mode)
154 int width = TILEX, height = TILEY;
156 int src_x, src_y, dest_x, dest_y;
161 DrawGraphic_MM(x, y, graphic);
166 if (dx || dy) // Verschiebung der Grafik?
168 if (x < BX1) // Element kommt von links ins Bild
175 else if (x > BX2) // Element kommt von rechts ins Bild
181 else if (x==BX1 && dx < 0) // Element verläßt links das Bild
187 else if (x==BX2 && dx > 0) // Element verläßt rechts das Bild
189 else if (dx) // allg. Bewegung in x-Richtung
190 MarkTileDirty(x + SIGN(dx), y);
192 if (y < BY1) // Element kommt von oben ins Bild
194 if (cut_mode==CUT_BELOW) // Element oberhalb des Bildes
202 else if (y > BY2) // Element kommt von unten ins Bild
208 else if (y==BY1 && dy < 0) // Element verläßt oben das Bild
214 else if (dy > 0 && cut_mode == CUT_ABOVE)
216 if (y == BY2) // Element unterhalb des Bildes
222 MarkTileDirty(x, y + 1);
223 } // Element verläßt unten das Bild
224 else if (dy > 0 && (y == BY2 || cut_mode == CUT_BELOW))
228 else if (dy) // allg. Bewegung in y-Richtung
230 MarkTileDirty(x, y + SIGN(dy));
234 getGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
239 dest_x = cFX + x * TILEX + dx;
240 dest_y = cFY + y * TILEY + dy;
243 if (!IN_SCR_FIELD(x,y))
245 Debug("game:mm:DrawGraphicShifted_MM", "x = %d, y = %d, graphic = %d",
247 Debug("game:mm:DrawGraphicShifted_MM", "This should never happen!");
253 if (mask_mode == USE_MASKING)
254 BlitBitmapMasked(src_bitmap, drawto_field,
255 src_x, src_y, TILEX, TILEY, dest_x, dest_y);
257 BlitBitmap(src_bitmap, drawto_field,
258 src_x, src_y, width, height, dest_x, dest_y);
263 void DrawGraphicShiftedThruMask_MM(int x,int y, int dx,int dy, int graphic,
266 DrawGraphicShifted_MM(x, y, dx, dy, graphic, cut_mode, USE_MASKING);
269 void DrawScreenElementExt_MM(int x, int y, int dx, int dy, int element,
270 int cut_mode, int mask_mode)
272 int ux = LEVELX(x), uy = LEVELY(y);
273 int graphic = el2gfx(element);
274 int phase8 = ABS(MovPos[ux][uy]) / (TILEX / 8);
275 int phase2 = phase8 / 4;
276 int dir = MovDir[ux][uy];
278 if (element == EL_PACMAN)
280 graphic = (phase2 ? IMG_MM_PACMAN_RIGHT : IMG_MM_PACMAN_EATING_RIGHT);
284 else if (dir == MV_LEFT)
286 else if (dir == MV_DOWN)
291 DrawGraphicShifted_MM(x, y, dx, dy, graphic, cut_mode, mask_mode);
292 else if (mask_mode == USE_MASKING)
293 DrawGraphicThruMask_MM(x, y, graphic);
295 DrawGraphic_MM(x, y, graphic);
298 void DrawLevelElementExt_MM(int x, int y, int dx, int dy, int element,
299 int cut_mode, int mask_mode)
301 if (IN_LEV_FIELD(x, y) && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
302 DrawScreenElementExt_MM(SCREENX(x), SCREENY(y), dx, dy, element,
303 cut_mode, mask_mode);
306 void DrawScreenElementShifted_MM(int x, int y, int dx, int dy, int element,
309 DrawScreenElementExt_MM(x, y, dx, dy, element, cut_mode, NO_MASKING);
312 void DrawLevelElementShifted_MM(int x, int y, int dx, int dy, int element,
315 DrawLevelElementExt_MM(x, y, dx, dy, element, cut_mode, NO_MASKING);
318 void DrawScreenElementThruMask_MM(int x, int y, int element)
320 DrawScreenElementExt_MM(x, y, 0, 0, element, NO_CUTTING, USE_MASKING);
323 void DrawLevelElementThruMask_MM(int x, int y, int element)
325 DrawLevelElementExt_MM(x, y, 0, 0, element, NO_CUTTING, USE_MASKING);
328 void DrawLevelFieldThruMask_MM(int x, int y)
330 DrawLevelElementExt_MM(x, y, 0, 0, Tile[x][y], NO_CUTTING, USE_MASKING);
333 void DrawScreenElement_MM(int x, int y, int element)
335 DrawScreenElementExt_MM(x, y, 0, 0, element, NO_CUTTING, NO_MASKING);
338 void DrawLevelElement_MM(int x, int y, int element)
340 if (IN_LEV_FIELD(x, y) && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
341 DrawScreenElement_MM(SCREENX(x), SCREENY(y), element);
344 void DrawScreenField_MM(int x, int y)
346 int element = Tile[x][y];
348 if (!IN_LEV_FIELD(x, y))
353 int horiz_move = (MovDir[x][y] == MV_LEFT || MovDir[x][y] == MV_RIGHT);
355 DrawScreenElement_MM(x, y, EL_EMPTY);
358 DrawScreenElementShifted_MM(x, y, MovPos[x][y], 0, element, NO_CUTTING);
360 DrawScreenElementShifted_MM(x, y, 0, MovPos[x][y], element, NO_CUTTING);
362 else if (IS_BLOCKED(x, y))
368 Blocked2Moving(x, y, &oldx, &oldy);
372 horiz_move = (MovDir[oldx][oldy] == MV_LEFT ||
373 MovDir[oldx][oldy] == MV_RIGHT);
375 DrawScreenElement_MM(x, y, EL_EMPTY);
377 element = Tile[oldx][oldy];
380 DrawScreenElementShifted_MM(sx, sy, MovPos[oldx][oldy], 0, element,
383 DrawScreenElementShifted_MM(sx, sy, 0, MovPos[oldx][oldy], element,
386 else if (IS_DRAWABLE(element))
388 DrawScreenElement_MM(x, y, element);
392 DrawScreenElement_MM(x, y, EL_EMPTY);
396 void DrawLevelField_MM(int x, int y)
398 DrawScreenField_MM(x, y);
401 void DrawMiniElement_MM(int x, int y, int element)
407 DrawMiniGraphic_MM(x, y, IMG_EMPTY);
412 graphic = el2gfx(element);
414 DrawMiniGraphic_MM(x, y, graphic);
417 void DrawMiniElementOrWall_MM(int sx, int sy, int scroll_x, int scroll_y)
419 int x = sx + scroll_x, y = sy + scroll_y;
421 if (x < -1 || x > lev_fieldx || y < -1 || y > lev_fieldy)
422 DrawMiniElement_MM(sx, sy, EL_EMPTY);
423 else if (x > -1 && x < lev_fieldx && y > -1 && y < lev_fieldy)
424 DrawMiniElement_MM(sx, sy, Tile[x][y]);
427 void DrawField_MM(int x, int y)
429 int element = Tile[x][y];
431 DrawElement_MM(x, y, element);
434 void DrawLevel_MM(void)
440 for (x = 0; x < lev_fieldx; x++)
441 for (y = 0; y < lev_fieldy; y++)
444 redraw_mask |= REDRAW_FIELD;
447 void DrawWallsExt_MM(int x, int y, int element, int draw_mask)
450 int graphic = el2gfx(WALL_BASE(element));
454 getMiniGraphicSource(graphic, &bitmap, &gx, &gy);
456 DrawGraphic_MM(x, y, IMG_EMPTY);
459 if (IS_WALL_WOOD(element) || IS_WALL_AMOEBA(element) ||
460 IS_DF_WALL_WOOD(element))
462 if (IS_WALL_ICE(element) || IS_WALL_AMOEBA(element))
466 for (i = 0; i < 4; i++)
468 int dest_x = cSX + x * TILEX + MINI_TILEX * (i % 2);
469 int dest_y = cSY + y * TILEY + MINI_TILEY * (i / 2);
471 if (!((1 << i) & draw_mask))
474 if (element & (1 << i))
475 BlitBitmap(bitmap, drawto, gx, gy, MINI_TILEX, MINI_TILEY,
478 ClearRectangle(drawto, dest_x, dest_y, MINI_TILEX, MINI_TILEY);
484 void DrawWalls_MM(int x, int y, int element)
486 DrawWallsExt_MM(x, y, element, HIT_MASK_ALL);
489 void DrawWallsAnimation_MM(int x, int y, int element, int phase, int bit_mask)
495 DrawWalls_MM(x, y, element);
500 for (i = 0; i < 4; i++)
502 if (element & (1 << i))
508 int dst_x = cSX + x * TILEX + (i % 2) * MINI_TILEX;
509 int dst_y = cSY + y * TILEY + (i / 2) * MINI_TILEY;
511 if (bit_mask & (1 << i))
513 graphic = (IS_WALL_AMOEBA(element) ?
514 IMG_MM_AMOEBA_WALL_GROWING :
515 IMG_MM_ICE_WALL_SHRINKING);
520 graphic = (IS_WALL_AMOEBA(element) ?
526 getSizedGraphicSource(graphic, frame, MINI_TILESIZE, &bitmap,
529 BlitBitmap(bitmap, drawto, src_x, src_y, MINI_TILEX, MINI_TILEY,
537 void DrawElement_MM(int x, int y, int element)
539 if (element == EL_EMPTY)
540 DrawGraphic_MM(x, y, IMG_EMPTY);
541 else if (IS_WALL(element))
542 DrawWalls_MM(x, y, element);
544 else if (IS_WALL_CHANGING(element) && IS_WALL_CHANGING(Tile[x][y]))
546 int wall_element = Tile[x][y] - EL_WALL_CHANGING + Store[x][y];
548 DrawWalls_MM(x, y, wall_element);
551 else if (element == EL_PACMAN)
552 DrawLevelField_MM(x, y);
553 else if (element == EL_FUSE_ON &&
557 DrawGraphic_MM(x, y, IMG_MM_FUSE);
559 DrawGraphic_MM(x, y, el2gfx(element));
563 static void DrawMicroWalls_MM(int x, int y, int element)
566 int graphic = el2gfx(WALL_BASE(element));
570 getMicroGraphicSource(graphic, &bitmap, &gx, &gy);
572 for (i = 0; i < 4; i++)
574 int xpos = MICROLEV_XPOS + x * MICRO_TILEX + MICRO_WALLX * (i % 2);
575 int ypos = MICROLEV_YPOS + y * MICRO_TILEY + MICRO_WALLY * (i / 2);
577 if (element & (1 << i))
578 BlitBitmap(bitmap, drawto, gx, gy, MICRO_WALLX, MICRO_WALLY, xpos, ypos);
580 ClearRectangle(drawto, xpos, ypos, MICRO_WALLX, MICRO_WALLY);
584 static void DrawMicroElement_MM(int x, int y, int element)
587 int graphic = el2gfx(element);
590 if (element == EL_EMPTY)
593 if (IS_WALL(element))
595 DrawMicroWalls_MM(x, y, element);
600 getMicroGraphicSource(graphic, &bitmap, &gx, &gy);
602 BlitBitmap(bitmap, drawto, gx, gy, MICRO_TILEX, MICRO_TILEY,
603 MICROLEV_XPOS + x * MICRO_TILEX, MICROLEV_YPOS + y * MICRO_TILEY);
606 static void DrawMicroLevelExt_MM(int xpos, int ypos)
610 ClearRectangle(drawto, xpos, ypos, MICROLEV_XSIZE, MICROLEV_YSIZE);
612 for (x = 0; x < STD_LEV_FIELDX; x++)
613 for (y = 0; y < STD_LEV_FIELDY; y++)
614 DrawMicroElement_MM(x, y, Ur[x][y]);
616 redraw_mask |= REDRAW_FIELD;
620 void DrawMiniLevel_MM(int size_x, int size_y, int scroll_x, int scroll_y)
624 for (x = 0; x < size_x; x++)
625 for (y = 0; y < size_y; y++)
626 DrawMiniElementOrWall_MM(x, y, scroll_x, scroll_y);
628 redraw_mask |= REDRAW_FIELD;
632 // ----------------------------------------------------------------------------
634 // ----------------------------------------------------------------------------
636 #define XSN_RND(x) ((x) != 0 ? rand() % (x) : 0)
637 #define XSN_ALPHA_VALUE(x) (SDL_ALPHA_OPAQUE * (x) / 100)
639 #define XSN_MAX_ITEMS 100
640 #define XSN_MAX_HEIGHT 40
642 #define XSN_MAX_DY 10
643 #define XSN_CHECK_DELAY 3
644 #define XSN_START_DELAY 60
645 #define XSN_UPDATE_DELAY 50
646 #define XSN_GROWTH_DELAY 3
647 #define XSN_GROWTH_RATE 3
648 #define XSN_CHANGE_DELAY 30
649 #define XSN_CHANGE_FACTOR 3
650 #define XSN_ALPHA_DEFAULT XSN_ALPHA_VALUE(95)
651 #define XSN_DEBUG_STEPS 5
653 static byte xsn_bits_0[] = { 0x05, 0x02, 0x05 };
654 static byte xsn_bits_1[] = { 0x22, 0x6b, 0x14, 0x2a, 0x14, 0x6b, 0x22 };
655 static byte xsn_bits_2[] = { 0x14, 0x08, 0x49, 0x36, 0x49, 0x08, 0x14 };
665 { ARRAY_SIZE(xsn_bits_0), xsn_bits_0 },
666 { ARRAY_SIZE(xsn_bits_1), xsn_bits_1 },
667 { ARRAY_SIZE(xsn_bits_2), xsn_bits_2 },
668 { ARRAY_SIZE(xsn_bits_2), xsn_bits_2 },
669 { ARRAY_SIZE(xsn_bits_1), xsn_bits_1 },
670 { ARRAY_SIZE(xsn_bits_2), xsn_bits_2 },
671 { ARRAY_SIZE(xsn_bits_0), xsn_bits_0 },
673 static int num_xsn_data = ARRAY_SIZE(xsn_data);
702 struct XsnItem items[XSN_MAX_ITEMS];
707 static struct Xsn xsn = { 0 };
709 static int xsn_percent(void)
712 int xsn_m1 = xsn_m0 + 10;
713 int xsn_m2 = xsn_m1 + 10;
714 int xsn_m3 = xsn_m2 + 10;
715 time_t xsn_e0 = time(NULL);
716 struct tm *xsn_t0 = localtime(&xsn_e0);
717 struct tm xsn_t1 = { 0,0,0, xsn_m2*3, xsn_m3/3, xsn_t0->tm_year, 0,0,-1 };
718 time_t xsn_e1 = mktime(&xsn_t1);
719 int xsn_c0 = (25 * xsn_m3) << xsn_m1;
720 int xsn_c1 = (xsn_t1.tm_wday - xsn_m1) * !!xsn_t1.tm_wday;
722 for (xsn_m0 = 5; xsn_m0 > 0; xsn_m0--)
724 int xsn_c2 = (xsn_m0 > 4 ? 0 : xsn_c1) - xsn_m1 * xsn_m0;
725 int xsn_off = (xsn_m0 > 4 ? xsn_c0 : 0);
726 time_t xsn_e3 = xsn_e1 - xsn_c2 * xsn_c0;
728 if (xsn_e0 > xsn_e3 - xsn_off &&
729 xsn_e0 < xsn_e3 + xsn_off + xsn_c0)
730 return xsn_m0 * (xsn_m3 - xsn_m1);
736 static void xsn_init_item(int nr)
738 struct XsnItem *item = &xsn.items[nr];
740 item->type = XSN_RND(num_xsn_data);
742 if (xsn.change_type != 0)
744 int new_x = XSN_RND(xsn.area_xsize / 3);
746 item->x = (xsn.change_dir == 1 ? new_x : xsn.area_xsize - new_x);
747 item->y = XSN_RND(xsn.area_ysize);
751 item->x = XSN_RND(xsn.area_xsize - xsn_data[item->type].size);
752 item->y = XSN_RND(xsn.area_ysize / 10);
755 item->dy = XSN_RND(xsn.max_dy + 1) + 1;
756 item->dx = XSN_RND(item->dy / 4 + 1) * (XSN_RND(1000) > 500 ? -1 : 1);
761 static void xsn_update_item(int nr)
763 struct XsnItem *item = &xsn.items[nr];
768 if (xsn.change_type != 0)
770 int dx_new = ABS(item->dx) +
771 (xsn.change_type == 1 ?
772 XSN_RND(XSN_CHANGE_FACTOR + 1) - XSN_CHANGE_FACTOR / 2 :
775 item->dx = MIN(MAX(-50, dx_new * xsn.change_dir), 50);
778 int new_x = item->x + item->dx;
779 int new_y = item->y + item->dy;
781 item->active = (new_y < xsn.area_ysize);
783 if (xsn.change_type != 0)
784 item->active = (item->active && new_x > 0 && new_x < xsn.area_xsize);
786 int item_size = xsn_data[item->type].size;
787 int half_item_size = item_size / 2;
788 int mid_x = new_x + half_item_size;
789 int mid_y = new_y + half_item_size;
790 int upper_border = xsn.area_ysize - xsn.max_height;
793 new_y >= upper_border &&
795 new_x <= xsn.area_xsize - item_size &&
796 mid_y >= xsn.height[mid_x] &&
797 mid_y < xsn.area_ysize)
799 Bitmap *item_bitmap = xsn_data[item->type].bitmap;
800 SDL_Surface *surface = xsn.bitmap->surface;
801 SDL_Surface *surface_masked = xsn.bitmap->surface_masked;
802 int item_alpha = XSN_ALPHA_VALUE(81 + XSN_RND(20));
806 xsn.bitmap->surface = surface_masked;
808 SDLSetAlpha(item_bitmap->surface_masked, TRUE, item_alpha);
810 // blit to masked surface instead of opaque surface
811 BlitBitmapMasked(item_bitmap, xsn.bitmap, 0, 0, item_size, item_size,
812 new_x, new_y - upper_border);
814 SDLSetAlpha(item_bitmap->surface_masked, TRUE, XSN_ALPHA_DEFAULT);
816 for (i = -half_item_size; i <= half_item_size; i++)
818 int xpos = mid_x + i;
820 if (xpos >= 0 && xpos < xsn.area_xsize)
821 xsn.height[xpos] = MIN(new_y + ABS(i), xsn.height[xpos]);
824 if (xsn.height[mid_x] <= upper_border + shrink)
826 int xpos1 = MAX(0, new_x - half_item_size);
827 int xpos2 = MIN(new_x + 3 * half_item_size, xsn.area_xsize);
828 int xsize = xpos2 - xpos1;
829 int ysize1 = XSN_RND(xsn.max_height - shrink);
830 int ysize2 = xsn.max_height - ysize1;
832 SDLSetAlpha(surface_masked, FALSE, 0);
834 FillRectangle(xsn.bitmap, xpos1, xsn.max_height, xsize, xsn.max_height,
836 BlitBitmapMasked(xsn.bitmap, xsn.bitmap, xpos1, 0, xsize, ysize1,
837 xpos1, xsn.max_height + shrink);
838 BlitBitmapMasked(xsn.bitmap, xsn.bitmap, xpos1, ysize1, xsize, ysize2,
839 xpos1, xsn.max_height + ysize1);
840 FillRectangle(xsn.bitmap, xpos1, 0, xsize, xsn.max_height,
842 BlitBitmapMasked(xsn.bitmap, xsn.bitmap, xpos1, xsn.max_height,
843 xsize, xsn.max_height, xpos1, 0);
845 SDLSetAlpha(surface_masked, TRUE, XSN_ALPHA_DEFAULT);
847 for (i = xpos1; i < xpos2; i++)
848 xsn.height[i] = MIN(xsn.height[i] + shrink, xsn.area_ysize - 1);
851 SDLFreeBitmapTextures(xsn.bitmap);
852 SDLCreateBitmapTextures(xsn.bitmap);
854 xsn.bitmap->surface = surface;
859 item->dx += XSN_RND(XSN_CHANGE_FACTOR) * (XSN_RND(1000) > 500 ? -1 : 1);
861 if (xsn.change_type == 0)
862 item->dx = MIN(MAX(-xsn.max_dx, item->dx), xsn.max_dx);
868 static void xsn_update_change(void)
870 if (XSN_RND(100) > 65)
872 xsn.change_dir = (XSN_RND(10) > 4 ? 1 : -1);
873 xsn.change_delay = XSN_RND(5) + 1;
876 else if (xsn.change_type == 2)
878 xsn.change_delay = XSN_RND(3) + 1;
883 xsn.change_delay = XSN_CHANGE_DELAY;
888 static void DrawTileCursor_Xsn(int draw_target)
890 static boolean initialized = FALSE;
891 static boolean started = FALSE;
892 static boolean active = FALSE;
893 static boolean debug = FALSE;
894 static unsigned int check_delay = 0;
895 static unsigned int start_delay = 0;
896 static unsigned int growth_delay = 0;
897 static unsigned int update_delay = 0;
898 static unsigned int change_delay = 0;
899 static unsigned int check_delay_value = XSN_CHECK_DELAY * 1000;
900 static unsigned int start_delay_value = 0;
901 static unsigned int growth_delay_value = 0;
902 static unsigned int update_delay_value = 0;
903 static unsigned int change_delay_value = 0;
904 static int percent = 0;
905 static int debug_value = 0;
906 boolean reinitialize = FALSE;
907 boolean active_last = active;
910 if (draw_target != DRAW_TO_SCREEN)
913 if (DelayReached(&check_delay, check_delay_value))
915 percent = (debug ? debug_value * 100 / XSN_DEBUG_STEPS : xsn_percent());
916 active = (percent > 0);
918 else if (tile_cursor.xsn_debug)
920 debug_value = (active ? 0 : MIN(debug_value + 1, XSN_DEBUG_STEPS));
924 DelayReached(&check_delay, 0);
926 tile_cursor.xsn_debug = FALSE;
934 start_delay_value = (debug ? 0 : XSN_RND(XSN_START_DELAY * 2) * 1000);
937 DelayReached(&start_delay, 0);
944 xsn.area_xsize = gfx.win_xsize;
945 xsn.area_ysize = gfx.win_ysize;
947 for (i = 0; i < num_xsn_data; i++)
949 int size = xsn_data[i].size;
950 byte *bits = xsn_data[i].bits;
951 Bitmap *bitmap = CreateBitmap(size, size, DEFAULT_DEPTH);
953 FillRectangle(bitmap, 0, 0, size, size, BLACK_PIXEL);
955 for (y = 0; y < size; y++)
956 for (x = 0; x < size; x++)
957 if ((bits[y] >> x) & 0x01)
958 SDLPutPixel(bitmap, x, y, WHITE_PIXEL);
960 SDL_Surface *surface = bitmap->surface;
962 if ((bitmap->surface_masked = SDLGetNativeSurface(surface)) == NULL)
963 Fail("SDLGetNativeSurface() failed");
965 SDL_Surface *surface_masked = bitmap->surface_masked;
967 SDL_SetColorKey(surface_masked, SET_TRANSPARENT_PIXEL,
968 SDL_MapRGB(surface_masked->format, 0x00, 0x00, 0x00));
970 SDLSetAlpha(surface, TRUE, XSN_ALPHA_DEFAULT);
971 SDLSetAlpha(surface_masked, TRUE, XSN_ALPHA_DEFAULT);
973 xsn_data[i].bitmap = bitmap;
976 srand((unsigned int)time(NULL));
984 xsn.max_items = percent * XSN_MAX_ITEMS / 100;
985 xsn.max_height = percent * XSN_MAX_HEIGHT / 100;
987 xsn.max_dx = XSN_MAX_DX;
988 xsn.max_dy = XSN_MAX_DY;
990 xsn.change_delay = XSN_CHANGE_DELAY;
994 for (i = 0; i < xsn.max_items; i++)
998 if (xsn.area_xsize != gfx.win_xsize ||
999 xsn.area_ysize != gfx.win_ysize ||
1002 xsn.area_xsize = gfx.win_xsize;
1003 xsn.area_ysize = gfx.win_ysize;
1005 if (xsn.bitmap != NULL)
1006 FreeBitmap(xsn.bitmap);
1008 xsn.bitmap = CreateBitmap(xsn.area_xsize, xsn.max_height * 2,
1011 FillRectangle(xsn.bitmap, 0, 0, xsn.area_xsize, xsn.max_height,
1014 SDL_Surface *surface = xsn.bitmap->surface;
1016 if ((xsn.bitmap->surface_masked = SDLGetNativeSurface(surface)) == NULL)
1017 Fail("SDLGetNativeSurface() failed");
1019 SDL_Surface *surface_masked = xsn.bitmap->surface_masked;
1021 SDL_SetColorKey(surface_masked, SET_TRANSPARENT_PIXEL,
1022 SDL_MapRGB(surface_masked->format, 0x00, 0x00, 0x00));
1024 SDLSetAlpha(surface, TRUE, XSN_ALPHA_DEFAULT);
1025 SDLSetAlpha(surface_masked, TRUE, XSN_ALPHA_DEFAULT);
1027 SDLCreateBitmapTextures(xsn.bitmap);
1029 for (i = 0; i < num_xsn_data; i++)
1031 SDLFreeBitmapTextures(xsn_data[i].bitmap);
1032 SDLCreateBitmapTextures(xsn_data[i].bitmap);
1035 if (xsn.height != NULL)
1036 checked_free(xsn.height);
1038 xsn.height = checked_calloc(xsn.area_xsize * sizeof(int));
1040 for (i = 0; i < xsn.area_xsize; i++)
1041 xsn.height[i] = xsn.area_ysize - 1;
1046 if (!DelayReached(&start_delay, start_delay_value))
1049 update_delay_value = XSN_UPDATE_DELAY;
1050 growth_delay_value = XSN_GROWTH_DELAY * 1000;
1051 change_delay_value = XSN_CHANGE_DELAY * 1000;
1053 DelayReached(&growth_delay, 0);
1054 DelayReached(&update_delay, 0);
1055 DelayReached(&change_delay, 0);
1060 if (xsn.num_items < xsn.max_items)
1062 if (DelayReached(&growth_delay, growth_delay_value))
1064 xsn.num_items += XSN_RND(XSN_GROWTH_RATE * 2);
1065 xsn.num_items = MIN(xsn.num_items, xsn.max_items);
1069 if (DelayReached(&update_delay, update_delay_value))
1071 for (i = 0; i < xsn.num_items; i++)
1075 if (DelayReached(&change_delay, change_delay_value))
1077 xsn_update_change();
1079 change_delay_value = xsn.change_delay * 1000;
1082 BlitToScreenMasked(xsn.bitmap, 0, 0, xsn.area_xsize, xsn.max_height,
1083 0, xsn.area_ysize - xsn.max_height);
1085 for (i = 0; i < xsn.num_items; i++)
1087 int dst_x = xsn.items[i].x;
1088 int dst_y = xsn.items[i].y;
1089 int type = xsn.items[i].type;
1090 int size = xsn_data[type].size;
1091 Bitmap *bitmap = xsn_data[type].bitmap;
1093 BlitToScreenMasked(bitmap, 0, 0, size, size, dst_x, dst_y);
1097 void DrawTileCursor_MM(int draw_target, boolean tile_cursor_active)
1099 if (program.headless)
1102 Bitmap *fade_bitmap;
1106 int graphic = IMG_GLOBAL_TILE_CURSOR;
1108 int tilesize = TILESIZE_VAR;
1109 int width = tilesize;
1110 int height = tilesize;
1112 DrawTileCursor_Xsn(draw_target);
1114 if (!tile_cursor.enabled ||
1115 !tile_cursor.active ||
1116 !tile_cursor_active)
1119 if (tile_cursor.moving)
1121 int step = TILESIZE_VAR / 4;
1122 int dx = tile_cursor.target_x - tile_cursor.x;
1123 int dy = tile_cursor.target_y - tile_cursor.y;
1126 tile_cursor.x = tile_cursor.target_x;
1128 tile_cursor.x += SIGN(dx) * step;
1131 tile_cursor.y = tile_cursor.target_y;
1133 tile_cursor.y += SIGN(dy) * step;
1135 if (tile_cursor.x == tile_cursor.target_x &&
1136 tile_cursor.y == tile_cursor.target_y)
1137 tile_cursor.moving = FALSE;
1140 dst_x = tile_cursor.x;
1141 dst_y = tile_cursor.y;
1143 frame = getGraphicAnimationFrame(graphic, -1);
1145 getSizedGraphicSource(graphic, frame, tilesize, &src_bitmap, &src_x, &src_y);
1148 (draw_target == DRAW_TO_FADE_SOURCE ? gfx.fade_bitmap_source :
1149 draw_target == DRAW_TO_FADE_TARGET ? gfx.fade_bitmap_target : NULL);
1151 if (draw_target == DRAW_TO_SCREEN)
1152 BlitToScreenMasked(src_bitmap, src_x, src_y, width, height, dst_x, dst_y);
1154 BlitBitmapMasked(src_bitmap, fade_bitmap, src_x, src_y, width, height,
1159 static int REQ_in_range(int x, int y)
1161 if (y > DY + 249 && y < DY + 278)
1163 if (x > DX + 1 && x < DX + 48)
1165 else if (x > DX + 51 && x < DX + 98)
1173 Pixel ReadPixel(DrawBuffer *bitmap, int x, int y)
1175 return GetPixel(bitmap, x, y);
1178 void SetRGB(unsigned int pixel,
1179 unsigned short red, unsigned short green, unsigned short blue)
1183 int get_base_element(int element)
1185 if (IS_MIRROR(element))
1186 return EL_MIRROR_START;
1187 else if (IS_MIRROR_FIXED(element))
1188 return EL_MIRROR_FIXED_START;
1189 else if (IS_POLAR(element))
1190 return EL_POLAR_START;
1191 else if (IS_POLAR_CROSS(element))
1192 return EL_POLAR_CROSS_START;
1193 else if (IS_BEAMER(element))
1194 return EL_BEAMER_RED_START + BEAMER_NR(element) * 16;
1195 else if (IS_FIBRE_OPTIC(element))
1196 return EL_FIBRE_OPTIC_START + FIBRE_OPTIC_NR(element) * 2;
1197 else if (IS_MCDUFFIN(element))
1198 return EL_MCDUFFIN_START;
1199 else if (IS_LASER(element))
1200 return EL_LASER_START;
1201 else if (IS_RECEIVER(element))
1202 return EL_RECEIVER_START;
1203 else if (IS_DF_MIRROR(element))
1204 return EL_DF_MIRROR_START;
1205 else if (IS_DF_MIRROR_AUTO(element))
1206 return EL_DF_MIRROR_AUTO_START;
1207 else if (IS_PACMAN(element))
1208 return EL_PACMAN_START;
1209 else if (IS_GRID_STEEL(element))
1210 return EL_GRID_STEEL_START;
1211 else if (IS_GRID_WOOD(element))
1212 return EL_GRID_WOOD_START;
1213 else if (IS_GRID_STEEL_FIXED(element))
1214 return EL_GRID_STEEL_FIXED_START;
1215 else if (IS_GRID_WOOD_FIXED(element))
1216 return EL_GRID_WOOD_FIXED_START;
1217 else if (IS_GRID_STEEL_AUTO(element))
1218 return EL_GRID_STEEL_AUTO_START;
1219 else if (IS_GRID_WOOD_AUTO(element))
1220 return EL_GRID_WOOD_AUTO_START;
1221 else if (IS_WALL_STEEL(element))
1222 return EL_WALL_STEEL_START;
1223 else if (IS_WALL_WOOD(element))
1224 return EL_WALL_WOOD_START;
1225 else if (IS_WALL_ICE(element))
1226 return EL_WALL_ICE_START;
1227 else if (IS_WALL_AMOEBA(element))
1228 return EL_WALL_AMOEBA_START;
1229 else if (IS_DF_WALL_STEEL(element))
1230 return EL_DF_WALL_STEEL_START;
1231 else if (IS_DF_WALL_WOOD(element))
1232 return EL_DF_WALL_WOOD_START;
1233 else if (IS_CHAR(element))
1234 return EL_CHAR_START;
1239 int get_element_phase(int element)
1241 return element - get_base_element(element);
1244 int get_num_elements(int element)
1246 if (IS_MIRROR(element) ||
1247 IS_POLAR(element) ||
1248 IS_BEAMER(element) ||
1249 IS_DF_MIRROR(element) ||
1250 IS_DF_MIRROR_AUTO(element))
1252 else if (IS_GRID_STEEL_FIXED(element) ||
1253 IS_GRID_WOOD_FIXED(element) ||
1254 IS_GRID_STEEL_AUTO(element) ||
1255 IS_GRID_WOOD_AUTO(element))
1257 else if (IS_MIRROR_FIXED(element) ||
1258 IS_POLAR_CROSS(element) ||
1259 IS_MCDUFFIN(element) ||
1260 IS_LASER(element) ||
1261 IS_RECEIVER(element) ||
1262 IS_PACMAN(element) ||
1263 IS_GRID_STEEL(element) ||
1264 IS_GRID_WOOD(element))
1270 int get_rotated_element(int element, int step)
1272 int base_element = get_base_element(element);
1273 int num_elements = get_num_elements(element);
1274 int element_phase = element - base_element;
1276 return base_element + (element_phase + step + num_elements) % num_elements;
1279 static int map_element(int element)
1283 case EL_WALL_STEEL: return EL_STEEL_WALL;
1284 case EL_WALL_WOOD: return EL_WOODEN_WALL;
1285 case EL_WALL_ICE: return EL_ICE_WALL;
1286 case EL_WALL_AMOEBA: return EL_AMOEBA_WALL;
1287 case EL_DF_WALL_STEEL: return EL_DF_STEEL_WALL;
1288 case EL_DF_WALL_WOOD: return EL_DF_WOODEN_WALL;
1290 default: return element;
1294 int el2gfx(int element)
1296 element = map_element(element);
1301 return IMG_MM_LIGHTBALL_RED + RND(3);
1304 return el2img_mm(element);
1308 void RedrawPlayfield_MM(void)
1314 void BlitScreenToBitmap_MM(Bitmap *target_bitmap)
1316 BlitBitmap(drawto_field, target_bitmap,
1317 REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE, REAL_SX, REAL_SY);