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)
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
603
st->robots[x].death--;
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
709
/* This is the main loop. The mothership movement and laser firing happens inside
717
robots = (struct robot_state *) malloc(NUM_ROBOTS * sizeof (struct robot_state));
718
for(x=0;x<NUM_ROBOTS;x++) {
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;
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;
735
stars[x].angle2 = 360 * 64;
742
XFillArcs(dpy,window,black,stars,NUM_STARS);
743
if(MOVE_STARS_RANDOM) {
720
init_stars(struct state *st)
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;
738
blaster_draw (Display *dpy, Window window, void *closure)
740
struct state *st = (struct state *) closure;
742
#ifdef HAVE_COCOA /* Don't second-guess Quartz's double-buffering */
743
XClearWindow (dpy, window);
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;
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) {
770
st->draw_y = (-1)*st->draw_y;
749
772
if(random()%173==0) {
755
if(y>MOVE_STARS_RANDOM) {
756
y = MOVE_STARS_RANDOM;
761
if(y < -(MOVE_STARS_RANDOM)) {
762
y = -(MOVE_STARS_RANDOM);
769
if(z>MOVE_STARS_RANDOM) {
770
z = MOVE_STARS_RANDOM;
775
if(z < -MOVE_STARS_RANDOM) {
776
z = -MOVE_STARS_RANDOM;
782
for(x=0;x<NUM_STARS;x++) {
783
stars[x].x = stars[x].x + y;
784
stars[x].y = stars[x].y + z;
786
stars[x].x = stars[x].x + xgwa.width;
788
else if(stars[x].x>xgwa.width) {
789
stars[x].x = stars[x].x - xgwa.width;
792
stars[x].y = stars[x].y + xgwa.height;
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;
778
if(st->draw_y>st->MOVE_STARS_RANDOM) {
779
st->draw_y = st->MOVE_STARS_RANDOM;
784
if(st->draw_y < -(st->MOVE_STARS_RANDOM)) {
785
st->draw_y = -(st->MOVE_STARS_RANDOM);
792
if(st->draw_z>st->MOVE_STARS_RANDOM) {
793
st->draw_z = st->MOVE_STARS_RANDOM;
798
if(st->draw_z < -st->MOVE_STARS_RANDOM) {
799
st->draw_z = -st->MOVE_STARS_RANDOM;
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;
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;
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;
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;
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;
804
stars[x].x = stars[x].x + xgwa.width;
806
else if(stars[x].x>xgwa.width) {
807
stars[x].x = stars[x].x - xgwa.width;
810
stars[x].y = stars[x].y + xgwa.height;
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;
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;
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;
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;
817
XFillArcs(dpy,window,s_color,stars,NUM_STARS);
840
XFillArcs(st->dpy,st->window,st->s_color,st->stars,st->NUM_STARS);
820
XFillArcs(dpy,window,s_color,stars,NUM_STARS);
843
XFillArcs(st->dpy,st->window,st->s_color,st->stars,st->NUM_STARS);
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) {
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;
843
if(mother->old_x==mother->new_x) {
844
if(mother->old_x==0) {
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) {
848
mother->new_x=mother->new_x-3;
871
st->mother->new_x=st->mother->new_x-3;
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) {
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);
862
mother->old_x = mother->new_x;
863
mother->new_x = mother->new_x+3;
864
if(mother->new_x>xgwa.width) {
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);
873
if(mother->lasers[x].active) {
895
for(st->draw_x=0;st->draw_x<8;st->draw_x++) {
896
if(st->mother->lasers[st->draw_x].active) {
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);
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);
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;
907
screenhack_handle_events(dpy);
908
if(delay) usleep(delay);
919
char *progclass = "Blaster";
921
char *defaults [] = {
933
blaster_init (Display *d, Window w)
935
struct state *st = (struct state *) calloc (1, sizeof(*st));
942
XGetWindowAttributes(st->dpy, st->window, &st->xgwa);
943
cmap = st->xgwa.colormap;
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;
954
st->RANDOM_MOVE_STYLE=1;
955
st->NUM_MOVE_STYLES=2;
957
st->EXPLODE_SIZE_1=27;
958
st->EXPLODE_SIZE_2=19;
959
st->EXPLODE_SIZE_3=7;
962
st->delay = get_integer_resource(st->dpy, "delay", "Integer");
966
st->NUM_ROBOTS = get_integer_resource(st->dpy, "num_robots","Integer");
967
if(st->NUM_ROBOTS==0) {
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");
975
st->NUM_STARS = get_integer_resource(st->dpy, "num_stars","Integer");
976
if(get_boolean_resource(st->dpy, "move_stars","Boolean")) {
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");
987
bg = get_pixel_resource(st->dpy, cmap, "background","Background");
988
gcv.function = GXcopy;
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)
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");
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;
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");
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");
1031
make_gc (st->s_color,"star_color");
1033
make_gc (st->EXPLODE_COLOR_1,"explode_color_1");
1034
make_gc (st->EXPLODE_COLOR_2,"explode_color_2");
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 */
1047
make_gc (st->black,"background");
1056
blaster_reshape (Display *dpy, Window window, void *closure,
1057
unsigned int w, unsigned int h)
1059
struct state *st = (struct state *) closure;
1060
XGetWindowAttributes (dpy, window, &st->xgwa);
1061
XClearWindow (dpy, window);
1066
blaster_event (Display *dpy, Window window, void *closure, XEvent *event)
1072
blaster_free (Display *dpy, Window window, void *closure)
1074
struct state *st = (struct state *) closure;
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);
1088
free (st->mother->lasers);
1091
for (i = 0; i < st->NUM_ROBOTS; i++)
1092
free (st->robots[i].lasers);
1098
static const char *blaster_defaults [] = {
922
1099
".background: black",
923
1100
".foreground: white",
924
"*r_color0: magenta",
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",