1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * (c) 1995-2001 Artsoft Entertainment *
6 * Detmolder Strasse 189 *
9 * e-mail: info@artsoft.org *
10 *----------------------------------------------------------*
12 ***********************************************************/
19 static void HandleAnimation(int);
20 static boolean AnimateToon(int, boolean);
21 static void DrawAnim(Bitmap *, GC, int, int, int, int, int, int, int, int);
28 int frames_per_second;
35 /* values for cartoon figures */
38 #define DWARF_XSIZE 40
39 #define DWARF_YSIZE 48
43 #define DWARF_FRAMES 8
45 #define DWARF_STEPSIZE 4
46 #define JUMPER_XSIZE 48
47 #define JUMPER_YSIZE 56
50 #define JUMPER_FRAMES 8
52 #define JUMPER_STEPSIZE 4
53 #define CLOWN_XSIZE 80
54 #define CLOWN_YSIZE 110
57 #define CLOWN_FRAMES 1
59 #define CLOWN_STEPSIZE 4
68 #define BIRD_STEPSIZE 4
70 #define GAMETOON_XSIZE TILEX
71 #define GAMETOON_YSIZE TILEY
72 #define GAMETOON_FRAMES_4 4
73 #define GAMETOON_FRAMES_8 8
74 #define GAMETOON_FPS 20
75 #define GAMETOON_STEPSIZE 4
77 #define ANIMDIR_LEFT 1
78 #define ANIMDIR_RIGHT 2
80 #define ANIMDIR_DOWN 8
83 #define ANIMPOS_LEFT 1
84 #define ANIMPOS_RIGHT 2
86 #define ANIMPOS_DOWN 8
87 #define ANIMPOS_UPPER 16
90 #define ANIM_CONTINUE 1
95 HandleAnimation(ANIM_START);
100 HandleAnimation(ANIM_STOP);
105 HandleAnimation(ANIM_CONTINUE);
108 void HandleAnimation(int mode)
110 static unsigned long animstart_delay = -1;
111 static unsigned long animstart_delay_value = 0;
112 static boolean anim_restart = TRUE;
113 static boolean reset_delay = TRUE;
114 static int toon_nr = 0;
126 /* Fill empty backbuffer for animation functions */
127 if (setup.direct_draw && game_status == PLAYING)
131 SetDrawtoField(DRAW_BACKBUFFER);
133 for(xx=0; xx<SCR_FIELDX; xx++)
134 for(yy=0; yy<SCR_FIELDY; yy++)
135 DrawScreenField(xx,yy);
138 SetDrawtoField(DRAW_DIRECT);
141 if (setup.soft_scrolling && game_status == PLAYING)
143 int fx = FX, fy = FY;
145 fx += (ScreenMovDir & (MV_LEFT|MV_RIGHT) ? ScreenGfxPos : 0);
146 fy += (ScreenMovDir & (MV_UP|MV_DOWN) ? ScreenGfxPos : 0);
148 BlitBitmap(fieldbuffer, backbuffer, fx,fy, SXSIZE,SYSIZE, SX,SY);
156 redraw_mask |= (REDRAW_FIELD | REDRAW_FROM_BACKBUFFER);
158 /* Redraw background even when in direct drawing mode */
159 draw_mode = setup.direct_draw;
160 setup.direct_draw = FALSE;
164 setup.direct_draw = draw_mode;
174 animstart_delay = Counter();
175 animstart_delay_value = SimpleRND(3000);
181 if (!DelayReached(&animstart_delay, animstart_delay_value))
184 toon_nr = SimpleRND(NUM_TOONS);
187 anim_restart = reset_delay = AnimateToon(toon_nr,anim_restart);
190 boolean AnimateToon(int toon_nr, boolean restart)
192 static int pos_x = 0, pos_y = 0;
193 static int delta_x = 0, delta_y = 0;
194 static int frame = 0, frame_step = 1;
195 static boolean horiz_move, vert_move;
196 static unsigned long anim_delay = 0;
197 static unsigned long anim_delay_value = 0;
198 static int width,height;
199 static int pad_x,pad_y;
200 static int cut_x,cut_y;
201 static int src_x, src_y;
202 static int dest_x, dest_y;
203 static struct AnimInfo toon[NUM_TOONS] =
206 DWARF_XSIZE, DWARF_YSIZE,
216 DWARF_XSIZE, DWARF_YSIZE,
226 JUMPER_XSIZE, JUMPER_YSIZE,
236 CLOWN_XSIZE, CLOWN_YSIZE,
246 BIRD_XSIZE, BIRD_YSIZE,
256 BIRD_XSIZE, BIRD_YSIZE,
266 GAMETOON_XSIZE, GAMETOON_YSIZE,
267 ((GFX_SPIELER1_LEFT - GFX_START_ROCKSHEROES) % HEROES_PER_LINE)*TILEX,
268 ((GFX_SPIELER1_LEFT - GFX_START_ROCKSHEROES) / HEROES_PER_LINE)*TILEY,
277 GAMETOON_XSIZE, GAMETOON_YSIZE,
278 ((GFX_SPIELER1_RIGHT - GFX_START_ROCKSHEROES) % HEROES_PER_LINE)*TILEX,
279 ((GFX_SPIELER1_RIGHT - GFX_START_ROCKSHEROES) / HEROES_PER_LINE)*TILEY,
288 GAMETOON_XSIZE, GAMETOON_YSIZE,
289 ((GFX_PINGUIN_LEFT - GFX_START_ROCKSHEROES) % HEROES_PER_LINE)*TILEX,
290 ((GFX_PINGUIN_LEFT - GFX_START_ROCKSHEROES) / HEROES_PER_LINE)*TILEY,
299 GAMETOON_XSIZE, GAMETOON_YSIZE,
300 ((GFX_PINGUIN_RIGHT - GFX_START_ROCKSHEROES) % HEROES_PER_LINE)*TILEX,
301 ((GFX_PINGUIN_RIGHT - GFX_START_ROCKSHEROES) / HEROES_PER_LINE)*TILEY,
310 GAMETOON_XSIZE, GAMETOON_YSIZE,
311 ((GFX_MOLE_LEFT - GFX_START_ROCKSHEROES) % HEROES_PER_LINE)*TILEX,
312 ((GFX_MOLE_LEFT - GFX_START_ROCKSHEROES) / HEROES_PER_LINE)*TILEY,
321 GAMETOON_XSIZE, GAMETOON_YSIZE,
322 ((GFX_MOLE_RIGHT - GFX_START_ROCKSHEROES) % HEROES_PER_LINE)*TILEX,
323 ((GFX_MOLE_RIGHT - GFX_START_ROCKSHEROES) / HEROES_PER_LINE)*TILEY,
332 GAMETOON_XSIZE, GAMETOON_YSIZE,
333 ((GFX_SCHWEIN_LEFT - GFX_START_ROCKSHEROES) % HEROES_PER_LINE)*TILEX,
334 ((GFX_SCHWEIN_LEFT - GFX_START_ROCKSHEROES) / HEROES_PER_LINE)*TILEY,
343 GAMETOON_XSIZE, GAMETOON_YSIZE,
344 ((GFX_SCHWEIN_RIGHT - GFX_START_ROCKSHEROES) % HEROES_PER_LINE)*TILEX,
345 ((GFX_SCHWEIN_RIGHT - GFX_START_ROCKSHEROES) / HEROES_PER_LINE)*TILEY,
354 GAMETOON_XSIZE, GAMETOON_YSIZE,
355 ((GFX_DRACHE_LEFT - GFX_START_ROCKSHEROES) % HEROES_PER_LINE)*TILEX,
356 ((GFX_DRACHE_LEFT - GFX_START_ROCKSHEROES) / HEROES_PER_LINE)*TILEY,
365 GAMETOON_XSIZE, GAMETOON_YSIZE,
366 ((GFX_DRACHE_RIGHT - GFX_START_ROCKSHEROES) % HEROES_PER_LINE)*TILEX,
367 ((GFX_DRACHE_RIGHT - GFX_START_ROCKSHEROES) / HEROES_PER_LINE)*TILEY,
376 GAMETOON_XSIZE, GAMETOON_YSIZE,
377 ((GFX_SONDE - GFX_START_ROCKSHEROES) % HEROES_PER_LINE)*TILEX,
378 ((GFX_SONDE - GFX_START_ROCKSHEROES) / HEROES_PER_LINE)*TILEY,
387 GAMETOON_XSIZE, GAMETOON_YSIZE,
388 ((GFX_SONDE - GFX_START_ROCKSHEROES) % HEROES_PER_LINE)*TILEX,
389 ((GFX_SONDE - GFX_START_ROCKSHEROES) / HEROES_PER_LINE)*TILEY,
398 struct AnimInfo *anim = &toon[toon_nr];
399 int anim_bitmap_nr = (toon_nr < 6 ? PIX_TOONS : PIX_HEROES);
400 Bitmap *anim_bitmap = pix[anim_bitmap_nr];
401 GC anim_clip_gc = pix[anim_bitmap_nr]->stored_clip_gc;
405 horiz_move = (anim->direction & (ANIMDIR_LEFT | ANIMDIR_RIGHT));
406 vert_move = (anim->direction & (ANIMDIR_UP | ANIMDIR_DOWN));
407 anim_delay_value = 1000/anim->frames_per_second;
412 if (anim->position==ANIMPOS_UP)
414 else if (anim->position==ANIMPOS_DOWN)
415 pos_y = FULL_SYSIZE-anim->height;
416 else if (anim->position==ANIMPOS_UPPER)
417 pos_y = SimpleRND((FULL_SYSIZE-anim->height)/2);
419 pos_y = SimpleRND(FULL_SYSIZE-anim->height);
421 if (anim->direction==ANIMDIR_RIGHT)
423 delta_x = anim->stepsize;
424 pos_x = -anim->width+delta_x;
428 delta_x = -anim->stepsize;
429 pos_x = FULL_SXSIZE+delta_x;
435 if (anim->position==ANIMPOS_LEFT)
437 else if (anim->position==ANIMPOS_RIGHT)
438 pos_x = FULL_SXSIZE-anim->width;
440 pos_x = SimpleRND(FULL_SXSIZE-anim->width);
442 if (anim->direction==ANIMDIR_DOWN)
444 delta_y = anim->stepsize;
445 pos_y = -anim->height+delta_y;
449 delta_y = -anim->stepsize;
450 pos_y = FULL_SYSIZE+delta_y;
456 if (pos_x <= -anim->width - anim->stepsize ||
457 pos_x >= FULL_SXSIZE + anim->stepsize ||
458 pos_y <= -anim->height - anim->stepsize ||
459 pos_y >= FULL_SYSIZE + anim->stepsize)
462 if (!DelayReached(&anim_delay, anim_delay_value))
464 if ((game_status == HELPSCREEN ||
465 (game_status == MAINMENU && redraw_mask & REDRAW_MICROLEVEL))
467 DrawAnim(anim_bitmap, anim_clip_gc,
468 src_x + cut_x, src_y + cut_y, width, height,
469 REAL_SX + dest_x, REAL_SY + dest_y, pad_x, pad_y);
474 if (pos_x<-anim->width)
475 pos_x = -anim->width;
476 else if (pos_x>FULL_SXSIZE)
478 if (pos_y<-anim->height)
479 pos_y = -anim->height;
480 else if (pos_y>FULL_SYSIZE)
483 pad_x = (horiz_move ? anim->stepsize : 0);
484 pad_y = (vert_move ? anim->stepsize : 0);
485 src_x = anim->src_x + frame * anim->width;
491 height = anim->height;
499 else if (pos_x>FULL_SXSIZE-anim->width)
500 width -= (pos_x - (FULL_SXSIZE-anim->width));
508 else if (pos_y>FULL_SYSIZE-anim->height)
509 height -= (pos_y - (FULL_SYSIZE-anim->height));
511 DrawAnim(anim_bitmap,anim_clip_gc,
512 src_x+cut_x,src_y+cut_y, width,height,
513 REAL_SX+dest_x,REAL_SY+dest_y, pad_x,pad_y);
519 if (frame<0 || frame>=anim->frames)
524 frame = (frame<0 ? 1 : anim->frames-2);
527 frame = (frame<0 ? anim->frames-1 : 0);
533 void DrawAnim(Bitmap *toon_bitmap, GC toon_clip_gc,
534 int src_x, int src_y, int width, int height,
535 int dest_x, int dest_y, int pad_x, int pad_y)
537 int buf_x = DOOR_GFX_PAGEX3, buf_y = DOOR_GFX_PAGEY1;
540 /* special method to avoid flickering interference with BackToFront() */
541 BlitBitmap(backbuffer, pix[PIX_DB_DOOR], dest_x-pad_x, dest_y-pad_y,
542 width+2*pad_x, height+2*pad_y, buf_x, buf_y);
543 SetClipOrigin(toon_bitmap, toon_clip_gc, dest_x-src_x, dest_y-src_y);
544 BlitBitmapMasked(toon_bitmap, backbuffer,
545 src_x, src_y, width, height, dest_x, dest_y);
546 BlitBitmap(backbuffer, window, dest_x-pad_x, dest_y-pad_y,
547 width+2*pad_x, height+2*pad_y, dest_x-pad_x, dest_y-pad_y);
549 BlitBitmap(pix[PIX_DB_DOOR], backbuffer, buf_x, buf_y,
550 width+2*pad_x, height+2*pad_y, dest_x-pad_x, dest_y-pad_y);
552 /* normal method, causing flickering interference with BackToFront() */
553 BlitBitmap(backbuffer, pix[PIX_DB_DOOR], dest_x-pad_x, dest_y-pad_y,
554 width+2*pad_x, height+2*pad_y, buf_x, buf_y);
555 SetClipOrigin(toon_bitmap,toon_clip_gc, buf_x-src_x+pad_x,buf_y-src_y+pad_y);
556 BlitBitmapMasked(toon_bitmap, pix[PIX_DB_DOOR],
557 src_x, src_y, width, height, buf_x+pad_x, buf_y+pad_y);
558 BlitBitmap(pix[PIX_DB_DOOR], window, buf_x, buf_y,
559 width+2*pad_x, height+2*pad_y, dest_x-pad_x, dest_y-pad_y);