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