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; |
---|
9 | |
---|
10 | for( i = 0; i < WEAPONS; i++ ) |
---|
11 | { |
---|
12 | if( wp->y[i] >= 0 ) |
---|
13 | { |
---|
14 | if( wp->x[i] <= t->left[wp->y[i]+1] |
---|
15 | || wp->x[i] >= t->right[wp->y[i]+1] ) |
---|
16 | { |
---|
17 | add_explosion( g, ex, wp->x[i], wp->y[i]+1, 0, 1, 0 ); |
---|
18 | |
---|
19 | if( wp->x[i] <= t->left[wp->y[i]+1] ) |
---|
20 | { |
---|
21 | t->left[wp->y[i]]--; |
---|
22 | t->left[wp->y[i]+1]-=2; |
---|
23 | t->left[wp->y[i]+2]--; |
---|
24 | } |
---|
25 | else |
---|
26 | { |
---|
27 | t->right[wp->y[i]]++; |
---|
28 | t->right[wp->y[i]+1]+=2; |
---|
29 | t->right[wp->y[i]+2]++; |
---|
30 | } |
---|
31 | |
---|
32 | wp->y[i] = -1; |
---|
33 | } |
---|
34 | else if( wp->x[i] <= t->left[wp->y[i]] |
---|
35 | || wp->x[i] >= t->right[wp->y[i]] ) |
---|
36 | { |
---|
37 | add_explosion( g, ex, wp->x[i], wp->y[i], 0, 1, 0 ); |
---|
38 | |
---|
39 | if( wp->x[i] <= t->left[wp->y[i]] ) |
---|
40 | { |
---|
41 | t->left[wp->y[i]-1]--; |
---|
42 | t->left[wp->y[i]]-=2; |
---|
43 | t->left[wp->y[i]+1]--; |
---|
44 | } |
---|
45 | else |
---|
46 | { |
---|
47 | t->right[wp->y[i]-1]++; |
---|
48 | t->right[wp->y[i]]+=2; |
---|
49 | t->right[wp->y[i]+1]++; |
---|
50 | } |
---|
51 | |
---|
52 | wp->y[i] = -1; |
---|
53 | } |
---|
54 | } |
---|
55 | } |
---|
56 | } |
---|
57 | |
---|
58 | void collide_weapons_aliens( game *g, weapons *wp, aliens *al, explosions *ex ) |
---|
59 | { |
---|
60 | int i, j; |
---|
61 | |
---|
62 | for( i = 0; i < WEAPONS; i++ ) |
---|
63 | { |
---|
64 | if( wp->y[i] >= 0 ) |
---|
65 | { |
---|
66 | int ok = 0; |
---|
67 | int r; |
---|
68 | |
---|
69 | switch( wp->type[i] ) |
---|
70 | { |
---|
71 | case 2: |
---|
72 | /* Big nuke */ |
---|
73 | r = (34 - wp->n[i]) * (34 - wp->n[i]) / 10; |
---|
74 | |
---|
75 | for( j = 0; j < ALIENS; j++ ) |
---|
76 | { |
---|
77 | if( al->x[j] < 0 ) |
---|
78 | { |
---|
79 | continue; |
---|
80 | } |
---|
81 | |
---|
82 | if( (al->x[j] - wp->x[i]) * (al->x[j] - wp->x[i]) |
---|
83 | + 4 * (al->y[j] - wp->y[i]) * (al->y[j] - wp->y[i]) |
---|
84 | <= r * r ) |
---|
85 | { |
---|
86 | /* Kill alien, not nuke */ |
---|
87 | add_explosion( g, ex, al->x[j], al->y[j], 0, 0, 1 ); |
---|
88 | al->x[j] = -1; |
---|
89 | al->y[j] = -1; |
---|
90 | } |
---|
91 | } |
---|
92 | break; |
---|
93 | |
---|
94 | case 1: |
---|
95 | default: |
---|
96 | for( j = 0; j < ALIENS; j++ ) |
---|
97 | { |
---|
98 | if( wp->x[i] >= al->x[j] |
---|
99 | && wp->x[i] <= al->x[j] + 4 |
---|
100 | && wp->y[i] >= al->y[j] |
---|
101 | && wp->y[i] <= al->y[j] + 2 ) |
---|
102 | { |
---|
103 | al->life[j]--; |
---|
104 | if( al->life[j] == 0 ) |
---|
105 | { |
---|
106 | al->x[j] = -1; |
---|
107 | al->y[j] = -1; |
---|
108 | add_explosion( g, ex, wp->x[i], wp->y[i], 0, 0, 1 ); |
---|
109 | } |
---|
110 | ok = 1; |
---|
111 | } |
---|
112 | else if( wp->x[i] >= al->x[j] |
---|
113 | && wp->x[i] <= al->x[j] + 4 |
---|
114 | && wp->y[i]+1 >= al->y[j] |
---|
115 | && wp->y[i]+1 <= al->y[j] + 2 ) |
---|
116 | { |
---|
117 | al->life[j]--; |
---|
118 | if( al->life[j] == 0 ) |
---|
119 | { |
---|
120 | al->x[j] = -1; |
---|
121 | al->y[j] = -1; |
---|
122 | add_explosion( g, ex, wp->x[i], wp->y[i]+1, 0, 0, 1 ); |
---|
123 | } |
---|
124 | ok = 1; |
---|
125 | } |
---|
126 | } |
---|
127 | |
---|
128 | if( ok ) |
---|
129 | { |
---|
130 | wp->y[i] = -1; |
---|
131 | } |
---|
132 | break; |
---|
133 | } |
---|
134 | } |
---|
135 | } |
---|
136 | } |
---|
137 | |
---|
138 | void collide_player_tunnel( game *g, player *p, tunnel *t, explosions *ex ) |
---|
139 | { |
---|
140 | if( p->x <= t->left[p->y] ) |
---|
141 | { |
---|
142 | p->x += 3; |
---|
143 | //add_explosion( g, ex, x+1, y-2, 0, 1, 0 ); |
---|
144 | } |
---|
145 | else if( p->x + 5 >= t->right[p->y] ) |
---|
146 | { |
---|
147 | p->x -= 3; |
---|
148 | //add_explosion( g, ex, x+4, y-2, 0, 1, 0 ); |
---|
149 | } |
---|
150 | } |
---|
151 | |
---|