rnd-20050815-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 0
26 #if 1
27   if (lev.time_initial == 0)
28     lev.time++;
29   else if (lev.time > 0)
30     lev.time--;
31 #else
32   if (lev.time)
33     lev.time--;
34 #endif
35 #endif
36
37   if (lev.android_move_cnt-- == 0)
38     lev.android_move_cnt = lev.android_move_time;
39   if (lev.android_clone_cnt-- == 0)
40     lev.android_clone_cnt = lev.android_clone_time;
41   if (lev.ball_state)
42     if (lev.ball_cnt-- == 0)
43       lev.ball_cnt = lev.ball_time;
44   if (lev.lenses_cnt)
45     lev.lenses_cnt--;
46   if (lev.magnify_cnt)
47     lev.magnify_cnt--;
48   if (lev.wheel_cnt)
49     lev.wheel_cnt--;
50   if (lev.wind_cnt)
51     lev.wind_cnt--;
52   if (lev.wonderwall_time && lev.wonderwall_state)
53     lev.wonderwall_time--;
54
55 #if 0
56   if (lev.time_initial > 0 &&
57       lev.time > 0 && lev.time <= 50 && lev.time % 5 == 0 && setup.time_limit)
58     play_sound(-1, -1, SAMPLE_time);
59 #endif
60
61   if (lev.wheel_cnt)
62     play_element_sound(lev.wheel_x, lev.wheel_y, SAMPLE_wheel, Xwheel);
63
64   /* grow amoeba */
65
66   random = RandomEM;
67
68   for (count = lev.amoeba_time; count--;)
69   {
70     x = (random >> 10) % (WIDTH - 2);
71     y = (random >> 20) % (HEIGHT - 2);
72     switch (Cave[y][x])
73     {
74       case Xblank:
75       case Yacid_splash_eB:
76       case Yacid_splash_wB:
77       case Xgrass:
78       case Xdirt:
79       case Xsand:
80       case Xplant:
81       case Yplant:
82         if (tab_amoeba[Cave[y-1][x]] ||
83             tab_amoeba[Cave[y][x+1]] ||
84             tab_amoeba[Cave[y+1][x]] ||
85             tab_amoeba[Cave[y][x-1]])
86           Cave[y][x] = Xdrip_eat;
87     }
88
89     random = random * 129 + 1;
90   }
91
92   RandomEM = random;
93
94   /* handle explosions */
95
96   for (y = 1; y < HEIGHT - 1; y++)
97     for (x = 1; x < WIDTH - 1; x++)
98     {
99       switch (Cave[y][x])
100       {
101         case Znormal:
102           Cave[y][x] = Xboom_1;
103           Cave[y-1][x] = tab_explode_normal[Cave[y-1][x]];
104           Cave[y][x-1] = tab_explode_normal[Cave[y][x-1]];
105           Cave[y][x+1] = tab_explode_normal[Cave[y][x+1]];
106           Cave[y+1][x] = tab_explode_normal[Cave[y+1][x]];
107           Cave[y-1][x-1] = tab_explode_normal[Cave[y-1][x-1]];
108           Cave[y-1][x+1] = tab_explode_normal[Cave[y-1][x+1]];
109           Cave[y+1][x-1] = tab_explode_normal[Cave[y+1][x-1]];
110           Cave[y+1][x+1] = tab_explode_normal[Cave[y+1][x+1]];
111           break;
112
113         case Zdynamite:
114           Cave[y][x] = Xboom_1;
115           Cave[y-1][x] = tab_explode_dynamite[Cave[y-1][x]];
116           Cave[y][x-1] = tab_explode_dynamite[Cave[y][x-1]];
117           Cave[y][x+1] = tab_explode_dynamite[Cave[y][x+1]];
118           Cave[y+1][x] = tab_explode_dynamite[Cave[y+1][x]];
119           Cave[y-1][x-1] = tab_explode_dynamite[Cave[y-1][x-1]];
120           Cave[y-1][x+1] = tab_explode_dynamite[Cave[y-1][x+1]];
121           Cave[y+1][x-1] = tab_explode_dynamite[Cave[y+1][x-1]];
122           Cave[y+1][x+1] = tab_explode_dynamite[Cave[y+1][x+1]];
123           break;
124       }
125     }
126
127   /* triple buffering */
128
129   for (y = 0; y < HEIGHT; y++)
130     for (x = 0; x < WIDTH; x++)
131       Next[y][x] = Cave[y][x];
132 }