improved Makefile for packaging and added targets for Android package
[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 int random;
17
18   /* update variables */
19
20   if (lev.score > 9999)
21     lev.score = 9999;
22
23   if (lev.android_move_cnt-- == 0)
24     lev.android_move_cnt = lev.android_move_time;
25   if (lev.android_clone_cnt-- == 0)
26     lev.android_clone_cnt = lev.android_clone_time;
27   if (lev.ball_state)
28     if (lev.ball_cnt-- == 0)
29       lev.ball_cnt = lev.ball_time;
30   if (lev.lenses_cnt)
31     lev.lenses_cnt--;
32   if (lev.magnify_cnt)
33     lev.magnify_cnt--;
34   if (lev.wheel_cnt)
35     lev.wheel_cnt--;
36   if (lev.wind_cnt)
37     lev.wind_cnt--;
38   if (lev.wonderwall_time && lev.wonderwall_state)
39     lev.wonderwall_time--;
40
41   if (lev.wheel_cnt)
42     play_element_sound(lev.wheel_x, lev.wheel_y, SAMPLE_wheel, Xwheel);
43
44   /* grow amoeba */
45
46   random = RandomEM;
47
48   for (count = lev.amoeba_time; count--;)
49   {
50     x = (random >> 10) % (WIDTH - 2);
51     y = (random >> 20) % (HEIGHT - 2);
52     switch (Cave[y][x])
53     {
54       case Xblank:
55       case Yacid_splash_eB:
56       case Yacid_splash_wB:
57       case Xgrass:
58       case Xdirt:
59       case Xsand:
60       case Xplant:
61       case Yplant:
62         if (tab_amoeba[Cave[y-1][x]] ||
63             tab_amoeba[Cave[y][x+1]] ||
64             tab_amoeba[Cave[y+1][x]] ||
65             tab_amoeba[Cave[y][x-1]])
66           Cave[y][x] = Xdrip_eat;
67     }
68
69     random = random * 129 + 1;
70   }
71
72   RandomEM = random;
73
74   /* handle explosions */
75
76   for (y = 1; y < HEIGHT - 1; y++)
77     for (x = 1; x < WIDTH - 1; x++)
78     {
79       switch (Cave[y][x])
80       {
81         case Znormal:
82           Cave[y][x] = Xboom_1;
83           Cave[y-1][x] = tab_explode_normal[Cave[y-1][x]];
84           Cave[y][x-1] = tab_explode_normal[Cave[y][x-1]];
85           Cave[y][x+1] = tab_explode_normal[Cave[y][x+1]];
86           Cave[y+1][x] = tab_explode_normal[Cave[y+1][x]];
87           Cave[y-1][x-1] = tab_explode_normal[Cave[y-1][x-1]];
88           Cave[y-1][x+1] = tab_explode_normal[Cave[y-1][x+1]];
89           Cave[y+1][x-1] = tab_explode_normal[Cave[y+1][x-1]];
90           Cave[y+1][x+1] = tab_explode_normal[Cave[y+1][x+1]];
91           break;
92
93         case Zdynamite:
94           Cave[y][x] = Xboom_1;
95           Cave[y-1][x] = tab_explode_dynamite[Cave[y-1][x]];
96           Cave[y][x-1] = tab_explode_dynamite[Cave[y][x-1]];
97           Cave[y][x+1] = tab_explode_dynamite[Cave[y][x+1]];
98           Cave[y+1][x] = tab_explode_dynamite[Cave[y+1][x]];
99           Cave[y-1][x-1] = tab_explode_dynamite[Cave[y-1][x-1]];
100           Cave[y-1][x+1] = tab_explode_dynamite[Cave[y-1][x+1]];
101           Cave[y+1][x-1] = tab_explode_dynamite[Cave[y+1][x-1]];
102           Cave[y+1][x+1] = tab_explode_dynamite[Cave[y+1][x+1]];
103           break;
104       }
105     }
106
107   /* triple buffering */
108
109   for (y = 0; y < HEIGHT; y++)
110     for (x = 0; x < WIDTH; x++)
111       Next[y][x] = Cave[y][x];
112 }