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