rnd-20050307-1-src
[rocksndiamonds.git] / src / game_em / synchro_3.c
1 /* third part of synchro.
2  *
3  * handle global elements.
4  *
5  * this should be spread over the frames for reduced cpu load.
6  */
7
8 #include "tile.h"
9 #include "level.h"
10 #include "sample.h"
11
12
13 void synchro_3(void)
14 {
15   register unsigned int x;
16   register unsigned int y;
17   register unsigned int count;
18   register unsigned long random;
19
20   /* update variables */
21
22   if (lev.score > 9999)
23     lev.score = 9999;
24
25 #if 1
26   if (lev.time_initial == 0)
27     lev.time++;
28   else if (lev.time)
29     lev.time--;
30 #else
31   if (lev.time)
32     lev.time--;
33 #endif
34
35   if (lev.android_move_cnt-- == 0)
36     lev.android_move_cnt = lev.android_move_time;
37   if (lev.android_clone_cnt-- == 0)
38     lev.android_clone_cnt = lev.android_clone_time;
39   if (lev.ball_state)
40     if (lev.ball_cnt-- == 0)
41       lev.ball_cnt = lev.ball_time;
42   if (lev.lenses_cnt)
43     lev.lenses_cnt--;
44   if (lev.magnify_cnt)
45     lev.magnify_cnt--;
46   if (lev.wheel_cnt)
47     lev.wheel_cnt--;
48   if (lev.wind_cnt)
49     lev.wind_cnt--;
50   if (lev.wonderwall_time && lev.wonderwall_state)
51     lev.wonderwall_time--;
52
53   if (lev.time_initial > 0 &&
54       lev.time > 0 && lev.time <= 50 && lev.time % 5 == 0)
55     play_sound(-1, -1, SAMPLE_time);
56
57   if (lev.wheel_cnt)
58     play_element_sound(lev.wheel_x, lev.wheel_y, SAMPLE_wheel, Xwheel);
59
60   /* grow amoeba */
61
62   random = Random;
63
64   for (count = lev.amoeba_time; count--;)
65   {
66     x = (random >> 10) % (WIDTH - 2);
67     y = (random >> 20) % (HEIGHT - 2);
68     switch (Cave[y][x])
69     {
70       case Xblank:
71       case Yacid_splash_eB:
72       case Yacid_splash_wB:
73       case Xgrass:
74       case Xdirt:
75       case Xsand:
76       case Xplant:
77       case Yplant:
78         if (tab_amoeba[Cave[y-1][x]] ||
79             tab_amoeba[Cave[y][x+1]] ||
80             tab_amoeba[Cave[y+1][x]] ||
81             tab_amoeba[Cave[y][x-1]])
82           Cave[y][x] = Xdrip_eat;
83     }
84
85     random = random * 129 + 1;
86   }
87
88   Random = random;
89
90   /* handle explosions */
91
92   for (y = 1; y < HEIGHT - 1; y++)
93     for (x = 1; x < WIDTH - 1; x++)
94     {
95       switch (Cave[y][x])
96       {
97         case Znormal:
98           Cave[y][x] = Xboom_1;
99           Cave[y-1][x] = tab_explode_normal[Cave[y-1][x]];
100           Cave[y][x-1] = tab_explode_normal[Cave[y][x-1]];
101           Cave[y][x+1] = tab_explode_normal[Cave[y][x+1]];
102           Cave[y+1][x] = tab_explode_normal[Cave[y+1][x]];
103           Cave[y-1][x-1] = tab_explode_normal[Cave[y-1][x-1]];
104           Cave[y-1][x+1] = tab_explode_normal[Cave[y-1][x+1]];
105           Cave[y+1][x-1] = tab_explode_normal[Cave[y+1][x-1]];
106           Cave[y+1][x+1] = tab_explode_normal[Cave[y+1][x+1]];
107           break;
108
109         case Zdynamite:
110           Cave[y][x] = Xboom_1;
111           Cave[y-1][x] = tab_explode_dynamite[Cave[y-1][x]];
112           Cave[y][x-1] = tab_explode_dynamite[Cave[y][x-1]];
113           Cave[y][x+1] = tab_explode_dynamite[Cave[y][x+1]];
114           Cave[y+1][x] = tab_explode_dynamite[Cave[y+1][x]];
115           Cave[y-1][x-1] = tab_explode_dynamite[Cave[y-1][x-1]];
116           Cave[y-1][x+1] = tab_explode_dynamite[Cave[y-1][x+1]];
117           Cave[y+1][x-1] = tab_explode_dynamite[Cave[y+1][x-1]];
118           Cave[y+1][x+1] = tab_explode_dynamite[Cave[y+1][x+1]];
119           break;
120       }
121     }
122
123   /* triple buffering */
124
125   for (y = 0; y < HEIGHT; y++)
126     for (x = 0; x < WIDTH; x++)
127       Next[y][x] = Cave[y][x];
128 }