1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * ©1995 Artsoft Development *
6 * 33659 Bielefeld-Senne *
7 * Telefon: (0521) 493245 *
8 * eMail: aeglos@valinor.owl.de *
9 * aeglos@uni-paderborn.de *
10 * q99492@pbhrzx.uni-paderborn.de *
11 *----------------------------------------------------------*
14 * Letzte Aenderung: 15.06.1995 *
15 ***********************************************************/
24 #include <sys/param.h>
25 #include <sys/types.h>
27 void microsleep(unsigned long usec)
31 delay.tv_sec = usec / 1000000;
32 delay.tv_usec = usec % 1000000;
34 if (select(0,NULL,NULL,NULL,&delay)!=0)
35 fprintf(stderr,"%s: in function microsleep: select failed!\n",
39 unsigned long be2long(unsigned long *be) /* big-endian -> longword */
41 unsigned char *ptr = (unsigned char *)be;
43 return(ptr[0]<<24 | ptr[1]<<16 | ptr[2]<<8 | ptr[3]);
46 char *int2str(int ct, int nr)
50 sprintf(str,"%09d",ct);
51 return(&str[strlen(str)-nr]);
54 unsigned int RND(unsigned int max)
59 unsigned int InitRND(long seed)
61 struct timeval current_time;
63 if (seed==NEW_RANDOMIZE)
65 gettimeofday(¤t_time,NULL);
66 srand((unsigned int) current_time.tv_usec);
67 return((unsigned int) current_time.tv_usec);
71 srand((unsigned int) seed);
72 return((unsigned int) seed);
80 if (!(pwd=getpwuid(getuid())))
86 static struct AnimInfo toon[NUM_TOONS] =
88 DWARF_XSIZE, DWARF_YSIZE,
97 DWARF_XSIZE, DWARF_YSIZE,
106 JUMPER_XSIZE, JUMPER_YSIZE,
115 CLOWN_XSIZE, CLOWN_YSIZE,
124 BIRD_XSIZE, BIRD_YSIZE,
133 BIRD_XSIZE, BIRD_YSIZE,
145 HandleAnimation(ANIM_START);
150 HandleAnimation(ANIM_STOP);
155 HandleAnimation(ANIM_CONTINUE);
158 void HandleAnimation(int mode)
160 static long animstart_delay = -1;
161 static long animstart_delay_value = 0;
162 static BOOL anim_restart = TRUE;
163 static BOOL reset_delay = TRUE;
164 static int toon_nr = 0;
166 if (!toons_on || game_status==PLAYING)
179 redraw_mask |= REDRAW_FIELD;
189 animstart_delay = Counter();
190 animstart_delay_value = RND(500);
196 if (!DelayReached(&animstart_delay,animstart_delay_value))
199 toon_nr = RND(NUM_TOONS);
202 anim_restart = reset_delay = AnimateToon(toon_nr,anim_restart);
205 BOOL AnimateToon(int toon_nr, BOOL restart)
207 static pos_x = 0, pos_y = 0;
208 static delta_x = 0, delta_y = 0;
209 static int frame = 0, frame_step = 1;
210 static BOOL horiz_move, vert_move;
211 static long anim_delay = 0;
212 static int anim_delay_value = 0;
213 struct AnimInfo *anim = &toon[toon_nr];
214 static int width,height;
215 static int pad_x,pad_y;
216 static int cut_x,cut_y;
217 static int src_x, src_y;
218 static int dest_x, dest_y;
222 horiz_move = (anim->direction & (ANIMDIR_LEFT | ANIMDIR_RIGHT));
223 vert_move = (anim->direction & (ANIMDIR_UP | ANIMDIR_DOWN));
224 anim_delay_value = 100/anim->frames_per_second;
229 if (anim->position==ANIMPOS_UP)
231 else if (anim->position==ANIMPOS_DOWN)
232 pos_y = FULL_SYSIZE-anim->height;
233 else if (anim->position==ANIMPOS_UPPER)
234 pos_y = RND((FULL_SYSIZE-anim->height)/2);
236 pos_y = RND(FULL_SYSIZE-anim->height);
238 if (anim->direction==ANIMDIR_RIGHT)
240 delta_x = anim->stepsize;
241 pos_x = -anim->width+delta_x;
245 delta_x = -anim->stepsize;
246 pos_x = FULL_SXSIZE+delta_x;
252 if (anim->position==ANIMPOS_LEFT)
254 else if (anim->position==ANIMPOS_RIGHT)
255 pos_x = FULL_SXSIZE-anim->width;
257 pos_x = RND(FULL_SXSIZE-anim->width);
259 if (anim->direction==ANIMDIR_DOWN)
261 delta_y = anim->stepsize;
262 pos_y = -anim->height+delta_y;
266 delta_y = -anim->stepsize;
267 pos_y = FULL_SYSIZE+delta_y;
273 if (pos_x <= -anim->width - anim->stepsize ||
274 pos_x >= FULL_SXSIZE + anim->stepsize ||
275 pos_y <= -anim->height - anim->stepsize ||
276 pos_y >= FULL_SYSIZE + anim->stepsize)
279 if (!DelayReached(&anim_delay,anim_delay_value))
281 if (game_status==HELPSCREEN && !restart)
282 DrawAnim(src_x+cut_x,src_y+cut_y, width,height,
283 REAL_SX+dest_x,REAL_SY+dest_y, pad_x,pad_y);
288 if (pos_x<-anim->width)
289 pos_x = -anim->width;
290 else if (pos_x>FULL_SXSIZE)
292 if (pos_y<-anim->height)
293 pos_y = -anim->height;
294 else if (pos_y>FULL_SYSIZE)
297 pad_x = (horiz_move ? anim->stepsize : 0);
298 pad_y = (vert_move ? anim->stepsize : 0);
299 src_x = anim->src_x + frame * anim->width;
305 height = anim->height;
313 else if (pos_x>FULL_SXSIZE-anim->width)
314 width -= (pos_x - (FULL_SXSIZE-anim->width));
322 else if (pos_y>FULL_SYSIZE-anim->height)
323 height -= (pos_y - (FULL_SYSIZE-anim->height));
325 DrawAnim(src_x+cut_x,src_y+cut_y, width,height,
326 REAL_SX+dest_x,REAL_SY+dest_y, pad_x,pad_y);
332 if (frame<0 || frame>=anim->frames)
337 frame = (frame<0 ? 1 : anim->frames-2);
340 frame = (frame<0 ? anim->frames-1 : 0);
346 void DrawAnim(int src_x, int src_y, int width, int height,
347 int dest_x, int dest_y, int pad_x, int pad_y)
349 int buf_x = DOOR_GFX_PAGEX3, buf_y = DOOR_GFX_PAGEY1;
351 XCopyArea(display,backbuffer,pix[PIX_DB_DOOR],gc,dest_x-pad_x,dest_y-pad_y,
352 width+2*pad_x,height+2*pad_y, buf_x,buf_y);
353 XSetClipOrigin(display,clip_gc[PIX_TOONS],dest_x-src_x,dest_y-src_y);
354 XCopyArea(display,pix[PIX_TOONS],backbuffer,clip_gc[PIX_TOONS],
355 src_x,src_y, width,height, dest_x,dest_y);
356 XCopyArea(display,backbuffer,window,gc, dest_x-pad_x,dest_y-pad_y,
357 width+2*pad_x,height+2*pad_y, dest_x-pad_x,dest_y-pad_y);
361 XCopyArea(display,pix[PIX_DB_DOOR],backbuffer,gc, buf_x,buf_y,
362 width+2*pad_x,height+2*pad_y, dest_x-pad_x,dest_y-pad_y);
365 XCopyArea(display,backbuffer,pix[PIX_DB_DOOR],gc,dest_x-pad_x,dest_y-pad_y,
366 width+2*pad_x,height+2*pad_y, buf_x,buf_y);
367 XSetClipOrigin(display,clip_gc[PIX_TOONS],
368 buf_x-src_x+pad_x,buf_y-src_y+pad_y);
369 XCopyArea(display,pix[PIX_TOONS],pix[PIX_DB_DOOR],clip_gc[PIX_TOONS],
370 src_x,src_y, width,height, buf_x+pad_x,buf_y+pad_y);
371 XCopyArea(display,pix[PIX_DB_DOOR],window,gc, buf_x,buf_y,
372 width+2*pad_x,height+2*pad_y, dest_x-pad_x,dest_y-pad_y);