Lines Matching refs:st

112 static void make_new_robot(struct state *st, int index)  in make_new_robot()  argument
117 for(x=0;x<st->NUM_LASERS;x++) { in make_new_robot()
118 if(st->robots[index].lasers[x].active) { in make_new_robot()
119 x=st->NUM_LASERS; in make_new_robot()
124 st->robots[index].alive=1; in make_new_robot()
126 st->robots[index].radius = 7+(random()%7); in make_new_robot()
128 st->robots[index].move_style = random()%st->NUM_MOVE_STYLES; in make_new_robot()
130 st->robots[index].new_x=random()%(st->xgwa.width-st->robots[index].radius); in make_new_robot()
131 st->robots[index].old_x=st->robots[index].new_x; in make_new_robot()
133 st->robots[index].new_y=0; in make_new_robot()
134 st->robots[index].old_y=0; in make_new_robot()
137 st->robots[index].new_y=st->xgwa.height-st->robots[index].radius; in make_new_robot()
138 st->robots[index].old_y = st->robots[index].new_y; in make_new_robot()
142 st->robots[index].new_y=random()%(st->xgwa.height-st->robots[index].radius); in make_new_robot()
143 st->robots[index].old_y = st->robots[index].new_y; in make_new_robot()
145 st->robots[index].new_x=0; in make_new_robot()
146 st->robots[index].old_x=0; in make_new_robot()
149 st->robots[index].new_x=st->xgwa.width-st->robots[index].radius; in make_new_robot()
150 st->robots[index].old_x=st->robots[index].new_x; in make_new_robot()
156 st->robots[index].robot_color = st->r_color0; in make_new_robot()
159 st->robots[index].robot_color = st->r_color1; in make_new_robot()
162 st->robots[index].robot_color = st->r_color2; in make_new_robot()
165 st->robots[index].robot_color = st->r_color3; in make_new_robot()
168 st->robots[index].robot_color = st->r_color4; in make_new_robot()
171 st->robots[index].robot_color = st->r_color5; in make_new_robot()
175 st->robots[index].laser_color = st->l_color0; in make_new_robot()
178 st->robots[index].laser_color = st->l_color1; in make_new_robot()
181 if(st->NUM_ROBOTS>1) { in make_new_robot()
182 st->robots[index].target = random()%st->NUM_ROBOTS; in make_new_robot()
183 while(st->robots[index].target==index) { in make_new_robot()
184 st->robots[index].target = random()%st->NUM_ROBOTS; in make_new_robot()
193 static void move_robots(struct state *st) in move_robots() argument
203 for(x=0;x<st->NUM_ROBOTS;x++) { in move_robots()
204 if(st->robots[x].alive) { in move_robots()
205 … if((st->robots[x].new_x == st->robots[x].old_x) && (st->robots[x].new_y == st->robots[x].old_y)) { in move_robots()
206 if(st->robots[x].new_x==0) { in move_robots()
207 st->robots[x].old_x = -((random()%3)+1); in move_robots()
210 st->robots[x].old_x = st->robots[x].old_x + (random()%3)+1; in move_robots()
212 if(st->robots[x].new_y==0) { in move_robots()
213 st->robots[x].old_y = -((random()%3)+1); in move_robots()
216 st->robots[x].old_y = st->robots[x].old_y + (random()%3)+1; in move_robots()
219 if(st->robots[x].move_style==st->LINE_MOVE_STYLE) { in move_robots()
220 dx = st->robots[x].new_x - st->robots[x].old_x; in move_robots()
221 dy = st->robots[x].new_y - st->robots[x].old_y; in move_robots()
234 st->robots[x].old_x = st->robots[x].new_x; in move_robots()
235 st->robots[x].old_y = st->robots[x].new_y; in move_robots()
237 st->robots[x].new_x = st->robots[x].new_x + dx; in move_robots()
238 st->robots[x].new_y = st->robots[x].new_y + dy; in move_robots()
240 else if(st->robots[x].move_style==st->RANDOM_MOVE_STYLE) { in move_robots()
241 dx = st->robots[x].new_x - st->robots[x].old_x; in move_robots()
242 dy = st->robots[x].new_y - st->robots[x].old_y; in move_robots()
276 st->robots[x].old_x = st->robots[x].new_x; in move_robots()
277 st->robots[x].old_y = st->robots[x].new_y; in move_robots()
279 st->robots[x].new_x = st->robots[x].new_x + dx; in move_robots()
280 st->robots[x].new_y = st->robots[x].new_y + dy; in move_robots()
284 if(st->robots[x].new_x >= st->xgwa.width-st->robots[x].radius) { in move_robots()
285 st->robots[x].new_x = st->xgwa.width - st->robots[x].radius; in move_robots()
287 else if(st->robots[x].new_x < 0) { in move_robots()
288 st->robots[x].new_x = 0; in move_robots()
290 if(st->robots[x].new_y >= st->xgwa.height-st->robots[x].radius) { in move_robots()
291 st->robots[x].new_y = st->xgwa.height - st->robots[x].radius; in move_robots()
293 else if(st->robots[x].new_y < 0) { in move_robots()
294 st->robots[x].new_y = 0; in move_robots()
298 st->robots[x].move_style = 1; in move_robots()
301 st->robots[x].move_style = 0; in move_robots()
304 if(st->NUM_ROBOTS>1) { in move_robots()
307 st->robots[x].target = random()%st->NUM_ROBOTS; in move_robots()
308 while(st->robots[x].target==x) { in move_robots()
309 st->robots[x].target = random()%st->NUM_ROBOTS; in move_robots()
311 for(y=0;y<st->NUM_LASERS;y++) { in move_robots()
312 if(st->robots[x].lasers[y].active == 0) { in move_robots()
313 st->robots[x].lasers[y].active = 1; in move_robots()
316 st->robots[x].lasers[y].start_x = st->robots[x].new_x+st->robots[x].radius; in move_robots()
317 st->robots[x].lasers[y].start_y = st->robots[x].new_y+st->robots[x].radius; in move_robots()
318 st->robots[x].lasers[y].end_x = st->robots[x].lasers[y].start_x+7; in move_robots()
319 st->robots[x].lasers[y].end_y = st->robots[x].lasers[y].start_y+7; in move_robots()
322 st->robots[x].lasers[y].start_x = st->robots[x].new_x-st->robots[x].radius; in move_robots()
323 st->robots[x].lasers[y].start_y = st->robots[x].new_y+st->robots[x].radius; in move_robots()
324 st->robots[x].lasers[y].end_x = st->robots[x].lasers[y].start_x-7; in move_robots()
325 st->robots[x].lasers[y].end_y = st->robots[x].lasers[y].start_y+7; in move_robots()
330 st->robots[x].lasers[y].start_x = st->robots[x].new_x-st->robots[x].radius; in move_robots()
331 st->robots[x].lasers[y].start_y = st->robots[x].new_y-st->robots[x].radius; in move_robots()
332 st->robots[x].lasers[y].end_x = st->robots[x].lasers[y].start_x-7; in move_robots()
333 st->robots[x].lasers[y].end_y = st->robots[x].lasers[y].start_y-7; in move_robots()
336 st->robots[x].lasers[y].start_x = st->robots[x].new_x+st->robots[x].radius; in move_robots()
337 st->robots[x].lasers[y].start_y = st->robots[x].new_y-st->robots[x].radius; in move_robots()
338 st->robots[x].lasers[y].end_x = st->robots[x].lasers[y].start_x+7; in move_robots()
339 st->robots[x].lasers[y].end_y = st->robots[x].lasers[y].start_y-7; in move_robots()
342 y = st->NUM_LASERS; in move_robots()
347 for(y=0;y<st->NUM_LASERS;y++) { in move_robots()
348 if(st->robots[x].lasers[y].active==0) { in move_robots()
349 target_x = st->robots[st->robots[x].target].new_x; in move_robots()
350 target_y = st->robots[st->robots[x].target].new_y; in move_robots()
351 if((target_x-st->robots[x].new_x)!=0) { in move_robots()
352 slope = ((double)target_y-st->robots[x].new_y)/((double)(target_x-st->robots[x].new_x)); in move_robots()
355 if(target_x>st->robots[x].new_x) { in move_robots()
356 st->robots[x].lasers[y].start_x = st->robots[x].radius; in move_robots()
357 st->robots[x].lasers[y].end_x = st->robots[x].lasers[y].start_x + 7; in move_robots()
360 st->robots[x].lasers[y].start_x = -st->robots[x].radius; in move_robots()
361 st->robots[x].lasers[y].end_x = st->robots[x].lasers[y].start_x - 7; in move_robots()
363 st->robots[x].lasers[y].start_y = (int)(st->robots[x].lasers[y].start_x * slope); in move_robots()
364 st->robots[x].lasers[y].end_y = (int)(st->robots[x].lasers[y].end_x * slope); in move_robots()
367 slope = (target_x-st->robots[x].new_x)/(target_y-st->robots[x].new_y); in move_robots()
368 if(target_y>st->robots[x].new_y) { in move_robots()
369 st->robots[x].lasers[y].start_y = st->robots[x].radius; in move_robots()
370 st->robots[x].lasers[y].end_y = st->robots[x].lasers[y].start_y + 7; in move_robots()
373 st->robots[x].lasers[y].start_y = -st->robots[x].radius; in move_robots()
374 st->robots[x].lasers[y].end_y = st->robots[x].lasers[y].start_y - 7; in move_robots()
376 st->robots[x].lasers[y].start_x = (int)(st->robots[x].lasers[y].start_y * slope);; in move_robots()
377 st->robots[x].lasers[y].end_x = (int)(st->robots[x].lasers[y].end_y * slope); in move_robots()
379 st->robots[x].lasers[y].start_x = st->robots[x].lasers[y].start_x + st->robots[x].new_x; in move_robots()
380 st->robots[x].lasers[y].start_y = st->robots[x].lasers[y].start_y + st->robots[x].new_y; in move_robots()
381 st->robots[x].lasers[y].end_x = st->robots[x].lasers[y].end_x + st->robots[x].new_x; in move_robots()
382 st->robots[x].lasers[y].end_y = st->robots[x].lasers[y].end_y + st->robots[x].new_y; in move_robots()
385 if(target_y > st->robots[x].new_y) { in move_robots()
386 st->robots[x].lasers[y].start_x = st->robots[x].new_x; in move_robots()
387 st->robots[x].lasers[y].start_y = st->robots[x].new_y+st->robots[x].radius; in move_robots()
388 st->robots[x].lasers[y].end_x = st->robots[x].new_x; in move_robots()
389 st->robots[x].lasers[y].end_y = st->robots[x].lasers[y].start_y+7; in move_robots()
392 st->robots[x].lasers[y].start_x = st->robots[x].new_x; in move_robots()
393 st->robots[x].lasers[y].start_y = st->robots[x].new_y-st->robots[x].radius; in move_robots()
394 st->robots[x].lasers[y].end_x = st->robots[x].new_x; in move_robots()
395 st->robots[x].lasers[y].end_y = st->robots[x].lasers[y].start_y-7; in move_robots()
399 if((((st->robots[x].lasers[y].start_x - st->robots[x].lasers[y].end_x) > 7) || in move_robots()
400 ((st->robots[x].lasers[y].end_x - st->robots[x].lasers[y].start_x) > 7)) && in move_robots()
401 (((st->robots[x].lasers[y].start_y - st->robots[x].lasers[y].end_y) > 7) || in move_robots()
402 ((st->robots[x].lasers[y].end_y - st->robots[x].lasers[y].start_y) > 7))) { in move_robots()
405 st->robots[x].lasers[y].active = 1; in move_robots()
406 y = st->NUM_LASERS; in move_robots()
415 if(st->robots[x].death==0) { in move_robots()
416 make_new_robot(st,x); in move_robots()
425 static void move_laser(struct state *st, int rindex, int index) in move_laser() argument
434 laser = st->robots[rindex].lasers; in move_laser()
437 laser = st->mother->lasers; in move_laser()
441 for(x=0;x<st->NUM_ROBOTS;x++) { in move_laser()
443 if(st->robots[x].alive) { in move_laser()
444 y = laser[index].start_x-st->robots[x].new_x; in move_laser()
446 y = st->robots[x].new_x-laser[index].start_x; in move_laser()
448 z = laser[index].start_y-st->robots[x].new_y; in move_laser()
450 z = st->robots[x].new_y-laser[index].start_y; in move_laser()
452 if((z<st->robots[x].radius-1)&&(y<st->robots[x].radius-1)) { in move_laser()
453 st->robots[x].alive = 0; in move_laser()
454 st->robots[x].death = 20; in move_laser()
455 …if (st->black) XFillArc(st->dpy, st->window, st->black, st->robots[x].old_x, st->robots[x].old_y, in move_laser()
456 …if (st->black) XFillArc(st->dpy, st->window, st->black, st->robots[x].new_x, st->robots[x].new_y, in move_laser()
458 x = st->NUM_ROBOTS; in move_laser()
461 y = laser[index].end_x-st->robots[x].new_x; in move_laser()
463 y = st->robots[x].new_x-laser[index].end_x; in move_laser()
465 z = laser[index].end_y-st->robots[x].new_y; in move_laser()
467 z = st->robots[x].new_y-laser[index].end_y; in move_laser()
469 if((z<st->robots[x].radius-1)&&(y<st->robots[x].radius-1)) { in move_laser()
470 st->robots[x].alive = 0; in move_laser()
471 st->robots[x].death = 20; in move_laser()
472 …if (st->black) XFillArc(st->dpy, st->window, st->black, st->robots[x].old_x, st->robots[x].old_y, in move_laser()
473 …if (st->black) XFillArc(st->dpy, st->window, st->black, st->robots[x].new_x, st->robots[x].new_y, in move_laser()
475 x = st->NUM_ROBOTS; in move_laser()
481 if((st->MOTHER_SHIP)&&(rindex!=-1)) { in move_laser()
483 if(st->mother->active) { in move_laser()
484 y = laser[index].start_x-st->mother->new_x; in move_laser()
486 y = st->mother->new_x-laser[index].start_x; in move_laser()
488 z = laser[index].start_y-st->mother->y; in move_laser()
490 z = st->mother->y-laser[index].start_y; in move_laser()
492 if((z<st->MOTHER_SHIP_HEIGHT-1)&&(y<st->MOTHER_SHIP_WIDTH-1)) { in move_laser()
494 st->mother->active--; in move_laser()
497 y = laser[index].end_x-st->mother->new_x; in move_laser()
499 y = st->mother->new_x-laser[index].end_x; in move_laser()
501 z = laser[index].end_y-st->mother->y; in move_laser()
503 z = st->mother->y-laser[index].end_y; in move_laser()
505 if((z<st->MOTHER_SHIP_HEIGHT-1)&&(y<st->MOTHER_SHIP_WIDTH-1)) { in move_laser()
507 st->mother->active--; in move_laser()
511 if(st->mother->active==0) { in move_laser()
512 st->mother->death=20; in move_laser()
527 if((laser[index].end_x < 0) || (laser[index].end_x >= st->xgwa.width) || in move_laser()
528 (laser[index].end_y < 0) || (laser[index].end_y >= st->xgwa.height)) { in move_laser()
538 static void draw_robots(struct state *st) in draw_robots() argument
543 for(x=0;x<st->NUM_ROBOTS;x++) { in draw_robots()
544 if(st->robots[x].alive) { in draw_robots()
545 …if (st->black) XFillArc(st->dpy, st->window, st->black, st->robots[x].old_x, st->robots[x].old_y, in draw_robots()
546 …XFillArc(st->dpy, st->window, st->robots[x].robot_color, st->robots[x].new_x, st->robots[x].new_y,… in draw_robots()
549 …if (st->black) XFillArc(st->dpy, st->window, st->black, st->robots[x].old_x, st->robots[x].old_y, in draw_robots()
550 if(st->robots[x].death) { in draw_robots()
551 if(st->robots[x].death==20) { in draw_robots()
552st->dpy, st->window, st->EXPLODE_COLOR_1, st->robots[x].new_x+(st->robots[x].radius/3), st->robots… in draw_robots()
554 else if(st->robots[x].death==18) { in draw_robots()
555st->dpy, st->window, st->EXPLODE_COLOR_2, st->robots[x].new_x+(st->robots[x].radius/3), st->robots… in draw_robots()
557 else if(st->robots[x].death==17) { in draw_robots()
558st->dpy, st->window, st->EXPLODE_COLOR_1, st->robots[x].new_x+(st->robots[x].radius/3), st->robots… in draw_robots()
560 else if(st->robots[x].death==15) { in draw_robots()
561st->black) XFillArc(st->dpy, st->window, st->black, st->robots[x].new_x+(st->robots[x].radius/3), in draw_robots()
563 else if(st->robots[x].death==14) { in draw_robots()
564st->dpy, st->window, st->EXPLODE_COLOR_2, st->robots[x].new_x+(st->robots[x].radius/3), st->robots… in draw_robots()
566 else if(st->robots[x].death==13) { in draw_robots()
567st->black) XFillArc(st->dpy, st->window, st->black, st->robots[x].new_x+(st->robots[x].radius/3), in draw_robots()
569 else if(st->robots[x].death==12) { in draw_robots()
570st->dpy, st->window, st->EXPLODE_COLOR_1, st->robots[x].new_x+(st->robots[x].radius/3), st->robots… in draw_robots()
572 else if(st->robots[x].death==11) { in draw_robots()
573st->black) XFillArc(st->dpy, st->window, st->black, st->robots[x].new_x+(st->robots[x].radius/3), in draw_robots()
575 else if(st->robots[x].death==10) { in draw_robots()
576st->dpy, st->window, st->EXPLODE_COLOR_2, st->robots[x].new_x+(st->robots[x].radius/3), st->robots… in draw_robots()
578 else if(st->robots[x].death==9) { in draw_robots()
579st->black) XFillArc(st->dpy, st->window, st->black, st->robots[x].new_x+(st->robots[x].radius/3), in draw_robots()
581 else if(st->robots[x].death==8) { in draw_robots()
582st->dpy, st->window, st->EXPLODE_COLOR_1, st->robots[x].new_x+(st->robots[x].radius/3), st->robots… in draw_robots()
584 else if(st->robots[x].death==7) { in draw_robots()
585st->black) XFillArc(st->dpy, st->window, st->black, st->robots[x].new_x+(st->robots[x].radius/3), in draw_robots()
587 else if(st->robots[x].death==6) { in draw_robots()
588st->dpy, st->window, st->EXPLODE_COLOR_2, st->robots[x].new_x+(st->robots[x].radius/3), st->robots… in draw_robots()
590 else if(st->robots[x].death==4) { in draw_robots()
591st->black) XFillArc(st->dpy, st->window, st->black, st->robots[x].new_x+(st->robots[x].radius/3), in draw_robots()
593 else if(st->robots[x].death==3) { in draw_robots()
594st->dpy, st->window, st->EXPLODE_COLOR_1, st->robots[x].new_x+(st->robots[x].radius/3), st->robots… in draw_robots()
596 else if(st->robots[x].death==2) { in draw_robots()
597st->black) XFillArc(st->dpy, st->window, st->black, st->robots[x].new_x+(st->robots[x].radius/3), in draw_robots()
598st->dpy, st->window, st->EXPLODE_COLOR_2, st->robots[x].new_x+(1.7*st->robots[x].radius/2), st->ro… in draw_robots()
600 else if(st->robots[x].death==1) { in draw_robots()
601st->black) XFillArc(st->dpy, st->window, st->black, st->robots[x].new_x+(1.7*st->robots[x].radius/… in draw_robots()
603 st->robots[x].death--; in draw_robots()
608 for(x=0;x<st->NUM_ROBOTS;x++) { in draw_robots()
609 for(y=0;y<st->NUM_LASERS;y++) { in draw_robots()
610 if(st->robots[x].lasers[y].active) { in draw_robots()
611 if (st->black) XDrawLine(st->dpy, st->window, st->black, st->robots[x].lasers[y].start_x, in draw_robots()
612 st->robots[x].lasers[y].start_y, in draw_robots()
613 st->robots[x].lasers[y].end_x, in draw_robots()
614 st->robots[x].lasers[y].end_y); in draw_robots()
615 move_laser(st, x, y); in draw_robots()
616 if(st->robots[x].lasers[y].active) { in draw_robots()
617 XDrawLine(st->dpy, st->window, st->robots[x].laser_color, st->robots[x].lasers[y].start_x, in draw_robots()
618 st->robots[x].lasers[y].start_y, in draw_robots()
619 st->robots[x].lasers[y].end_x, in draw_robots()
620 st->robots[x].lasers[y].end_y); in draw_robots()
623 if (st->black) XDrawLine(st->dpy, st->window, st->black, st->robots[x].lasers[y].start_x, in draw_robots()
624 st->robots[x].lasers[y].start_y, in draw_robots()
625 st->robots[x].lasers[y].end_x, in draw_robots()
626 st->robots[x].lasers[y].end_y); in draw_robots()
632 if(st->MOTHER_SHIP) { in draw_robots()
633 if(st->mother->active) { in draw_robots()
634 …if (st->black) XFillArc(st->dpy, st->window, st->black, st->mother->old_x, st->mother->y, st->MOTH… in draw_robots()
635 …XFillArc(st->dpy, st->window, st->mother->ship_color, st->mother->new_x, st->mother->y, st->MOTHER… in draw_robots()
638 if(st->mother->death) { in draw_robots()
639 …if (st->black) XFillArc(st->dpy, st->window, st->black, st->mother->old_x, st->mother->y, st->MOTH… in draw_robots()
640 if(st->mother->death==20) { in draw_robots()
641 …XFillArc(st->dpy, st->window, st->EXPLODE_COLOR_1, st->mother->new_x+1, st->mother->y+1, st->EXPLO… in draw_robots()
643 else if(st->mother->death==18) { in draw_robots()
644 …XFillArc(st->dpy, st->window, st->EXPLODE_COLOR_2, st->mother->new_x+1, st->mother->y+1, st->EXPLO… in draw_robots()
646 else if(st->mother->death==17) { in draw_robots()
647 …XFillArc(st->dpy, st->window, st->EXPLODE_COLOR_1, st->mother->new_x+1, st->mother->y+1, st->EXPLO… in draw_robots()
649 else if(st->mother->death==15) { in draw_robots()
650 …if (st->black) XFillArc(st->dpy, st->window, st->black, st->mother->new_x+1, st->mother->y+1, st->… in draw_robots()
652 else if(st->mother->death==14) { in draw_robots()
653 …XFillArc(st->dpy, st->window, st->EXPLODE_COLOR_2, st->mother->new_x+1, st->mother->y+1, st->EXPLO… in draw_robots()
655 else if(st->mother->death==13) { in draw_robots()
656 …if (st->black) XFillArc(st->dpy, st->window, st->black, st->mother->new_x+1, st->mother->y+1, st->… in draw_robots()
658 else if(st->mother->death==12) { in draw_robots()
659 …XFillArc(st->dpy, st->window, st->EXPLODE_COLOR_1, st->mother->new_x+1, st->mother->y+1, st->EXPLO… in draw_robots()
661 else if(st->mother->death==11) { in draw_robots()
662 …if (st->black) XFillArc(st->dpy, st->window, st->black, st->mother->new_x+1, st->mother->y+1, st->… in draw_robots()
664 else if(st->mother->death==10) { in draw_robots()
665 …XFillArc(st->dpy, st->window, st->EXPLODE_COLOR_2, st->mother->new_x+1, st->mother->y+1, st->EXPLO… in draw_robots()
667 else if(st->mother->death==9) { in draw_robots()
668 …if (st->black) XFillArc(st->dpy, st->window, st->black, st->mother->new_x+1, st->mother->y+1, st->… in draw_robots()
670 else if(st->mother->death==8) { in draw_robots()
671 …XFillArc(st->dpy, st->window, st->EXPLODE_COLOR_1, st->mother->new_x+1, st->mother->y+1, st->EXPLO… in draw_robots()
673 else if(st->mother->death==7) { in draw_robots()
674 …if (st->black) XFillArc(st->dpy, st->window, st->black, st->mother->new_x+1, st->mother->y+1, st->… in draw_robots()
676 else if(st->mother->death==6) { in draw_robots()
677 …XFillArc(st->dpy, st->window, st->EXPLODE_COLOR_2, st->mother->new_x+1, st->mother->y+1, st->EXPLO… in draw_robots()
679 else if(st->mother->death==4) { in draw_robots()
680 …if (st->black) XFillArc(st->dpy, st->window, st->black, st->mother->new_x+1, st->mother->y+1, st->… in draw_robots()
682 else if(st->mother->death==3) { in draw_robots()
683 …XFillArc(st->dpy, st->window, st->EXPLODE_COLOR_1, st->mother->new_x+1, st->mother->y+1, st->EXPLO… in draw_robots()
685 else if(st->mother->death==2) { in draw_robots()
686 …if (st->black) XFillArc(st->dpy, st->window, st->black, st->mother->new_x+1, st->mother->y+1, st->… in draw_robots()
687st->dpy, st->window, st->EXPLODE_COLOR_2, st->mother->new_x+(1.7*st->MOTHER_SHIP_WIDTH/2), st->mot… in draw_robots()
689 else if(st->mother->death==1) { in draw_robots()
690st->black) XFillArc(st->dpy, st->window, st->black, st->mother->new_x+(1.7*st->MOTHER_SHIP_WIDTH/2… in draw_robots()
692 st->mother->death--; in draw_robots()
696 if(st->mother->lasers[y].active) { in draw_robots()
697 if (st->black) XDrawLine(st->dpy, st->window, st->black, st->mother->lasers[y].start_x, in draw_robots()
698 st->mother->lasers[y].start_y, in draw_robots()
699 st->mother->lasers[y].end_x, in draw_robots()
700 st->mother->lasers[y].end_y); in draw_robots()
701 move_laser(st, -1,y); in draw_robots()
702 if(st->mother->lasers[y].active) { in draw_robots()
703 XDrawLine(st->dpy, st->window, st->mother->laser_color, st->mother->lasers[y].start_x, in draw_robots()
704 st->mother->lasers[y].start_y, in draw_robots()
705 st->mother->lasers[y].end_x, in draw_robots()
706 st->mother->lasers[y].end_y); in draw_robots()
709 if (st->black) XDrawLine(st->dpy, st->window, st->black, st->mother->lasers[y].start_x, in draw_robots()
710 st->mother->lasers[y].start_y, in draw_robots()
711 st->mother->lasers[y].end_x, in draw_robots()
712 st->mother->lasers[y].end_y); in draw_robots()
720 init_stars(struct state *st) in init_stars() argument
722 if(st->NUM_STARS) { in init_stars()
723 if (! st->stars) in init_stars()
724 st->stars = (XArc *) malloc (st->NUM_STARS * sizeof(XArc)); in init_stars()
725 for(st->draw_x=0;st->draw_x<st->NUM_STARS;st->draw_x++) { in init_stars()
726 st->stars[st->draw_x].x = random()%st->xgwa.width; in init_stars()
727 st->stars[st->draw_x].y = random()%st->xgwa.height; in init_stars()
728 st->stars[st->draw_x].width = random()%4 + 1; in init_stars()
729 st->stars[st->draw_x].height = st->stars[st->draw_x].width; in init_stars()
730 st->stars[st->draw_x].angle1 = 0; in init_stars()
731 st->stars[st->draw_x].angle2 = 360 * 64; in init_stars()
740 struct state *st = (struct state *) closure; in blaster_draw() local
746 if (!st->initted) in blaster_draw()
748 st->initted = 1; in blaster_draw()
750 st->robots = (struct robot_state *) malloc(st->NUM_ROBOTS * sizeof (struct robot_state)); in blaster_draw()
751 for(st->draw_x=0;st->draw_x<st->NUM_ROBOTS;st->draw_x++) { in blaster_draw()
752 st->robots[st->draw_x].alive = 0; in blaster_draw()
753 st->robots[st->draw_x].death = 0; in blaster_draw()
754st->robots[st->draw_x].lasers = (struct laser_state *) malloc (st->NUM_LASERS * sizeof(struct lase… in blaster_draw()
755 for(st->draw_y=0;st->draw_y<st->NUM_LASERS;st->draw_y++) { in blaster_draw()
756 st->robots[st->draw_x].lasers[st->draw_y].active = 0; in blaster_draw()
760 init_stars(st); in blaster_draw()
763 if(st->NUM_STARS) { in blaster_draw()
764 if(st->MOVE_STARS) { in blaster_draw()
765 if (st->black) XFillArcs(st->dpy,st->window,st->black,st->stars,st->NUM_STARS); in blaster_draw()
766 if(st->MOVE_STARS_RANDOM) { in blaster_draw()
767 st->draw_y = st->MOVE_STARS_X; in blaster_draw()
768 st->draw_z = st->MOVE_STARS_Y; in blaster_draw()
770 st->draw_y = (-1)*st->draw_y; in blaster_draw()
773 st->draw_z = (-1)*st->draw_z; in blaster_draw()
777 st->draw_y++; in blaster_draw()
778 if(st->draw_y>st->MOVE_STARS_RANDOM) { in blaster_draw()
779 st->draw_y = st->MOVE_STARS_RANDOM; in blaster_draw()
783 st->draw_y--; in blaster_draw()
784 if(st->draw_y < -(st->MOVE_STARS_RANDOM)) { in blaster_draw()
785 st->draw_y = -(st->MOVE_STARS_RANDOM); in blaster_draw()
791 st->draw_z++; in blaster_draw()
792 if(st->draw_z>st->MOVE_STARS_RANDOM) { in blaster_draw()
793 st->draw_z = st->MOVE_STARS_RANDOM; in blaster_draw()
797 st->draw_z--; in blaster_draw()
798 if(st->draw_z < -st->MOVE_STARS_RANDOM) { in blaster_draw()
799 st->draw_z = -st->MOVE_STARS_RANDOM; in blaster_draw()
803 st->MOVE_STARS_X = st->draw_y; in blaster_draw()
804 st->MOVE_STARS_Y = st->draw_z; in blaster_draw()
805 for(st->draw_x=0;st->draw_x<st->NUM_STARS;st->draw_x++) { in blaster_draw()
806 st->stars[st->draw_x].x = st->stars[st->draw_x].x + st->draw_y; in blaster_draw()
807 st->stars[st->draw_x].y = st->stars[st->draw_x].y + st->draw_z; in blaster_draw()
808 if(st->stars[st->draw_x].x<0) { in blaster_draw()
809 st->stars[st->draw_x].x = st->stars[st->draw_x].x + st->xgwa.width; in blaster_draw()
811 else if(st->stars[st->draw_x].x>st->xgwa.width) { in blaster_draw()
812 st->stars[st->draw_x].x = st->stars[st->draw_x].x - st->xgwa.width; in blaster_draw()
814 if(st->stars[st->draw_x].y<0) { in blaster_draw()
815 st->stars[st->draw_x].y = st->stars[st->draw_x].y + st->xgwa.height; in blaster_draw()
817 else if(st->stars[st->draw_x].y>st->xgwa.height) { in blaster_draw()
818 st->stars[st->draw_x].y = st->stars[st->draw_x].y - st->xgwa.height; in blaster_draw()
823 for(st->draw_x=0;st->draw_x<st->NUM_STARS;st->draw_x++) { in blaster_draw()
824 st->stars[st->draw_x].x = st->stars[st->draw_x].x + st->MOVE_STARS_X; in blaster_draw()
825 st->stars[st->draw_x].y = st->stars[st->draw_x].y + st->MOVE_STARS_Y; in blaster_draw()
826 if(st->stars[st->draw_x].x<0) { in blaster_draw()
827 st->stars[st->draw_x].x = st->stars[st->draw_x].x + st->xgwa.width; in blaster_draw()
829 else if(st->stars[st->draw_x].x>st->xgwa.width) { in blaster_draw()
830 st->stars[st->draw_x].x = st->stars[st->draw_x].x - st->xgwa.width; in blaster_draw()
832 if(st->stars[st->draw_x].y<0) { in blaster_draw()
833 st->stars[st->draw_x].y = st->stars[st->draw_x].y + st->xgwa.height; in blaster_draw()
835 else if(st->stars[st->draw_x].y>st->xgwa.height) { in blaster_draw()
836 st->stars[st->draw_x].y = st->stars[st->draw_x].y - st->xgwa.height; in blaster_draw()
840 XFillArcs(st->dpy,st->window,st->s_color,st->stars,st->NUM_STARS); in blaster_draw()
843 XFillArcs(st->dpy,st->window,st->s_color,st->stars,st->NUM_STARS); in blaster_draw()
847 if(st->MOTHER_SHIP) { in blaster_draw()
848 if(random()%st->MOTHER_SHIP_PERIOD==0) { in blaster_draw()
849 if((st->mother->active==0)&&(st->mother->death==0)) { in blaster_draw()
850 st->mother->active = st->MOTHER_SHIP_HITS; in blaster_draw()
851 st->mother->y = random()%(st->xgwa.height-7); in blaster_draw()
853 st->mother->old_x=0; in blaster_draw()
854 st->mother->new_x=0; in blaster_draw()
857 st->mother->old_x=st->xgwa.width-25; in blaster_draw()
858 st->mother->new_x=st->xgwa.width-25; in blaster_draw()
863 move_robots(st); in blaster_draw()
864 if(st->MOTHER_SHIP) { in blaster_draw()
865 if(st->mother->active) { in blaster_draw()
866 if(st->mother->old_x==st->mother->new_x) { in blaster_draw()
867 if(st->mother->old_x==0) { in blaster_draw()
868 st->mother->new_x=3; in blaster_draw()
871 st->mother->new_x=st->mother->new_x-3; in blaster_draw()
875 if(st->mother->old_x>st->mother->new_x) { in blaster_draw()
876 st->mother->old_x = st->mother->new_x; in blaster_draw()
877 st->mother->new_x = st->mother->new_x-3; in blaster_draw()
878 if(st->mother->new_x<0) { in blaster_draw()
879 st->mother->active=0; in blaster_draw()
880 …if (st->black) XFillArc(st->dpy, st->window, st->black, st->mother->old_x, st->mother->y, st->MOTH… in blaster_draw()
881 …if (st->black) XFillArc(st->dpy, st->window, st->black, st->mother->new_x, st->mother->y, st->MOTH… in blaster_draw()
885 st->mother->old_x = st->mother->new_x; in blaster_draw()
886 st->mother->new_x = st->mother->new_x+3; in blaster_draw()
887 if(st->mother->new_x>st->xgwa.width) { in blaster_draw()
888 st->mother->active=0; in blaster_draw()
889 …if (st->black) XFillArc(st->dpy, st->window, st->black, st->mother->old_x, st->mother->y, st->MOTH… in blaster_draw()
890 …if (st->black) XFillArc(st->dpy, st->window, st->black, st->mother->new_x, st->mother->y, st->MOTH… in blaster_draw()
894 st->draw_y=0; in blaster_draw()
895 for(st->draw_x=0;st->draw_x<8;st->draw_x++) { in blaster_draw()
896 if(st->mother->lasers[st->draw_x].active) { in blaster_draw()
897 st->draw_y=1; in blaster_draw()
898 st->draw_x=8; in blaster_draw()
901 if(st->draw_y==0) { in blaster_draw()
902 for(st->draw_x=0;st->draw_x<8;st->draw_x++) { in blaster_draw()
903 st->mother->lasers[st->draw_x].active = 1; in blaster_draw()
904 st->mother->lasers[st->draw_x].start_x=st->mother->new_x+(st->MOTHER_SHIP_WIDTH/2); in blaster_draw()
905 st->mother->lasers[st->draw_x].start_y=st->mother->y+(st->MOTHER_SHIP_HEIGHT/2); in blaster_draw()
907 st->draw_y = (int)(st->MOTHER_SHIP_LASER/1.5); in blaster_draw()
908 st->mother->lasers[0].end_x=st->mother->lasers[0].start_x-st->MOTHER_SHIP_LASER; in blaster_draw()
909 st->mother->lasers[0].end_y=st->mother->lasers[0].start_y; in blaster_draw()
910 st->mother->lasers[1].end_x=st->mother->lasers[1].start_x-st->draw_y; in blaster_draw()
911 st->mother->lasers[1].end_y=st->mother->lasers[1].start_y-st->draw_y; in blaster_draw()
912 st->mother->lasers[2].end_x=st->mother->lasers[2].start_x; in blaster_draw()
913 st->mother->lasers[2].end_y=st->mother->lasers[2].start_y-st->MOTHER_SHIP_LASER; in blaster_draw()
914 st->mother->lasers[3].end_x=st->mother->lasers[3].start_x+st->draw_y; in blaster_draw()
915 st->mother->lasers[3].end_y=st->mother->lasers[3].start_y-st->draw_y; in blaster_draw()
916 st->mother->lasers[4].end_x=st->mother->lasers[4].start_x+st->MOTHER_SHIP_LASER; in blaster_draw()
917 st->mother->lasers[4].end_y=st->mother->lasers[4].start_y; in blaster_draw()
918 st->mother->lasers[5].end_x=st->mother->lasers[5].start_x+st->draw_y; in blaster_draw()
919 st->mother->lasers[5].end_y=st->mother->lasers[5].start_y+st->draw_y; in blaster_draw()
920 st->mother->lasers[6].end_x=st->mother->lasers[6].start_x; in blaster_draw()
921 st->mother->lasers[6].end_y=st->mother->lasers[6].start_y+st->MOTHER_SHIP_LASER; in blaster_draw()
922 st->mother->lasers[7].end_x=st->mother->lasers[7].start_x-st->draw_y; in blaster_draw()
923 st->mother->lasers[7].end_y=st->mother->lasers[7].start_y+st->draw_y; in blaster_draw()
927 draw_robots(st); in blaster_draw()
929 return st->delay; in blaster_draw()
935 struct state *st = (struct state *) calloc (1, sizeof(*st)); in blaster_init() local
940 st->dpy = d; in blaster_init()
941 st->window = w; in blaster_init()
942 XGetWindowAttributes(st->dpy, st->window, &st->xgwa); in blaster_init()
943 cmap = st->xgwa.colormap; in blaster_init()
945 st->NUM_ROBOTS=5; in blaster_init()
946 st->NUM_LASERS=3; in blaster_init()
948 st->MOTHER_SHIP_WIDTH=25; in blaster_init()
949 st->MOTHER_SHIP_HEIGHT=7; in blaster_init()
950 st->MOTHER_SHIP_LASER=15; in blaster_init()
951 st->MOTHER_SHIP_PERIOD=150; in blaster_init()
952 st->MOTHER_SHIP_HITS=10; in blaster_init()
954 st->RANDOM_MOVE_STYLE=1; in blaster_init()
955 st->NUM_MOVE_STYLES=2; in blaster_init()
957 st->EXPLODE_SIZE_1=27; in blaster_init()
958 st->EXPLODE_SIZE_2=19; in blaster_init()
959 st->EXPLODE_SIZE_3=7; in blaster_init()
962 st->delay = get_integer_resource(st->dpy, "delay", "Integer"); in blaster_init()
963 if(st->delay==0) { in blaster_init()
964 st->delay=10000; in blaster_init()
966 st->NUM_ROBOTS = get_integer_resource(st->dpy, "num_robots","Integer"); in blaster_init()
967 if(st->NUM_ROBOTS==0) { in blaster_init()
968 st->NUM_ROBOTS=5; in blaster_init()
970 st->NUM_LASERS = get_integer_resource(st->dpy, "num_lasers","Integer"); in blaster_init()
971 st->EXPLODE_SIZE_1 = get_integer_resource(st->dpy, "explode_size_1","Integer"); in blaster_init()
972 st->EXPLODE_SIZE_2 = get_integer_resource(st->dpy, "explode_size_2","Integer"); in blaster_init()
973 st->EXPLODE_SIZE_3 = get_integer_resource(st->dpy, "explode_size_3","Integer"); in blaster_init()
975 st->NUM_STARS = get_integer_resource(st->dpy, "num_stars","Integer"); in blaster_init()
976 if(get_boolean_resource(st->dpy, "move_stars","Boolean")) { in blaster_init()
977 st->MOVE_STARS = 1; in blaster_init()
978 st->MOVE_STARS_X = get_integer_resource(st->dpy, "move_stars_x","Integer"); in blaster_init()
979 st->MOVE_STARS_Y = get_integer_resource(st->dpy, "move_stars_y","Integer"); in blaster_init()
980 st->MOVE_STARS_RANDOM = get_integer_resource(st->dpy, "move_stars_random","Integer"); in blaster_init()
983 st->MOVE_STARS = 0; in blaster_init()
987 bg = get_pixel_resource(st->dpy, cmap, "background","Background"); in blaster_init()
991 gcv.foreground = get_pixel_resource (st->dpy, cmap, (name), "Foreground"); \ in blaster_init()
992 color = XCreateGC (st->dpy, st->window, GCForeground|GCFunction, &gcv) in blaster_init()
996 st->black = XCreateGC(st->dpy, st->window, GCForeground|GCFunction, &gcv); in blaster_init()
997 gcv.foreground = get_pixel_resource(st->dpy, cmap, "foreground", "Foreground"); in blaster_init()
998st->r_color0 = st->r_color1 = st->r_color2 = st->r_color3 = st->r_color4 = st->r_color5 = st->l_co… in blaster_init()
999 XCreateGC(st->dpy, st->window, GCForeground|GCFunction, &gcv); in blaster_init()
1000 if(get_boolean_resource(st->dpy, "mother_ship","Boolean")) { in blaster_init()
1001 st->MOTHER_SHIP_WIDTH=get_integer_resource(st->dpy, "mother_ship_width","Integer"); in blaster_init()
1002 st->MOTHER_SHIP_HEIGHT=get_integer_resource(st->dpy, "mother_ship_height","Integer"); in blaster_init()
1003 st->MOTHER_SHIP_LASER=get_integer_resource(st->dpy, "mother_ship_laser","Integer"); in blaster_init()
1004 st->MOTHER_SHIP_PERIOD=get_integer_resource(st->dpy, "mother_ship_period","Integer"); in blaster_init()
1005 st->MOTHER_SHIP_HITS=get_integer_resource(st->dpy, "mother_ship_hits","Integer"); in blaster_init()
1006 st->MOTHER_SHIP=1; in blaster_init()
1007 st->mother = (struct mother_ship_state *) malloc(sizeof(struct mother_ship_state)); in blaster_init()
1008 st->mother->lasers = (struct laser_state *) malloc(8*sizeof(struct laser_state)); in blaster_init()
1009 st->mother->active = 0; in blaster_init()
1010 st->mother->death = 0; in blaster_init()
1011 st->mother->ship_color = st->r_color0; in blaster_init()
1012 st->mother->laser_color = st->r_color0; in blaster_init()
1016 if(get_boolean_resource(st->dpy, "mother_ship","Boolean")) { in blaster_init()
1017 st->MOTHER_SHIP_WIDTH=get_integer_resource(st->dpy, "mother_ship_width","Integer"); in blaster_init()
1018 st->MOTHER_SHIP_HEIGHT=get_integer_resource(st->dpy, "mother_ship_height","Integer"); in blaster_init()
1019 st->MOTHER_SHIP_LASER=get_integer_resource(st->dpy, "mother_ship_laser","Integer"); in blaster_init()
1020 st->MOTHER_SHIP_PERIOD=get_integer_resource(st->dpy, "mother_ship_period","Integer"); in blaster_init()
1021 st->MOTHER_SHIP_HITS=get_integer_resource(st->dpy, "mother_ship_hits","Integer"); in blaster_init()
1022 st->MOTHER_SHIP=1; in blaster_init()
1023 st->mother = (struct mother_ship_state *) malloc(sizeof(struct mother_ship_state)); in blaster_init()
1024 st->mother->lasers = (struct laser_state *) malloc(8*sizeof(struct laser_state)); in blaster_init()
1025 st->mother->active = 0; in blaster_init()
1026 st->mother->death = 0; in blaster_init()
1027 make_gc(st->mother->ship_color,"mother_ship_color0"); in blaster_init()
1028 make_gc(st->mother->laser_color,"mother_ship_color1"); in blaster_init()
1031 make_gc (st->s_color,"star_color"); in blaster_init()
1033 make_gc (st->EXPLODE_COLOR_1,"explode_color_1"); in blaster_init()
1034 make_gc (st->EXPLODE_COLOR_2,"explode_color_2"); in blaster_init()
1036 make_gc (st->r_color0,"r_color0"); in blaster_init()
1037 make_gc (st->r_color1,"r_color1"); in blaster_init()
1038 make_gc (st->r_color2,"r_color2"); in blaster_init()
1039 make_gc (st->r_color3,"r_color3"); in blaster_init()
1040 make_gc (st->r_color4,"r_color4"); in blaster_init()
1041 make_gc (st->r_color5,"r_color5"); in blaster_init()
1042 make_gc (st->l_color0,"l_color0"); in blaster_init()
1043 make_gc (st->l_color1,"l_color1"); in blaster_init()
1045 st->black = 0; in blaster_init()
1047 make_gc (st->black,"background"); in blaster_init()
1051 return st; in blaster_init()
1059 struct state *st = (struct state *) closure; in blaster_reshape() local
1060 XGetWindowAttributes (dpy, window, &st->xgwa); in blaster_reshape()
1062 init_stars (st); in blaster_reshape()
1074 struct state *st = (struct state *) closure; in blaster_free() local
1076 if (st->r_color0) XFreeGC (dpy, st->r_color0); in blaster_free()
1077 if (st->r_color1) XFreeGC (dpy, st->r_color1); in blaster_free()
1078 if (st->r_color2) XFreeGC (dpy, st->r_color2); in blaster_free()
1079 if (st->r_color3) XFreeGC (dpy, st->r_color3); in blaster_free()
1080 if (st->r_color4) XFreeGC (dpy, st->r_color4); in blaster_free()
1081 if (st->r_color5) XFreeGC (dpy, st->r_color5); in blaster_free()
1082 if (st->l_color0) XFreeGC (dpy, st->l_color0); in blaster_free()
1083 if (st->l_color1) XFreeGC (dpy, st->l_color1); in blaster_free()
1084 if (st->s_color) XFreeGC (dpy, st->s_color); in blaster_free()
1085 if (st->black) XFreeGC (dpy, st->black); in blaster_free()
1086 if (st->EXPLODE_COLOR_1) XFreeGC (dpy, st->EXPLODE_COLOR_1); in blaster_free()
1087 if (st->EXPLODE_COLOR_2) XFreeGC (dpy, st->EXPLODE_COLOR_2); in blaster_free()
1088 if (st->stars) free (st->stars); in blaster_free()
1089 if (st->mother) { in blaster_free()
1090 free (st->mother->lasers); in blaster_free()
1091 free (st->mother); in blaster_free()
1093 for (i = 0; i < st->NUM_ROBOTS; i++) in blaster_free()
1094 free (st->robots[i].lasers); in blaster_free()
1095 free (st->robots); in blaster_free()
1096 free (st); in blaster_free()