rnd-20040814-1-src
[rocksndiamonds.git] / src / libem / synchro_3.c
1
2 /* third part of synchro.
3  *
4  * handle global elements.
5  *
6  * this should be spread over the frames for reduced cpu load.
7  */
8
9 #include "tile.h"
10 #include "level.h"
11 #include "sample.h"
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         if(lev.score > 9999) lev.score = 9999;
22
23         if(lev.time) lev.time--;
24         if(lev.android_move_cnt-- == 0) lev.android_move_cnt = lev.android_move_time;
25         if(lev.android_clone_cnt-- == 0) lev.android_clone_cnt = lev.android_clone_time;
26         if(lev.ball_state) if(lev.ball_cnt-- == 0) lev.ball_cnt = lev.ball_time;
27         if(lev.lenses_cnt) lev.lenses_cnt--;
28         if(lev.magnify_cnt) lev.magnify_cnt--;
29         if(lev.wheel_cnt) lev.wheel_cnt--;
30         if(lev.wind_cnt) lev.wind_cnt--;
31         if(lev.wonderwall_time && lev.wonderwall_state) lev.wonderwall_time--;
32
33         if(lev.time > 0 && lev.time <= 50 && lev.time % 5 == 0) play[SAMPLE_time] = 1;
34         if(lev.wheel_cnt) play[SAMPLE_wheel] = 1;
35
36 /* grow ameuba */
37         random = Random;
38         for(count = lev.ameuba_time; count--;) {
39                 x = (random >> 10) % (WIDTH - 2);
40                 y = (random >> 20) % (HEIGHT - 2);
41                 switch(Cave[y][x]) {
42                 case Xblank:
43                 case Yacid_splash_eB:
44                 case Yacid_splash_wB:
45                 case Xgrass:
46                 case Xdirt:
47                 case Xsand:
48                 case Xplant:
49                 case Yplant:
50                         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;
51                 }
52                 random = random * 129 + 1;
53         }
54         Random = random;
55
56 /* handle explosions */
57         for(y = 1; y < HEIGHT - 1; y++) for(x = 1; x < WIDTH - 1; x++) {
58                 switch(Cave[y][x]) {
59                 case Znormal:
60                         Cave[y][x] = Xboom_1;
61                         Cave[y-1][x] = tab_explode_normal[Cave[y-1][x]];
62                         Cave[y][x-1] = tab_explode_normal[Cave[y][x-1]];
63                         Cave[y][x+1] = tab_explode_normal[Cave[y][x+1]];
64                         Cave[y+1][x] = tab_explode_normal[Cave[y+1][x]];
65                         Cave[y-1][x-1] = tab_explode_normal[Cave[y-1][x-1]];
66                         Cave[y-1][x+1] = tab_explode_normal[Cave[y-1][x+1]];
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                         break;
70                 case Zdynamite:
71                         Cave[y][x] = Xboom_1;
72                         Cave[y-1][x] = tab_explode_dynamite[Cave[y-1][x]];
73                         Cave[y][x-1] = tab_explode_dynamite[Cave[y][x-1]];
74                         Cave[y][x+1] = tab_explode_dynamite[Cave[y][x+1]];
75                         Cave[y+1][x] = tab_explode_dynamite[Cave[y+1][x]];
76                         Cave[y-1][x-1] = tab_explode_dynamite[Cave[y-1][x-1]];
77                         Cave[y-1][x+1] = tab_explode_dynamite[Cave[y-1][x+1]];
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                         break;
81                 }
82         }
83
84 /* triple buffering */
85         for(y = 0; y < HEIGHT; y++) for(x = 0; x < WIDTH; x++) {
86                 Next[y][x] = Cave[y][x];
87         }
88 }