~ubuntu-branches/ubuntu/intrepid/xscreensaver/intrepid

« back to all changes in this revision

Viewing changes to hacks/blaster.c

  • Committer: Bazaar Package Importer
  • Author(s): Oliver Grawert
  • Date: 2007-12-06 09:53:12 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20071206095312-fkzcwe4vqm50z208
Tags: 5.04-1ubuntu1
* Merge from debian unstable, remaining changes:
  - split xscreensaver into xscreensaver, xscreensaver-data (hacks we ship),
    xscreensaver-data-extra (hacks in universe). split out gl hacks for
    universe to xscreensaver-gl-extra
  - use fridge for rss screensavers
  - create and install .desktop files for gnome-screensaver

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#include <math.h>
22
22
#include "screenhack.h"
23
23
 
24
 
static Display *dpy;
25
 
static Window window;
26
 
static GC r_color0, r_color1, r_color2, r_color3, r_color4, r_color5, l_color0, l_color1;
27
 
static GC s_color;
28
 
static GC black;
29
 
 
30
 
static int delay;
31
 
 
32
 
static int NUM_ROBOTS=5;
33
 
static int NUM_LASERS=3;
34
 
 
35
 
static int MOTHER_SHIP=0;
36
 
static int MOTHER_SHIP_WIDTH=25;
37
 
static int MOTHER_SHIP_HEIGHT=7;
38
 
static int MOTHER_SHIP_LASER=15;
39
 
static int MOTHER_SHIP_PERIOD=150;
40
 
static int MOTHER_SHIP_HITS=10;
41
 
 
42
 
static int LINE_MOVE_STYLE=0;
43
 
static int RANDOM_MOVE_STYLE=1;
44
 
static int NUM_MOVE_STYLES=2;
45
 
 
46
 
static int EXPLODE_SIZE_1=27;
47
 
static int EXPLODE_SIZE_2=19;
48
 
static int EXPLODE_SIZE_3=7;
49
 
static GC EXPLODE_COLOR_1;
50
 
static GC EXPLODE_COLOR_2;
51
 
 
52
24
struct laser_state {
53
25
        int active;
54
26
        int start_x,start_y;
81
53
        struct laser_state *lasers;
82
54
};
83
55
 
84
 
static XArc *stars;
85
 
static int NUM_STARS;
86
 
static int MOVE_STARS;
87
 
static int MOVE_STARS_X;
88
 
static int MOVE_STARS_Y;
89
 
static int MOVE_STARS_RANDOM;
90
 
 
91
 
static struct mother_ship_state *mother;
92
 
 
93
 
static struct robot_state *robots;
94
 
 
95
 
XWindowAttributes xgwa;
96
 
 
97
 
 
 
56
 
 
57
 
 
58
 
 
59
struct state {
 
60
  Display *dpy;
 
61
  Window window;
 
62
 
 
63
  GC r_color0, r_color1, r_color2, r_color3, r_color4, r_color5, l_color0, l_color1;
 
64
  GC s_color;
 
65
  GC black;
 
66
 
 
67
  int delay;
 
68
 
 
69
  int NUM_ROBOTS;
 
70
  int NUM_LASERS;
 
71
 
 
72
  int MOTHER_SHIP;
 
73
  int MOTHER_SHIP_WIDTH;
 
74
  int MOTHER_SHIP_HEIGHT;
 
75
  int MOTHER_SHIP_LASER;
 
76
  int MOTHER_SHIP_PERIOD;
 
77
  int MOTHER_SHIP_HITS;
 
78
 
 
79
  int LINE_MOVE_STYLE;
 
80
  int RANDOM_MOVE_STYLE;
 
81
  int NUM_MOVE_STYLES;
 
82
 
 
83
  int EXPLODE_SIZE_1;
 
84
  int EXPLODE_SIZE_2;
 
85
  int EXPLODE_SIZE_3;
 
86
  GC EXPLODE_COLOR_1;
 
87
  GC EXPLODE_COLOR_2;
 
88
 
 
89
  XArc *stars;
 
90
  int NUM_STARS;
 
91
  int MOVE_STARS;
 
92
  int MOVE_STARS_X;
 
93
  int MOVE_STARS_Y;
 
94
  int MOVE_STARS_RANDOM;
 
95
 
 
96
  struct mother_ship_state *mother;
 
97
 
 
98
  struct robot_state *robots;
 
99
 
 
100
  XWindowAttributes xgwa;
 
101
 
 
102
  int initted;
 
103
 
 
104
  int draw_x;
 
105
  int draw_y;
 
106
  int draw_z;
 
107
};
98
108
 
99
109
 
100
110
/* creates a new robot. It starts out on one of the edges somewhere and
101
111
        has no initial velocity. A target is randomly picked. */
102
 
static void make_new_robot(int index)
 
112
static void make_new_robot(struct state *st, int index)
103
113
{
104
114
        int laser_check = 0;
105
115
        int x=0;
106
116
 
107
 
        for(x=0;x<NUM_LASERS;x++) {
108
 
                if(robots[index].lasers[x].active) {
109
 
                        x=NUM_LASERS;
 
117
        for(x=0;x<st->NUM_LASERS;x++) {
 
118
                if(st->robots[index].lasers[x].active) {
 
119
                        x=st->NUM_LASERS;
110
120
                        laser_check = 1;
111
121
                }
112
122
        }
113
123
        if(laser_check==0) {
114
 
                robots[index].alive=1;
115
 
 
116
 
                robots[index].radius = 7+(random()%7);
117
 
 
118
 
                robots[index].move_style = random()%NUM_MOVE_STYLES;
 
124
                st->robots[index].alive=1;
 
125
 
 
126
                st->robots[index].radius = 7+(random()%7);
 
127
 
 
128
                st->robots[index].move_style = random()%st->NUM_MOVE_STYLES;
119
129
                if(random()%2==0) {
120
 
                        robots[index].new_x=random()%(xgwa.width-robots[index].radius);
121
 
                        robots[index].old_x=robots[index].new_x;
 
130
                        st->robots[index].new_x=random()%(st->xgwa.width-st->robots[index].radius);
 
131
                        st->robots[index].old_x=st->robots[index].new_x;
122
132
                        if(random()%2==0) {
123
 
                                robots[index].new_y=0;
124
 
                                robots[index].old_y=0;
 
133
                                st->robots[index].new_y=0;
 
134
                                st->robots[index].old_y=0;
125
135
                        }
126
136
                        else {
127
 
                                robots[index].new_y=xgwa.height-robots[index].radius;
128
 
                                robots[index].old_y = robots[index].new_y;
 
137
                                st->robots[index].new_y=st->xgwa.height-st->robots[index].radius;
 
138
                                st->robots[index].old_y = st->robots[index].new_y;
129
139
                        }
130
140
                }
131
141
                else {
132
 
                        robots[index].new_y=random()%(xgwa.height-robots[index].radius);
133
 
                        robots[index].old_y = robots[index].new_y;
 
142
                        st->robots[index].new_y=random()%(st->xgwa.height-st->robots[index].radius);
 
143
                        st->robots[index].old_y = st->robots[index].new_y;
134
144
                        if(random()%2) {
135
 
                                robots[index].new_x=0;
136
 
                                robots[index].old_x=0;
 
145
                                st->robots[index].new_x=0;
 
146
                                st->robots[index].old_x=0;
137
147
                        }
138
148
                        else {
139
 
                                robots[index].new_x=xgwa.width-robots[index].radius;
140
 
                                robots[index].old_x=robots[index].new_x;
 
149
                                st->robots[index].new_x=st->xgwa.width-st->robots[index].radius;
 
150
                                st->robots[index].old_x=st->robots[index].new_x;
141
151
                        }
142
152
                }
143
153
                        
144
154
                x=random()%6;
145
155
                if(x==0) {
146
 
                        robots[index].robot_color = r_color0;
 
156
                        st->robots[index].robot_color = st->r_color0;
147
157
                }
148
158
                else if(x==1) {
149
 
                        robots[index].robot_color = r_color1;
 
159
                        st->robots[index].robot_color = st->r_color1;
150
160
                }
151
161
                else if(x==2) {
152
 
                        robots[index].robot_color = r_color2;
 
162
                        st->robots[index].robot_color = st->r_color2;
153
163
                }
154
164
                else if(x==3) {
155
 
                        robots[index].robot_color = r_color3;
 
165
                        st->robots[index].robot_color = st->r_color3;
156
166
                }
157
167
                else if(x==4) {
158
 
                        robots[index].robot_color = r_color4;
 
168
                        st->robots[index].robot_color = st->r_color4;
159
169
                }
160
170
                else if(x==5) {
161
 
                        robots[index].robot_color = r_color5;
 
171
                        st->robots[index].robot_color = st->r_color5;
162
172
                }
163
173
 
164
174
                if(random()%2==0) {
165
 
                        robots[index].laser_color = l_color0;
 
175
                        st->robots[index].laser_color = st->l_color0;
166
176
                }
167
177
                else {
168
 
                        robots[index].laser_color = l_color1;
 
178
                        st->robots[index].laser_color = st->l_color1;
169
179
                }
170
180
 
171
 
                if(NUM_ROBOTS>1) {
172
 
                        robots[index].target = random()%NUM_ROBOTS;
173
 
                        while(robots[index].target==index) {
174
 
                                robots[index].target = random()%NUM_ROBOTS;
 
181
                if(st->NUM_ROBOTS>1) {
 
182
                        st->robots[index].target = random()%st->NUM_ROBOTS;
 
183
                        while(st->robots[index].target==index) {
 
184
                                st->robots[index].target = random()%st->NUM_ROBOTS;
175
185
                        }       
176
186
                }
177
187
        }
180
190
/* moves each robot, randomly changing its direction and velocity.
181
191
        At random a laser is shot toward that robot's target. Also at random
182
192
        the target can change. */
183
 
static void move_robots(void)
 
193
static void move_robots(struct state *st)
184
194
{
185
195
        int x=0;
186
196
        int y=0;
190
200
        int target_y = 0;
191
201
        double slope = 0;
192
202
 
193
 
        for(x=0;x<NUM_ROBOTS;x++) {
194
 
                if(robots[x].alive) {
195
 
                        if((robots[x].new_x == robots[x].old_x) && (robots[x].new_y == robots[x].old_y)) {
196
 
                                if(robots[x].new_x==0) {
197
 
                                        robots[x].old_x = -((random()%3)+1);
198
 
                                }
199
 
                                else {
200
 
                                        robots[x].old_x = robots[x].old_x + (random()%3)+1;
201
 
                                }
202
 
                                if(robots[x].new_y==0) {
203
 
                                        robots[x].old_y = -((random()%3)+1);
204
 
                                }
205
 
                                else {
206
 
                                        robots[x].old_y = robots[x].old_y + (random()%3)+1;
 
203
        for(x=0;x<st->NUM_ROBOTS;x++) {
 
204
                if(st->robots[x].alive) {
 
205
                        if((st->robots[x].new_x == st->robots[x].old_x) && (st->robots[x].new_y == st->robots[x].old_y)) {
 
206
                                if(st->robots[x].new_x==0) {
 
207
                                        st->robots[x].old_x = -((random()%3)+1);
 
208
                                }
 
209
                                else {
 
210
                                        st->robots[x].old_x = st->robots[x].old_x + (random()%3)+1;
 
211
                                }
 
212
                                if(st->robots[x].new_y==0) {
 
213
                                        st->robots[x].old_y = -((random()%3)+1);
 
214
                                }
 
215
                                else {
 
216
                                        st->robots[x].old_y = st->robots[x].old_y + (random()%3)+1;
207
217
                                }
208
218
                        }
209
 
                        if(robots[x].move_style==LINE_MOVE_STYLE) {
210
 
                                dx = robots[x].new_x - robots[x].old_x;
211
 
                                dy = robots[x].new_y - robots[x].old_y;
 
219
                        if(st->robots[x].move_style==st->LINE_MOVE_STYLE) {
 
220
                                dx = st->robots[x].new_x - st->robots[x].old_x;
 
221
                                dy = st->robots[x].new_y - st->robots[x].old_y;
212
222
                                if(dx > 3) {
213
223
                                        dx = 3;
214
224
                                }
221
231
                                else if(dy < -3) {
222
232
                                        dy = -3;
223
233
                                }
224
 
                                robots[x].old_x = robots[x].new_x;
225
 
                                robots[x].old_y = robots[x].new_y;
 
234
                                st->robots[x].old_x = st->robots[x].new_x;
 
235
                                st->robots[x].old_y = st->robots[x].new_y;
226
236
 
227
 
                                robots[x].new_x = robots[x].new_x + dx;
228
 
                                robots[x].new_y = robots[x].new_y + dy;
 
237
                                st->robots[x].new_x = st->robots[x].new_x + dx;
 
238
                                st->robots[x].new_y = st->robots[x].new_y + dy;
229
239
                        }
230
 
                        else if(robots[x].move_style==RANDOM_MOVE_STYLE) {
231
 
                                dx = robots[x].new_x - robots[x].old_x;
232
 
                                dy = robots[x].new_y - robots[x].old_y;
 
240
                        else if(st->robots[x].move_style==st->RANDOM_MOVE_STYLE) {
 
241
                                dx = st->robots[x].new_x - st->robots[x].old_x;
 
242
                                dy = st->robots[x].new_y - st->robots[x].old_y;
233
243
                                y=random()%3;
234
244
                                if(y==0) {
235
245
                                        dx = dx - ((random()%7)+1);
263
273
                                else if(dy < -3) {
264
274
                                        dy = -3;
265
275
                                }
266
 
                                robots[x].old_x = robots[x].new_x;
267
 
                                robots[x].old_y = robots[x].new_y;
 
276
                                st->robots[x].old_x = st->robots[x].new_x;
 
277
                                st->robots[x].old_y = st->robots[x].new_y;
268
278
 
269
 
                                robots[x].new_x = robots[x].new_x + dx;
270
 
                                robots[x].new_y = robots[x].new_y + dy;
 
279
                                st->robots[x].new_x = st->robots[x].new_x + dx;
 
280
                                st->robots[x].new_y = st->robots[x].new_y + dy;
271
281
                        }
272
282
 
273
283
                        /* bounds corrections */
274
 
                        if(robots[x].new_x >= xgwa.width-robots[x].radius) {
275
 
                                robots[x].new_x = xgwa.width - robots[x].radius;
276
 
                        }
277
 
                        else if(robots[x].new_x < 0) {
278
 
                                robots[x].new_x = 0;
279
 
                        }
280
 
                        if(robots[x].new_y >= xgwa.height-robots[x].radius) {
281
 
                                robots[x].new_y = xgwa.height - robots[x].radius;
282
 
                        }
283
 
                        else if(robots[x].new_y < 0) {
284
 
                                robots[x].new_y = 0;
 
284
                        if(st->robots[x].new_x >= st->xgwa.width-st->robots[x].radius) {
 
285
                                st->robots[x].new_x = st->xgwa.width - st->robots[x].radius;
 
286
                        }
 
287
                        else if(st->robots[x].new_x < 0) {
 
288
                                st->robots[x].new_x = 0;
 
289
                        }
 
290
                        if(st->robots[x].new_y >= st->xgwa.height-st->robots[x].radius) {
 
291
                                st->robots[x].new_y = st->xgwa.height - st->robots[x].radius;
 
292
                        }
 
293
                        else if(st->robots[x].new_y < 0) {
 
294
                                st->robots[x].new_y = 0;
285
295
                        }
286
296
                
287
297
                        if(random()%10==0) {
288
 
                                robots[x].move_style = 1;
 
298
                                st->robots[x].move_style = 1;
289
299
                        }
290
300
                        else {
291
 
                                robots[x].move_style = 0;
 
301
                                st->robots[x].move_style = 0;
292
302
                        }
293
303
 
294
 
                        if(NUM_ROBOTS>1) {
 
304
                        if(st->NUM_ROBOTS>1) {
295
305
                                if(random()%2==0) {
296
306
                                        if(random()%200==0) {
297
 
                                                robots[x].target = random()%NUM_ROBOTS;
298
 
                                                while(robots[x].target==x) {
299
 
                                                        robots[x].target = random()%NUM_ROBOTS;
 
307
                                                st->robots[x].target = random()%st->NUM_ROBOTS;
 
308
                                                while(st->robots[x].target==x) {
 
309
                                                        st->robots[x].target = random()%st->NUM_ROBOTS;
300
310
                                                }       
301
 
                                                for(y=0;y<NUM_LASERS;y++) {
302
 
                                                        if(robots[x].lasers[y].active == 0) {
303
 
                                                                robots[x].lasers[y].active = 1;
 
311
                                                for(y=0;y<st->NUM_LASERS;y++) {
 
312
                                                        if(st->robots[x].lasers[y].active == 0) {
 
313
                                                                st->robots[x].lasers[y].active = 1;
304
314
                                                                if(random()%2==0) {
305
315
                                                                        if(random()%2==0) {
306
 
                                                                                robots[x].lasers[y].start_x = robots[x].new_x+robots[x].radius;
307
 
                                                                                robots[x].lasers[y].start_y = robots[x].new_y+robots[x].radius;
308
 
                                                                                robots[x].lasers[y].end_x = robots[x].lasers[y].start_x+7;
309
 
                                                                                robots[x].lasers[y].end_y = robots[x].lasers[y].start_y+7;
 
316
                                                                                st->robots[x].lasers[y].start_x = st->robots[x].new_x+st->robots[x].radius;
 
317
                                                                                st->robots[x].lasers[y].start_y = st->robots[x].new_y+st->robots[x].radius;
 
318
                                                                                st->robots[x].lasers[y].end_x = st->robots[x].lasers[y].start_x+7;
 
319
                                                                                st->robots[x].lasers[y].end_y = st->robots[x].lasers[y].start_y+7;
310
320
                                                                        }
311
321
                                                                        else {
312
 
                                                                                robots[x].lasers[y].start_x = robots[x].new_x-robots[x].radius;
313
 
                                                                                robots[x].lasers[y].start_y = robots[x].new_y+robots[x].radius;
314
 
                                                                                robots[x].lasers[y].end_x = robots[x].lasers[y].start_x-7;
315
 
                                                                                robots[x].lasers[y].end_y = robots[x].lasers[y].start_y+7;
 
322
                                                                                st->robots[x].lasers[y].start_x = st->robots[x].new_x-st->robots[x].radius;
 
323
                                                                                st->robots[x].lasers[y].start_y = st->robots[x].new_y+st->robots[x].radius;
 
324
                                                                                st->robots[x].lasers[y].end_x = st->robots[x].lasers[y].start_x-7;
 
325
                                                                                st->robots[x].lasers[y].end_y = st->robots[x].lasers[y].start_y+7;
316
326
                                                                        }
317
327
                                                                }
318
328
                                                                else {
319
329
                                                                        if(random()%2==0) {
320
 
                                                                                robots[x].lasers[y].start_x = robots[x].new_x-robots[x].radius;
321
 
                                                                                robots[x].lasers[y].start_y = robots[x].new_y-robots[x].radius;
322
 
                                                                                robots[x].lasers[y].end_x = robots[x].lasers[y].start_x-7;
323
 
                                                                                robots[x].lasers[y].end_y = robots[x].lasers[y].start_y-7;
 
330
                                                                                st->robots[x].lasers[y].start_x = st->robots[x].new_x-st->robots[x].radius;
 
331
                                                                                st->robots[x].lasers[y].start_y = st->robots[x].new_y-st->robots[x].radius;
 
332
                                                                                st->robots[x].lasers[y].end_x = st->robots[x].lasers[y].start_x-7;
 
333
                                                                                st->robots[x].lasers[y].end_y = st->robots[x].lasers[y].start_y-7;
324
334
                                                                        }
325
335
                                                                        else {
326
 
                                                                                robots[x].lasers[y].start_x = robots[x].new_x+robots[x].radius;
327
 
                                                                                robots[x].lasers[y].start_y = robots[x].new_y-robots[x].radius;
328
 
                                                                                robots[x].lasers[y].end_x = robots[x].lasers[y].start_x+7;
329
 
                                                                                robots[x].lasers[y].end_y = robots[x].lasers[y].start_y-7;
 
336
                                                                                st->robots[x].lasers[y].start_x = st->robots[x].new_x+st->robots[x].radius;
 
337
                                                                                st->robots[x].lasers[y].start_y = st->robots[x].new_y-st->robots[x].radius;
 
338
                                                                                st->robots[x].lasers[y].end_x = st->robots[x].lasers[y].start_x+7;
 
339
                                                                                st->robots[x].lasers[y].end_y = st->robots[x].lasers[y].start_y-7;
330
340
                                                                        }
331
341
                                                                }
332
 
                                                                y = NUM_LASERS;
 
342
                                                                y = st->NUM_LASERS;
333
343
                                                        }
334
344
                                                }
335
345
                                        }
336
346
                                        else {
337
 
                                                for(y=0;y<NUM_LASERS;y++) {
338
 
                                                        if(robots[x].lasers[y].active==0) {
339
 
                                                                target_x = robots[robots[x].target].new_x;
340
 
                                                                target_y = robots[robots[x].target].new_y;
341
 
                                                                if((target_x-robots[x].new_x)!=0) {
342
 
                                                                        slope = ((double)target_y-robots[x].new_y)/((double)(target_x-robots[x].new_x));
 
347
                                                for(y=0;y<st->NUM_LASERS;y++) {
 
348
                                                        if(st->robots[x].lasers[y].active==0) {
 
349
                                                                target_x = st->robots[st->robots[x].target].new_x;
 
350
                                                                target_y = st->robots[st->robots[x].target].new_y;
 
351
                                                                if((target_x-st->robots[x].new_x)!=0) {
 
352
                                                                        slope = ((double)target_y-st->robots[x].new_y)/((double)(target_x-st->robots[x].new_x));
343
353
 
344
354
                                                                        if((slope<1) && (slope>-1)) {
345
 
                                                                                if(target_x>robots[x].new_x) {
346
 
                                                                                        robots[x].lasers[y].start_x = robots[x].radius;
347
 
                                                                                        robots[x].lasers[y].end_x = robots[x].lasers[y].start_x + 7;
 
355
                                                                                if(target_x>st->robots[x].new_x) {
 
356
                                                                                        st->robots[x].lasers[y].start_x = st->robots[x].radius;
 
357
                                                                                        st->robots[x].lasers[y].end_x = st->robots[x].lasers[y].start_x + 7;
348
358
                                                                                }
349
359
                                                                                else {
350
 
                                                                                        robots[x].lasers[y].start_x = -robots[x].radius;
351
 
                                                                                        robots[x].lasers[y].end_x = robots[x].lasers[y].start_x - 7;
 
360
                                                                                        st->robots[x].lasers[y].start_x = -st->robots[x].radius;
 
361
                                                                                        st->robots[x].lasers[y].end_x = st->robots[x].lasers[y].start_x - 7;
352
362
                                                                                }
353
 
                                                                                robots[x].lasers[y].start_y = (int)(robots[x].lasers[y].start_x * slope);
354
 
                                                                                robots[x].lasers[y].end_y = (int)(robots[x].lasers[y].end_x * slope);
 
363
                                                                                st->robots[x].lasers[y].start_y = (int)(st->robots[x].lasers[y].start_x * slope);
 
364
                                                                                st->robots[x].lasers[y].end_y = (int)(st->robots[x].lasers[y].end_x * slope);
355
365
                                                                        }
356
366
                                                                        else {
357
 
                                                                                slope = (target_x-robots[x].new_x)/(target_y-robots[x].new_y);
358
 
                                                                                if(target_y>robots[x].new_y) {
359
 
                                                                                        robots[x].lasers[y].start_y = robots[x].radius;
360
 
                                                                                        robots[x].lasers[y].end_y = robots[x].lasers[y].start_y + 7;
 
367
                                                                                slope = (target_x-st->robots[x].new_x)/(target_y-st->robots[x].new_y);
 
368
                                                                                if(target_y>st->robots[x].new_y) {
 
369
                                                                                        st->robots[x].lasers[y].start_y = st->robots[x].radius;
 
370
                                                                                        st->robots[x].lasers[y].end_y = st->robots[x].lasers[y].start_y + 7;
361
371
                                                                                }
362
372
                                                                                else {
363
 
                                                                                        robots[x].lasers[y].start_y = -robots[x].radius;
364
 
                                                                                        robots[x].lasers[y].end_y = robots[x].lasers[y].start_y - 7;
 
373
                                                                                        st->robots[x].lasers[y].start_y = -st->robots[x].radius;
 
374
                                                                                        st->robots[x].lasers[y].end_y = st->robots[x].lasers[y].start_y - 7;
365
375
                                                                                }
366
 
                                                                                robots[x].lasers[y].start_x = (int)(robots[x].lasers[y].start_y * slope);;
367
 
                                                                                robots[x].lasers[y].end_x = (int)(robots[x].lasers[y].end_y * slope);
 
376
                                                                                st->robots[x].lasers[y].start_x = (int)(st->robots[x].lasers[y].start_y * slope);;
 
377
                                                                                st->robots[x].lasers[y].end_x = (int)(st->robots[x].lasers[y].end_y * slope);
368
378
                                                                        }
369
 
                                                                        robots[x].lasers[y].start_x = robots[x].lasers[y].start_x + robots[x].new_x;
370
 
                                                                        robots[x].lasers[y].start_y = robots[x].lasers[y].start_y + robots[x].new_y;
371
 
                                                                        robots[x].lasers[y].end_x = robots[x].lasers[y].end_x + robots[x].new_x;
372
 
                                                                        robots[x].lasers[y].end_y = robots[x].lasers[y].end_y + robots[x].new_y;
 
379
                                                                        st->robots[x].lasers[y].start_x = st->robots[x].lasers[y].start_x + st->robots[x].new_x;
 
380
                                                                        st->robots[x].lasers[y].start_y = st->robots[x].lasers[y].start_y + st->robots[x].new_y;
 
381
                                                                        st->robots[x].lasers[y].end_x = st->robots[x].lasers[y].end_x + st->robots[x].new_x;
 
382
                                                                        st->robots[x].lasers[y].end_y = st->robots[x].lasers[y].end_y + st->robots[x].new_y;
373
383
                                                                }
374
384
                                                                else {
375
 
                                                                        if(target_y > robots[x].new_y) {
376
 
                                                                                robots[x].lasers[y].start_x = robots[x].new_x;
377
 
                                                                                robots[x].lasers[y].start_y = robots[x].new_y+robots[x].radius;
378
 
                                                                                robots[x].lasers[y].end_x = robots[x].new_x;
379
 
                                                                                robots[x].lasers[y].end_y = robots[x].lasers[y].start_y+7;
 
385
                                                                        if(target_y > st->robots[x].new_y) {
 
386
                                                                                st->robots[x].lasers[y].start_x = st->robots[x].new_x;
 
387
                                                                                st->robots[x].lasers[y].start_y = st->robots[x].new_y+st->robots[x].radius;
 
388
                                                                                st->robots[x].lasers[y].end_x = st->robots[x].new_x;
 
389
                                                                                st->robots[x].lasers[y].end_y = st->robots[x].lasers[y].start_y+7;
380
390
                                                                        }
381
391
                                                                        else {
382
 
                                                                                robots[x].lasers[y].start_x = robots[x].new_x;
383
 
                                                                                robots[x].lasers[y].start_y = robots[x].new_y-robots[x].radius;
384
 
                                                                                robots[x].lasers[y].end_x = robots[x].new_x;
385
 
                                                                                robots[x].lasers[y].end_y = robots[x].lasers[y].start_y-7;
 
392
                                                                                st->robots[x].lasers[y].start_x = st->robots[x].new_x;
 
393
                                                                                st->robots[x].lasers[y].start_y = st->robots[x].new_y-st->robots[x].radius;
 
394
                                                                                st->robots[x].lasers[y].end_x = st->robots[x].new_x;
 
395
                                                                                st->robots[x].lasers[y].end_y = st->robots[x].lasers[y].start_y-7;
386
396
                                                                        }
387
397
                                                                }
388
398
                                                        
389
 
                                                                if((((robots[x].lasers[y].start_x - robots[x].lasers[y].end_x) > 7) || 
390
 
                                                                         ((robots[x].lasers[y].end_x - robots[x].lasers[y].start_x) > 7)) &&  
391
 
                                                                        (((robots[x].lasers[y].start_y - robots[x].lasers[y].end_y) > 7) || 
392
 
                                                                         ((robots[x].lasers[y].end_y - robots[x].lasers[y].start_y) > 7))) {
 
399
                                                                if((((st->robots[x].lasers[y].start_x - st->robots[x].lasers[y].end_x) > 7) || 
 
400
                                                                         ((st->robots[x].lasers[y].end_x - st->robots[x].lasers[y].start_x) > 7)) &&  
 
401
                                                                        (((st->robots[x].lasers[y].start_y - st->robots[x].lasers[y].end_y) > 7) || 
 
402
                                                                         ((st->robots[x].lasers[y].end_y - st->robots[x].lasers[y].start_y) > 7))) {
393
403
                                                                }
394
404
                                                                else {
395
 
                                                                        robots[x].lasers[y].active = 1;
396
 
                                                                        y = NUM_LASERS;
 
405
                                                                        st->robots[x].lasers[y].active = 1;
 
406
                                                                        y = st->NUM_LASERS;
397
407
                                                                }
398
408
                                                        }
399
409
                                                }
402
412
                        }
403
413
                }
404
414
                else {
405
 
                        if(robots[x].death==0) {
406
 
                                make_new_robot(x);
 
415
                        if(st->robots[x].death==0) {
 
416
                                make_new_robot(st,x);
407
417
                        }
408
418
                }
409
419
        }
412
422
 
413
423
/* This moves a single laser one frame. collisions with other robots or
414
424
        the mothership is checked. */
415
 
static void move_laser(int rindex, int index)
 
425
static void move_laser(struct state *st, int rindex, int index)
416
426
{
417
427
        int x=0;
418
428
        int y=0;
421
431
        int dy=0;
422
432
        struct laser_state *laser;
423
433
        if(rindex>=0) {
424
 
                laser = robots[rindex].lasers;
 
434
                laser = st->robots[rindex].lasers;
425
435
        }
426
436
        else {
427
 
                laser = mother->lasers;
 
437
                laser = st->mother->lasers;
428
438
        }
429
439
        if(laser[index].active) {
430
440
                /* collision with other robots are checked here */
431
 
                for(x=0;x<NUM_ROBOTS;x++) {
 
441
                for(x=0;x<st->NUM_ROBOTS;x++) {
432
442
                        if(x!=rindex) {
433
 
                                if(robots[x].alive) {
434
 
                                        y = laser[index].start_x-robots[x].new_x;
 
443
                                if(st->robots[x].alive) {
 
444
                                        y = laser[index].start_x-st->robots[x].new_x;
435
445
                                        if(y<0) {
436
 
                                                y = robots[x].new_x-laser[index].start_x;
 
446
                                                y = st->robots[x].new_x-laser[index].start_x;
437
447
                                        }
438
 
                                        z = laser[index].start_y-robots[x].new_y;
 
448
                                        z = laser[index].start_y-st->robots[x].new_y;
439
449
                                        if(z<0) {
440
 
                                                z = robots[x].new_y-laser[index].start_y;
 
450
                                                z = st->robots[x].new_y-laser[index].start_y;
441
451
                                        }
442
 
                                        if((z<robots[x].radius-1)&&(y<robots[x].radius-1)) {
443
 
                                                robots[x].alive = 0;
444
 
                                                robots[x].death = 20;
445
 
                                                XFillArc(dpy, window, black, robots[x].old_x, robots[x].old_y, robots[x].radius, robots[x].radius, 0, 360*64);
446
 
                                                XFillArc(dpy, window, black, robots[x].new_x, robots[x].new_y, robots[x].radius, robots[x].radius, 0, 360*64);
 
452
                                        if((z<st->robots[x].radius-1)&&(y<st->robots[x].radius-1)) {
 
453
                                                st->robots[x].alive = 0;
 
454
                                                st->robots[x].death = 20;
 
455
            if (st->black) XFillArc(st->dpy, st->window, st->black, st->robots[x].old_x, st->robots[x].old_y, st->robots[x].radius, st->robots[x].radius, 0, 360*64);
 
456
            if (st->black) XFillArc(st->dpy, st->window, st->black, st->robots[x].new_x, st->robots[x].new_y, st->robots[x].radius, st->robots[x].radius, 0, 360*64);
447
457
                                                laser[index].active = 0;
448
 
                                                x = NUM_ROBOTS;
 
458
                                                x = st->NUM_ROBOTS;
449
459
                                        }
450
460
                                        else {
451
 
                                                y = laser[index].end_x-robots[x].new_x;
 
461
                                                y = laser[index].end_x-st->robots[x].new_x;
452
462
                                                if(y<0) {
453
 
                                                        y = robots[x].new_x-laser[index].end_x;
 
463
                                                        y = st->robots[x].new_x-laser[index].end_x;
454
464
                                                }
455
 
                                                z = laser[index].end_y-robots[x].new_y;
 
465
                                                z = laser[index].end_y-st->robots[x].new_y;
456
466
                                                if(z<0) {
457
 
                                                        z = robots[x].new_y-laser[index].end_y;
 
467
                                                        z = st->robots[x].new_y-laser[index].end_y;
458
468
                                                }
459
 
                                                if((z<robots[x].radius-1)&&(y<robots[x].radius-1)) {
460
 
                                                        robots[x].alive = 0;
461
 
                                                        robots[x].death = 20;
462
 
                                                        XFillArc(dpy, window, black, robots[x].old_x, robots[x].old_y, robots[x].radius, robots[x].radius, 0, 360*64);
463
 
                                                        XFillArc(dpy, window, black, robots[x].new_x, robots[x].new_y, robots[x].radius, robots[x].radius, 0, 360*64);
 
469
                                                if((z<st->robots[x].radius-1)&&(y<st->robots[x].radius-1)) {
 
470
                                                        st->robots[x].alive = 0;
 
471
                                                        st->robots[x].death = 20;
 
472
            if (st->black) XFillArc(st->dpy, st->window, st->black, st->robots[x].old_x, st->robots[x].old_y, st->robots[x].radius, st->robots[x].radius, 0, 360*64);
 
473
            if (st->black) XFillArc(st->dpy, st->window, st->black, st->robots[x].new_x, st->robots[x].new_y, st->robots[x].radius, st->robots[x].radius, 0, 360*64);
464
474
                                                        laser[index].active = 0;
465
 
                                                        x = NUM_ROBOTS;
 
475
                                                        x = st->NUM_ROBOTS;
466
476
                                                }
467
477
                                        }
468
478
                                }
469
479
                        }
470
480
                }
471
 
                if((MOTHER_SHIP)&&(rindex!=-1)) {
 
481
                if((st->MOTHER_SHIP)&&(rindex!=-1)) {
472
482
                        if(laser[index].active) {
473
 
                                if(mother->active) {
474
 
                                        y = laser[index].start_x-mother->new_x;
 
483
                                if(st->mother->active) {
 
484
                                        y = laser[index].start_x-st->mother->new_x;
475
485
                                        if(y<0) {
476
 
                                                y = mother->new_x-laser[index].start_x;
 
486
                                                y = st->mother->new_x-laser[index].start_x;
477
487
                                        }
478
 
                                        z = laser[index].start_y-mother->y;
 
488
                                        z = laser[index].start_y-st->mother->y;
479
489
                                        if(z<0) {
480
 
                                                z = mother->y-laser[index].start_y;
 
490
                                                z = st->mother->y-laser[index].start_y;
481
491
                                        }
482
 
                                        if((z<MOTHER_SHIP_HEIGHT-1)&&(y<MOTHER_SHIP_WIDTH-1)) {
 
492
                                        if((z<st->MOTHER_SHIP_HEIGHT-1)&&(y<st->MOTHER_SHIP_WIDTH-1)) {
483
493
                                                laser[index].active = 0;
484
 
                                                mother->active--;
 
494
                                                st->mother->active--;
485
495
                                        }
486
496
                                        else {
487
 
                                                y = laser[index].end_x-mother->new_x;
 
497
                                                y = laser[index].end_x-st->mother->new_x;
488
498
                                                if(y<0) {
489
 
                                                        y = mother->new_x-laser[index].end_x;
 
499
                                                        y = st->mother->new_x-laser[index].end_x;
490
500
                                                }
491
 
                                                z = laser[index].end_y-mother->y;
 
501
                                                z = laser[index].end_y-st->mother->y;
492
502
                                                if(z<0) {
493
 
                                                        z = mother->y-laser[index].end_y;
 
503
                                                        z = st->mother->y-laser[index].end_y;
494
504
                                                }
495
 
                                                if((z<MOTHER_SHIP_HEIGHT-1)&&(y<MOTHER_SHIP_WIDTH-1)) {
 
505
                                                if((z<st->MOTHER_SHIP_HEIGHT-1)&&(y<st->MOTHER_SHIP_WIDTH-1)) {
496
506
                                                        laser[index].active = 0;
497
 
                                                        mother->active--;
 
507
                                                        st->mother->active--;
498
508
                                                }
499
509
                                        }
500
510
 
501
 
                                        if(mother->active==0) {
502
 
                                                mother->death=20;
 
511
                                        if(st->mother->active==0) {
 
512
                                                st->mother->death=20;
503
513
                                        }
504
514
                                }
505
515
                        }
514
524
                        laser[index].end_x = laser[index].end_x-dx;
515
525
                        laser[index].end_y = laser[index].end_y-dy;
516
526
                        
517
 
                        if((laser[index].end_x < 0) || (laser[index].end_x >= xgwa.width) ||
518
 
                                (laser[index].end_y < 0) || (laser[index].end_y >= xgwa.height)) {
 
527
                        if((laser[index].end_x < 0) || (laser[index].end_x >= st->xgwa.width) ||
 
528
                                (laser[index].end_y < 0) || (laser[index].end_y >= st->xgwa.height)) {
519
529
                                laser[index].active = 0;
520
530
                        }                               
521
531
                }
525
535
/* All the robots are drawn, including the mother ship and the explosions.
526
536
        After all the robots have been drawn, their laser banks are check and
527
537
        the active lasers are drawn. */
528
 
static void draw_robots(void)
 
538
static void draw_robots(struct state *st)
529
539
{
530
540
        int x=0;
531
541
        int y=0;
532
542
 
533
 
        for(x=0;x<NUM_ROBOTS;x++) {
534
 
                if(robots[x].alive) {
535
 
                        XFillArc(dpy, window, black, robots[x].old_x, robots[x].old_y, robots[x].radius, robots[x].radius, 0, 360*64);
536
 
                        XFillArc(dpy, window, robots[x].robot_color, robots[x].new_x, robots[x].new_y, robots[x].radius, robots[x].radius, 0, 360*64);
 
543
        for(x=0;x<st->NUM_ROBOTS;x++) {
 
544
                if(st->robots[x].alive) {
 
545
      if (st->black) XFillArc(st->dpy, st->window, st->black, st->robots[x].old_x, st->robots[x].old_y, st->robots[x].radius, st->robots[x].radius, 0, 360*64);
 
546
                        XFillArc(st->dpy, st->window, st->robots[x].robot_color, st->robots[x].new_x, st->robots[x].new_y, st->robots[x].radius, st->robots[x].radius, 0, 360*64);
537
547
                }
538
548
                else {
539
 
                        XFillArc(dpy, window, black, robots[x].old_x, robots[x].old_y, robots[x].radius, robots[x].radius, 0, 360*64);
540
 
                        if(robots[x].death) {
541
 
                                if(robots[x].death==20) {
542
 
                                        XFillArc(dpy, window, EXPLODE_COLOR_1, robots[x].new_x+(robots[x].radius/3), robots[x].new_y+(robots[x].radius/3), EXPLODE_SIZE_1, EXPLODE_SIZE_1, 0, 360*64);
543
 
                                }
544
 
                                else if(robots[x].death==18) {
545
 
                                        XFillArc(dpy, window, EXPLODE_COLOR_2, robots[x].new_x+(robots[x].radius/3), robots[x].new_y+(robots[x].radius/3), EXPLODE_SIZE_1, EXPLODE_SIZE_1, 0, 360*64);
546
 
                                }
547
 
                                else if(robots[x].death==17) {
548
 
                                        XFillArc(dpy, window, EXPLODE_COLOR_1, robots[x].new_x+(robots[x].radius/3), robots[x].new_y+(robots[x].radius/3), EXPLODE_SIZE_1, EXPLODE_SIZE_1, 0, 360*64);
549
 
                                }
550
 
                                else if(robots[x].death==15) {
551
 
                                        XFillArc(dpy, window, black, robots[x].new_x+(robots[x].radius/3), robots[x].new_y+(robots[x].radius/3), EXPLODE_SIZE_1, EXPLODE_SIZE_1, 0, 360*64);
552
 
                                }
553
 
                                else if(robots[x].death==14) {
554
 
                                        XFillArc(dpy, window, EXPLODE_COLOR_2, robots[x].new_x+(robots[x].radius/3), robots[x].new_y+(robots[x].radius/3), EXPLODE_SIZE_1, EXPLODE_SIZE_1, 0, 360*64);
555
 
                                }
556
 
                                else if(robots[x].death==13) {
557
 
                                        XFillArc(dpy, window, black, robots[x].new_x+(robots[x].radius/3), robots[x].new_y+(robots[x].radius/3), EXPLODE_SIZE_1, EXPLODE_SIZE_1, 0, 360*64);
558
 
                                }
559
 
                                else if(robots[x].death==12) {
560
 
                                        XFillArc(dpy, window, EXPLODE_COLOR_1, robots[x].new_x+(robots[x].radius/3), robots[x].new_y+(robots[x].radius/3), EXPLODE_SIZE_1, EXPLODE_SIZE_1, 0, 360*64);
561
 
                                }
562
 
                                else if(robots[x].death==11) {
563
 
                                        XFillArc(dpy, window, black, robots[x].new_x+(robots[x].radius/3), robots[x].new_y+(robots[x].radius/3), EXPLODE_SIZE_1, EXPLODE_SIZE_1, 0, 360*64);
564
 
                                }
565
 
                                else if(robots[x].death==10) {
566
 
                                        XFillArc(dpy, window, EXPLODE_COLOR_2, robots[x].new_x+(robots[x].radius/3), robots[x].new_y+(robots[x].radius/3), EXPLODE_SIZE_1, EXPLODE_SIZE_1, 0, 360*64);
567
 
                                }
568
 
                                else if(robots[x].death==9) {
569
 
                                        XFillArc(dpy, window, black, robots[x].new_x+(robots[x].radius/3), robots[x].new_y+(robots[x].radius/3), EXPLODE_SIZE_1, EXPLODE_SIZE_1, 0, 360*64);
570
 
                                }
571
 
                                else if(robots[x].death==8) {
572
 
                                        XFillArc(dpy, window, EXPLODE_COLOR_1, robots[x].new_x+(robots[x].radius/3), robots[x].new_y+(robots[x].radius/3), EXPLODE_SIZE_1, EXPLODE_SIZE_1, 0, 360*64);
573
 
                                }
574
 
                                else if(robots[x].death==7) {
575
 
                                        XFillArc(dpy, window, black, robots[x].new_x+(robots[x].radius/3), robots[x].new_y+(robots[x].radius/3), EXPLODE_SIZE_1, EXPLODE_SIZE_1, 0, 360*64);
576
 
                                }
577
 
                                else if(robots[x].death==6) {
578
 
                                        XFillArc(dpy, window, EXPLODE_COLOR_2, robots[x].new_x+(robots[x].radius/3), robots[x].new_y+(robots[x].radius/3), EXPLODE_SIZE_2, EXPLODE_SIZE_2, 0, 360*64);
579
 
                                }
580
 
                                else if(robots[x].death==4) {
581
 
                                        XFillArc(dpy, window, black, robots[x].new_x+(robots[x].radius/3), robots[x].new_y+(robots[x].radius/3), EXPLODE_SIZE_2, EXPLODE_SIZE_2, 0, 360*64);
582
 
                                }
583
 
                                else if(robots[x].death==3) {
584
 
                                        XFillArc(dpy, window, EXPLODE_COLOR_1, robots[x].new_x+(robots[x].radius/3), robots[x].new_y+(robots[x].radius/3), EXPLODE_SIZE_2, EXPLODE_SIZE_2, 0, 360*64);
585
 
                                }
586
 
                                else if(robots[x].death==2) {
587
 
                                        XFillArc(dpy, window, black, robots[x].new_x+(robots[x].radius/3), robots[x].new_y+(robots[x].radius/3), EXPLODE_SIZE_2, EXPLODE_SIZE_2, 0, 360*64);
588
 
                                        XFillArc(dpy, window, EXPLODE_COLOR_2, robots[x].new_x+(1.7*robots[x].radius/2), robots[x].new_y+(1.7*robots[x].radius/2), EXPLODE_SIZE_3, EXPLODE_SIZE_3, 0, 360*64);
589
 
                                }
590
 
                                else if(robots[x].death==1) {
591
 
                                        XFillArc(dpy, window, black, robots[x].new_x+(1.7*robots[x].radius/2), robots[x].new_y+(1.7*robots[x].radius/2), EXPLODE_SIZE_3, EXPLODE_SIZE_3, 0, 360*64);
592
 
                                }
593
 
                                robots[x].death--;
 
549
                        if (st->black) XFillArc(st->dpy, st->window, st->black, st->robots[x].old_x, st->robots[x].old_y, st->robots[x].radius, st->robots[x].radius, 0, 360*64);
 
550
                        if(st->robots[x].death) {
 
551
                                if(st->robots[x].death==20) {
 
552
                                        XFillArc(st->dpy, st->window, st->EXPLODE_COLOR_1, st->robots[x].new_x+(st->robots[x].radius/3), st->robots[x].new_y+(st->robots[x].radius/3), st->EXPLODE_SIZE_1, st->EXPLODE_SIZE_1, 0, 360*64);
 
553
                                }
 
554
                                else if(st->robots[x].death==18) {
 
555
                                        XFillArc(st->dpy, st->window, st->EXPLODE_COLOR_2, st->robots[x].new_x+(st->robots[x].radius/3), st->robots[x].new_y+(st->robots[x].radius/3), st->EXPLODE_SIZE_1, st->EXPLODE_SIZE_1, 0, 360*64);
 
556
                                }
 
557
                                else if(st->robots[x].death==17) {
 
558
                                        XFillArc(st->dpy, st->window, st->EXPLODE_COLOR_1, st->robots[x].new_x+(st->robots[x].radius/3), st->robots[x].new_y+(st->robots[x].radius/3), st->EXPLODE_SIZE_1, st->EXPLODE_SIZE_1, 0, 360*64);
 
559
                                }
 
560
                                else if(st->robots[x].death==15) {
 
561
                                        if (st->black) XFillArc(st->dpy, st->window, st->black, st->robots[x].new_x+(st->robots[x].radius/3), st->robots[x].new_y+(st->robots[x].radius/3), st->EXPLODE_SIZE_1, st->EXPLODE_SIZE_1, 0, 360*64);
 
562
                                }
 
563
                                else if(st->robots[x].death==14) {
 
564
                                        XFillArc(st->dpy, st->window, st->EXPLODE_COLOR_2, st->robots[x].new_x+(st->robots[x].radius/3), st->robots[x].new_y+(st->robots[x].radius/3), st->EXPLODE_SIZE_1, st->EXPLODE_SIZE_1, 0, 360*64);
 
565
                                }
 
566
                                else if(st->robots[x].death==13) {
 
567
          if (st->black) XFillArc(st->dpy, st->window, st->black, st->robots[x].new_x+(st->robots[x].radius/3), st->robots[x].new_y+(st->robots[x].radius/3), st->EXPLODE_SIZE_1, st->EXPLODE_SIZE_1, 0, 360*64);
 
568
                                }
 
569
                                else if(st->robots[x].death==12) {
 
570
                                        XFillArc(st->dpy, st->window, st->EXPLODE_COLOR_1, st->robots[x].new_x+(st->robots[x].radius/3), st->robots[x].new_y+(st->robots[x].radius/3), st->EXPLODE_SIZE_1, st->EXPLODE_SIZE_1, 0, 360*64);
 
571
                                }
 
572
                                else if(st->robots[x].death==11) {
 
573
                                        if (st->black) XFillArc(st->dpy, st->window, st->black, st->robots[x].new_x+(st->robots[x].radius/3), st->robots[x].new_y+(st->robots[x].radius/3), st->EXPLODE_SIZE_1, st->EXPLODE_SIZE_1, 0, 360*64);
 
574
                                }
 
575
                                else if(st->robots[x].death==10) {
 
576
                                        XFillArc(st->dpy, st->window, st->EXPLODE_COLOR_2, st->robots[x].new_x+(st->robots[x].radius/3), st->robots[x].new_y+(st->robots[x].radius/3), st->EXPLODE_SIZE_1, st->EXPLODE_SIZE_1, 0, 360*64);
 
577
                                }
 
578
                                else if(st->robots[x].death==9) {
 
579
          if (st->black) XFillArc(st->dpy, st->window, st->black, st->robots[x].new_x+(st->robots[x].radius/3), st->robots[x].new_y+(st->robots[x].radius/3), st->EXPLODE_SIZE_1, st->EXPLODE_SIZE_1, 0, 360*64);
 
580
                                }
 
581
                                else if(st->robots[x].death==8) {
 
582
                                        XFillArc(st->dpy, st->window, st->EXPLODE_COLOR_1, st->robots[x].new_x+(st->robots[x].radius/3), st->robots[x].new_y+(st->robots[x].radius/3), st->EXPLODE_SIZE_1, st->EXPLODE_SIZE_1, 0, 360*64);
 
583
                                }
 
584
                                else if(st->robots[x].death==7) {
 
585
                                        if (st->black) XFillArc(st->dpy, st->window, st->black, st->robots[x].new_x+(st->robots[x].radius/3), st->robots[x].new_y+(st->robots[x].radius/3), st->EXPLODE_SIZE_1, st->EXPLODE_SIZE_1, 0, 360*64);
 
586
                                }
 
587
                                else if(st->robots[x].death==6) {
 
588
                                        XFillArc(st->dpy, st->window, st->EXPLODE_COLOR_2, st->robots[x].new_x+(st->robots[x].radius/3), st->robots[x].new_y+(st->robots[x].radius/3), st->EXPLODE_SIZE_2, st->EXPLODE_SIZE_2, 0, 360*64);
 
589
                                }
 
590
                                else if(st->robots[x].death==4) {
 
591
                                        if (st->black) XFillArc(st->dpy, st->window, st->black, st->robots[x].new_x+(st->robots[x].radius/3), st->robots[x].new_y+(st->robots[x].radius/3), st->EXPLODE_SIZE_2, st->EXPLODE_SIZE_2, 0, 360*64);
 
592
                                }
 
593
                                else if(st->robots[x].death==3) {
 
594
                                        XFillArc(st->dpy, st->window, st->EXPLODE_COLOR_1, st->robots[x].new_x+(st->robots[x].radius/3), st->robots[x].new_y+(st->robots[x].radius/3), st->EXPLODE_SIZE_2, st->EXPLODE_SIZE_2, 0, 360*64);
 
595
                                }
 
596
                                else if(st->robots[x].death==2) {
 
597
                                        if (st->black) XFillArc(st->dpy, st->window, st->black, st->robots[x].new_x+(st->robots[x].radius/3), st->robots[x].new_y+(st->robots[x].radius/3), st->EXPLODE_SIZE_2, st->EXPLODE_SIZE_2, 0, 360*64);
 
598
                                        XFillArc(st->dpy, st->window, st->EXPLODE_COLOR_2, st->robots[x].new_x+(1.7*st->robots[x].radius/2), st->robots[x].new_y+(1.7*st->robots[x].radius/2), st->EXPLODE_SIZE_3, st->EXPLODE_SIZE_3, 0, 360*64);
 
599
                                }
 
600
                                else if(st->robots[x].death==1) {
 
601
          if (st->black) XFillArc(st->dpy, st->window, st->black, st->robots[x].new_x+(1.7*st->robots[x].radius/2), st->robots[x].new_y+(1.7*st->robots[x].radius/2), st->EXPLODE_SIZE_3, st->EXPLODE_SIZE_3, 0, 360*64);
 
602
                                }
 
603
                                st->robots[x].death--;
594
604
                        }
595
605
                }
596
606
        }
597
607
 
598
 
        for(x=0;x<NUM_ROBOTS;x++) {
599
 
                for(y=0;y<NUM_LASERS;y++) {
600
 
                        if(robots[x].lasers[y].active) {
601
 
                                XDrawLine(dpy, window, black, robots[x].lasers[y].start_x,
602
 
                                                         robots[x].lasers[y].start_y,
603
 
                                                         robots[x].lasers[y].end_x,
604
 
                                                         robots[x].lasers[y].end_y);
605
 
                                move_laser(x, y);
606
 
                                if(robots[x].lasers[y].active) {
607
 
                                        XDrawLine(dpy, window, robots[x].laser_color, robots[x].lasers[y].start_x,
608
 
                                                                 robots[x].lasers[y].start_y,
609
 
                                                                 robots[x].lasers[y].end_x,
610
 
                                                                 robots[x].lasers[y].end_y);
 
608
        for(x=0;x<st->NUM_ROBOTS;x++) {
 
609
                for(y=0;y<st->NUM_LASERS;y++) {
 
610
                        if(st->robots[x].lasers[y].active) {
 
611
                                if (st->black) XDrawLine(st->dpy, st->window, st->black, st->robots[x].lasers[y].start_x,
 
612
                                                         st->robots[x].lasers[y].start_y,
 
613
                                                         st->robots[x].lasers[y].end_x,
 
614
                                                         st->robots[x].lasers[y].end_y);
 
615
                                move_laser(st, x, y);
 
616
                                if(st->robots[x].lasers[y].active) {
 
617
                                        XDrawLine(st->dpy, st->window, st->robots[x].laser_color, st->robots[x].lasers[y].start_x,
 
618
                                                                 st->robots[x].lasers[y].start_y,
 
619
                                                                 st->robots[x].lasers[y].end_x,
 
620
                                                                 st->robots[x].lasers[y].end_y);
611
621
                                }
612
622
                                else {
613
 
                                        XDrawLine(dpy, window, black, robots[x].lasers[y].start_x,
614
 
                                                                 robots[x].lasers[y].start_y,
615
 
                                                                 robots[x].lasers[y].end_x,
616
 
                                                                 robots[x].lasers[y].end_y);
 
623
                                        if (st->black) XDrawLine(st->dpy, st->window, st->black, st->robots[x].lasers[y].start_x,
 
624
                                                                 st->robots[x].lasers[y].start_y,
 
625
                                                                 st->robots[x].lasers[y].end_x,
 
626
                                                                 st->robots[x].lasers[y].end_y);
617
627
                                }                                       
618
628
                        }
619
629
                }
620
630
        }
621
631
 
622
 
        if(MOTHER_SHIP) {
623
 
                if(mother->active) {
624
 
                        XFillArc(dpy, window, black, mother->old_x, mother->y, MOTHER_SHIP_WIDTH, MOTHER_SHIP_HEIGHT, 0 , 360*64);
625
 
                        XFillArc(dpy, window, mother->ship_color, mother->new_x, mother->y, MOTHER_SHIP_WIDTH, MOTHER_SHIP_HEIGHT, 0 , 360*64);
 
632
        if(st->MOTHER_SHIP) {
 
633
                if(st->mother->active) {
 
634
                        if (st->black) XFillArc(st->dpy, st->window, st->black, st->mother->old_x, st->mother->y, st->MOTHER_SHIP_WIDTH, st->MOTHER_SHIP_HEIGHT, 0 , 360*64);
 
635
                        XFillArc(st->dpy, st->window, st->mother->ship_color, st->mother->new_x, st->mother->y, st->MOTHER_SHIP_WIDTH, st->MOTHER_SHIP_HEIGHT, 0 , 360*64);
626
636
                }
627
637
                else {
628
 
                        if(mother->death) {
629
 
                                XFillArc(dpy, window, black, mother->old_x, mother->y, MOTHER_SHIP_WIDTH, MOTHER_SHIP_HEIGHT, 0 , 360*64);
630
 
                                if(mother->death==20) {
631
 
                                        XFillArc(dpy, window, EXPLODE_COLOR_1, mother->new_x+1, mother->y+1, EXPLODE_SIZE_1, EXPLODE_SIZE_1, 0, 360*64);
632
 
                                }
633
 
                                else if(mother->death==18) {
634
 
                                        XFillArc(dpy, window, EXPLODE_COLOR_2, mother->new_x+1, mother->y+1, EXPLODE_SIZE_1, EXPLODE_SIZE_1, 0, 360*64);
635
 
                                }
636
 
                                else if(mother->death==17) {
637
 
                                        XFillArc(dpy, window, EXPLODE_COLOR_1, mother->new_x+1, mother->y+1, EXPLODE_SIZE_1, EXPLODE_SIZE_1, 0, 360*64);
638
 
                                }
639
 
                                else if(mother->death==15) {
640
 
                                        XFillArc(dpy, window, black, mother->new_x+1, mother->y+1, EXPLODE_SIZE_1, EXPLODE_SIZE_1, 0, 360*64);
641
 
                                }
642
 
                                else if(mother->death==14) {
643
 
                                        XFillArc(dpy, window, EXPLODE_COLOR_2, mother->new_x+1, mother->y+1, EXPLODE_SIZE_1, EXPLODE_SIZE_1, 0, 360*64);
644
 
                                }
645
 
                                else if(mother->death==13) {
646
 
                                        XFillArc(dpy, window, black, mother->new_x+1, mother->y+1, EXPLODE_SIZE_1, EXPLODE_SIZE_1, 0, 360*64);
647
 
                                }
648
 
                                else if(mother->death==12) {
649
 
                                        XFillArc(dpy, window, EXPLODE_COLOR_1, mother->new_x+1, mother->y+1, EXPLODE_SIZE_1, EXPLODE_SIZE_1, 0, 360*64);
650
 
                                }
651
 
                                else if(mother->death==11) {
652
 
                                        XFillArc(dpy, window, black, mother->new_x+1, mother->y+1, EXPLODE_SIZE_1, EXPLODE_SIZE_1, 0, 360*64);
653
 
                                }
654
 
                                else if(mother->death==10) {
655
 
                                        XFillArc(dpy, window, EXPLODE_COLOR_2, mother->new_x+1, mother->y+1, EXPLODE_SIZE_1, EXPLODE_SIZE_1, 0, 360*64);
656
 
                                }
657
 
                                else if(mother->death==9) {
658
 
                                        XFillArc(dpy, window, black, mother->new_x+1, mother->y+1, EXPLODE_SIZE_1, EXPLODE_SIZE_1, 0, 360*64);
659
 
                                }
660
 
                                else if(mother->death==8) {
661
 
                                        XFillArc(dpy, window, EXPLODE_COLOR_1, mother->new_x+1, mother->y+1, EXPLODE_SIZE_1, EXPLODE_SIZE_1, 0, 360*64);
662
 
                                }
663
 
                                else if(mother->death==7) {
664
 
                                        XFillArc(dpy, window, black, mother->new_x+1, mother->y+1, EXPLODE_SIZE_1, EXPLODE_SIZE_1, 0, 360*64);
665
 
                                }
666
 
                                else if(mother->death==6) {
667
 
                                        XFillArc(dpy, window, EXPLODE_COLOR_2, mother->new_x+1, mother->y+1, EXPLODE_SIZE_2, EXPLODE_SIZE_2, 0, 360*64);
668
 
                                }
669
 
                                else if(mother->death==4) {
670
 
                                        XFillArc(dpy, window, black, mother->new_x+1, mother->y+1, EXPLODE_SIZE_2, EXPLODE_SIZE_2, 0, 360*64);
671
 
                                }
672
 
                                else if(mother->death==3) {
673
 
                                        XFillArc(dpy, window, EXPLODE_COLOR_1, mother->new_x+1, mother->y+1, EXPLODE_SIZE_2, EXPLODE_SIZE_2, 0, 360*64);
674
 
                                }
675
 
                                else if(mother->death==2) {
676
 
                                        XFillArc(dpy, window, black, mother->new_x+1, mother->y+1, EXPLODE_SIZE_2, EXPLODE_SIZE_2, 0, 360*64);
677
 
                                        XFillArc(dpy, window, EXPLODE_COLOR_2, mother->new_x+(1.7*MOTHER_SHIP_WIDTH/2), mother->y+(1.7*MOTHER_SHIP_HEIGHT/2), EXPLODE_SIZE_3, EXPLODE_SIZE_3, 0, 360*64);
678
 
                                }
679
 
                                else if(mother->death==1) {
680
 
                                        XFillArc(dpy, window, black, mother->new_x+(1.7*MOTHER_SHIP_WIDTH/2), mother->y+(1.7*MOTHER_SHIP_HEIGHT/2), EXPLODE_SIZE_3, EXPLODE_SIZE_3, 0, 360*64);
681
 
                                }
682
 
                                mother->death--;
 
638
                        if(st->mother->death) {
 
639
                                if (st->black) XFillArc(st->dpy, st->window, st->black, st->mother->old_x, st->mother->y, st->MOTHER_SHIP_WIDTH, st->MOTHER_SHIP_HEIGHT, 0 , 360*64);
 
640
                                if(st->mother->death==20) {
 
641
                                        XFillArc(st->dpy, st->window, st->EXPLODE_COLOR_1, st->mother->new_x+1, st->mother->y+1, st->EXPLODE_SIZE_1, st->EXPLODE_SIZE_1, 0, 360*64);
 
642
                                }
 
643
                                else if(st->mother->death==18) {
 
644
                                        XFillArc(st->dpy, st->window, st->EXPLODE_COLOR_2, st->mother->new_x+1, st->mother->y+1, st->EXPLODE_SIZE_1, st->EXPLODE_SIZE_1, 0, 360*64);
 
645
                                }
 
646
                                else if(st->mother->death==17) {
 
647
                                        XFillArc(st->dpy, st->window, st->EXPLODE_COLOR_1, st->mother->new_x+1, st->mother->y+1, st->EXPLODE_SIZE_1, st->EXPLODE_SIZE_1, 0, 360*64);
 
648
                                }
 
649
                                else if(st->mother->death==15) {
 
650
                                        if (st->black) XFillArc(st->dpy, st->window, st->black, st->mother->new_x+1, st->mother->y+1, st->EXPLODE_SIZE_1, st->EXPLODE_SIZE_1, 0, 360*64);
 
651
                                }
 
652
                                else if(st->mother->death==14) {
 
653
                                        XFillArc(st->dpy, st->window, st->EXPLODE_COLOR_2, st->mother->new_x+1, st->mother->y+1, st->EXPLODE_SIZE_1, st->EXPLODE_SIZE_1, 0, 360*64);
 
654
                                }
 
655
                                else if(st->mother->death==13) {
 
656
                                        if (st->black) XFillArc(st->dpy, st->window, st->black, st->mother->new_x+1, st->mother->y+1, st->EXPLODE_SIZE_1, st->EXPLODE_SIZE_1, 0, 360*64);
 
657
                                }
 
658
                                else if(st->mother->death==12) {
 
659
                                        XFillArc(st->dpy, st->window, st->EXPLODE_COLOR_1, st->mother->new_x+1, st->mother->y+1, st->EXPLODE_SIZE_1, st->EXPLODE_SIZE_1, 0, 360*64);
 
660
                                }
 
661
                                else if(st->mother->death==11) {
 
662
                                        if (st->black) XFillArc(st->dpy, st->window, st->black, st->mother->new_x+1, st->mother->y+1, st->EXPLODE_SIZE_1, st->EXPLODE_SIZE_1, 0, 360*64);
 
663
                                }
 
664
                                else if(st->mother->death==10) {
 
665
                                        XFillArc(st->dpy, st->window, st->EXPLODE_COLOR_2, st->mother->new_x+1, st->mother->y+1, st->EXPLODE_SIZE_1, st->EXPLODE_SIZE_1, 0, 360*64);
 
666
                                }
 
667
                                else if(st->mother->death==9) {
 
668
                                        if (st->black) XFillArc(st->dpy, st->window, st->black, st->mother->new_x+1, st->mother->y+1, st->EXPLODE_SIZE_1, st->EXPLODE_SIZE_1, 0, 360*64);
 
669
                                }
 
670
                                else if(st->mother->death==8) {
 
671
                                        XFillArc(st->dpy, st->window, st->EXPLODE_COLOR_1, st->mother->new_x+1, st->mother->y+1, st->EXPLODE_SIZE_1, st->EXPLODE_SIZE_1, 0, 360*64);
 
672
                                }
 
673
                                else if(st->mother->death==7) {
 
674
                                        if (st->black) XFillArc(st->dpy, st->window, st->black, st->mother->new_x+1, st->mother->y+1, st->EXPLODE_SIZE_1, st->EXPLODE_SIZE_1, 0, 360*64);
 
675
                                }
 
676
                                else if(st->mother->death==6) {
 
677
                                        XFillArc(st->dpy, st->window, st->EXPLODE_COLOR_2, st->mother->new_x+1, st->mother->y+1, st->EXPLODE_SIZE_2, st->EXPLODE_SIZE_2, 0, 360*64);
 
678
                                }
 
679
                                else if(st->mother->death==4) {
 
680
                                        if (st->black) XFillArc(st->dpy, st->window, st->black, st->mother->new_x+1, st->mother->y+1, st->EXPLODE_SIZE_2, st->EXPLODE_SIZE_2, 0, 360*64);
 
681
                                }
 
682
                                else if(st->mother->death==3) {
 
683
                                        XFillArc(st->dpy, st->window, st->EXPLODE_COLOR_1, st->mother->new_x+1, st->mother->y+1, st->EXPLODE_SIZE_2, st->EXPLODE_SIZE_2, 0, 360*64);
 
684
                                }
 
685
                                else if(st->mother->death==2) {
 
686
                                        if (st->black) XFillArc(st->dpy, st->window, st->black, st->mother->new_x+1, st->mother->y+1, st->EXPLODE_SIZE_2, st->EXPLODE_SIZE_2, 0, 360*64);
 
687
                                        XFillArc(st->dpy, st->window, st->EXPLODE_COLOR_2, st->mother->new_x+(1.7*st->MOTHER_SHIP_WIDTH/2), st->mother->y+(1.7*st->MOTHER_SHIP_HEIGHT/2), st->EXPLODE_SIZE_3, st->EXPLODE_SIZE_3, 0, 360*64);
 
688
                                }
 
689
                                else if(st->mother->death==1) {
 
690
                                        if (st->black) XFillArc(st->dpy, st->window, st->black, st->mother->new_x+(1.7*st->MOTHER_SHIP_WIDTH/2), st->mother->y+(1.7*st->MOTHER_SHIP_HEIGHT/2), st->EXPLODE_SIZE_3, st->EXPLODE_SIZE_3, 0, 360*64);
 
691
                                }
 
692
                                st->mother->death--;
683
693
                        }
684
694
                }
685
695
                for(y=0;y<8;y++) {
686
 
                        if(mother->lasers[y].active) {
687
 
                                XDrawLine(dpy, window, black, mother->lasers[y].start_x,
688
 
                                                         mother->lasers[y].start_y,
689
 
                                                         mother->lasers[y].end_x,
690
 
                                                         mother->lasers[y].end_y);
691
 
                                move_laser(-1,y);
692
 
                                if(mother->lasers[y].active) {
693
 
                                XDrawLine(dpy, window, mother->laser_color, mother->lasers[y].start_x,
694
 
                                                         mother->lasers[y].start_y,
695
 
                                                         mother->lasers[y].end_x,
696
 
                                                         mother->lasers[y].end_y);
 
696
                        if(st->mother->lasers[y].active) {
 
697
                                if (st->black) XDrawLine(st->dpy, st->window, st->black, st->mother->lasers[y].start_x,
 
698
                                                         st->mother->lasers[y].start_y,
 
699
                                                         st->mother->lasers[y].end_x,
 
700
                                                         st->mother->lasers[y].end_y);
 
701
                                move_laser(st, -1,y);
 
702
                                if(st->mother->lasers[y].active) {
 
703
                                XDrawLine(st->dpy, st->window, st->mother->laser_color, st->mother->lasers[y].start_x,
 
704
                                                         st->mother->lasers[y].start_y,
 
705
                                                         st->mother->lasers[y].end_x,
 
706
                                                         st->mother->lasers[y].end_y);
697
707
                                }
698
708
                                else {
699
 
                                        XDrawLine(dpy, window, black, mother->lasers[y].start_x,
700
 
                                                                 mother->lasers[y].start_y,
701
 
                                                                 mother->lasers[y].end_x,
702
 
                                                                 mother->lasers[y].end_y);
 
709
                                        if (st->black) XDrawLine(st->dpy, st->window, st->black, st->mother->lasers[y].start_x,
 
710
                                                                 st->mother->lasers[y].start_y,
 
711
                                                                 st->mother->lasers[y].end_x,
 
712
                                                                 st->mother->lasers[y].end_y);
703
713
                                }
704
714
                        }
705
715
                }
706
716
        }
707
717
}
708
718
 
709
 
/* This is the main loop. The mothership movement and laser firing happens inside
710
 
        this loop. */
711
 
static void 
712
 
start_blaster(void)
713
 
{
714
 
        int x=0;
715
 
        int y=0;
716
 
        int z=0;
717
 
        robots = (struct robot_state *) malloc(NUM_ROBOTS * sizeof (struct robot_state));
718
 
        for(x=0;x<NUM_ROBOTS;x++) {
719
 
                robots[x].alive = 0;
720
 
                robots[x].death = 0;
721
 
                robots[x].lasers = (struct laser_state *) malloc (NUM_LASERS * sizeof(struct laser_state));
722
 
                for(y=0;y<NUM_LASERS;y++) {
723
 
                        robots[x].lasers[y].active = 0;
724
 
                }
725
 
        }
726
 
 
727
 
        if(NUM_STARS) {
728
 
                stars = (XArc *) malloc (NUM_STARS * sizeof(XArc));
729
 
                for(x=0;x<NUM_STARS;x++) {
730
 
                        stars[x].x = random()%xgwa.width;
731
 
                        stars[x].y = random()%xgwa.height;
732
 
                        stars[x].width = random()%4 + 1;
733
 
                        stars[x].height = stars[x].width;
734
 
                        stars[x].angle1 = 0;
735
 
                        stars[x].angle2 = 360 * 64;
736
 
                }
737
 
        }
738
 
 
739
 
        while(1) {
740
 
                if(NUM_STARS) {
741
 
                        if(MOVE_STARS) {
742
 
                                XFillArcs(dpy,window,black,stars,NUM_STARS);
743
 
                                if(MOVE_STARS_RANDOM) {
744
 
                                        y = MOVE_STARS_X;
745
 
                                        z = MOVE_STARS_Y;
 
719
static void
 
720
init_stars(struct state *st)
 
721
{
 
722
  if(st->NUM_STARS) {
 
723
    if (! st->stars)
 
724
      st->stars = (XArc *) malloc (st->NUM_STARS * sizeof(XArc));
 
725
    for(st->draw_x=0;st->draw_x<st->NUM_STARS;st->draw_x++) {
 
726
      st->stars[st->draw_x].x = random()%st->xgwa.width;
 
727
      st->stars[st->draw_x].y = random()%st->xgwa.height;
 
728
      st->stars[st->draw_x].width = random()%4 + 1;
 
729
      st->stars[st->draw_x].height = st->stars[st->draw_x].width;
 
730
      st->stars[st->draw_x].angle1 = 0;
 
731
      st->stars[st->draw_x].angle2 = 360 * 64;
 
732
    }
 
733
  }
 
734
}
 
735
 
 
736
 
 
737
static unsigned long
 
738
blaster_draw (Display *dpy, Window window, void *closure)
 
739
{
 
740
  struct state *st = (struct state *) closure;
 
741
 
 
742
#ifdef HAVE_COCOA       /* Don't second-guess Quartz's double-buffering */
 
743
  XClearWindow (dpy, window);
 
744
#endif
 
745
 
 
746
  if (!st->initted) 
 
747
    {
 
748
      st->initted = 1;
 
749
 
 
750
      st->robots = (struct robot_state *) malloc(st->NUM_ROBOTS * sizeof (struct robot_state));
 
751
      for(st->draw_x=0;st->draw_x<st->NUM_ROBOTS;st->draw_x++) {
 
752
        st->robots[st->draw_x].alive = 0;
 
753
        st->robots[st->draw_x].death = 0;
 
754
        st->robots[st->draw_x].lasers = (struct laser_state *) malloc (st->NUM_LASERS * sizeof(struct laser_state));
 
755
        for(st->draw_y=0;st->draw_y<st->NUM_LASERS;st->draw_y++) {
 
756
          st->robots[st->draw_x].lasers[st->draw_y].active = 0;
 
757
        }
 
758
      }
 
759
 
 
760
      init_stars(st);
 
761
    }
 
762
 
 
763
                if(st->NUM_STARS) {
 
764
                        if(st->MOVE_STARS) {
 
765
                                if (st->black) XFillArcs(st->dpy,st->window,st->black,st->stars,st->NUM_STARS);
 
766
                                if(st->MOVE_STARS_RANDOM) {
 
767
                                        st->draw_y = st->MOVE_STARS_X;
 
768
                                        st->draw_z = st->MOVE_STARS_Y;
746
769
                                        if(random()%167==0) {
747
 
                                                y = (-1)*y;
 
770
                                                st->draw_y = (-1)*st->draw_y;
748
771
                                        }
749
772
                                        if(random()%173==0) {
750
 
                                                z = (-1)*z;
751
 
                                        }
752
 
                                        if(random()%50==0) {
753
 
                                                if(random()%2) {
754
 
                                                        y++;
755
 
                                                        if(y>MOVE_STARS_RANDOM) {
756
 
                                                                y = MOVE_STARS_RANDOM;
757
 
                                                        }
758
 
                                                }
759
 
                                                else {
760
 
                                                        y--;
761
 
                                                        if(y < -(MOVE_STARS_RANDOM)) {
762
 
                                                                y = -(MOVE_STARS_RANDOM);
763
 
                                                        }
764
 
                                                }
765
 
                                        }
766
 
                                        if(random()%50==0) {
767
 
                                                if(random()%2) {
768
 
                                                        z++;
769
 
                                                        if(z>MOVE_STARS_RANDOM) {
770
 
                                                                z = MOVE_STARS_RANDOM;
771
 
                                                        }
772
 
                                                }
773
 
                                                else {
774
 
                                                        z--;
775
 
                                                        if(z < -MOVE_STARS_RANDOM) {
776
 
                                                                z = -MOVE_STARS_RANDOM;
777
 
                                                        }
778
 
                                                }
779
 
                                        }
780
 
                                        MOVE_STARS_X = y;
781
 
                                        MOVE_STARS_Y = z;
782
 
                                        for(x=0;x<NUM_STARS;x++) {
783
 
                                                stars[x].x = stars[x].x + y;
784
 
                                                stars[x].y = stars[x].y + z;
785
 
                                                if(stars[x].x<0) {
786
 
                                                        stars[x].x = stars[x].x + xgwa.width;
787
 
                                                }
788
 
                                                else if(stars[x].x>xgwa.width) {
789
 
                                                        stars[x].x = stars[x].x - xgwa.width;
790
 
                                                }
791
 
                                                if(stars[x].y<0) {
792
 
                                                        stars[x].y = stars[x].y + xgwa.height;
793
 
                                                }
794
 
                                                else if(stars[x].y>xgwa.height) {
795
 
                                                        stars[x].y = stars[x].y - xgwa.height;
 
773
                                                st->draw_z = (-1)*st->draw_z;
 
774
                                        }
 
775
                                        if(random()%50==0) {
 
776
                                                if(random()%2) {
 
777
                                                        st->draw_y++;
 
778
                                                        if(st->draw_y>st->MOVE_STARS_RANDOM) {
 
779
                                                                st->draw_y = st->MOVE_STARS_RANDOM;
 
780
                                                        }
 
781
                                                }
 
782
                                                else {
 
783
                                                        st->draw_y--;
 
784
                                                        if(st->draw_y < -(st->MOVE_STARS_RANDOM)) {
 
785
                                                                st->draw_y = -(st->MOVE_STARS_RANDOM);
 
786
                                                        }
 
787
                                                }
 
788
                                        }
 
789
                                        if(random()%50==0) {
 
790
                                                if(random()%2) {
 
791
                                                        st->draw_z++;
 
792
                                                        if(st->draw_z>st->MOVE_STARS_RANDOM) {
 
793
                                                                st->draw_z = st->MOVE_STARS_RANDOM;
 
794
                                                        }
 
795
                                                }
 
796
                                                else {
 
797
                                                        st->draw_z--;
 
798
                                                        if(st->draw_z < -st->MOVE_STARS_RANDOM) {
 
799
                                                                st->draw_z = -st->MOVE_STARS_RANDOM;
 
800
                                                        }
 
801
                                                }
 
802
                                        }
 
803
                                        st->MOVE_STARS_X = st->draw_y;
 
804
                                        st->MOVE_STARS_Y = st->draw_z;
 
805
                                        for(st->draw_x=0;st->draw_x<st->NUM_STARS;st->draw_x++) {
 
806
                                                st->stars[st->draw_x].x = st->stars[st->draw_x].x + st->draw_y;
 
807
                                                st->stars[st->draw_x].y = st->stars[st->draw_x].y + st->draw_z;
 
808
                                                if(st->stars[st->draw_x].x<0) {
 
809
                                                        st->stars[st->draw_x].x = st->stars[st->draw_x].x + st->xgwa.width;
 
810
                                                }
 
811
                                                else if(st->stars[st->draw_x].x>st->xgwa.width) {
 
812
                                                        st->stars[st->draw_x].x = st->stars[st->draw_x].x - st->xgwa.width;
 
813
                                                }
 
814
                                                if(st->stars[st->draw_x].y<0) {
 
815
                                                        st->stars[st->draw_x].y = st->stars[st->draw_x].y + st->xgwa.height;
 
816
                                                }
 
817
                                                else if(st->stars[st->draw_x].y>st->xgwa.height) {
 
818
                                                        st->stars[st->draw_x].y = st->stars[st->draw_x].y - st->xgwa.height;
796
819
                                                }
797
820
                                        }
798
821
                                }
799
822
                                else {
800
 
                                        for(x=0;x<NUM_STARS;x++) {
801
 
                                                stars[x].x = stars[x].x + MOVE_STARS_X;
802
 
                                                stars[x].y = stars[x].y + MOVE_STARS_Y;
803
 
                                                if(stars[x].x<0) {
804
 
                                                        stars[x].x = stars[x].x + xgwa.width;
805
 
                                                }
806
 
                                                else if(stars[x].x>xgwa.width) {
807
 
                                                        stars[x].x = stars[x].x - xgwa.width;
808
 
                                                }
809
 
                                                if(stars[x].y<0) {
810
 
                                                        stars[x].y = stars[x].y + xgwa.height;
811
 
                                                }
812
 
                                                else if(stars[x].y>xgwa.height) {
813
 
                                                        stars[x].y = stars[x].y - xgwa.height;
 
823
                                        for(st->draw_x=0;st->draw_x<st->NUM_STARS;st->draw_x++) {
 
824
                                                st->stars[st->draw_x].x = st->stars[st->draw_x].x + st->MOVE_STARS_X;
 
825
                                                st->stars[st->draw_x].y = st->stars[st->draw_x].y + st->MOVE_STARS_Y;
 
826
                                                if(st->stars[st->draw_x].x<0) {
 
827
                                                        st->stars[st->draw_x].x = st->stars[st->draw_x].x + st->xgwa.width;
 
828
                                                }
 
829
                                                else if(st->stars[st->draw_x].x>st->xgwa.width) {
 
830
                                                        st->stars[st->draw_x].x = st->stars[st->draw_x].x - st->xgwa.width;
 
831
                                                }
 
832
                                                if(st->stars[st->draw_x].y<0) {
 
833
                                                        st->stars[st->draw_x].y = st->stars[st->draw_x].y + st->xgwa.height;
 
834
                                                }
 
835
                                                else if(st->stars[st->draw_x].y>st->xgwa.height) {
 
836
                                                        st->stars[st->draw_x].y = st->stars[st->draw_x].y - st->xgwa.height;
814
837
                                                }
815
838
                                        }
816
839
                                }
817
 
                                XFillArcs(dpy,window,s_color,stars,NUM_STARS);
 
840
                                XFillArcs(st->dpy,st->window,st->s_color,st->stars,st->NUM_STARS);
818
841
                        }
819
842
                        else {
820
 
                                XFillArcs(dpy,window,s_color,stars,NUM_STARS);
 
843
                                XFillArcs(st->dpy,st->window,st->s_color,st->stars,st->NUM_STARS);
821
844
                        }
822
845
                }
823
846
 
824
 
                if(MOTHER_SHIP) {
825
 
                        if(random()%MOTHER_SHIP_PERIOD==0) {
826
 
                                if((mother->active==0)&&(mother->death==0)) {
827
 
                                        mother->active = MOTHER_SHIP_HITS;
828
 
                                        mother->y = random()%(xgwa.height-7);
 
847
                if(st->MOTHER_SHIP) {
 
848
                        if(random()%st->MOTHER_SHIP_PERIOD==0) {
 
849
                                if((st->mother->active==0)&&(st->mother->death==0)) {
 
850
                                        st->mother->active = st->MOTHER_SHIP_HITS;
 
851
                                        st->mother->y = random()%(st->xgwa.height-7);
829
852
                                        if(random()%2==0) {
830
 
                                                mother->old_x=0;
831
 
                                                mother->new_x=0;
 
853
                                                st->mother->old_x=0;
 
854
                                                st->mother->new_x=0;
832
855
                                        }
833
856
                                        else {
834
 
                                                mother->old_x=xgwa.width-25;
835
 
                                                mother->new_x=xgwa.width-25;
 
857
                                                st->mother->old_x=st->xgwa.width-25;
 
858
                                                st->mother->new_x=st->xgwa.width-25;
836
859
                                        }
837
860
                                }
838
861
                        }
839
862
                }
840
 
                move_robots();
841
 
                if(MOTHER_SHIP) {
842
 
                        if(mother->active) {
843
 
                                if(mother->old_x==mother->new_x) {
844
 
                                        if(mother->old_x==0) {
845
 
                                                mother->new_x=3;
 
863
                move_robots(st);
 
864
                if(st->MOTHER_SHIP) {
 
865
                        if(st->mother->active) {
 
866
                                if(st->mother->old_x==st->mother->new_x) {
 
867
                                        if(st->mother->old_x==0) {
 
868
                                                st->mother->new_x=3;
846
869
                                        }
847
870
                                        else {
848
 
                                                mother->new_x=mother->new_x-3;
 
871
                                                st->mother->new_x=st->mother->new_x-3;
849
872
                                        }
850
873
                                }
851
874
                                else {
852
 
                                        if(mother->old_x>mother->new_x) {
853
 
                                                mother->old_x = mother->new_x;
854
 
                                                mother->new_x = mother->new_x-3;
855
 
                                                if(mother->new_x<0) {
856
 
                                                        mother->active=0;
857
 
                                                        XFillArc(dpy, window, black, mother->old_x, mother->y, MOTHER_SHIP_WIDTH, MOTHER_SHIP_HEIGHT, 0 , 360*64);
858
 
                                                        XFillArc(dpy, window, black, mother->new_x, mother->y, MOTHER_SHIP_WIDTH, MOTHER_SHIP_HEIGHT, 0 , 360*64);
 
875
                                        if(st->mother->old_x>st->mother->new_x) {
 
876
                                                st->mother->old_x = st->mother->new_x;
 
877
                                                st->mother->new_x = st->mother->new_x-3;
 
878
                                                if(st->mother->new_x<0) {
 
879
                                                        st->mother->active=0;
 
880
                                                        if (st->black) XFillArc(st->dpy, st->window, st->black, st->mother->old_x, st->mother->y, st->MOTHER_SHIP_WIDTH, st->MOTHER_SHIP_HEIGHT, 0 , 360*64);
 
881
                                                        if (st->black) XFillArc(st->dpy, st->window, st->black, st->mother->new_x, st->mother->y, st->MOTHER_SHIP_WIDTH, st->MOTHER_SHIP_HEIGHT, 0 , 360*64);
859
882
                                                }
860
883
                                        }
861
884
                                        else {
862
 
                                                mother->old_x = mother->new_x;
863
 
                                                mother->new_x = mother->new_x+3;
864
 
                                                if(mother->new_x>xgwa.width) {
865
 
                                                        mother->active=0;
866
 
                                                        XFillArc(dpy, window, black, mother->old_x, mother->y, MOTHER_SHIP_WIDTH, MOTHER_SHIP_HEIGHT, 0 , 360*64);
867
 
                                                        XFillArc(dpy, window, black, mother->new_x, mother->y, MOTHER_SHIP_WIDTH, MOTHER_SHIP_HEIGHT, 0 , 360*64);
 
885
                                                st->mother->old_x = st->mother->new_x;
 
886
                                                st->mother->new_x = st->mother->new_x+3;
 
887
                                                if(st->mother->new_x>st->xgwa.width) {
 
888
                                                        st->mother->active=0;
 
889
                                                        if (st->black) XFillArc(st->dpy, st->window, st->black, st->mother->old_x, st->mother->y, st->MOTHER_SHIP_WIDTH, st->MOTHER_SHIP_HEIGHT, 0 , 360*64);
 
890
                                                        if (st->black) XFillArc(st->dpy, st->window, st->black, st->mother->new_x, st->mother->y, st->MOTHER_SHIP_WIDTH, st->MOTHER_SHIP_HEIGHT, 0 , 360*64);
868
891
                                                }
869
892
                                        }
870
893
                                }
871
 
                                y=0;
872
 
                                for(x=0;x<8;x++) {
873
 
                                        if(mother->lasers[x].active) {
874
 
                                                y=1;
875
 
                                                x=8;
 
894
                                st->draw_y=0;
 
895
                                for(st->draw_x=0;st->draw_x<8;st->draw_x++) {
 
896
                                        if(st->mother->lasers[st->draw_x].active) {
 
897
                                                st->draw_y=1;
 
898
                                                st->draw_x=8;
876
899
                                        }
877
900
                                }
878
 
                                if(y==0) {
879
 
                                        for(x=0;x<8;x++) {
880
 
                                                mother->lasers[x].active = 1;
881
 
                                                mother->lasers[x].start_x=mother->new_x+(MOTHER_SHIP_WIDTH/2);
882
 
                                                mother->lasers[x].start_y=mother->y+(MOTHER_SHIP_HEIGHT/2);
 
901
                                if(st->draw_y==0) {
 
902
                                        for(st->draw_x=0;st->draw_x<8;st->draw_x++) {
 
903
                                                st->mother->lasers[st->draw_x].active = 1;
 
904
                                                st->mother->lasers[st->draw_x].start_x=st->mother->new_x+(st->MOTHER_SHIP_WIDTH/2);
 
905
                                                st->mother->lasers[st->draw_x].start_y=st->mother->y+(st->MOTHER_SHIP_HEIGHT/2);
883
906
                                        }
884
 
                                        y = (int)(MOTHER_SHIP_LASER/1.5);
885
 
                                        mother->lasers[0].end_x=mother->lasers[0].start_x-MOTHER_SHIP_LASER;
886
 
                                        mother->lasers[0].end_y=mother->lasers[0].start_y;
887
 
                                        mother->lasers[1].end_x=mother->lasers[1].start_x-y;
888
 
                                        mother->lasers[1].end_y=mother->lasers[1].start_y-y;
889
 
                                        mother->lasers[2].end_x=mother->lasers[2].start_x;
890
 
                                        mother->lasers[2].end_y=mother->lasers[2].start_y-MOTHER_SHIP_LASER;
891
 
                                        mother->lasers[3].end_x=mother->lasers[3].start_x+y;
892
 
                                        mother->lasers[3].end_y=mother->lasers[3].start_y-y;
893
 
                                        mother->lasers[4].end_x=mother->lasers[4].start_x+MOTHER_SHIP_LASER;
894
 
                                        mother->lasers[4].end_y=mother->lasers[4].start_y;
895
 
                                        mother->lasers[5].end_x=mother->lasers[5].start_x+y;
896
 
                                        mother->lasers[5].end_y=mother->lasers[5].start_y+y;
897
 
                                        mother->lasers[6].end_x=mother->lasers[6].start_x;
898
 
                                        mother->lasers[6].end_y=mother->lasers[6].start_y+MOTHER_SHIP_LASER;
899
 
                                        mother->lasers[7].end_x=mother->lasers[7].start_x-y;
900
 
                                        mother->lasers[7].end_y=mother->lasers[7].start_y+y;
 
907
                                        st->draw_y = (int)(st->MOTHER_SHIP_LASER/1.5);
 
908
                                        st->mother->lasers[0].end_x=st->mother->lasers[0].start_x-st->MOTHER_SHIP_LASER;
 
909
                                        st->mother->lasers[0].end_y=st->mother->lasers[0].start_y;
 
910
                                        st->mother->lasers[1].end_x=st->mother->lasers[1].start_x-st->draw_y;
 
911
                                        st->mother->lasers[1].end_y=st->mother->lasers[1].start_y-st->draw_y;
 
912
                                        st->mother->lasers[2].end_x=st->mother->lasers[2].start_x;
 
913
                                        st->mother->lasers[2].end_y=st->mother->lasers[2].start_y-st->MOTHER_SHIP_LASER;
 
914
                                        st->mother->lasers[3].end_x=st->mother->lasers[3].start_x+st->draw_y;
 
915
                                        st->mother->lasers[3].end_y=st->mother->lasers[3].start_y-st->draw_y;
 
916
                                        st->mother->lasers[4].end_x=st->mother->lasers[4].start_x+st->MOTHER_SHIP_LASER;
 
917
                                        st->mother->lasers[4].end_y=st->mother->lasers[4].start_y;
 
918
                                        st->mother->lasers[5].end_x=st->mother->lasers[5].start_x+st->draw_y;
 
919
                                        st->mother->lasers[5].end_y=st->mother->lasers[5].start_y+st->draw_y;
 
920
                                        st->mother->lasers[6].end_x=st->mother->lasers[6].start_x;
 
921
                                        st->mother->lasers[6].end_y=st->mother->lasers[6].start_y+st->MOTHER_SHIP_LASER;
 
922
                                        st->mother->lasers[7].end_x=st->mother->lasers[7].start_x-st->draw_y;
 
923
                                        st->mother->lasers[7].end_y=st->mother->lasers[7].start_y+st->draw_y;
901
924
                                }
902
925
                        }
903
926
                }
904
 
                draw_robots();
905
 
 
906
 
                XSync(dpy, False);
907
 
                screenhack_handle_events(dpy);
908
 
                if(delay) usleep(delay);
909
 
        }
910
 
}
911
 
 
912
 
 
913
 
 
914
 
 
915
 
 
916
 
 
917
 
 
918
 
 
919
 
char *progclass = "Blaster";
920
 
 
921
 
char *defaults [] = {
 
927
                draw_robots(st);
 
928
 
 
929
    return st->delay;
 
930
}
 
931
 
 
932
static void *
 
933
blaster_init (Display *d, Window w)
 
934
{
 
935
  struct state *st = (struct state *) calloc (1, sizeof(*st));
 
936
        XGCValues gcv;
 
937
        Colormap cmap;
 
938
        unsigned long bg;
 
939
 
 
940
        st->dpy = d;
 
941
        st->window = w;
 
942
        XGetWindowAttributes(st->dpy, st->window, &st->xgwa);
 
943
        cmap = st->xgwa.colormap;
 
944
 
 
945
  st->NUM_ROBOTS=5;
 
946
  st->NUM_LASERS=3;
 
947
 
 
948
  st->MOTHER_SHIP_WIDTH=25;
 
949
  st->MOTHER_SHIP_HEIGHT=7;
 
950
  st->MOTHER_SHIP_LASER=15;
 
951
  st->MOTHER_SHIP_PERIOD=150;
 
952
  st->MOTHER_SHIP_HITS=10;
 
953
 
 
954
  st->RANDOM_MOVE_STYLE=1;
 
955
  st->NUM_MOVE_STYLES=2;
 
956
 
 
957
  st->EXPLODE_SIZE_1=27;
 
958
  st->EXPLODE_SIZE_2=19;
 
959
  st->EXPLODE_SIZE_3=7;
 
960
 
 
961
 
 
962
        st->delay = get_integer_resource(st->dpy, "delay", "Integer");
 
963
        if(st->delay==0) {
 
964
                st->delay=10000;
 
965
        }
 
966
        st->NUM_ROBOTS = get_integer_resource(st->dpy, "num_robots","Integer");
 
967
        if(st->NUM_ROBOTS==0) {
 
968
                st->NUM_ROBOTS=5;
 
969
        }
 
970
        st->NUM_LASERS = get_integer_resource(st->dpy, "num_lasers","Integer");
 
971
        st->EXPLODE_SIZE_1 = get_integer_resource(st->dpy, "explode_size_1","Integer");
 
972
        st->EXPLODE_SIZE_2 = get_integer_resource(st->dpy, "explode_size_2","Integer");
 
973
        st->EXPLODE_SIZE_3 = get_integer_resource(st->dpy, "explode_size_3","Integer");
 
974
 
 
975
        st->NUM_STARS = get_integer_resource(st->dpy, "num_stars","Integer");
 
976
        if(get_boolean_resource(st->dpy, "move_stars","Boolean")) {
 
977
                st->MOVE_STARS = 1;
 
978
                st->MOVE_STARS_X = get_integer_resource(st->dpy, "move_stars_x","Integer");
 
979
                st->MOVE_STARS_Y = get_integer_resource(st->dpy, "move_stars_y","Integer");
 
980
                st->MOVE_STARS_RANDOM = get_integer_resource(st->dpy, "move_stars_random","Integer");
 
981
        }
 
982
        else {
 
983
                st->MOVE_STARS = 0;
 
984
        }
 
985
 
 
986
 
 
987
        bg = get_pixel_resource(st->dpy, cmap, "background","Background");
 
988
        gcv.function = GXcopy;
 
989
 
 
990
#define make_gc(color,name) \
 
991
        gcv.foreground = get_pixel_resource (st->dpy, cmap, (name), "Foreground"); \
 
992
        color = XCreateGC (st->dpy, st->window, GCForeground|GCFunction, &gcv)
 
993
 
 
994
        if(mono_p) {
 
995
                gcv.foreground = bg;
 
996
                st->black = XCreateGC(st->dpy, st->window, GCForeground|GCFunction, &gcv);
 
997
                gcv.foreground = get_pixel_resource(st->dpy, cmap, "foreground", "Foreground");
 
998
                st->r_color0 = st->r_color1 = st->r_color2 = st->r_color3 = st->r_color4 = st->r_color5 = st->l_color0 = st->l_color1 = st->s_color=
 
999
                        XCreateGC(st->dpy, st->window, GCForeground|GCFunction, &gcv);
 
1000
                if(get_boolean_resource(st->dpy, "mother_ship","Boolean")) {
 
1001
                        st->MOTHER_SHIP_WIDTH=get_integer_resource(st->dpy, "mother_ship_width","Integer");
 
1002
                        st->MOTHER_SHIP_HEIGHT=get_integer_resource(st->dpy, "mother_ship_height","Integer");
 
1003
                        st->MOTHER_SHIP_LASER=get_integer_resource(st->dpy, "mother_ship_laser","Integer");
 
1004
                        st->MOTHER_SHIP_PERIOD=get_integer_resource(st->dpy, "mother_ship_period","Integer");
 
1005
                        st->MOTHER_SHIP_HITS=get_integer_resource(st->dpy, "mother_ship_hits","Integer");
 
1006
                        st->MOTHER_SHIP=1;
 
1007
                        st->mother = (struct mother_ship_state *) malloc(sizeof(struct mother_ship_state));
 
1008
                        st->mother->lasers = (struct laser_state *) malloc(8*sizeof(struct laser_state));
 
1009
                        st->mother->active = 0;
 
1010
                        st->mother->death = 0;
 
1011
                        st->mother->ship_color = st->r_color0;
 
1012
                        st->mother->laser_color = st->r_color0;
 
1013
                }
 
1014
        }
 
1015
        else {
 
1016
                if(get_boolean_resource(st->dpy, "mother_ship","Boolean")) {
 
1017
                        st->MOTHER_SHIP_WIDTH=get_integer_resource(st->dpy, "mother_ship_width","Integer");
 
1018
                        st->MOTHER_SHIP_HEIGHT=get_integer_resource(st->dpy, "mother_ship_height","Integer");
 
1019
                        st->MOTHER_SHIP_LASER=get_integer_resource(st->dpy, "mother_ship_laser","Integer");
 
1020
                        st->MOTHER_SHIP_PERIOD=get_integer_resource(st->dpy, "mother_ship_period","Integer");
 
1021
                        st->MOTHER_SHIP_HITS=get_integer_resource(st->dpy, "mother_ship_hits","Integer");
 
1022
                        st->MOTHER_SHIP=1;
 
1023
                        st->mother = (struct mother_ship_state *) malloc(sizeof(struct mother_ship_state));
 
1024
                        st->mother->lasers = (struct laser_state *) malloc(8*sizeof(struct laser_state));
 
1025
                        st->mother->active = 0;
 
1026
                        st->mother->death = 0;
 
1027
                        make_gc(st->mother->ship_color,"mother_ship_color0");
 
1028
                        make_gc(st->mother->laser_color,"mother_ship_color1");          
 
1029
                }
 
1030
 
 
1031
                make_gc (st->s_color,"star_color");
 
1032
                
 
1033
                make_gc (st->EXPLODE_COLOR_1,"explode_color_1");
 
1034
                make_gc (st->EXPLODE_COLOR_2,"explode_color_2");
 
1035
                
 
1036
      make_gc (st->r_color0,"r_color0");
 
1037
      make_gc (st->r_color1,"r_color1");
 
1038
      make_gc (st->r_color2,"r_color2");
 
1039
      make_gc (st->r_color3,"r_color3");
 
1040
      make_gc (st->r_color4,"r_color4");
 
1041
      make_gc (st->r_color5,"r_color5");
 
1042
      make_gc (st->l_color0,"l_color0");
 
1043
      make_gc (st->l_color1,"l_color1");
 
1044
#ifdef HAVE_COCOA       /* Don't second-guess Quartz's double-buffering */
 
1045
    st->black = 0;
 
1046
#else
 
1047
                make_gc (st->black,"background");
 
1048
#endif
 
1049
        }
 
1050
 
 
1051
  return st;
 
1052
}
 
1053
 
 
1054
 
 
1055
static void
 
1056
blaster_reshape (Display *dpy, Window window, void *closure, 
 
1057
                 unsigned int w, unsigned int h)
 
1058
{
 
1059
  struct state *st = (struct state *) closure;
 
1060
        XGetWindowAttributes (dpy, window, &st->xgwa);
 
1061
  XClearWindow (dpy, window);
 
1062
  init_stars (st);
 
1063
}
 
1064
 
 
1065
static Bool
 
1066
blaster_event (Display *dpy, Window window, void *closure, XEvent *event)
 
1067
{
 
1068
  return False;
 
1069
}
 
1070
 
 
1071
static void
 
1072
blaster_free (Display *dpy, Window window, void *closure)
 
1073
{
 
1074
  struct state *st = (struct state *) closure;
 
1075
  int i;
 
1076
  if (st->r_color0) XFreeGC (dpy, st->r_color0);
 
1077
  if (st->r_color1) XFreeGC (dpy, st->r_color1);
 
1078
  if (st->r_color2) XFreeGC (dpy, st->r_color2);
 
1079
  if (st->r_color3) XFreeGC (dpy, st->r_color3);
 
1080
  if (st->r_color4) XFreeGC (dpy, st->r_color4);
 
1081
  if (st->r_color5) XFreeGC (dpy, st->r_color5);
 
1082
  if (st->l_color0) XFreeGC (dpy, st->l_color0);
 
1083
  if (st->l_color1) XFreeGC (dpy, st->l_color1);
 
1084
  if (st->s_color)  XFreeGC (dpy, st->s_color);
 
1085
  if (st->black)    XFreeGC (dpy, st->black);
 
1086
  if (st->stars) free (st->stars);
 
1087
  if (st->mother) {
 
1088
    free (st->mother->lasers);
 
1089
    free (st->mother);
 
1090
  }
 
1091
  for (i = 0; i < st->NUM_ROBOTS; i++)
 
1092
    free (st->robots[i].lasers);
 
1093
  free (st->robots);
 
1094
  free (st);
 
1095
}
 
1096
 
 
1097
 
 
1098
static const char *blaster_defaults [] = {
922
1099
  ".background: black",
923
1100
  ".foreground: white",
924
 
  "*r_color0:   magenta",
925
 
  "*r_color1:   orange",
926
 
  "*r_color2:   yellow",
927
 
  "*r_color3:   white",
928
 
  "*r_color4:   blue",
929
 
  "*r_color5:   cyan",
930
 
  "*l_color0:   green",
931
 
  "*l_color1:   red",
932
 
  "*mother_ship_color0: darkblue",
933
 
  "*mother_ship_color1: white",
934
 
  "*explode_color_1: yellow",
935
 
  "*explode_color_2: orange",
 
1101
  "*r_color0:   #FF00FF",
 
1102
  "*r_color1:   #FFA500",
 
1103
  "*r_color2:   #FFFF00",
 
1104
  "*r_color3:   #FFFFFF",
 
1105
  "*r_color4:   #0000FF",
 
1106
  "*r_color5:   #00FFFF",
 
1107
  "*l_color0:   #00FF00",
 
1108
  "*l_color1:   #FF0000",
 
1109
  "*mother_ship_color0: #00008B",
 
1110
  "*mother_ship_color1: #FFFFFF",
 
1111
  "*explode_color_1: #FFFF00",
 
1112
  "*explode_color_2: #FFA500",
936
1113
  "*delay: 10000",
937
1114
  "*num_robots: 5",
938
1115
  "*num_lasers: 3",
954
1131
  0
955
1132
};
956
1133
 
957
 
XrmOptionDescRec options [] = {
 
1134
static XrmOptionDescRec blaster_options [] = {
958
1135
        /* These are the 6 robot colors */
959
1136
  { "-r_color0",                ".r_color0",    XrmoptionSepArg, 0 },
960
1137
  { "-r_color1",                ".r_color1",    XrmoptionSepArg, 0 },
1006
1183
  { 0, 0, 0, 0 }
1007
1184
};
1008
1185
 
1009
 
 
1010
 
 
1011
 
void screenhack(Display *d, Window w)
1012
 
{
1013
 
        XGCValues gcv;
1014
 
        Colormap cmap;
1015
 
        unsigned long bg;
1016
 
 
1017
 
        dpy = d;
1018
 
        window = w;
1019
 
        XGetWindowAttributes(dpy, window, &xgwa);
1020
 
        cmap = xgwa.colormap;
1021
 
 
1022
 
        delay = get_integer_resource("delay", "Integer");
1023
 
        if(delay==0) {
1024
 
                delay=10000;
1025
 
        }
1026
 
        NUM_ROBOTS = get_integer_resource("num_robots","Integer");
1027
 
        if(NUM_ROBOTS==0) {
1028
 
                NUM_ROBOTS=5;
1029
 
        }
1030
 
        NUM_LASERS = get_integer_resource("num_lasers","Integer");
1031
 
        EXPLODE_SIZE_1 = get_integer_resource("explode_size_1","Integer");
1032
 
        EXPLODE_SIZE_2 = get_integer_resource("explode_size_2","Integer");
1033
 
        EXPLODE_SIZE_3 = get_integer_resource("explode_size_3","Integer");
1034
 
 
1035
 
        NUM_STARS = get_integer_resource("num_stars","Integer");
1036
 
        if(get_boolean_resource("move_stars","Boolean")) {
1037
 
                MOVE_STARS = 1;
1038
 
                MOVE_STARS_X = get_integer_resource("move_stars_x","Integer");
1039
 
                MOVE_STARS_Y = get_integer_resource("move_stars_y","Integer");
1040
 
                MOVE_STARS_RANDOM = get_integer_resource("move_stars_random","Integer");
1041
 
        }
1042
 
        else {
1043
 
                MOVE_STARS = 0;
1044
 
        }
1045
 
 
1046
 
 
1047
 
        bg = get_pixel_resource("background","Background", dpy, cmap);
1048
 
        gcv.function = GXcopy;
1049
 
 
1050
 
#define make_gc(color,name) \
1051
 
        gcv.foreground = bg ^ get_pixel_resource ((name), "Foreground", \
1052
 
                                                  dpy, cmap);           \
1053
 
        color = XCreateGC (dpy, window, GCForeground|GCFunction, &gcv)
1054
 
 
1055
 
        if(mono_p) {
1056
 
                gcv.foreground = bg;
1057
 
                black = XCreateGC(dpy, window, GCForeground|GCFunction, &gcv);
1058
 
                gcv.foreground = get_pixel_resource("foreground", "Foreground", dpy, cmap);
1059
 
                r_color0 = r_color1 = r_color2 = r_color3 = r_color4 = r_color5 = l_color0 = l_color1 = s_color=
1060
 
                        XCreateGC(dpy, window, GCForeground|GCFunction, &gcv);
1061
 
                if(get_boolean_resource("mother_ship","Boolean")) {
1062
 
                        MOTHER_SHIP_WIDTH=get_integer_resource("mother_ship_width","Integer");
1063
 
                        MOTHER_SHIP_HEIGHT=get_integer_resource("mother_ship_height","Integer");
1064
 
                        MOTHER_SHIP_LASER=get_integer_resource("mother_ship_laser","Integer");
1065
 
                        MOTHER_SHIP_PERIOD=get_integer_resource("mother_ship_period","Integer");
1066
 
                        MOTHER_SHIP_HITS=get_integer_resource("mother_ship_hits","Integer");
1067
 
                        MOTHER_SHIP=1;
1068
 
                        mother = (struct mother_ship_state *) malloc(sizeof(struct mother_ship_state));
1069
 
                        mother->lasers = (struct laser_state *) malloc(8*sizeof(struct laser_state));
1070
 
                        mother->active = 0;
1071
 
                        mother->death = 0;
1072
 
                        mother->ship_color = r_color0;
1073
 
                        mother->laser_color = r_color0;
1074
 
                }
1075
 
        }
1076
 
        else {
1077
 
                if(get_boolean_resource("mother_ship","Boolean")) {
1078
 
                        MOTHER_SHIP_WIDTH=get_integer_resource("mother_ship_width","Integer");
1079
 
                        MOTHER_SHIP_HEIGHT=get_integer_resource("mother_ship_height","Integer");
1080
 
                        MOTHER_SHIP_LASER=get_integer_resource("mother_ship_laser","Integer");
1081
 
                        MOTHER_SHIP_PERIOD=get_integer_resource("mother_ship_period","Integer");
1082
 
                        MOTHER_SHIP_HITS=get_integer_resource("mother_ship_hits","Integer");
1083
 
                        MOTHER_SHIP=1;
1084
 
                        mother = (struct mother_ship_state *) malloc(sizeof(struct mother_ship_state));
1085
 
                        mother->lasers = (struct laser_state *) malloc(8*sizeof(struct laser_state));
1086
 
                        mother->active = 0;
1087
 
                        mother->death = 0;
1088
 
                        make_gc(mother->ship_color,"mother_ship_color0");
1089
 
                        make_gc(mother->laser_color,"mother_ship_color1");              
1090
 
                }
1091
 
 
1092
 
                make_gc (s_color,"star_color");
1093
 
                
1094
 
                make_gc (EXPLODE_COLOR_1,"explode_color_1");
1095
 
                make_gc (EXPLODE_COLOR_2,"explode_color_2");
1096
 
                
1097
 
      make_gc (r_color0,"r_color0");
1098
 
      make_gc (r_color1,"r_color1");
1099
 
      make_gc (r_color2,"r_color2");
1100
 
      make_gc (r_color3,"r_color3");
1101
 
      make_gc (r_color4,"r_color4");
1102
 
      make_gc (r_color5,"r_color5");
1103
 
      make_gc (l_color0,"l_color0");
1104
 
      make_gc (l_color1,"l_color1");
1105
 
                make_gc (black,"background");
1106
 
        }
1107
 
 
1108
 
        start_blaster();
1109
 
}
 
1186
XSCREENSAVER_MODULE ("Blaster", blaster)