rnd-20060319-2-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 "main_em.h"
9
10
11 void synchro_3(void)
12 {
13   int x;
14   int y;
15   int count;
16   unsigned long random;
17
18   /* update variables */
19
20   if (lev.score > 9999)
21     lev.score = 9999;
22
23 #if 0
24 #if 1
25   if (lev.time_initial == 0)
26     lev.time++;
27   else if (lev.time > 0)
28     lev.time--;
29 #else
30   if (lev.time)
31     lev.time--;
32 #endif
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 0
54   if (lev.time_initial > 0 &&
55       lev.time > 0 && lev.time <= 50 && lev.time % 5 == 0 && setup.time_limit)
56     play_sound(-1, -1, SAMPLE_time);
57 #endif
58
59   if (lev.wheel_cnt)
60     play_element_sound(lev.wheel_x, lev.wheel_y, SAMPLE_wheel, Xwheel);
61
62   /* grow amoeba */
63
64   random = RandomEM;
65
66   for (count = lev.amoeba_time; count--;)
67   {
68     x = (random >> 10) % (WIDTH - 2);
69     y = (random >> 20) % (HEIGHT - 2);
70     switch (Cave[y][x])
71     {
72       case Xblank:
73       case Yacid_splash_eB:
74       case Yacid_splash_wB:
75       case Xgrass:
76       case Xdirt:
77       case Xsand:
78       case Xplant:
79       case Yplant:
80         if (tab_amoeba[Cave[y-1][x]] ||
81             tab_amoeba[Cave[y][x+1]] ||
82             tab_amoeba[Cave[y+1][x]] ||
83             tab_amoeba[Cave[y][x-1]])
84           Cave[y][x] = Xdrip_eat;
85     }
86
87     random = random * 129 + 1;
88   }
89
90   RandomEM = random;
91
92   /* handle explosions */
93
94   for (y = 1; y < HEIGHT - 1; y++)
95     for (x = 1; x < WIDTH - 1; x++)
96     {
97       switch (Cave[y][x])
98       {
99         case Znormal:
100           Cave[y][x] = Xboom_1;
101           Cave[y-1][x] = tab_explode_normal[Cave[y-1][x]];
102           Cave[y][x-1] = tab_explode_normal[Cave[y][x-1]];
103           Cave[y][x+1] = tab_explode_normal[Cave[y][x+1]];
104           Cave[y+1][x] = tab_explode_normal[Cave[y+1][x]];
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           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           break;
110
111         case Zdynamite:
112           Cave[y][x] = Xboom_1;
113           Cave[y-1][x] = tab_explode_dynamite[Cave[y-1][x]];
114           Cave[y][x-1] = tab_explode_dynamite[Cave[y][x-1]];
115           Cave[y][x+1] = tab_explode_dynamite[Cave[y][x+1]];
116           Cave[y+1][x] = tab_explode_dynamite[Cave[y+1][x]];
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           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           break;
122       }
123     }
124
125   /* triple buffering */
126
127   for (y = 0; y < HEIGHT; y++)
128     for (x = 0; x < WIDTH; x++)
129       Next[y][x] = Cave[y][x];
130 }