1 /***********************************************************
2 * Mirror Magic -- McDuffin's Revenge *
3 *----------------------------------------------------------*
4 * (c) 1994-2001 Artsoft Entertainment *
6 * Detmolder Strasse 189 *
9 * e-mail: info@artsoft.org *
10 *----------------------------------------------------------*
12 ***********************************************************/
22 ClearRectangle(backbuffer, REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
24 SetDrawtoField(DRAW_BACKBUFFER);
26 redraw_mask |= REDRAW_FIELD;
29 void DrawGraphicAnimation_MM(int x, int y, int graphic, int frame)
34 getGraphicSource(graphic, frame, &bitmap, &src_x, &src_y);
36 BlitBitmap(bitmap, drawto_field, src_x, src_y, TILEX, TILEY,
37 FX + x * TILEX, FY + y * TILEY);
40 void DrawGraphic_MM(int x, int y, int graphic)
43 if (!IN_SCR_FIELD(x,y))
45 printf("DrawGraphic_MM(): x = %d, y = %d, graphic = %d\n",x,y,graphic);
46 printf("DrawGraphic_MM(): This should never happen!\n");
51 DrawGraphicExt_MM(drawto_field, FX + x*TILEX, FY + y*TILEY, graphic);
55 void DrawGraphicExt_MM(DrawBuffer *d, int x, int y, int graphic)
60 getGraphicSource(graphic, 0, &bitmap, &src_x, &src_y);
61 BlitBitmap(bitmap, d, src_x, src_y, TILEX, TILEY, x, y);
64 void DrawGraphicThruMask_MM(int x, int y, int graphic)
67 if (!IN_SCR_FIELD(x,y))
69 printf("DrawGraphicThruMask_MM(): x = %d,y = %d, graphic = %d\n",x,y,graphic);
70 printf("DrawGraphicThruMask_MM(): This should never happen!\n");
75 DrawGraphicThruMaskExt_MM(drawto_field, FX + x*TILEX, FY + y*TILEY, graphic);
79 void DrawGraphicThruMaskExt_MM(DrawBuffer *d, int dest_x, int dest_y,
85 if (graphic == IMG_EMPTY)
88 getGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
90 BlitBitmapMasked(src_bitmap, d, src_x, src_y, TILEX, TILEY, dest_x, dest_y);
93 void DrawMiniGraphic_MM(int x, int y, int graphic)
95 DrawMiniGraphicExt_MM(drawto, SX + x*MINI_TILEX, SY + y*MINI_TILEY, graphic);
96 MarkTileDirty(x/2, y/2);
99 void getMicroGraphicSource(int graphic, Bitmap **bitmap, int *x, int *y)
101 getSizedGraphicSource(graphic, 0, TILESIZE / 4, bitmap, x, y);
104 void DrawMiniGraphicExt_MM(DrawBuffer *d, int x, int y, int graphic)
109 getMiniGraphicSource(graphic, &bitmap, &src_x, &src_y);
110 BlitBitmap(bitmap, d, src_x, src_y, MINI_TILEX, MINI_TILEY, x, y);
113 void DrawGraphicShifted_MM(int x,int y, int dx,int dy, int graphic,
114 int cut_mode, int mask_mode)
116 int width = TILEX, height = TILEY;
118 int src_x, src_y, dest_x, dest_y;
123 DrawGraphic_MM(x, y, graphic);
127 if (dx || dy) /* Verschiebung der Grafik? */
129 if (x < BX1) /* Element kommt von links ins Bild */
136 else if (x > BX2) /* Element kommt von rechts ins Bild */
142 else if (x==BX1 && dx < 0) /* Element verläßt links das Bild */
148 else if (x==BX2 && dx > 0) /* Element verläßt rechts das Bild */
150 else if (dx) /* allg. Bewegung in x-Richtung */
151 MarkTileDirty(x + SIGN(dx), y);
153 if (y < BY1) /* Element kommt von oben ins Bild */
155 if (cut_mode==CUT_BELOW) /* Element oberhalb des Bildes */
163 else if (y > BY2) /* Element kommt von unten ins Bild */
169 else if (y==BY1 && dy < 0) /* Element verläßt oben das Bild */
175 else if (dy > 0 && cut_mode == CUT_ABOVE)
177 if (y == BY2) /* Element unterhalb des Bildes */
183 MarkTileDirty(x, y + 1);
184 } /* Element verläßt unten das Bild */
185 else if (dy > 0 && (y == BY2 || cut_mode == CUT_BELOW))
187 else if (dy) /* allg. Bewegung in y-Richtung */
188 MarkTileDirty(x, y + SIGN(dy));
191 getGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
196 dest_x = FX + x * TILEX + dx;
197 dest_y = FY + y * TILEY + dy;
200 if (!IN_SCR_FIELD(x,y))
202 printf("DrawGraphicShifted_MM(): x = %d, y = %d, graphic = %d\n",x,y,graphic);
203 printf("DrawGraphicShifted_MM(): This should never happen!\n");
208 if (mask_mode == USE_MASKING)
210 BlitBitmapMasked(src_bitmap, drawto_field,
211 src_x, src_y, TILEX, TILEY, dest_x, dest_y);
214 BlitBitmap(src_bitmap, drawto_field,
215 src_x, src_y, width, height, dest_x, dest_y);
220 void DrawGraphicShiftedThruMask_MM(int x,int y, int dx,int dy, int graphic,
223 DrawGraphicShifted_MM(x,y, dx,dy, graphic, cut_mode, USE_MASKING);
226 void DrawScreenElementExt_MM(int x, int y, int dx, int dy, int element,
227 int cut_mode, int mask_mode)
229 int ux = LEVELX(x), uy = LEVELY(y);
230 int graphic = el2gfx(element);
231 int phase8 = ABS(MovPos[ux][uy]) / (TILEX / 8);
232 int phase2 = phase8 / 4;
233 int dir = MovDir[ux][uy];
235 if (element == EL_PACMAN)
237 graphic = (phase2 ? IMG_MM_PACMAN_RIGHT : IMG_MM_PACMAN_EATING_RIGHT);
241 else if (dir == MV_LEFT)
243 else if (dir == MV_DOWN)
248 DrawGraphicShifted_MM(x, y, dx, dy, graphic, cut_mode, mask_mode);
249 else if (mask_mode == USE_MASKING)
250 DrawGraphicThruMask_MM(x, y, graphic);
252 DrawGraphic_MM(x, y, graphic);
255 void DrawLevelElementExt_MM(int x, int y, int dx, int dy, int element,
256 int cut_mode, int mask_mode)
258 if (IN_LEV_FIELD(x, y) && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
259 DrawScreenElementExt_MM(SCREENX(x), SCREENY(y), dx, dy, element,
260 cut_mode, mask_mode);
263 void DrawScreenElementShifted_MM(int x, int y, int dx, int dy, int element,
266 DrawScreenElementExt_MM(x, y, dx, dy, element, cut_mode, NO_MASKING);
269 void DrawLevelElementShifted_MM(int x, int y, int dx, int dy, int element,
272 DrawLevelElementExt_MM(x, y, dx, dy, element, cut_mode, NO_MASKING);
275 void DrawScreenElementThruMask_MM(int x, int y, int element)
277 DrawScreenElementExt_MM(x, y, 0, 0, element, NO_CUTTING, USE_MASKING);
280 void DrawLevelElementThruMask_MM(int x, int y, int element)
282 DrawLevelElementExt_MM(x, y, 0, 0, element, NO_CUTTING, USE_MASKING);
285 void DrawLevelFieldThruMask_MM(int x, int y)
287 DrawLevelElementExt_MM(x, y, 0, 0, Feld[x][y], NO_CUTTING, USE_MASKING);
290 void DrawScreenElement_MM(int x, int y, int element)
292 DrawScreenElementExt_MM(x, y, 0, 0, element, NO_CUTTING, NO_MASKING);
295 void DrawLevelElement_MM(int x, int y, int element)
297 if (IN_LEV_FIELD(x, y) && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
298 DrawScreenElement_MM(SCREENX(x), SCREENY(y), element);
301 void DrawScreenField_MM(int x, int y)
303 int element = Feld[x][y];
305 if (!IN_LEV_FIELD(x, y))
310 int horiz_move = (MovDir[x][y] == MV_LEFT || MovDir[x][y] == MV_RIGHT);
312 DrawScreenElement_MM(x, y, EL_EMPTY);
315 DrawScreenElementShifted_MM(x, y, MovPos[x][y], 0, element, NO_CUTTING);
317 DrawScreenElementShifted_MM(x, y, 0, MovPos[x][y], element, NO_CUTTING);
319 else if (IS_BLOCKED(x, y))
325 Blocked2Moving(x, y, &oldx, &oldy);
328 horiz_move = (MovDir[oldx][oldy] == MV_LEFT ||
329 MovDir[oldx][oldy] == MV_RIGHT);
331 DrawScreenElement_MM(x, y, EL_EMPTY);
332 element = Feld[oldx][oldy];
335 DrawScreenElementShifted_MM(sx,sy, MovPos[oldx][oldy],0,element,NO_CUTTING);
337 DrawScreenElementShifted_MM(sx,sy, 0,MovPos[oldx][oldy],element,NO_CUTTING);
339 else if (IS_DRAWABLE(element))
340 DrawScreenElement_MM(x, y, element);
342 DrawScreenElement_MM(x, y, EL_EMPTY);
345 void DrawLevelField_MM(int x, int y)
347 DrawScreenField_MM(x, y);
350 void DrawMiniElement_MM(int x, int y, int element)
356 DrawMiniGraphic_MM(x, y, IMG_EMPTY);
360 graphic = el2gfx(element);
361 DrawMiniGraphic_MM(x, y, graphic);
364 void DrawMiniElementOrWall_MM(int sx, int sy, int scroll_x, int scroll_y)
366 int x = sx + scroll_x, y = sy + scroll_y;
368 if (x < -1 || x > lev_fieldx || y < -1 || y > lev_fieldy)
369 DrawMiniElement_MM(sx, sy, EL_EMPTY);
370 else if (x > -1 && x < lev_fieldx && y > -1 && y < lev_fieldy)
371 DrawMiniElement_MM(sx, sy, Feld[x][y]);
374 void DrawField_MM(int x, int y)
376 int element = Feld[x][y];
378 DrawElement_MM(x, y, element);
387 for (x=0; x<lev_fieldx; x++)
388 for (y=0; y<lev_fieldy; y++)
391 redraw_mask |= REDRAW_FIELD;
394 void DrawWallsExt_MM(int x, int y, int element, int draw_mask)
397 int graphic = el2gfx(WALL_BASE(element));
401 getMiniGraphicSource(graphic, &bitmap, &gx, &gy);
403 if (game_status != LEVELED || !editor.draw_walls_masked)
404 DrawGraphic_MM(x, y, IMG_EMPTY);
407 if (IS_WALL_WOOD(element) || IS_WALL_AMOEBA(element) ||
408 IS_DF_WALL_WOOD(element))
410 if (IS_WALL_ICE(element) || IS_WALL_AMOEBA(element))
416 int dest_x = SX + x * TILEX + MINI_TILEX * (i % 2);
417 int dest_y = SY + y * TILEY + MINI_TILEY * (i / 2);
419 if (!((1 << i) & draw_mask))
422 if (element & (1 << i))
423 BlitBitmap(bitmap, drawto, gx, gy, MINI_TILEX, MINI_TILEY,
425 else if (!editor.draw_walls_masked)
426 ClearRectangle(drawto, dest_x, dest_y, MINI_TILEX, MINI_TILEY);
432 void DrawWalls_MM(int x, int y, int element)
434 DrawWallsExt_MM(x, y, element, HIT_MASK_ALL);
437 void DrawWallsAnimation_MM(int x, int y, int element, int phase, int bit_mask)
443 DrawWalls_MM(x, y, element);
448 for (i = 0; i < 4; i++)
450 if (element & (1 << i))
456 int dst_x = SX + x * TILEX + (i % 2) * MINI_TILEX;
457 int dst_y = SY + y * TILEY + (i / 2) * MINI_TILEY;
459 if (bit_mask & (1 << i))
461 graphic = (IS_WALL_AMOEBA(element) ?
462 IMG_MM_AMOEBA_WALL_GROWING :
463 IMG_MM_ICE_WALL_SHRINKING);
468 graphic = (IS_WALL_AMOEBA(element) ?
474 getSizedGraphicSource(graphic, frame, MINI_TILESIZE, &bitmap,
477 BlitBitmap(bitmap, drawto, src_x, src_y, MINI_TILEX, MINI_TILEY,
485 void DrawElement_MM(int x, int y, int element)
487 if (element == EL_EMPTY)
488 DrawGraphic_MM(x, y, IMG_EMPTY);
489 else if (IS_WALL(element))
490 DrawWalls_MM(x, y, element);
492 else if (IS_WALL_CHANGING(element) && IS_WALL_CHANGING(Feld[x][y]))
494 int wall_element = Feld[x][y] - EL_WALL_CHANGING + Store[x][y];
496 DrawWalls_MM(x, y, wall_element);
499 else if (element == EL_PACMAN)
500 DrawLevelField_MM(x, y);
502 DrawGraphic_MM(x, y, el2gfx(element));
505 void DrawMicroWalls_MM(int x, int y, int element)
508 int graphic = el2gfx(WALL_BASE(element));
512 getMicroGraphicSource(graphic, &bitmap, &gx, &gy);
516 int xpos = MICROLEV_XPOS + x * MICRO_TILEX + MICRO_WALLX * (i % 2);
517 int ypos = MICROLEV_YPOS + y * MICRO_TILEY + MICRO_WALLY * (i / 2);
519 if (element & (1 << i))
520 BlitBitmap(bitmap, drawto, gx, gy, MICRO_WALLX, MICRO_WALLY, xpos, ypos);
522 ClearRectangle(drawto, xpos, ypos, MICRO_WALLX, MICRO_WALLY);
526 void DrawMicroElement_MM(int x, int y, int element)
529 int graphic = el2gfx(element);
532 if (element == EL_EMPTY)
535 if (IS_WALL(element))
537 DrawMicroWalls_MM(x, y, element);
541 getMicroGraphicSource(graphic, &bitmap, &gx, &gy);
543 BlitBitmap(bitmap, drawto, gx, gy, MICRO_TILEX, MICRO_TILEY,
544 MICROLEV_XPOS + x * MICRO_TILEX, MICROLEV_YPOS + y * MICRO_TILEY);
547 void DrawMicroLevelExt_MM(int xpos, int ypos)
551 ClearRectangle(drawto, xpos, ypos, MICROLEV_XSIZE, MICROLEV_YSIZE);
553 for (x=0; x<STD_LEV_FIELDX; x++)
554 for (y=0; y<STD_LEV_FIELDY; y++)
555 DrawMicroElement_MM(x, y, Ur[x][y]);
557 redraw_mask |= REDRAW_FIELD;
560 void DrawMiniLevel_MM(int size_x, int size_y, int scroll_x, int scroll_y)
564 for(x=0; x<size_x; x++)
565 for(y=0; y<size_y; y++)
566 DrawMiniElementOrWall_MM(x, y, scroll_x, scroll_y);
568 redraw_mask |= REDRAW_FIELD;
571 int REQ_in_range(int x, int y)
573 if (y > DY+249 && y < DY+278)
575 if (x > DX+1 && x < DX+48)
577 else if (x > DX+51 && x < DX+98)
583 Pixel ReadPixel(DrawBuffer *bitmap, int x, int y)
585 return GetPixel(bitmap, x, y);
588 void SetRGB(unsigned int pixel,
589 unsigned short red, unsigned short green, unsigned short blue)
593 int get_base_element(int element)
595 if (IS_MIRROR(element))
596 return EL_MIRROR_START;
597 else if (IS_MIRROR_FIXED(element))
598 return EL_MIRROR_FIXED_START;
599 else if (IS_POLAR(element))
600 return EL_POLAR_START;
601 else if (IS_POLAR_CROSS(element))
602 return EL_POLAR_CROSS_START;
603 else if (IS_BEAMER(element))
604 return EL_BEAMER_RED_START + BEAMER_NR(element) * 16;
605 else if (IS_FIBRE_OPTIC(element))
606 return EL_FIBRE_OPTIC_START + FIBRE_OPTIC_NR(element) * 2;
607 else if (IS_MCDUFFIN(element))
608 return EL_MCDUFFIN_START;
609 else if (IS_LASER(element))
610 return EL_LASER_START;
611 else if (IS_RECEIVER(element))
612 return EL_RECEIVER_START;
613 else if (IS_DF_MIRROR(element))
614 return EL_DF_MIRROR_START;
615 else if (IS_DF_MIRROR_AUTO(element))
616 return EL_DF_MIRROR_AUTO_START;
617 else if (IS_PACMAN(element))
618 return EL_PACMAN_START;
619 else if (IS_GRID_STEEL(element))
620 return EL_GRID_STEEL_START;
621 else if (IS_GRID_WOOD(element))
622 return EL_GRID_WOOD_START;
623 else if (IS_GRID_STEEL_FIXED(element))
624 return EL_GRID_STEEL_FIXED_START;
625 else if (IS_GRID_WOOD_FIXED(element))
626 return EL_GRID_WOOD_FIXED_START;
627 else if (IS_GRID_STEEL_AUTO(element))
628 return EL_GRID_STEEL_AUTO_START;
629 else if (IS_GRID_WOOD_AUTO(element))
630 return EL_GRID_WOOD_AUTO_START;
631 else if (IS_WALL_STEEL(element))
632 return EL_WALL_STEEL_START;
633 else if (IS_WALL_WOOD(element))
634 return EL_WALL_WOOD_START;
635 else if (IS_WALL_ICE(element))
636 return EL_WALL_ICE_START;
637 else if (IS_WALL_AMOEBA(element))
638 return EL_WALL_AMOEBA_START;
639 else if (IS_DF_WALL_STEEL(element))
640 return EL_DF_WALL_STEEL_START;
641 else if (IS_DF_WALL_WOOD(element))
642 return EL_DF_WALL_WOOD_START;
643 else if (IS_CHAR(element))
644 return EL_CHAR_START;
649 int get_element_phase(int element)
651 return element - get_base_element(element);
654 int get_num_elements(int element)
656 if (IS_MIRROR(element) ||
658 IS_BEAMER(element) ||
659 IS_DF_MIRROR(element) ||
660 IS_DF_MIRROR_AUTO(element))
662 else if (IS_GRID_STEEL_FIXED(element) ||
663 IS_GRID_WOOD_FIXED(element) ||
664 IS_GRID_STEEL_AUTO(element) ||
665 IS_GRID_WOOD_AUTO(element))
667 else if (IS_MIRROR_FIXED(element) ||
668 IS_POLAR_CROSS(element) ||
669 IS_MCDUFFIN(element) ||
671 IS_RECEIVER(element) ||
672 IS_PACMAN(element) ||
673 IS_GRID_STEEL(element) ||
674 IS_GRID_WOOD(element))
680 int get_rotated_element(int element, int step)
682 int base_element = get_base_element(element);
683 int num_elements = get_num_elements(element);
684 int element_phase = element - base_element;
686 return base_element + (element_phase + step + num_elements) % num_elements;
689 static int map_element(int element)
693 case EL_WALL_STEEL: return EL_STEEL_WALL;
694 case EL_WALL_WOOD: return EL_WOODEN_WALL;
695 case EL_WALL_ICE: return EL_ICE_WALL;
696 case EL_WALL_AMOEBA: return EL_AMOEBA_WALL;
697 case EL_DF_WALL_STEEL: return EL_DF_STEEL_WALL;
698 case EL_DF_WALL_WOOD: return EL_DF_WOODEN_WALL;
700 default: return element;
704 int el2gfx(int element)
706 element = map_element(element);
711 return IMG_MM_LIGHTBALL_RED + RND(3);
714 return el2img_mm(element);
718 void RedrawPlayfield_MM()
723 void BlitScreenToBitmap_MM(Bitmap *target_bitmap)
725 BlitBitmap(drawto_field, target_bitmap,
726 REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE, REAL_SX, REAL_SY);