1 | |
---|
2 | #include <stdlib.h> |
---|
3 | |
---|
4 | #include "common.h" |
---|
5 | |
---|
6 | void collide_weapons_tunnel( game *g, weapons *wp, tunnel *t, explosions *ex ) |
---|
7 | { |
---|
8 | int i, x, y; |
---|
9 | |
---|
10 | for( i = 0; i < WEAPONS; i++ ) |
---|
11 | { |
---|
12 | x = wp->x[i] >> 4; |
---|
13 | y = wp->y[i] >> 4; |
---|
14 | |
---|
15 | switch( wp->type[i] ) |
---|
16 | { |
---|
17 | case WEAPON_NONE: |
---|
18 | break; |
---|
19 | case WEAPON_SEEKER: |
---|
20 | if( x <= t->left[y] |
---|
21 | || x >= t->right[y] ) |
---|
22 | { |
---|
23 | add_explosion( g, ex, x, y, 0, 1, EXPLOSION_SMALL ); |
---|
24 | |
---|
25 | if( x <= t->left[y] ) |
---|
26 | { |
---|
27 | t->left[y-1]--; |
---|
28 | t->left[y]-=2; |
---|
29 | t->left[y+1]--; |
---|
30 | } |
---|
31 | else |
---|
32 | { |
---|
33 | t->right[y-1]++; |
---|
34 | t->right[y]+=2; |
---|
35 | t->right[y+1]++; |
---|
36 | } |
---|
37 | |
---|
38 | wp->type[i] = WEAPON_NONE; |
---|
39 | } |
---|
40 | break; |
---|
41 | case WEAPON_LASER: |
---|
42 | if( x <= t->left[y+1] |
---|
43 | || x >= t->right[y+1] ) |
---|
44 | { |
---|
45 | add_explosion( g, ex, x, y+1, 0, 1, EXPLOSION_SMALL ); |
---|
46 | |
---|
47 | if( x <= t->left[y+1] ) |
---|
48 | { |
---|
49 | t->left[y]--; |
---|
50 | t->left[y+1]-=2; |
---|
51 | t->left[y+2]--; |
---|
52 | } |
---|
53 | else |
---|
54 | { |
---|
55 | t->right[y]++; |
---|
56 | t->right[y+1]+=2; |
---|
57 | t->right[y+2]++; |
---|
58 | } |
---|
59 | |
---|
60 | wp->type[i] = WEAPON_NONE; |
---|
61 | } |
---|
62 | else if( x <= t->left[y] |
---|
63 | || x >= t->right[y] ) |
---|
64 | { |
---|
65 | add_explosion( g, ex, x, y, 0, 1, EXPLOSION_SMALL ); |
---|
66 | |
---|
67 | if( x <= t->left[y] ) |
---|
68 | { |
---|
69 | t->left[y-1]--; |
---|
70 | t->left[y]-=2; |
---|
71 | t->left[y+1]--; |
---|
72 | } |
---|
73 | else |
---|
74 | { |
---|
75 | t->right[y-1]++; |
---|
76 | t->right[y]+=2; |
---|
77 | t->right[y+1]++; |
---|
78 | } |
---|
79 | |
---|
80 | wp->type[i] = WEAPON_NONE; |
---|
81 | } |
---|
82 | break; |
---|
83 | case WEAPON_NUKE: |
---|
84 | /* The nuke does not break the tunnel */ |
---|
85 | break; |
---|
86 | } |
---|
87 | } |
---|
88 | } |
---|
89 | |
---|
90 | void collide_weapons_aliens( game *g, weapons *wp, aliens *al, explosions *ex ) |
---|
91 | { |
---|
92 | int i, j, x, y; |
---|
93 | |
---|
94 | for( i = 0; i < WEAPONS; i++ ) |
---|
95 | { |
---|
96 | int ok = 0; |
---|
97 | int r; |
---|
98 | |
---|
99 | x = wp->x[i] >> 4; |
---|
100 | y = wp->y[i] >> 4; |
---|
101 | |
---|
102 | switch( wp->type[i] ) |
---|
103 | { |
---|
104 | case WEAPON_NONE: |
---|
105 | break; |
---|
106 | case WEAPON_NUKE: |
---|
107 | /* Big nuke */ |
---|
108 | r = (29 - wp->n[i]) * (29 - wp->n[i]) / 8; |
---|
109 | |
---|
110 | for( j = 0; j < ALIENS; j++ ) |
---|
111 | { |
---|
112 | if( al->type[j] == ALIEN_NONE ) |
---|
113 | { |
---|
114 | continue; |
---|
115 | } |
---|
116 | |
---|
117 | if( wp->n[i] == 0 /* Nuke destroys _everything_ */ || |
---|
118 | (al->x[j] - x) * (al->x[j] - x) |
---|
119 | + 4 * (al->y[j] - y) * (al->y[j] - y) |
---|
120 | <= r * r ) |
---|
121 | { |
---|
122 | /* Kill alien, not nuke */ |
---|
123 | al->type[j] = ALIEN_NONE; |
---|
124 | add_explosion( g, ex, al->x[j], al->y[j], 0, 0, EXPLOSION_MEDIUM ); |
---|
125 | add_bonus( g, g->bo, al->x[j], al->y[j], GET_RAND(0,5) ? BONUS_GREEN : BONUS_LIFE ); |
---|
126 | } |
---|
127 | } |
---|
128 | break; |
---|
129 | case WEAPON_LASER: |
---|
130 | for( j = 0; j < ALIENS; j++ ) |
---|
131 | { |
---|
132 | if( al->type[j] == ALIEN_NONE ) |
---|
133 | { |
---|
134 | continue; |
---|
135 | } |
---|
136 | |
---|
137 | if( x >= al->x[j] && x <= al->x[j] + 4 |
---|
138 | && y >= al->y[j] && y <= al->y[j] + 2 ) |
---|
139 | { |
---|
140 | al->life[j]--; |
---|
141 | if( al->life[j] <= 0 ) |
---|
142 | { |
---|
143 | al->type[j] = ALIEN_NONE; |
---|
144 | add_explosion( g, ex, x, y, 0, 0, EXPLOSION_MEDIUM ); |
---|
145 | add_bonus( g, g->bo, x, y, GET_RAND(0,5) ? BONUS_GREEN : BONUS_LIFE ); |
---|
146 | } |
---|
147 | ok = 1; |
---|
148 | } |
---|
149 | else if( x >= al->x[j] && x <= al->x[j] + 4 |
---|
150 | && y+1 >= al->y[j] && y+1 <= al->y[j] + 2 ) |
---|
151 | { |
---|
152 | al->life[j]--; |
---|
153 | if( al->life[j] <= 0 ) |
---|
154 | { |
---|
155 | al->type[j] = ALIEN_NONE; |
---|
156 | add_explosion( g, ex, x, y+1, 0, 0, EXPLOSION_MEDIUM ); |
---|
157 | add_bonus( g, g->bo, x, y+1, GET_RAND(0,5) ? BONUS_GREEN : BONUS_LIFE ); |
---|
158 | } |
---|
159 | ok = 1; |
---|
160 | } |
---|
161 | } |
---|
162 | |
---|
163 | if( ok ) |
---|
164 | { |
---|
165 | wp->type[i] = WEAPON_NONE; |
---|
166 | } |
---|
167 | break; |
---|
168 | |
---|
169 | case WEAPON_SEEKER: |
---|
170 | for( j = 0; j < ALIENS; j++ ) |
---|
171 | { |
---|
172 | if( al->type[j] == ALIEN_NONE ) |
---|
173 | { |
---|
174 | continue; |
---|
175 | } |
---|
176 | |
---|
177 | if( x >= al->x[j] && x <= al->x[j] + 4 |
---|
178 | && y >= al->y[j] && y <= al->y[j] + 2 ) |
---|
179 | { |
---|
180 | al->life[j]--; |
---|
181 | if( al->life[j] <= 0 ) |
---|
182 | { |
---|
183 | al->type[j] = ALIEN_NONE; |
---|
184 | add_explosion( g, ex, x, y, 0, 0, EXPLOSION_MEDIUM ); |
---|
185 | add_bonus( g, g->bo, x, y, GET_RAND(0,5) ? BONUS_GREEN : BONUS_LIFE ); |
---|
186 | } |
---|
187 | ok = 1; |
---|
188 | } |
---|
189 | } |
---|
190 | |
---|
191 | if( ok ) |
---|
192 | { |
---|
193 | wp->type[i] = WEAPON_NONE; |
---|
194 | } |
---|
195 | break; |
---|
196 | } |
---|
197 | } |
---|
198 | } |
---|
199 | |
---|
200 | void collide_player_tunnel( game *g, player *p, tunnel *t, explosions *ex ) |
---|
201 | { |
---|
202 | if( p->x <= t->left[p->y] ) |
---|
203 | { |
---|
204 | p->x += 2; |
---|
205 | add_explosion( g, ex, p->x+1, p->y-2, 0, 0, EXPLOSION_SMALL ); |
---|
206 | } |
---|
207 | else if( p->x + 5 >= t->right[p->y] ) |
---|
208 | { |
---|
209 | p->x -= 2; |
---|
210 | add_explosion( g, ex, p->x+4, p->y-2, 0, 0, EXPLOSION_SMALL ); |
---|
211 | } |
---|
212 | } |
---|
213 | |
---|