rnd-20030208-1-src
[rocksndiamonds.git] / src / cartoons.c
1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back!               *
3 *----------------------------------------------------------*
4 * (c) 1995-2002 Artsoft Entertainment                      *
5 *               Holger Schemel                             *
6 *               Detmolder Strasse 189                      *
7 *               33604 Bielefeld                            *
8 *               Germany                                    *
9 *               e-mail: info@artsoft.org                   *
10 *----------------------------------------------------------*
11 * cartoons.c                                               *
12 ***********************************************************/
13
14 #include "cartoons.h"
15 #include "main.h"
16 #include "tools.h"
17
18
19 /* values for toon definition */
20 #if 0
21 #define NUM_TOONS       18
22 #else
23 #define NUM_TOONS       6
24 #endif
25
26 #define DWARF_XSIZE     40
27 #define DWARF_YSIZE     48
28 #define DWARF_X         2
29 #define DWARF_Y         72
30 #define DWARF2_Y        186
31 #define DWARF_FRAMES    8
32 #define DWARF_DELAY     5
33 #define DWARF_STEPSIZE  4
34 #define JUMPER_XSIZE    48
35 #define JUMPER_YSIZE    56
36 #define JUMPER_X        2
37 #define JUMPER_Y        125
38 #define JUMPER_FRAMES   8
39 #define JUMPER_DELAY    5
40 #define JUMPER_STEPSIZE 4
41 #define CLOWN_XSIZE     80
42 #define CLOWN_YSIZE     110
43 #define CLOWN_X         327
44 #define CLOWN_Y         10
45 #define CLOWN_FRAMES    1
46 #define CLOWN_DELAY     5
47 #define CLOWN_STEPSIZE  4
48 #define BIRD_XSIZE      32
49 #define BIRD_YSIZE      30
50 #define BIRD1_X         2
51 #define BIRD1_Y         2
52 #define BIRD2_X         2
53 #define BIRD2_Y         37
54 #define BIRD_FRAMES     8
55 #define BIRD_DELAY      2
56 #define BIRD_STEPSIZE   4
57
58 struct ToonInfo toons[NUM_TOONS] =
59 {
60 #if 0
61   {
62     IMG_GLOBAL_TOONS,
63     DWARF_XSIZE, DWARF_YSIZE,
64     DWARF_X, DWARF_Y,
65     DWARF_FRAMES,
66     DWARF_DELAY,
67     DWARF_STEPSIZE,
68     ANIM_LOOP,
69     ANIMDIR_RIGHT,
70     ANIMPOS_DOWN
71   },
72   {
73     IMG_GLOBAL_TOONS,
74     DWARF_XSIZE, DWARF_YSIZE,
75     DWARF_X, DWARF2_Y,
76     DWARF_FRAMES,
77     DWARF_DELAY,
78     DWARF_STEPSIZE,
79     ANIM_LOOP,
80     ANIMDIR_LEFT,
81     ANIMPOS_DOWN
82   },
83   {
84     IMG_GLOBAL_TOONS,
85     JUMPER_XSIZE, JUMPER_YSIZE,
86     JUMPER_X, JUMPER_Y,
87     JUMPER_FRAMES,
88     JUMPER_DELAY,
89     JUMPER_STEPSIZE,
90     ANIM_LOOP,
91     ANIMDIR_RIGHT,
92     ANIMPOS_DOWN
93   },
94   {
95     IMG_GLOBAL_TOONS,
96     CLOWN_XSIZE, CLOWN_YSIZE,
97     CLOWN_X, CLOWN_Y,
98     CLOWN_FRAMES,
99     CLOWN_DELAY,
100     CLOWN_STEPSIZE,
101     ANIM_LOOP,
102     ANIMDIR_UP,
103     ANIMPOS_ANY
104   },
105   {
106     IMG_GLOBAL_TOONS,
107     BIRD_XSIZE, BIRD_YSIZE,
108     BIRD1_X, BIRD1_Y,
109     BIRD_FRAMES,
110     BIRD_DELAY,
111     BIRD_STEPSIZE,
112     ANIM_PINGPONG,
113     ANIMDIR_RIGHT,
114     ANIMPOS_UPPER
115   },
116   {
117     IMG_GLOBAL_TOONS,
118     BIRD_XSIZE, BIRD_YSIZE,
119     BIRD2_X, BIRD2_Y,
120     BIRD_FRAMES,
121     BIRD_DELAY,
122     BIRD_STEPSIZE,
123     ANIM_PINGPONG,
124     ANIMDIR_LEFT,
125     ANIMPOS_UPPER
126   },
127 #else
128   {
129     IMG_TOON_1,
130     -1, -1,
131     -1, -1,
132     -1,
133     -1,
134     -1,
135     -1,
136     ANIMDIR_RIGHT,
137     ANIMPOS_DOWN
138   },
139   {
140     IMG_TOON_2,
141     -1, -1,
142     -1, -1,
143     -1,
144     -1,
145     -1,
146     -1,
147     ANIMDIR_LEFT,
148     ANIMPOS_DOWN
149   },
150   {
151     IMG_TOON_3,
152     -1, -1,
153     -1, -1,
154     -1,
155     -1,
156     -1,
157     -1,
158     ANIMDIR_RIGHT,
159     ANIMPOS_DOWN
160   },
161   {
162     IMG_TOON_4,
163     -1, -1,
164     -1, -1,
165     -1,
166     -1,
167     -1,
168     -1,
169     ANIMDIR_UP,
170     ANIMPOS_ANY
171   },
172   {
173     IMG_TOON_5,
174     -1, -1,
175     -1, -1,
176     -1,
177     -1,
178     -1,
179     -1,
180     ANIMDIR_RIGHT,
181     ANIMPOS_UPPER
182   },
183   {
184     IMG_TOON_6,
185     -1, -1,
186     -1, -1,
187     -1,
188     -1,
189     -1,
190     -1,
191     ANIMDIR_LEFT,
192     ANIMPOS_UPPER
193   },
194 #endif
195
196 #if 0
197   {
198     IMG_PLAYER1_MOVING_LEFT,
199     -1, -1,
200     -1, -1,
201     -1,
202     -1,
203     -1,
204     -1,
205     ANIMDIR_LEFT,
206     ANIMPOS_DOWN
207   },
208   {
209     IMG_PLAYER1_MOVING_RIGHT,
210     -1, -1,
211     -1, -1,
212     -1,
213     -1,
214     -1,
215     -1,
216     ANIMDIR_RIGHT,
217     ANIMPOS_DOWN
218   },
219   {
220     IMG_PENGUIN_MOVING_LEFT,
221     -1, -1,
222     -1, -1,
223     -1,
224     -1,
225     -1,
226     -1,
227     ANIMDIR_LEFT,
228     ANIMPOS_DOWN
229   },
230   {
231     IMG_PENGUIN_MOVING_RIGHT,
232     -1, -1,
233     -1, -1,
234     -1,
235     -1,
236     -1,
237     -1,
238     ANIMDIR_RIGHT,
239     ANIMPOS_DOWN
240   },
241   {
242     IMG_MOLE_MOVING_LEFT,
243     -1, -1,
244     -1, -1,
245     -1,
246     -1,
247     -1,
248     -1,
249     ANIMDIR_LEFT,
250     ANIMPOS_DOWN
251   },
252   {
253     IMG_MOLE_MOVING_RIGHT,
254     -1, -1,
255     -1, -1,
256     -1,
257     -1,
258     -1,
259     -1,
260     ANIMDIR_RIGHT,
261     ANIMPOS_DOWN
262   },
263   {
264     IMG_PIG_MOVING_LEFT,
265     -1, -1,
266     -1, -1,
267     -1,
268     -1,
269     -1,
270     -1,
271     ANIMDIR_LEFT,
272     ANIMPOS_DOWN
273   },
274   {
275     IMG_PIG_MOVING_RIGHT,
276     -1, -1,
277     -1, -1,
278     -1,
279     -1,
280     -1,
281     -1,
282     ANIMDIR_RIGHT,
283     ANIMPOS_DOWN
284   },
285   {
286     IMG_DRAGON_MOVING_LEFT,
287     -1, -1,
288     -1, -1,
289     -1,
290     -1,
291     -1,
292     -1,
293     ANIMDIR_LEFT,
294     ANIMPOS_DOWN
295   },
296   {
297     IMG_DRAGON_MOVING_RIGHT,
298     -1, -1,
299     -1, -1,
300     -1,
301     -1,
302     -1,
303     -1,
304     ANIMDIR_RIGHT,
305     ANIMPOS_DOWN
306   },
307   {
308     IMG_SATELLITE_MOVING,
309     -1, -1,
310     -1, -1,
311     -1,
312     -1,
313     -1,
314     -1,
315     ANIMDIR_LEFT,
316     ANIMPOS_ANY
317   },
318   {
319     IMG_SATELLITE_MOVING,
320     -1, -1,
321     -1, -1,
322     -1,
323     -1,
324     -1,
325     -1,
326     ANIMDIR_RIGHT,
327     ANIMPOS_ANY
328   },
329 #endif
330
331 };
332
333 static void PrepareBackbuffer()
334 {
335   /* Fill empty backbuffer for animation functions */
336   if (setup.direct_draw && game_status == PLAYING)
337   {
338     int xx,yy;
339
340     SetDrawtoField(DRAW_BACKBUFFER);
341
342     for(xx=0; xx<SCR_FIELDX; xx++)
343       for(yy=0; yy<SCR_FIELDY; yy++)
344         DrawScreenField(xx,yy);
345     DrawAllPlayers();
346
347     SetDrawtoField(DRAW_DIRECT);
348   }
349
350   if (setup.soft_scrolling && game_status == PLAYING)
351   {
352     int fx = FX, fy = FY;
353
354     fx += (ScreenMovDir & (MV_LEFT|MV_RIGHT) ? ScreenGfxPos : 0);
355     fy += (ScreenMovDir & (MV_UP|MV_DOWN)    ? ScreenGfxPos : 0);
356
357     BlitBitmap(fieldbuffer, backbuffer, fx,fy, SXSIZE,SYSIZE, SX,SY);
358   }
359 }
360
361 boolean ToonNeedsRedraw()
362 {
363   return (game_status == HELPSCREEN ||
364           (game_status == MAINMENU &&
365            ((redraw_mask & REDRAW_MICROLEVEL) ||
366             (redraw_mask & REDRAW_MICROLABEL))));
367 }
368
369 void InitToons()
370 {
371   int i;
372
373   for (i=0; i<NUM_TOONS; i++)
374   {
375     int graphic = toons[i].graphic;
376
377     toons[i].bitmap = graphic_info[graphic].bitmap;
378
379     toons[i].src_x = graphic_info[graphic].src_x;
380     toons[i].src_y = graphic_info[graphic].src_y;
381
382     toons[i].width  = graphic_info[graphic].width;
383     toons[i].height = graphic_info[graphic].height;
384
385     toons[i].anim_frames      = graphic_info[graphic].anim_frames;
386     toons[i].anim_delay       = graphic_info[graphic].anim_delay;
387     toons[i].anim_mode        = graphic_info[graphic].anim_mode;
388     toons[i].anim_start_frame = graphic_info[graphic].anim_start_frame;
389
390     toons[i].step_offset = graphic_info[graphic].step_offset;
391     toons[i].step_delay  = graphic_info[graphic].step_delay;
392   }
393
394   InitToonScreen(bitmap_db_door,
395                  BackToFront, PrepareBackbuffer, ToonNeedsRedraw,
396                  toons, NUM_TOONS,
397                  REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE,
398                  GAME_FRAME_DELAY);
399 }