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