removed obsolete toon animation code (done by global animations now)
[rocksndiamonds.git] / src / libgame / toons.c
1 // ============================================================================
2 // Artsoft Retro-Game Library
3 // ----------------------------------------------------------------------------
4 // (c) 1995-2014 by Artsoft Entertainment
5 //                  Holger Schemel
6 //                  info@artsoft.org
7 //                  http://www.artsoft.org/
8 // ----------------------------------------------------------------------------
9 // toons.c
10 // ============================================================================
11
12 #include "toons.h"
13 #include "misc.h"
14
15
16 /* ========================================================================= */
17 /* generic animation frame calculation                                       */
18 /* ========================================================================= */
19
20 int getAnimationFrame(int num_frames, int delay, int mode, int start_frame,
21                       int sync_frame)
22 {
23   int frame = 0;
24
25   sync_frame += start_frame * delay;
26
27   if (mode & ANIM_LOOP)                 /* looping animation */
28   {
29     frame = (sync_frame % (delay * num_frames)) / delay;
30   }
31   else if (mode & ANIM_LINEAR)          /* linear (non-looping) animation */
32   {
33     frame = sync_frame / delay;
34
35     if (frame > num_frames - 1)
36       frame = num_frames - 1;
37   }
38   else if (mode & ANIM_PINGPONG)        /* oscillate (border frames once) */
39   {
40     int max_anim_frames = (num_frames > 1 ? 2 * num_frames - 2 : 1);
41
42     frame = (sync_frame % (delay * max_anim_frames)) / delay;
43     frame = (frame < num_frames ? frame : max_anim_frames - frame);
44   }
45   else if (mode & ANIM_PINGPONG2)       /* oscillate (border frames twice) */
46   {
47     int max_anim_frames = 2 * num_frames;
48
49     frame = (sync_frame % (delay * max_anim_frames)) / delay;
50     frame = (frame < num_frames ? frame : max_anim_frames - frame - 1);
51   }
52   else if (mode & ANIM_RANDOM)          /* play frames in random order */
53   {
54     /* note: expect different frames for the same delay cycle! */
55
56     if (gfx.anim_random_frame < 0)
57       frame = GetSimpleRandom(num_frames);
58     else
59       frame = gfx.anim_random_frame % num_frames;
60   }
61   else if (mode & (ANIM_CE_VALUE | ANIM_CE_SCORE | ANIM_CE_DELAY))
62   {
63     frame = sync_frame % num_frames;
64   }
65
66   if (mode & ANIM_REVERSE)              /* use reverse animation direction */
67     frame = num_frames - frame - 1;
68
69   return frame;
70 }