 
// Llama's amazing Puzzle Bobble rip-off!
// Started on 5th September 1996
// Finished on 11th October 1996. (fucking 6am...)

//compile with: gcc -w -m486 -O3 myballs.c -lalleg -o myballs.exe

//several times the code jumps nastily out of loops. stopping the stack
//from building up is left as an exercise for the acolyte.

#include <allegro.h>
#include <stdlib.h>
#include <stdio.h>

void doendseq();
void doredraw();
void doredraw2();
void doredraw3();
char helpful,helpful2;
char rev;
char rndsel[8];
char rndsel2;
char rndselmark;
char blowupanyway;
void doinfo();
char startsave;
void dofireworks(); 
void doblowup();
void kafireworks();
void dowinner();
char whoop=0,twowhoop=0;
char whoop2,twowhoop2;
char f4,g4,lll,flishcount,ballcount,onesuchprime,flashcount,pointcount;
char flashcount2,pointcount2;
float xx9;
void dograf3();
void docol();
void docol2();
int g29,f29,h9;
void doholditprime();
void drawgive();
void drawgive2();
unsigned char give[100];
unsigned char give2[100];
int gv,gv2,gov,gov2;
void doflish();
void dohold1();
void dohold2();
void doflash();
unsigned char fx[100],fy[100],fc[100],fx2[100],fy2[100],fc2[100];
unsigned char flish,flish2,flx,flishchex;
void doquirk3();
void dostop3();
void doscaw();
void doquirk2();
void dostop2();
void ballmove2();
void keytest2();
void doremove();
void doremove2();
void doremove3();
void doric(bmp,x,y,d);
void graf2();
void graf1();
void lockup();
void kadrop();
void doaim();
void doaim2();
void doaim3();
void dostop();
void keytest();
void ballmove();
void doquirk();
void kaboom();
void kaboom2();
void llamascree();
void mainscree();
void whoo();
allegro_init();


int rd=0;
char rounds[6][40]={"first to 3","first to 5","first to 7","first to 10",
		    "first to 20",
		    "until some creature presses escape"};
		    
int il=3,rownd=1;
char gecko[3][25]={"Elgin Marbles","Trippy Alien Insanity","Egyptian Madness"};
int gk=0;
int intballs=0;
char yn[2][15]={"no way matey","go on then..."};

int vr,vr2,onesuch,onesuch2;
int scaw,scaw2;
int exx[307200],exy[307200];
int select[15];
char exdx[307200],exdy[307200];
unsigned char exc[307200];
unsigned int exnum=0;

int tog=0;
unsigned char string[100];
int newvar=0,jig=1,jig2=1,diff=1,bb2,bb,start=0;
int f3=0,opt=0,sel=0,opt2=0,sel2=0,cunt=0,cunt2=0,ff2=0,gg2=0,ff=0,gg=0,f2=0,g2=0,f=0,g=0,h=0,h2=0,i=0,i2=0,angle=0,angle2=0,fire=0,fire2=0,sol=0,redo=0,redo2=0,goat=0;
float firex=304,firey=425,firex2,firey2,twofirex2,twofirey2,nfirex,nfirey,nfirex2,nfirey2,newx2=0,newy2=0,newx=0,newy=0,extra=0,extra2=0;
float twofirex,twofirey;
int realx,realy,realx2,realy2,nrealx2,nrealy2,nrealx,nrealy,chex,chex2,next,next2,shots=0,shots2=0,fucked=0,fucked2=0;
float rx=0,ry=0,nrx=0,nry=0,rx2=0,ry2=0,nrx2=0,nry2=0;
int set=0,set2=0,todrop=0,bf=0,bf2=0,holdit=0,holdit2=0,hit2=0,hit=0,flash=0,flash2=0,ok=0,top=0,top2=0;
int linex2[20],liney2[20],linex[20],liney[20],nolines,nolines2,aim=0,aim2=0,count=0,count2=0;
int dropx[200],dropy[200],dropc[200];
int dropno=0;
int cont=0;
float xx=0,nxx=0,nxx2=0,xx2=0,yy2=0,yy=0;
char map[17][12],map2[17][12],map3[17][12];
char twomap2[8][12],twomap3[8][12];
char twomap[8][12];
int bfset[50];
int bfc,bfc2,freeze2,freeze;
char level[50][17][12];
char credits[350][120];
char buff[100];
char difftext[4][10]={"EASY","NORMAL","HARD","STUPID"};
int ln=0,l=0;

int upto=0,players=1;
FILE *creds;
int pix=0,pix2=0;

PALLETE pal[256];
PALLETE pal2[256];
BITMAP *view;
        BITMAP *red;
        BITMAP *orange;
        BITMAP *yellow;
        BITMAP *green;
        BITMAP *blue;
        BITMAP *purple;
        BITMAP *white;
        BITMAP *black;
        BITMAP *drop;
        BITMAP *bomb;
        BITMAP *wall;
        BITMAP *key2;
	BITMAP *eye;
BITMAP *smiley;
BITMAP *ball[14];


BITMAP *firetemp;
BITMAP *firetemp2;
BITMAP *arrow;
BITMAP *b;
BITMAP *llama;
BITMAP *realtech;
BITMAP *title;
BITMAP *side;
BITMAP *oldwheel;
BITMAP *wheel;
BITMAP *oldarrow;

BITMAP *wheel2;
BITMAP *sqview;
BITMAP *c;

SAMPLE *appearw;
SAMPLE *chal1w;
SAMPLE *chal2w;
SAMPLE *chal3w;
SAMPLE *mummy;
SAMPLE *firew;
SAMPLE *clunkw;
SAMPLE *bouncew;
SAMPLE *explodew;
SAMPLE *fallw;
SAMPLE *donew;
SAMPLE *fukdw;
SAMPLE *dangerw;
SAMPLE *dangerw2;

SAMPLE *readyw;
SAMPLE *fightw;
SAMPLE *player1w;
SAMPLE *player2w;
BITMAP *mini;
BITMAP *mini2;


void main(){
lockup();                          
        mini=create_bitmap(14*8,8);
        mini2=create_bitmap(16,8);
        wheel=create_bitmap(120,100);
        wheel2=create_bitmap(120,100);
        sqview=create_bitmap(256,352);
        arrow=create_bitmap(120,120);
        b=create_bitmap(640,480);
	
        firetemp=create_bitmap(32,32);
        firetemp2=create_bitmap(32,32);
	appearw=load_sample("wav/belch.wav");
        chal1w=load_sample("wav/chal1.wav");
        chal2w=load_sample("wav/chal2.wav");
        chal3w=load_sample("wav/chal3.wav");
        firew=load_sample("wav/whine2.wav");
        clunkw=load_sample("wav/clunk.wav");
        bouncew=load_sample("wav/chord.wav");
        explodew=load_sample("wav/explode.wav");
        fallw=load_sample("wav/hawkroll.wav");
        donew=load_sample("wav/done.wav");
        fukdw=load_sample("wav/balldrop.wav");
        dangerw=load_sample("wav/danger.wav");
        dangerw2=load_sample("wav/danger.wav");
	     
	readyw=load_sample("wav/ready.wav");
	fightw=load_sample("wav/fight.wav");
	player1w=load_sample("wav/player1.wav");
	player2w=load_sample("wav/player2.wav");

        set_gfx_mode(GFX_AUTODETECT,640,480,0,0);

creds=fopen("levels.dat","rb");
                        for(l=0;l<50;l++)
                        for(g=0;g<11;g++)
                        for(f=0;f<16+(!(g%2));f++)
                          level[l][f][g]=fgetc(creds);
                        fclose(creds);

                        for(l=0;l<50;l++)
                        for(f=0;f<16+(!(g%2));f++)
                            level[l][f][11]=8;
install_keyboard();
install_timer();
install_sound(DIGI_AUTODETECT,MIDI_AUTODETECT,NULL);

llamascree();



shaftmain:
graf1();
mainscree();


if(start==999)goto shutdown;


if(players==2){
                if(diff==0){helpful=1;helpful2=1;}
                else{helpful=0;helpful2=0;}
                l=0;
                rownd=1;
                scaw=0;scaw2=0;
                todrop=(diff<2)?15:10;
                tog=(diff==3)?1:0;
                if(gk==2)graf3();
                if(gk==1)graf2();
                if(gk==0)graf1();
                goto levup;
               }


if(start>19&&start<40)graf2();
if(start>39)graf3();

        l=start;todrop=(diff<2)?15:10;
        tog=(diff==3)?1:0;
        

levup:

        if(players==2){
        	       if(  (rd==0&&(scaw==3||scaw2==3))
        	       	 || (rd==1&&(scaw==5||scaw2==5))
        	       	 || (rd==2&&(scaw==7||scaw2==7))
        	       	 || (rd==3&&(scaw==10||scaw2==10))
        	       	 || (rd==4&&(scaw==20||scaw2==20)))
			{dofireworks();
			 goto shaftmain;}       	       
        	       
        	       
        	       
        	       flish=0;flish2=0;
                       lll=0;realy=0;
                       gv=0;gv2=0;
                       gov=0;gov2=0;
                       exnum=0;dropno=0;
                       onesuch=0;onesuch2=0;
                       vr=0;vr2=0;
                       whoop=0;whoop2=1;
                       twowhoop=0;twowhoop2=1;
                       stop_sample(dangerw);stop_sample(dangerw2);
                       fucked=0;fucked2=0;
                       fire=0;fire2=0;
                       set_pallete(pal2);
                       clear(b);
                       rectfill(b,43,353,299,479,8);
                       blit(title,b,0,0,0,0,640,48);
                       stretch_blit(side,b,0,0,48,432,299,48,43,432);
                       
                       doscaw();
                       blit(sqview,b,0,0,43,48,256,352);
                       blit(sqview,b,0,0,342,48,256,352);
                        blit(sqview,wheel,68,333,0,0,120,20);
                        blit(sqview,wheel2,68,333,0,0,120,20);
                       blit(wheel2,b,0,0,131-20,401-20,120,100);
                       blit(wheel,b,0,0,430-20,401-20,120,100);

                       count=0;top=0;angle=0;
                       count2=0;top2=0;angle2=0;
                       freeze=0;freeze2=0;

                       for(g=0;g<12;g++)for(f=0;f<7+(!(g%2^top));f++)
                        {
                        if(g<il){
                        sel=random()%8;
                        if(intballs)if(random()%16==4)sel=(random()%(3+gk))+9;
                        map[f][g]=sel;
                        twomap[f][g]=sel;
                        if(sel!=11)count++;}
                        else{map[f][g]=8;twomap[f][g]=8;}

                        }
                        count2=count;

                        for(f=0;f<50;f++)bfset[f]=random()%8;

                        bfc=2;bfc2=2;
                        bf=bfset[0];bf2=bf;
                        next=bfset[1];next2=next;
                        shots=0;set=0;cunt=0;i=0;
                        shots2=0;set2=0;cunt2=0;i2=0;
                        if(diff<2){textout(b,font,"NEXT:",131+120,412,1);
                                   textout(b,font,"NEXT:",430+120,412,1);
                        draw_sprite(b,ball[next],251,425);
                        draw_sprite(b,ball[next],430+120,425);}
                        for(g=0;g<11;g++){
                        for(f=0;f<7+(!(g%2^top));f++){
  if(map[f][g]!=8){draw_sprite(b,ball[map[f][g]],43+(16*(g%2^top))+(f*32),48+(g*32));
                  draw_sprite(b,ball[map[f][g]],43+43+256+(16*(g%2^top))+(f*32),48+(g*32));}                

                   }}
draw_sprite(b,arrow,131-20,381);
draw_sprite(b,arrow,430-20,381);
blit (b,screen,0,0,0,0,640,480);
twofirex=44+131-20;twofirey=425;
firex=454;firey=425;
draw_sprite(screen,ball[bf],firex,firey);
draw_sprite(screen,ball[bf],twofirex,twofirey);
draw_sprite(b,ball[bf],firex,firey);
draw_sprite(b,ball[bf],twofirex,twofirey);


play_sample(readyw,255,128,1000,0);
sprintf(string,"ROUND %d",rownd);
sel=(7+(rownd>9));
f29=251;
whoo();

sprintf(string,"GET READY");
sel=9;
f29=251;
whoo();
	
play_sample(fightw,255,128,1000,0);
sprintf(string,"FIGHT!");
sel=6;
whoo2();
ballcount=0;
install_int(doflash,10);

if(helpful){aim=0;flash=random()%256;doaim2();}
if(helpful2){aim2=0;flash2=random()%256;doaim3();}

goto loopylemur;                      
                        }


        if(l==20&&start<20)graf2();
	if(l==40&&start<40)graf3();
        cont=l;
        stop_sample(dangerw);
        fucked=0;
        set_pallete(pal2);

        
        clear(b);
        blit(title,b,0,0,0,0,640,48);
        blit(side,b,0,0,0,48,48,432);
        blit(side,b,0,0,639-47,48,48,432);
        blit(view,b,0,0,48,48,544,352);
        blit(view,wheel,212,333,0,0,120,20);

        blit(wheel,b,0,0,260,401-20,120,100);
    
    

count=0;top=0;angle=0;helpful=0;
rev=(random()%1000>500);
for(g=0;g<12;g++)for(f=0;f<16+(!(g%2^top));f++)
       {
        if (rev)
        {map[f][g]=level[l][f][g];
        if(map[f][g]!=8&&map[f][g]!=11)count++;}

        else
        {map[(15+(!(g%2^top)))-f][g]=level[l][f][g];
        if(map[(15+(!(g%2^top)))-f][g]!=8&&map[(15+(!(g%2^top)))-f][g]!=11)count++;}

        }


bf=random()%8;
next=random()%8;

lll=0;ballcount=0;shots=0;set=0;set2=0;cunt=0;i=0;
if(diff<2){textout(b,font,"NEXT:",492,412,1);
           draw_sprite(b,ball[next],492,425);}
sprintf(string,"Level= %d   ",l+1);
textout(b,font,string,60,412,1);
textout(b,font,difftext[diff],60,432,65);

        for(g=0;g<11;g++){
                for(f=0;f<16+(!(g%2^top));f++){
                 if(map[f][g]!=8)draw_sprite(b,ball[map[f][g]],48+(16*(g%2^top))+(f*32),48+(g*32));
                                  

                   }}

draw_sprite(b,arrow,260,381);

blit (b,screen,0,0,0,0,640,480);

firex=304;firey=425;
draw_sprite(screen,ball[bf],firex,firey);
draw_sprite(b,ball[bf],firex,firey);

if(l<20)play_sample(chal1w,255,128,1000,0);
if(l>19&&l<40)play_sample(chal2w,255,128,1000,0);
if(l>39)play_sample(chal3w,255,128,1000,0);
sprintf(string,"LEVEL %d",l+1);
sel=7+(l>8);
f29=251;
whoo();




install_int(doflash,10);

if(diff==0){aim=0;flash=random()%256;
doaim();}
goto loopyllama;

loopylemur://2 player main loop


if(exnum!=0)kaboom();
if(dropno!=0)kadrop();
if(flishcount==2)doflish();
if(ballcount==1)ballmove2();
docol();
docol2();
if(holdit!=0)dohold1();//fucked, drop, wuz balls on etc...
if(holdit2!=0)dohold2();//same for player2

keytest2();
if(l==999)	{remove_int(flash);
		stop_sample(dangerw);stop_sample(dangerw2);
		goto shaftmain;
		}

if(lll==1)goto levup;
goto loopylemur;//back to 2 player main loop

loopyllama:

docol();
if(exnum!=0)kaboom();
if(dropno!=0)kadrop();
if(ballcount==1)ballmove();
if(holdit!=0)doholditprime();
keytest();
if(l==999)	{remove_int(doflash);
		stop_sample(dangerw);stop_sample(fukdw);
		goto shaftmain;}
		



if(count==0||key[KEY_F1]){
                   remove_int(doflash);
		   stop_sample(dangerw);                  
                   doremove();
                   play_sample(donew,255,128,1000,0);
                   
                   pieces:
                   kaboom();
                   if(dropno!=0)kadrop();
                   if(exnum!=0||dropno!=0)goto pieces;
                   
                   if(l==49){doendseq();goto shaftmain;}
                   extra=1;
                   exnum=0;
                   for(f=0;f<640;f++)
                    for (g=0;g<480;g++)
                     {goat=getpixel(screen,f,g);
                     if(goat)
                       {exx[exnum]=f;exy[exnum]=g;
                        exdx[exnum]=(random()%11)-5;
                        exdy[exnum]=(random()%11)-5;
                        if(exdx[exnum]==0 && exdy[exnum]==0)
                                exdy[exnum]=1;
                        exc[exnum]=goat;
                        exnum++;}}
                   
                   
                   kaboom2();
		   l++;goto levup;
                  }




goto loopyllama;

shutdown:
allegro_exit();
printf("I'm an old man, but I like my sausages...");
exit(0);

}

void kaboom()
{


chex=0;

for(h=1;h<exnum+1;h++){
                    if(exx[h]>=0&&exx[h]<=639&&exy[h]>=0&&exy[h]<=479)
                     _putpixel(screen,exx[h],exy[h],getpixel(b,exx[h],exy[h]));
                    
                    exx[h]+=exdx[h]*extra;
                    exy[h]+=exdy[h]*extra2;

                    if(exx[h]>=0&&exx[h]<=639&&exy[h]>=0&&exy[h]<=479)

                       {
                        _putpixel(screen,exx[h],exy[h],exc[h]);
                        chex=1;
                       }
                    }
extra+=0.03;
extra2+=0.03;
if(chex==0)exnum=0;
}



void kaboom2()
{
for(newvar=0;newvar<9;newvar++){
clear(b);
for(f=0;f<exnum;f++){
                    exx[f]+=exdx[f]*extra;
                    exy[f]+=exdy[f]*extra;
                    if(exx[f]>=0&&exx[f]<=639&&exy[f]>=0&&exy[f]<=479)
                        _putpixel(b,exx[f],exy[f],exc[f]);
                        
                        
                    }
extra+=0.5;
blit(b,screen,0,0,0,0,640,480);
}
fade_out(1);exnum=0;

}


void kadrop()
{
chex2=0;

for(h2=1;h2<dropno;h2++){
                         if(dropy[h2]<480){
                         chex2=1;
                         blit(b,screen,dropx[h2],dropy[h2],dropx[h2],dropy[h2],32,32);
                         dropy[h2]+=6;
                         draw_sprite(screen,ball[dropc[h2]],dropx[h2],dropy[h2]);
                                         }
                        }
if(chex2==0)dropno=0;

}

void keytest(){


if(key[KEY_ESC]){
l=999;
}
                 
if(!key[KEY_UP])onesuchprime=0;

if (!key[KEY_CONTROL]||(!key[KEY_LEFT]&&!key[KEY_RIGHT]))
        cunt=0;
                
if (   pointcount==1&&key[KEY_RIGHT] && angle<60  &&cunt==0){pointcount=0;angle+=1;i++;if(key[KEY_CONTROL])cunt=1;}
if (   pointcount==1&&key[KEY_LEFT]  && angle>-60 &&cunt==0){pointcount=0;angle-=1;i++;if(key[KEY_CONTROL])cunt=1;}
if(diff==0&&aim==1){
           
            flash=random()%256;
            for(f=1;f<nolines+1;f++)
            line(screen,linex[f-1],liney[f-1],linex[f],liney[f],flash);
            rect(screen,48+(16*(realy%2^top))+(realx*32),48+(realy*32),80+(16*(realy%2^top))+(realx*32),80+(realy*32),flash);

           }

if (i!=0){
        i=0;

 //aiming contraption...
if(diff==0){        if(aim==1){aim=0;
                   doremove();
                  doaim();

                  }
            }
                //vsync();
                //blit(b,screen,260,381,260,381,120,120);
                //rotate_sprite(screen,arrow,260,381,itofix(angle));
                //draw_sprite(screen,ball[bf],firex,firey);
                //shelob
                blit(wheel,b,0,0,260,381,120,100);
                rotate_sprite(b,arrow,260,381,itofix(angle));
   if(fire==0)  draw_sprite(b,ball[bf],firex,firey);
                
                blit(b,screen,260,401-20,260,401-20,120,100);
         }
if (   key[KEY_UP] && fire==0 &&onesuchprime==0  ){
        onesuchprime=1;
        shots++;
        play_sample(firew,150,128,1000,0);
           

        blit(wheel,b,0,0,260,381,120,100);
        rotate_sprite(b,arrow,260,381,itofix(angle));
        blit(b,screen,260,401-20,260,401-20,120,100);
        
if(diff==0){                   aim=0;
                   doremove();
            }      


                                  fire++;
                                  newx=firex+6*fixtof(fsin(itofix(angle)));
                                  newy=firey+6*fixtof(fcos(itofix(angle)));
                                  xx=newx-firex;nxx=xx;
                                  yy=newy-firey;
                                  blit(b,firetemp,firex,firey,0,0,32,32);}
}


void keytest2(){



if(key[KEY_ESC]){
l=999;
}
                 
if(freeze==0){
if (!key[KEY_INSERT]||(!key[KEY_LEFT]&&!key[KEY_RIGHT]))
        cunt=0;
if(!key[KEY_UP])onesuch=0;
if (   pointcount==1&&key[KEY_RIGHT] && angle<60  &&cunt==0){pointcount=0;angle+=1;i++;if(key[KEY_INSERT])cunt=1;}
if (   pointcount==1&&key[KEY_LEFT]  && angle>-60 &&cunt==0){pointcount=0;angle-=1;i++;if(key[KEY_INSERT])cunt=1;}

if(helpful&&aim==1){
           
            flash=random()%256;
            for(f3=1;f3<nolines+1;f3++)
            line(screen,linex[f3-1],liney[f3-1],linex[f3],liney[f3],flash);
            rect(screen,342+(16*(realy%2^top))+(realx*32),48+(realy*32),374+(16*(realy%2^top))+(realx*32),80+(realy*32),flash);

           }
}


if(freeze2==0){
if (!key[KEY_CONTROL]||(!key[KEY_Z]&&!key[KEY_C]))
        cunt2=0;                
if(!key[KEY_S])onesuch2=0;
if (   pointcount2==1&&key[KEY_C] && angle2<60  &&cunt2==0){pointcount2=0;angle2+=1;i2++;if(key[KEY_CONTROL])cunt2=1;}
if (   pointcount2==1&&key[KEY_Z]  && angle2>-60 &&cunt2==0){pointcount2=0;angle2-=1;i2++;if(key[KEY_CONTROL])cunt2=1;}

if(helpful2&&aim2==1){
           
            flash2=random()%256;
            for(f3=1;f3<nolines2+1;f3++)
            line(screen,linex2[f3-1],liney2[f3-1],linex2[f3],liney2[f3],flash2);
            rect(screen,43+(16*(realy2%2^top2))+(realx2*32),48+(realy2*32),75+(16*(realy2%2^top2))+(realx2*32),80+(realy2*32),flash2);

           }
}

if (i!=0){
        i=0;

 //aiming contraption...

if(helpful){        if(aim==1){aim=0;                   
                   doremove2();
                  doaim2();

                  }
            }
                blit(wheel,b,0,0,410,381,120,100);
                rotate_sprite(b,arrow,410,381,itofix(angle));
   if(fire==0)  draw_sprite(b,ball[bf],firex,firey);
                
                blit(b,screen,410,401-20,410,401-20,120,100);
         }
if (   key[KEY_UP] && fire==0  &&freeze==0 && onesuch==0){
        shots++;onesuch=1;
        play_sample(firew,150,128,1000,0);
           

        blit(wheel,b,0,0,410,381,120,100);
        rotate_sprite(b,arrow,410,381,itofix(angle));
        blit(b,screen,410,401-20,410,401-20,120,100);
        

if(helpful){                   aim=0;
                   doremove2();
            }      


                                  fire++;
                                  newx=firex+6*fixtof(fsin(itofix(angle)));
                                  newy=firey+6*fixtof(fcos(itofix(angle)));
                                  xx=newx-firex;nxx=xx;
                                  yy=newy-firey;
                                  blit(b,firetemp,firex,firey,0,0,32,32);}

if (i2!=0){
        i2=0;

 //aiming contraption...

if(helpful2){        if(aim2==1){aim2=0;
                   doremove3();
                  doaim3();

                  }
            }
                blit(wheel2,b,0,0,111,381,120,100);
                rotate_sprite(b,arrow,111,381,itofix(angle2));
   if(fire2==0)  draw_sprite(b,ball[bf2],twofirex,twofirey);
                
                blit(b,screen,111,401-20,111,401-20,120,100);
         }
if (   key[KEY_S] && fire2==0 &&freeze2==0 && onesuch2==0 ){
        shots2++;onesuch2=1;
        play_sample(firew,150,128,1000,0);
           

        blit(wheel2,b,0,0,111,381,120,100);
        rotate_sprite(b,arrow,111,381,itofix(angle2));
        blit(b,screen,111,401-20,111,401-20,120,100);
        

if(helpful2){                   aim2=0;
                   doremove3();
            }      


                                  fire2++;
                                  newx2=twofirex+6*fixtof(fsin(itofix(angle2)));
                                  newy2=twofirey+6*fixtof(fcos(itofix(angle2)));
                                  xx2=newx2-twofirex;nxx2=xx2;
                                  yy2=newy2-twofirey;
                                  blit(b,firetemp2,twofirex,twofirey,0,0,32,32);}


}


void ballmove(){
        if (fire!=0 && holdit==0){
           adjust_sample(firew,150,firex/2.5,1000,0);
           //vsync();
           
           blit(firetemp,screen,0,0,firex,firey,32,32);
           
           firex+=xx;
           firey-=yy;
           nfirex=firex+nxx;
           nfirey=firey-yy;
           if(nfirex<=48-4 || nfirex>=576-12)nxx=-nxx;
           if(firex<=48-4 || firex>=576-12){xx=-xx;play_sample(bouncew,255,(firex<100?0:255),800+500-firey,0);}
           
           blit(b,firetemp,firex,firey,0,0,32,32);
           
           draw_sprite(screen,ball[bf],firex,firey);

           ry=((firey-48)/32);
           realy=ry;if(ry-realy>.5)realy++;
           rx=( firex-48-  (  16* (realy %2^top))     )/32;
           realx=rx;
           if(rx-realx>.5&&realx!=(16-(realy%2^top)))realx++;
           

           nry=((nfirey-48)/32);
           nrealy=nry;if(nry-nrealy>.5)nrealy++;
           nrx=( nfirex-48-  (16*(nrealy %2^top))    )/32;
           nrealx=nrx;
           if(nrx-nrealx>.5&&nrealx!=(16-(nrealy%2^top)))nrealx++;
           



           if(realy<12&&realx<(17-(realy%2^top)) && map[realx][realy]==8)
            if(   (nrealy<12&&nrealx<(17-(nrealy%2^top))&&map[nrealx][nrealy]!=8)
               || (realy==0)  )
              dostop();
           
           }
ballcount=0;
        }


void ballmove2(){
        if (fire!=0 && holdit==0){
           adjust_sample(firew,150,firex/2.5,1000,0);
           //vsync();
           
           blit(firetemp,screen,0,0,firex,firey,32,32);
           
           firex+=xx;
           firey-=yy;
           nfirex=firex+nxx;
           nfirey=firey-yy;
           if(nfirex<=342-4 || nfirex>=582-12)nxx=-nxx;
           if(firex<=342-4 || firex>=582-12){xx=-xx;play_sample(bouncew,255,(firex<400?128:255),800+500-firey,0);}
           
           blit(b,firetemp,firex,firey,0,0,32,32);
           
           draw_sprite(screen,ball[bf],firex,firey);

           ry=((firey-48)/32);
           realy=ry;if(ry-realy>.5)realy++;
           rx=( firex-342-  (  16* (realy %2^top))     )/32;
           realx=rx;
           if(rx-realx>.5&&realx!=(7-(realy%2^top)))realx++;
           

           nry=((nfirey-48)/32);
           nrealy=nry;if(nry-nrealy>.5)nrealy++;
           nrx=( nfirex-342-  (16*(nrealy %2^top))    )/32;
           nrealx=nrx;
           if(nrx-nrealx>.5&&nrealx!=(7-(nrealy%2^top)))nrealx++;
           



           if(realy<12&&realx<(8-(realy%2^top)) && map[realx][realy]==8)
            if(   (nrealy<12&&nrealx<(8-(nrealy%2^top))&&map[nrealx][nrealy]!=8)
               || (realy==0)  )
              dostop2();
           
           }

        if (fire2!=0 && holdit2==0){
           adjust_sample(firew,150,twofirex/2.5,1000,0);
           //vsync();
           
           blit(firetemp2,screen,0,0,twofirex,twofirey,32,32);
           
           twofirex+=xx2;
           twofirey-=yy2;
           nfirex2=twofirex+nxx2;
           nfirey2=twofirey-yy2;
           if(nfirex2<=43-4 || nfirex2>=342-42-16-12)nxx2=-nxx2;
           if(twofirex<=43-4 || twofirex>=342-42-16-12){xx2=-xx2;play_sample(bouncew,255,(twofirex<100?0:128),800+500-twofirey,0);}
           
           blit(b,firetemp2,twofirex,twofirey,0,0,32,32);
           
           draw_sprite(screen,ball[bf2],twofirex,twofirey);

           ry2=((twofirey-48)/32);
           realy2=ry2;if(ry2-realy2>.5)realy2++;
           rx2=( twofirex-43-  (  16* (realy2 %2^top2))     )/32;
           realx2=rx2;
           if(rx2-realx2>.5&&realx2!=(7-(realy2%2^top2)))realx2++;
           

           nry2=((nfirey2-48)/32);
           nrealy2=nry2;if(nry2-nrealy2>.5)nrealy2++;
           nrx2=( nfirex2-43-  (16*(nrealy2 %2^top2))    )/32;
           nrealx2=nrx2;
           if(nrx2-nrealx2>.5&&nrealx2!=(7-(nrealy2%2^top2)))nrealx2++;
           



           if(realy2<12&&realx2<(8-(realy2%2^top2)) && twomap[realx2][realy2]==8)
            if(   (nrealy2<12&&nrealx2<(8-(nrealy2%2^top2))&&twomap[nrealx2][nrealy2]!=8)
               || (realy2==0)  )
              dostop3();
           
           }



ballcount=0;
}





void dostop(){xx=0;yy=0;blowupanyway=0;
              play_sample(clunkw,255,firex/2.5,1000,0);
              blit(firetemp,screen,0,0,firex,firey,32,32);
              draw_sprite(screen,ball[bf],48+(16*(realy%2^top))+(realx*32),48+(realy*32));
              if( realy<11)
               draw_sprite(b,ball[bf],48+(16*(realy%2^top))+(realx*32),48+(realy*32));
              
              map[realx][realy]=bf;
              count++;

              //init stuff
              for(g=0;g<12;g++)for(f=0;f<17;f++){map2[f][g]=0;map3[f][g]=0;}
              hit=0;
                                   //map1=ballcolours. map2=1 if same colour joined
                                   //map3=1 if neighbours have been checked


//check for eye balls



   f=realx;g=realy;


              
                if(g%2^top){  if(g!=0&&map[f][g-1]==13){hit++;
                                  map2[f][g-1]=1;}
                          if(g!=0&&map[f+1][g-1]==13){hit++;
                                  map2[f+1][g-1]=1;}
                          if(f!=0&&map[f-1][g]==13){hit++;
                                            map2[f-1][g]=1;}
                          if(f!=15&&map[f+1][g]==13){hit++;
                                             map2[f+1][g]=1;}
                          if(g!=11&&map[f][g+1]==13){hit++;
                                             map2[f][g+1]=1;}
                          if(g!=11&&map[f+1][g+1]==13){hit++;
                                             map2[f+1][g+1]=1;}
                       }

                 else  { if(g!=0&&f!=16&&map[f][g-1]==13){hit++;
                                                  map2[f][g-1]=1;}
                         if(g!=0&&f!=0&&map[f-1][g-1]==13){hit++;
                                                 map2[f-1][g-1]=1;}
                         if(f!=0&&map[f-1][g]==13){hit++;
                                           map2[f-1][g]=1;}
                         if(f!=16&&map[f+1][g]==13){hit++;
                                            map2[f+1][g]=1;}
                         if(g!=11&&f!=16&&map[f][g+1]==13){hit++;
                                                   map2[f][g+1]=1;}
                         if(g!=11&&f!=0&&map[f-1][g+1]==13){hit++;
                                                  map2[f-1][g+1]=1;}                                    
                        }

              if(hit!=0&&count>2){
                        map2[realx][realy]=1;                        
                        //now eye and current have map2 set to 1
                        for(f=0;f<8;f++)rndsel[f]=0;
                        for(g=0;g<12;g++)
                        for(f=0;f<16+(!(g%2^top));f++)
                          if(map[f][g]<8)rndsel[map[f][g]]++;
                        
                        rndsel2=random()%8;
                        ty:
                        if(rndsel[rndsel2]==0){rndsel2++;if(rndsel2==8)rndsel2=0;goto ty;}
                        if(bf==0){
     				  for(g=0;g<12;g++)
                        for(f=0;f<16+(!(g%2^top));f++)
                             if(map[f][g]==rndsel2)map[f][g]=9;
                        	  doredraw();
                        	  }
                        if(bf==1){
    	                          for(g=0;g<12;g++)
                        for(f=0;f<16+(!(g%2^top));f++)
                             if(map[f][g]==rndsel2){map[f][g]=11;count--;}
                        	  doredraw();
    	                          }
    	                if(bf==2){
    	                          gg=random()%8;
    	                          for(g=0;g<12;g++)
                        for(f=0;f<16+(!(g%2^top));f++)
                             if(map[f][g]==11){map[f][g]=gg;count++;}
                        	  doredraw();
    	                	}
			 if(bf==3){
    	                          
    	                          for(g=0;g<12;g++)
                        for(f=0;f<16+(!(g%2^top));f++)
                             if(map[f][g]<8)map[f][g]=random()%8;
                        	  doredraw();
    	                	}
    	                if(bf==4){
    	                         helpful=1;
    	                	}
                       if(bf==5){
    	                          
    	                          for(g=0;g<12;g++)
                        for(f=0;f<16+(!(g%2^top));f++)
                             if(map[f][g]!=8)
                             {if(map[f][g]!=11)count--;
                             map[f][g]=random()%12;
                             if(map[f][g]!=11&&map[f][g]!=8)count++;} 
                        	  doredraw();
    	                	}
			if(bf==7){
    	                      	                    
    	                for(g=0;g<12;g++)
                        for(f=0;f<16+(!(g%2^top));f++)
                             if(map[f][g]<8&&random()%1000>333){hit++;map2[f][g]=1;}
                        	  goto slither;
    	                	}
    	               if(bf==6){
    	                   rndselmark=0;
    	                   for(f=0;f<8;f++)
    	                    if(rndsel[f]>rndsel[rndselmark])rndselmark=f;    	                    
    	                          for(g=0;g<12;g++)
                        for(f=0;f<16+(!(g%2^top));f++)
                             if(map[f][g]==rndselmark){hit++;map2[f][g]=1;}
                        	  goto slither;
    	                	}
                        hit=0;blowupanyway=1;
                         }


//end check for eyeballs



              //check for key balls...

              f=realx;g=realy;


              
                if(g%2^top){  if(g!=0&&map[f][g-1]==12){hit++;
                                  map2[f][g-1]=1;}
                          if(g!=0&&map[f+1][g-1]==12){hit++;
                                  map2[f+1][g-1]=1;}
                          if(f!=0&&map[f-1][g]==12){hit++;
                                            map2[f-1][g]=1;}
                          if(f!=15&&map[f+1][g]==12){hit++;
                                             map2[f+1][g]=1;}
                          if(g!=11&&map[f][g+1]==12){hit++;
                                             map2[f][g+1]=1;}
                          if(g!=11&&map[f+1][g+1]==12){hit++;
                                             map2[f+1][g+1]=1;}
                       }

                 else  { if(g!=0&&f!=16&&map[f][g-1]==12){hit++;
                                                  map2[f][g-1]=1;}
                         if(g!=0&&f!=0&&map[f-1][g-1]==12){hit++;
                                                 map2[f-1][g-1]=1;}
                         if(f!=0&&map[f-1][g]==12){hit++;
                                           map2[f-1][g]=1;}
                         if(f!=16&&map[f+1][g]==12){hit++;
                                            map2[f+1][g]=1;}
                         if(g!=11&&f!=16&&map[f][g+1]==12){hit++;
                                                   map2[f][g+1]=1;}
                         if(g!=11&&f!=0&&map[f-1][g+1]==12){hit++;
                                                  map2[f-1][g+1]=1;}                                    
                        }

              if(hit!=0){
                        for(g=0;g<12;g++)
                        for(f=0;f<16+(!(g%2^top));f++)
                        if(map[f][g]==bf){      hit++;
                                                map2[f][g]=1;
                                         }

                         goto slither;
                         }

              map2[realx][realy]=1;
              //main loop
              checkloop:
              redo=0;
              for(g=0;g<12;g++)
              for(f=0;f<16+(!(g%2^top));f++)
              if(map2[f][g]==1&&map3[f][g]==0)
                {map3[f][g]=1;
                if(g%2^top){  if(g!=0&&map[f][g-1]==bf&&map2[f][g-1]==0){redo++;hit++;
                                  map2[f][g-1]=1;}
                          if(g!=0&&map[f+1][g-1]==bf&&map2[f+1][g-1]==0){redo++;hit++;
                                  map2[f+1][g-1]=1;}
                          if(f!=0&&map[f-1][g]==bf&&map2[f-1][g]==0){redo++;hit++;
                                            map2[f-1][g]=1;}
                          if(f!=15&&map[f+1][g]==bf&&map2[f+1][g]==0){redo++;hit++;
                                             map2[f+1][g]=1;}
                          if(g!=11&&map[f][g+1]==bf&&map2[f][g+1]==0){redo++;hit++;
                                             map2[f][g+1]=1;}
                          if(g!=11&&map[f+1][g+1]==bf&&map2[f+1][g+1]==0){redo++;hit++;
                                             map2[f+1][g+1]=1;}
                       }

                 else  { if(g!=0&&f!=16&&map[f][g-1]==bf&&map2[f][g-1]==0){redo++;hit++;
                                                  map2[f][g-1]=1;}
                         if(g!=0&&f!=0&&map[f-1][g-1]==bf&&map2[f-1][g-1]==0){redo++;hit++;
                                                 map2[f-1][g-1]=1;}
                         if(f!=0&&map[f-1][g]==bf&&map2[f-1][g]==0){redo++;hit++;
                                           map2[f-1][g]=1;}
                         if(f!=16&&map[f+1][g]==bf&&map2[f+1][g]==0){redo++;hit++;
                                            map2[f+1][g]=1;}
                         if(g!=11&&f!=16&&map[f][g+1]==bf&&map2[f][g+1]==0){redo++;hit++;
                                                   map2[f][g+1]=1;}
                         if(g!=11&&f!=0&&map[f-1][g+1]==bf&&map2[f-1][g+1]==0){redo++;hit++;
                                                  map2[f-1][g+1]=1;}                                    
                        }

                 }

                 if(redo!=0)goto checkloop;                                                






                 if(hit>1+tog||blowupanyway==1){
                   slither:
      //check for exploding bombs

              for(g=0;g<12;g++)for(f=0;f<17;f++)map3[f][g]=0;
              
              
              checkloop3:
              redo=0;
              for(g=0;g<12;g++)
              for(f=0;f<16+(!(g%2^top));f++)
              if(map2[f][g]!=0&&map3[f][g]==0)
                {map3[f][g]=1;bb=(map[f][g]==10)?1:0;
                if(g%2^top){  if(g!=0){if(map[f][g-1]==10&&map2[f][g-1]==0)
                                                 {map2[f][g-1]=2;redo++;hit++;}
                                       if(bb&&map[f][g-1]!=8&&map2[f][g-1]==0)
                                                 {map2[f][g-1]=1;redo++;hit++;}}

                               
   
                               if(g!=0){if(map[f+1][g-1]==10&&map2[f+1][g-1]==0)
                                                 {map2[f+1][g-1]=2;redo++;hit++;}
                                       if(bb&&map[f+1][g-1]!=8&&map2[f+1][g-1]==0)
                                                 {map2[f+1][g-1]=1;redo++;hit++;}}
   
                               if(f!=0){if(map[f-1][g]==10&&map2[f-1][g]==0)
                                                 {map2[f-1][g]=2;redo++;hit++;}
                                       if(bb&&map[f-1][g]!=8&&map2[f-1][g]==0)
                                                 {map2[f-1][g]=1;redo++;hit++;}}

                               if(f!=15){if(map[f+1][g]==10&&map2[f+1][g]==0)
                                                 {map2[f+1][g]=2;redo++;hit++;}
                                       if(bb&&map[f+1][g]!=8&&map2[f+1][g]==0)
                                                 {map2[f+1][g]=1;redo++;hit++;}}

                               if(g!=11){if(map[f][g+1]==10&&map2[f][g+1]==0)
                                                 {map2[f][g+1]=2;redo++;hit++;}
                                       if(bb&&map[f][g+1]!=8&&map2[f][g+1]==0)
                                                 {map2[f][g+1]=1;redo++;hit++;}}

                               if(g!=11){if(map[f+1][g+1]==10&&map2[f+1][g+1]==0)
                                                 {map2[f+1][g+1]=2;redo++;hit++;}
                                       if(bb&&map[f+1][g+1]!=8&&map2[f+1][g+1]==0)
                                                 {map2[f+1][g+1]=1;redo++;hit++;}}

                         
                       }

                 else  { 

if(g!=0&&f!=16){if(map[f][g-1]==10&&map2[f][g-1]==0)
                                                 {map2[f][g-1]=2;redo++;hit++;}
                                       if(bb&&map[f][g-1]!=8&&map2[f][g-1]==0)
                                                 {map2[f][g-1]=1;redo++;hit++;}}



if(g!=0&&f!=0){if(map[f-1][g-1]==10&&map2[f-1][g-1]==0)
                                                 {map2[f-1][g-1]=2;redo++;hit++;}
                                       if(bb&&map[f-1][g-1]!=8&&map2[f-1][g-1]==0)
                                                 {map2[f-1][g-1]=1;redo++;hit++;}}

                         
if(f!=0){if(map[f-1][g]==10&&map2[f-1][g]==0)
                                                 {map2[f-1][g]=2;redo++;hit++;}
                                       if(bb&&map[f-1][g]!=8&&map2[f-1][g]==0)
                                                 {map2[f-1][g]=1;redo++;hit++;}}

if(f!=16){if(map[f+1][g]==10&&map2[f+1][g]==0)
                                                 {map2[f+1][g]=2;redo++;hit++;}
                                       if(bb&&map[f+1][g]!=8&&map2[f+1][g]==0)
                                                 {map2[f+1][g]=1;redo++;hit++;}}

if(g!=11&&f!=16){if(map[f][g+1]==10&&map2[f][g+1]==0)
                                                 {map2[f][g+1]=2;redo++;hit++;}
                                       if(bb&&map[f][g+1]!=8&&map2[f][g+1]==0)
                                                 {map2[f][g+1]=1;redo++;hit++;}}

if(g!=11&&f!=0){if(map[f-1][g+1]==10&&map2[f-1][g+1]==0)
                                                 {map2[f-1][g+1]=2;redo++;hit++;}
                                       if(bb&&map[f-1][g+1]!=8&&map2[f-1][g+1]==0)
                                                 {map2[f-1][g+1]=1;redo++;hit++;}}
                                 
                        }

                 }

                 if(redo!=0)goto checkloop3;                                                





     //end check for bombs
                           play_sample(explodew,(hit>7?255:hit*32),firex/2.5,1000,0);
                           jig=1;
                           hit=0;
                           //exnum=0;
                           extra=1;extra2=1;
                           for(g=0;g<12;g++)
                           for(f=0;f<16+(!(g%2^top));f++)
                               if(map2[f][g]!=0){if (g<11){
                                                 blit(view,screen,(16*(g%2^top))+(f*32),(g*32),48+(16*(g%2^top))+(f*32),48+(g*32),32,32);
                                                 blit(view,b,(16*(g%2^top))+(f*32),(g*32),48+(16*(g%2^top))+(f*32),48+(g*32),32,32);
                                                           }
                                                 else {
                                                 
                                                 blit(b,screen,48+(16*(g%2^top))+(f*32),(g*32),48+(16*(g%2^top))+(f*32),48+(g*32),32,32);

                                                       }

                                                   if(map[f][g]!=11)count--;
                                                   hit++;
                                                   if(hit>10)jig=2;
                                                   if(hit>20)jig=3;
                                                   
                                                   for(ff=0;ff<32;ff+=jig)
                                                   for(gg=0;gg<32;gg+=jig)
                                                     {pix=getpixel(ball[map[f][g]],ff,gg);
                                                     if(pix)
                                                         {
                                                          exnum++;
                                                          exx[exnum]=48+ff+(16*(g%2^top))+(f*32);
                                                          exy[exnum]=48+gg+(g*32);
                                                          exdx[exnum]=(random()%9)-4;
                                                          exdy[exnum]=(random()%9)-4;
                                                          if (exdx[exnum]==0&&exdy[exnum]==0)exdy[exnum]=1;
                                                          exc[exnum]=pix;
                                                          _putpixel(screen,exx[exnum],exy[exnum],exc[exnum]);
                                                          
                                                          
                                                          }
                                                    }
                                                   map[f][g]=8;
                                                                                                                                                
                                                  }






              for(g=0;g<12;g++)for(f=0;f<17;f++){map2[f][g]=0;map3[f][g]=0;
                                                if(g==0&&map[f][g]!=8)map2[f][g]=1;
                                                if(map[f][g]==11)map2[f][g]=1;}
              
              
                           
              checkloop2:
              redo=0;
              for(g=0;g<12;g++)
              for(f=0;f<16+(!(g%2^top));f++)
              if(map2[f][g]==1&&map3[f][g]==0)
                {map3[f][g]=1;
                if(g%2^top){  if(g!=0&&map[f][g-1]!=8){redo++;
                                  map2[f][g-1]=1;}
                          if(g!=0&&map[f+1][g-1]!=8){redo++;
                                  map2[f+1][g-1]=1;}
                          if(f!=0&&map[f-1][g]!=8){redo++;
                                            map2[f-1][g]=1;}
                          if(f!=15&&map[f+1][g]!=8){redo++;
                                             map2[f+1][g]=1;}
                          if(g!=11&&map[f][g+1]!=8){redo++;
                                             map2[f][g+1]=1;}
                          if(g!=11&&map[f+1][g+1]!=8){redo++;
                                             map2[f+1][g+1]=1;}
                       }

                 else  { if(g!=0&&f!=16&&map[f][g-1]!=8){redo++;
                                                  map2[f][g-1]=1;}
                         if(g!=0&&f!=0&&map[f-1][g-1]!=8){redo++;
                                                 map2[f-1][g-1]=1;}
                         if(f!=0&&map[f-1][g]!=8){redo++;
                                           map2[f-1][g]=1;}
                         if(f!=16&&map[f+1][g]!=8){redo++;
                                            map2[f+1][g]=1;}
                         if(g!=11&&f!=16&&map[f][g+1]!=8){redo++;
                                                   map2[f][g+1]=1;}
                         if(g!=11&&f!=0&&map[f-1][g+1]!=8){redo++;
                                                  map2[f-1][g+1]=1;}                                    
                        }

                 }

                 if(redo!=0)goto checkloop2;                                                
                 
                           hit=0;jig=1;//dropno=0;
                           for(g=0;g<12;g++)
                           for(f=0;f<16+(!(g%2^top));f++)
                               if(map2[f][g]!=1&&map[f][g]!=8)
                                                  {
                                                   if(g<11){
                                                   //blit(view,screen,(16*(g%2^top))+(f*32),(g*32),48+(16*(g%2^top))+(f*32),48+(g*32),32,32);
                                                   blit(view,b,(16*(g%2^top))+(f*32),(g*32),48+(16*(g%2^top))+(f*32),48+(g*32),32,32);
                                                            }
                                                   else {
                                                 blit(b,screen,48+(16*(g%2^top))+(f*32),48+(g*32),48+(16*(g%2^top))+(f*32),48+(g*32),32,32);

                                                   }
                                                   dropno++;
                                                   if(map[f][g]!=11)count--;
                                                   dropx[dropno]=48+(16*(g%2^top))+(f*32);
                                                   dropy[dropno]=48+(g*32);
                                                   dropc[dropno]=map[f][g];
                                                   map[f][g]=8;
                                                  }
                                                  if(dropno!=0)dropno++;
                           //if(hit>0)play_sample(explodew,(hit>7?255:hit*32),128,1000,0);

                           }




                           


                 
                 firex=304;firey=425;
                 bf=next;
                 doquirk();
                 if(diff<2&&count<11||helpful==1)
                   {h=0;
                    for(g=0;g<11;g++)
                    for(f=0;f<16+(!(g%2^top));f++)
                     if(map[f][g]<8)
                      {select[h]=map[f][g];
                       h++;}
                    select[h]=bf;h++;

                    next=select[random()%h];

                    //select
                   }
                 else next=random()%8;
                 holdit=1;
                 
           }

void dostop2(){xx=0;yy=0;blowupanyway=0;
              play_sample(clunkw,255,firex/2.5,1000,0);
              blit(firetemp,screen,0,0,firex,firey,32,32);
              draw_sprite(screen,ball[bf],342+(16*(realy%2^top))+(realx*32),48+(realy*32));
              if( realy<11)
               draw_sprite(b,ball[bf],342+(16*(realy%2^top))+(realx*32),48+(realy*32));
              
              map[realx][realy]=bf;
              count++;

              //init stuff
              for(g2=0;g2<12;g2++)for(f2=0;f2<8;f2++){map2[f2][g2]=0;map3[f2][g2]=0;}
              hit=0;
                                   //map1=ballcolours. map2=1 if same colour joined
                                   //map3=1 if neighbours have been checked

//check for eye balls



   f=realx;g=realy;


              
                if(g%2^top){  if(g!=0&&map[f][g-1]==13){hit++;
                                  map2[f][g-1]=1;}
                          if(g!=0&&map[f+1][g-1]==13){hit++;
                                  map2[f+1][g-1]=1;}
                          if(f!=0&&map[f-1][g]==13){hit++;
                                            map2[f-1][g]=1;}
                          if(f!=6&&map[f+1][g]==13){hit++;
                                             map2[f+1][g]=1;}
                          if(g!=11&&map[f][g+1]==13){hit++;
                                             map2[f][g+1]=1;}
                          if(g!=11&&map[f+1][g+1]==13){hit++;
                                             map2[f+1][g+1]=1;}
                       }

                 else  { if(g!=0&&f!=7&&map[f][g-1]==13){hit++;
                                                  map2[f][g-1]=1;}
                         if(g!=0&&f!=0&&map[f-1][g-1]==13){hit++;
                                                 map2[f-1][g-1]=1;}
                         if(f!=0&&map[f-1][g]==13){hit++;
                                           map2[f-1][g]=1;}
                         if(f!=7&&map[f+1][g]==13){hit++;
                                            map2[f+1][g]=1;}
                         if(g!=11&&f!=7&&map[f][g+1]==13){hit++;
                                                   map2[f][g+1]=1;}
                         if(g!=11&&f!=0&&map[f-1][g+1]==13){hit++;
                                                  map2[f-1][g+1]=1;}                                    
                        }

              if(hit!=0&&count>2){
                        map2[realx][realy]=1;                        
                        //now eye and current have map2 set to 1
                        for(f=0;f<8;f++)rndsel[f]=0;
                        for(g=0;g<12;g++)
                        for(f=0;f<7+(!(g%2^top));f++)
                          if(map[f][g]<8)rndsel[map[f][g]]++;
                        
                        rndsel2=random()%8;
                        ty2:
                        if(rndsel[rndsel2]==0){rndsel2++;if(rndsel2==8)rndsel2=0;goto ty2;}
                        if(bf==0){
     				  for(g=0;g<12;g++)
                        for(f=0;f<7+(!(g%2^top));f++)
                             if(map[f][g]==rndsel2)map[f][g]=9;
                        	  doredraw2();
                        	  }
                        if(bf==1){
    	                          for(g=0;g<12;g++)
                        for(f=0;f<7+(!(g%2^top));f++)
                             if(map[f][g]==rndsel2){map[f][g]=11;count--;}
                        	  doredraw2();
    	                          }
    	                if(bf==2){
    	                          gg=random()%8;
    	                          for(g=0;g<12;g++)
                        for(f=0;f<7+(!(g%2^top));f++)
                             if(map[f][g]==11){map[f][g]=gg;count++;}
                        	  doredraw2();
    	                	}
			 if(bf==3){
    	                          
    	                          for(g=0;g<12;g++)
                        for(f=0;f<7+(!(g%2^top));f++)
                             if(map[f][g]<8)map[f][g]=random()%8;                     	  
    	                	doredraw2();
    	                	}
    	                if(bf==4){
    	                         if(helpful2==1)doremove3;
    	                         helpful=1;helpful2=0;
    	                
    	                	}
                       if(bf==5){
    	                          
    	                          for(g=0;g<12;g++)
                        for(f=0;f<7+(!(g%2^top));f++)
                             if(map[f][g]!=8)
                             {if(map[f][g]!=11)count--;
                             map[f][g]=random()%12;
                             if(map[f][g]!=11&&map[f][g]!=8)count++;}
                        	  doredraw2();
    	                	}
			if(bf==7){
    	                      	                    
    	                for(g=0;g<12;g++)
                        for(f=0;f<7+(!(g%2^top));f++)
                             if(map[f][g]<8&&random()%1000>333){hit++;map2[f][g]=1;}
                        	  goto twoslither;
    	                	}
    	               if(bf==6){
    	                   rndselmark=0;
    	                   for(f=0;f<8;f++)
    	                    if(rndsel[f]>rndsel[rndselmark])rndselmark=f;    	                    
    	                          for(g=0;g<12;g++)
                        for(f=0;f<7+(!(g%2^top));f++)
                             if(map[f][g]==rndselmark){hit++;map2[f][g]=1;}
                        	  goto twoslither;
    	                	}
                        hit=0;blowupanyway=1;
                         }


//end check for eyeballs






              //check for key balls...

              f2=realx;g2=realy;


              
                if(g2%2^top){  if(g2!=0&&map[f2][g2-1]==12){hit++;
                                  map2[f2][g2-1]=1;}
                          if(g2!=0&&map[f2+1][g2-1]==12){hit++;
                                  map2[f2+1][g2-1]=1;}
                          if(f2!=0&&map[f2-1][g2]==12){hit++;
                                            map2[f2-1][g2]=1;}
                          if(f2!=6&&map[f2+1][g2]==12){hit++;
                                             map2[f2+1][g2]=1;}
                          if(g2!=11&&map[f2][g2+1]==12){hit++;
                                             map2[f2][g2+1]=1;}
                          if(g2!=11&&map[f2+1][g2+1]==12){hit++;
                                             map2[f2+1][g2+1]=1;}
                       }

                 else  { if(g2!=0&&f2!=7&&map[f2][g2-1]==12){hit++;
                                                  map2[f2][g2-1]=1;}
                         if(g2!=0&&f2!=0&&map[f2-1][g2-1]==12){hit++;
                                                 map2[f2-1][g2-1]=1;}
                         if(f2!=0&&map[f2-1][g2]==12){hit++;
                                           map2[f2-1][g2]=1;}
                         if(f2!=7&&map[f2+1][g2]==12){hit++;
                                            map2[f2+1][g2]=1;}
                         if(g2!=11&&f2!=7&&map[f2][g2+1]==12){hit++;
                                                   map2[f2][g2+1]=1;}
                         if(g2!=11&&f2!=0&&map[f2-1][g2+1]==12){hit++;
                                                  map2[f2-1][g2+1]=1;}                                    
                        }

              if(hit!=0){
                        for(g2=0;g2<12;g2++)
                        for(f2=0;f2<7+(!(g2%2^top));f2++)
                        if(map[f2][g2]==bf){      hit++;
                                                map2[f2][g2]=1;
                                         }

                         goto twoslither;
                         }

              map2[realx][realy]=1;
              //main loop
              twocheckloop:
              redo=0;
              for(g2=0;g2<12;g2++)
              for(f2=0;f2<7+(!(g2%2^top));f2++)
              if(map2[f2][g2]==1&&map3[f2][g2]==0)
                {map3[f2][g2]=1;
                if(g2%2^top){  if(g2!=0&&map[f2][g2-1]==bf&&map2[f2][g2-1]==0){redo++;hit++;
                                  map2[f2][g2-1]=1;}
                          if(g2!=0&&map[f2+1][g2-1]==bf&&map2[f2+1][g2-1]==0){redo++;hit++;
                                  map2[f2+1][g2-1]=1;}
                          if(f2!=0&&map[f2-1][g2]==bf&&map2[f2-1][g2]==0){redo++;hit++;
                                            map2[f2-1][g2]=1;}
                          if(f2!=6&&map[f2+1][g2]==bf&&map2[f2+1][g2]==0){redo++;hit++;
                                             map2[f2+1][g2]=1;}
                          if(g2!=11&&map[f2][g2+1]==bf&&map2[f2][g2+1]==0){redo++;hit++;
                                             map2[f2][g2+1]=1;}
                          if(g2!=11&&map[f2+1][g2+1]==bf&&map2[f2+1][g2+1]==0){redo++;hit++;
                                             map2[f2+1][g2+1]=1;}
                       }

                 else  { if(g2!=0&&f2!=7&&map[f2][g2-1]==bf&&map2[f2][g2-1]==0){redo++;hit++;
                                                  map2[f2][g2-1]=1;}
                         if(g2!=0&&f2!=0&&map[f2-1][g2-1]==bf&&map2[f2-1][g2-1]==0){redo++;hit++;
                                                 map2[f2-1][g2-1]=1;}
                         if(f2!=0&&map[f2-1][g2]==bf&&map2[f2-1][g2]==0){redo++;hit++;
                                           map2[f2-1][g2]=1;}
                         if(f2!=7&&map[f2+1][g2]==bf&&map2[f2+1][g2]==0){redo++;hit++;
                                            map2[f2+1][g2]=1;}
                         if(g2!=11&&f2!=7&&map[f2][g2+1]==bf&&map2[f2][g2+1]==0){redo++;hit++;
                                                   map2[f2][g2+1]=1;}
                         if(g2!=11&&f2!=0&&map[f2-1][g2+1]==bf&&map2[f2-1][g2+1]==0){redo++;hit++;
                                                  map2[f2-1][g2+1]=1;}                                    
                        }

                 }

                 if(redo!=0)goto twocheckloop;                                                






                 if(hit>1+tog||blowupanyway==1){
                   twoslither:
      //check for exploding bombs

              for(g2=0;g2<12;g2++)for(f2=0;f2<8;f2++)map3[f2][g2]=0;
              
              
              twocheckloop3:
              redo=0;
              for(g2=0;g2<12;g2++)
              for(f2=0;f2<7+(!(g2%2^top));f2++)
              if(map2[f2][g2]!=0&&map3[f2][g2]==0)
                {map3[f2][g2]=1;bb=(map[f2][g2]==10)?1:0;
                if(g2%2^top){  if(g2!=0){if(map[f2][g2-1]==10&&map2[f2][g2-1]==0)
                                                 {map2[f2][g2-1]=2;redo++;hit++;}
                                       if(bb&&map[f2][g2-1]!=8&&map2[f2][g2-1]==0)
                                                 {map2[f2][g2-1]=1;redo++;hit++;}}

                               
   
                               if(g2!=0){if(map[f2+1][g2-1]==10&&map2[f2+1][g2-1]==0)
                                                 {map2[f2+1][g2-1]=2;redo++;hit++;}
                                       if(bb&&map[f2+1][g2-1]!=8&&map2[f2+1][g2-1]==0)
                                                 {map2[f2+1][g2-1]=1;redo++;hit++;}}
   
                               if(f2!=0){if(map[f2-1][g2]==10&&map2[f2-1][g2]==0)
                                                 {map2[f2-1][g2]=2;redo++;hit++;}
                                       if(bb&&map[f2-1][g2]!=8&&map2[f2-1][g2]==0)
                                                 {map2[f2-1][g2]=1;redo++;hit++;}}

                               if(f2!=6){if(map[f2+1][g2]==10&&map2[f2+1][g2]==0)
                                                 {map2[f2+1][g2]=2;redo++;hit++;}
                                       if(bb&&map[f2+1][g2]!=8&&map2[f2+1][g2]==0)
                                                 {map2[f2+1][g2]=1;redo++;hit++;}}

                               if(g2!=11){if(map[f2][g2+1]==10&&map2[f2][g2+1]==0)
                                                 {map2[f2][g2+1]=2;redo++;hit++;}
                                       if(bb&&map[f2][g2+1]!=8&&map2[f2][g2+1]==0)
                                                 {map2[f2][g2+1]=1;redo++;hit++;}}

                               if(g2!=11){if(map[f2+1][g2+1]==10&&map2[f2+1][g2+1]==0)
                                                 {map2[f2+1][g2+1]=2;redo++;hit++;}
                                       if(bb&&map[f2+1][g2+1]!=8&&map2[f2+1][g2+1]==0)
                                                 {map2[f2+1][g2+1]=1;redo++;hit++;}}

                         
                       }

                 else  { 

if(g2!=0&&f2!=7){if(map[f2][g2-1]==10&&map2[f2][g2-1]==0)
                                                 {map2[f2][g2-1]=2;redo++;hit++;}
                                       if(bb&&map[f2][g2-1]!=8&&map2[f2][g2-1]==0)
                                                 {map2[f2][g2-1]=1;redo++;hit++;}}



if(g2!=0&&f2!=0){if(map[f2-1][g2-1]==10&&map2[f2-1][g2-1]==0)
                                                 {map2[f2-1][g2-1]=2;redo++;hit++;}
                                       if(bb&&map[f2-1][g2-1]!=8&&map2[f2-1][g2-1]==0)
                                                 {map2[f2-1][g2-1]=1;redo++;hit++;}}

                         
if(f2!=0){if(map[f2-1][g2]==10&&map2[f2-1][g2]==0)
                                                 {map2[f2-1][g2]=2;redo++;hit++;}
                                       if(bb&&map[f2-1][g2]!=8&&map2[f2-1][g2]==0)
                                                 {map2[f2-1][g2]=1;redo++;hit++;}}

if(f2!=7){if(map[f2+1][g2]==10&&map2[f2+1][g2]==0)
                                                 {map2[f2+1][g2]=2;redo++;hit++;}
                                       if(bb&&map[f2+1][g2]!=8&&map2[f2+1][g2]==0)
                                                 {map2[f2+1][g2]=1;redo++;hit++;}}

if(g2!=11&&f2!=7){if(map[f2][g2+1]==10&&map2[f2][g2+1]==0)
                                                 {map2[f2][g2+1]=2;redo++;hit++;}
                                       if(bb&&map[f2][g2+1]!=8&&map2[f2][g2+1]==0)
                                                 {map2[f2][g2+1]=1;redo++;hit++;}}

if(g2!=11&&f2!=0){if(map[f2-1][g2+1]==10&&map2[f2-1][g2+1]==0)
                                                 {map2[f2-1][g2+1]=2;redo++;hit++;}
                                       if(bb&&map[f2-1][g2+1]!=8&&map2[f2-1][g2+1]==0)
                                                 {map2[f2-1][g2+1]=1;redo++;hit++;}}
                                 
                        }

                 }

                 if(redo!=0)goto twocheckloop3;                                                





     //end check for bombs
                           play_sample(explodew,(hit>7?255:hit*32),firex/2.5,1000,0);
                           jig=1;
                           hit=0;
                           //exnum=0;
                           extra=1;extra2=1;
                           for(g2=0;g2<12;g2++)
                           for(f2=0;f2<7+(!(g2%2^top));f2++)
                               if(map2[f2][g2]!=0){if (g2<11){
                                                 blit(sqview,screen,(16*(g2%2^top))+(f2*32),(g2*32),343+(16*(g2%2^top))+(f2*32),48+(g2*32),32,32);
                                                 blit(sqview,b,(16*(g2%2^top))+(f2*32),(g2*32),343+(16*(g2%2^top))+(f2*32),48+(g2*32),32,32);
                                                           }
                                                 else {
                                                 
                                                 blit(b,screen,343+(16*(g2%2^top))+(f2*32),48+(g2*32),343+(16*(g2%2^top))+(f2*32),48+(g2*32),32,32);

                                                       }

                                                   if(map[f2][g2]!=11)count--;
                                                   hit++;
                                                   if(hit>10)jig=2;
                                                   if(hit>20)jig=3;
                                                   
                                                   for(ff=0;ff<32;ff+=jig)
                                                   for(gg=0;gg<32;gg+=jig)
                                                     {pix=getpixel(ball[map[f2][g2]],ff,gg);
                                                     if(pix)
                                                         {
                                                          exnum++;
                                                          exx[exnum]=343+ff+(16*(g2%2^top))+(f2*32);
                                                          exy[exnum]=48+gg+(g2*32);
                                                          exdx[exnum]=(random()%9)-4;
                                                          exdy[exnum]=(random()%9)-4;
                                                          if (exdx[exnum]==0&&exdy[exnum]==0)exdy[exnum]=1;
                                                          exc[exnum]=pix;
                                                          _putpixel(screen,exx[exnum],exy[exnum],exc[exnum]);
                                                          
                                                          
                                                          }
                                                    }
                                                   if(map[f2][g2]<8&&gov2<99){
                                                   gov2++;
                                                   give2[gov2]=map[f2][g2];}
                                                   map[f2][g2]=8;
                                                                                                                                                
                                                  }






              for(g2=0;g2<12;g2++)for(f2=0;f2<8;f2++){map2[f2][g2]=0;map3[f2][g2]=0;
                                                if(g2==0&&map[f2][g2]!=8)map2[f2][g2]=1;
                                                if(map[f2][g2]==11)map2[f2][g2]=1;}
              
              
                           
              twocheckloop2:
              redo=0;
              for(g2=0;g2<12;g2++)
              for(f2=0;f2<7+(!(g2%2^top));f2++)
              if(map2[f2][g2]==1&&map3[f2][g2]==0)
                {map3[f2][g2]=1;
                if(g2%2^top){  if(g2!=0&&map[f2][g2-1]!=8){redo++;
                                  map2[f2][g2-1]=1;}
                          if(g2!=0&&map[f2+1][g2-1]!=8){redo++;
                                  map2[f2+1][g2-1]=1;}
                          if(f2!=0&&map[f2-1][g2]!=8){redo++;
                                            map2[f2-1][g2]=1;}
                          if(f2!=6&&map[f2+1][g2]!=8){redo++;
                                             map2[f2+1][g2]=1;}
                          if(g2!=11&&map[f2][g2+1]!=8){redo++;
                                             map2[f2][g2+1]=1;}
                          if(g2!=11&&map[f2+1][g2+1]!=8){redo++;
                                             map2[f2+1][g2+1]=1;}
                       }

                 else  { if(g2!=0&&f2!=7&&map[f2][g2-1]!=8){redo++;
                                                  map2[f2][g2-1]=1;}
                         if(g2!=0&&f2!=0&&map[f2-1][g2-1]!=8){redo++;
                                                 map2[f2-1][g2-1]=1;}
                         if(f2!=0&&map[f2-1][g2]!=8){redo++;
                                           map2[f2-1][g2]=1;}
                         if(f2!=7&&map[f2+1][g2]!=8){redo++;
                                            map2[f2+1][g2]=1;}
                         if(g2!=11&&f2!=7&&map[f2][g2+1]!=8){redo++;
                                                   map2[f2][g2+1]=1;}
                         if(g2!=11&&f2!=0&&map[f2-1][g2+1]!=8){redo++;
                                                  map2[f2-1][g2+1]=1;}                                    
                        }

                 }

                 if(redo!=0)goto twocheckloop2;                                                
                 
                           hit=0;jig=1;//dropno=0;
                           for(g2=0;g2<12;g2++)
                           for(f2=0;f2<7+(!(g2%2^top));f2++)
                               if(map2[f2][g2]!=1&&map[f2][g2]!=8)
                                                  {
                                                   if(g2<11){
                                                   //blit(view,screen,(16*(g%2^top))+(f*32),(g*32),48+(16*(g%2^top))+(f*32),48+(g*32),32,32);
                                                   blit(sqview,b,(16*(g2%2^top))+(f2*32),(g2*32),342+(16*(g2%2^top))+(f2*32),48+(g2*32),32,32);
                                                            }
                                                   else {
                                                 blit(b,screen,342+(16*(g2%2^top))+(f2*32),48+(g2*32),342+(16*(g2%2^top))+(f2*32),48+(g2*32),32,32);

                                                   }
                                                   dropno++;
                                                   if(map[f2][g2]!=11)count--;
                                                   dropx[dropno]=342+(16*(g2%2^top))+(f2*32);
                                                   dropy[dropno]=48+(g2*32);
                                                   dropc[dropno]=map[f2][g2];
                                                   if(map[f2][g2]<8&&gov2<99){
                                                   gov2++;
                                                   give2[gov2]=map[f2][g2];}
                                                   map[f2][g2]=8;
                                                  }
                                                  if(dropno!=0)dropno++;
                           //if(hit>0)play_sample(explodew,(hit>7?255:hit*32),128,1000,0);

                           }




                           


                 
                 firex=454;firey=425;
                 bf=next;
                 next=bfset[bfc];bfc++;
                 if(bfc==50)bfc=0;
                 doquirk2();
                 holdit=1;
                 gov2-=(3+tog);
                 if(gov2>gv2)
                 {
                 gv2=gov2;
                            	 
           	 drawgive2();
           	 }
		 gov2=gv2;
           }



void dostop3(){xx2=0;yy2=0;blowupanyway=0;
              play_sample(clunkw,255,twofirex/2.5,1000,0);
              blit(firetemp2,screen,0,0,twofirex,twofirey,32,32);
              draw_sprite(screen,ball[bf2],43+(16*(realy2%2^top2))+(realx2*32),48+(realy2*32));
              if( realy2<11)
               draw_sprite(b,ball[bf2],43+(16*(realy2%2^top2))+(realx2*32),48+(realy2*32));
              
              twomap[realx2][realy2]=bf2;
              count2++;

              //init stuff
              for(g2=0;g2<12;g2++)for(f2=0;f2<8;f2++){twomap2[f2][g2]=0;twomap3[f2][g2]=0;}
              hit2=0;
                                   //map1=ballcolours. map2=1 if same colour joined
                                   //map3=1 if neighbours have been checked


//check for eye balls



   f=realx2;g=realy2;hit=0;


              
                if(g%2^top2){  if(g!=0&&twomap[f][g-1]==13){hit++;
                                  twomap2[f][g-1]=1;}
                          if(g!=0&&twomap[f+1][g-1]==13){hit++;
                                  twomap2[f+1][g-1]=1;}
                          if(f!=0&&twomap[f-1][g]==13){hit++;
                                            twomap2[f-1][g]=1;}
                          if(f!=6&&twomap[f+1][g]==13){hit++;
                                             twomap2[f+1][g]=1;}
                          if(g!=11&&twomap[f][g+1]==13){hit++;
                                             twomap2[f][g+1]=1;}
                          if(g!=11&&twomap[f+1][g+1]==13){hit++;
                                             twomap2[f+1][g+1]=1;}
                       }

                 else  { if(g!=0&&f!=7&&twomap[f][g-1]==13){hit++;
                                                  twomap2[f][g-1]=1;}
                         if(g!=0&&f!=0&&twomap[f-1][g-1]==13){hit++;
                                                 twomap2[f-1][g-1]=1;}
                         if(f!=0&&twomap[f-1][g]==13){hit++;
                                           twomap2[f-1][g]=1;}
                         if(f!=7&&twomap[f+1][g]==13){hit++;
                                            twomap2[f+1][g]=1;}
                         if(g!=11&&f!=7&&twomap[f][g+1]==13){hit++;
                                                   twomap2[f][g+1]=1;}
                         if(g!=11&&f!=0&&twomap[f-1][g+1]==13){hit++;
                                                  twomap2[f-1][g+1]=1;}                                    
                        }

              if(hit!=0&&count2>2){
                        twomap2[realx2][realy2]=1;                        
                        //now eye and current have map2 set to 1
                        for(f=0;f<8;f++)rndsel[f]=0;
                        for(g=0;g<12;g++)
                        for(f=0;f<7+(!(g%2^top2));f++)
                          if(twomap[f][g]<8)rndsel[twomap[f][g]]++;
                        
                        rndsel2=random()%8;
                        ty3:
                        if(rndsel[rndsel2]==0){rndsel2++;if(rndsel2==8)rndsel2=0;goto ty3;}
                        if(bf2==0){
     				  for(g=0;g<12;g++)
                        for(f=0;f<7+(!(g%2^top2));f++)
                             if(twomap[f][g]==rndsel2)twomap[f][g]=9;
                        	  doredraw3();
                        	  }
                        if(bf2==1){
    	                          for(g=0;g<12;g++)
                        for(f=0;f<7+(!(g%2^top2));f++)
                             if(twomap[f][g]==rndsel2){twomap[f][g]=11;count2--;}
                        	  doredraw3();
    	                          }
    	                if(bf2==2){
    	                          gg=random()%8;
    	                          for(g=0;g<12;g++)
                        for(f=0;f<7+(!(g%2^top2));f++)
                             if(twomap[f][g]==11){twomap[f][g]=gg;count2++;}
                        	  doredraw3();
    	                	}
			 if(bf2==3){
    	                          
    	                          for(g=0;g<12;g++)
                        for(f=0;f<7+(!(g%2^top2));f++)
                             if(twomap[f][g]<8)twomap[f][g]=random()%8;
                        	  doredraw3();
    	                	}
    	                if(bf2==4){
    	                         if(helpful==1)doremove2();
    	                         helpful2=1;helpful=0;
    	                	
    	                	}
                       if(bf2==5){
    	                          
    	                          for(g=0;g<12;g++)
                        for(f=0;f<7+(!(g%2^top2));f++)
                             if(twomap[f][g]!=8)
                             {if(twomap[f][g]!=11)count2--;
                             twomap[f][g]=random()%12;
                             if(twomap[f][g]!=11&&twomap[f][g]!=8)count2++;}  
                        	  doredraw3();
    	                	}
			if(bf2==7){
    	                      	                    
    	                for(g=0;g<12;g++)
                        for(f=0;f<7+(!(g%2^top2));f++)
                             if(twomap[f][g]<8&&random()%1000>333){hit2++;twomap2[f][g]=1;}
                        	  goto twoslither2;
    	                	}
    	               if(bf2==6){
    	                   rndselmark=0;
    	                   for(f=0;f<8;f++)
    	                    if(rndsel[f]>rndsel[rndselmark])rndselmark=f;    	                    
    	                          for(g=0;g<12;g++)
                        for(f=0;f<7+(!(g%2^top2));f++)
                             if(twomap[f][g]==rndselmark){hit2++;twomap2[f][g]=1;}
                        	  goto twoslither2;
    	                	}
                        hit=0;blowupanyway=1;
                         }


//end check for eyeballs



              //check for key balls...

              f2=realx2;g2=realy2;


              
                if(g2%2^top2){  if(g2!=0&&twomap[f2][g2-1]==12){hit2++;
                                  twomap2[f2][g2-1]=1;}
                          if(g2!=0&&twomap[f2+1][g2-1]==12){hit2++;
                                  twomap2[f2+1][g2-1]=1;}
                          if(f2!=0&&twomap[f2-1][g2]==12){hit2++;
                                            twomap2[f2-1][g2]=1;}
                          if(f2!=6&&twomap[f2+1][g2]==12){hit2++;
                                             twomap2[f2+1][g2]=1;}
                          if(g2!=11&&twomap[f2][g2+1]==12){hit2++;
                                             twomap2[f2][g2+1]=1;}
                          if(g2!=11&&twomap[f2+1][g2+1]==12){hit2++;
                                             twomap2[f2+1][g2+1]=1;}
                       }

                 else  { if(g2!=0&&f2!=7&&twomap[f2][g2-1]==12){hit2++;
                                                  twomap2[f2][g2-1]=1;}
                         if(g2!=0&&f2!=0&&twomap[f2-1][g2-1]==12){hit2++;
                                                 twomap2[f2-1][g2-1]=1;}
                         if(f2!=0&&twomap[f2-1][g2]==12){hit2++;
                                           twomap2[f2-1][g2]=1;}
                         if(f2!=7&&twomap[f2+1][g2]==12){hit2++;
                                            twomap2[f2+1][g2]=1;}
                         if(g2!=11&&f2!=7&&twomap[f2][g2+1]==12){hit2++;
                                                   twomap2[f2][g2+1]=1;}
                         if(g2!=11&&f2!=0&&twomap[f2-1][g2+1]==12){hit2++;
                                                  twomap2[f2-1][g2+1]=1;}                                    
                        }

              if(hit2!=0){
                        for(g2=0;g2<12;g2++)
                        for(f2=0;f2<7+(!(g2%2^top2));f2++)
                        if(twomap[f2][g2]==bf2){      hit2++;
                                                twomap2[f2][g2]=1;
                                         }

                         goto twoslither2;
                         }

              twomap2[realx2][realy2]=1;
              //main loop
              twocheckloop2:
              redo2=0;
              for(g2=0;g2<12;g2++)
              for(f2=0;f2<7+(!(g2%2^top2));f2++)
              if(twomap2[f2][g2]==1&&twomap3[f2][g2]==0)
                {twomap3[f2][g2]=1;
                if(g2%2^top2){  if(g2!=0&&twomap[f2][g2-1]==bf2&&twomap2[f2][g2-1]==0){redo2++;hit2++;
                                  twomap2[f2][g2-1]=1;}
                          if(g2!=0&&twomap[f2+1][g2-1]==bf2&&twomap2[f2+1][g2-1]==0){redo2++;hit2++;
                                  twomap2[f2+1][g2-1]=1;}
                          if(f2!=0&&twomap[f2-1][g2]==bf2&&twomap2[f2-1][g2]==0){redo2++;hit2++;
                                            twomap2[f2-1][g2]=1;}
                          if(f2!=6&&twomap[f2+1][g2]==bf2&&twomap2[f2+1][g2]==0){redo2++;hit2++;
                                             twomap2[f2+1][g2]=1;}
                          if(g2!=11&&twomap[f2][g2+1]==bf2&&twomap2[f2][g2+1]==0){redo2++;hit2++;
                                             twomap2[f2][g2+1]=1;}
                          if(g2!=11&&twomap[f2+1][g2+1]==bf2&&twomap2[f2+1][g2+1]==0){redo2++;hit2++;
                                             twomap2[f2+1][g2+1]=1;}
                       }

                 else  { if(g2!=0&&f2!=7&&twomap[f2][g2-1]==bf2&&twomap2[f2][g2-1]==0){redo2++;hit2++;
                                                  twomap2[f2][g2-1]=1;}
                         if(g2!=0&&f2!=0&&twomap[f2-1][g2-1]==bf2&&twomap2[f2-1][g2-1]==0){redo2++;hit2++;
                                                 twomap2[f2-1][g2-1]=1;}
                         if(f2!=0&&twomap[f2-1][g2]==bf2&&twomap2[f2-1][g2]==0){redo2++;hit2++;
                                           twomap2[f2-1][g2]=1;}
                         if(f2!=7&&twomap[f2+1][g2]==bf2&&twomap2[f2+1][g2]==0){redo2++;hit2++;
                                            twomap2[f2+1][g2]=1;}
                         if(g2!=11&&f2!=7&&twomap[f2][g2+1]==bf2&&twomap2[f2][g2+1]==0){redo2++;hit2++;
                                                   twomap2[f2][g2+1]=1;}
                         if(g2!=11&&f2!=0&&twomap[f2-1][g2+1]==bf2&&twomap2[f2-1][g2+1]==0){redo2++;hit2++;
                                                  twomap2[f2-1][g2+1]=1;}                                    
                        }

                 }

                 if(redo2!=0)goto twocheckloop2;                                                






                 if(hit2>1+tog||blowupanyway==1){
                   twoslither2:
      //check for exploding bombs

              for(g2=0;g2<12;g2++)for(f2=0;f2<8;f2++)twomap3[f2][g2]=0;
              
              
              twocheckloop32:
              redo2=0;
              for(g2=0;g2<12;g2++)
              for(f2=0;f2<7+(!(g2%2^top2));f2++)
              if(twomap2[f2][g2]!=0&&twomap3[f2][g2]==0)
                {twomap3[f2][g2]=1;bb2=(twomap[f2][g2]==10)?1:0;
                if(g2%2^top2){  if(g2!=0){if(twomap[f2][g2-1]==10&&twomap2[f2][g2-1]==0)
                                                 {twomap2[f2][g2-1]=2;redo2++;hit2++;}
                                       if(bb2&&twomap[f2][g2-1]!=8&&twomap2[f2][g2-1]==0)
                                                 {twomap2[f2][g2-1]=1;redo2++;hit2++;}}

                               
   
                               if(g2!=0){if(twomap[f2+1][g2-1]==10&&twomap2[f2+1][g2-1]==0)
                                                 {twomap2[f2+1][g2-1]=2;redo2++;hit2++;}
                                       if(bb2&&twomap[f2+1][g2-1]!=8&&twomap2[f2+1][g2-1]==0)
                                                 {twomap2[f2+1][g2-1]=1;redo2++;hit2++;}}
   
                               if(f2!=0){if(twomap[f2-1][g2]==10&&twomap2[f2-1][g2]==0)
                                                 {twomap2[f2-1][g2]=2;redo2++;hit2++;}
                                       if(bb2&&twomap[f2-1][g2]!=8&&twomap2[f2-1][g2]==0)
                                                 {twomap2[f2-1][g2]=1;redo2++;hit2++;}}

                               if(f2!=6){if(twomap[f2+1][g2]==10&&twomap2[f2+1][g2]==0)
                                                 {twomap2[f2+1][g2]=2;redo2++;hit2++;}
                                       if(bb2&&twomap[f2+1][g2]!=8&&twomap2[f2+1][g2]==0)
                                                 {twomap2[f2+1][g2]=1;redo2++;hit2++;}}

                               if(g2!=11){if(twomap[f2][g2+1]==10&&twomap2[f2][g2+1]==0)
                                                 {twomap2[f2][g2+1]=2;redo2++;hit2++;}
                                       if(bb2&&twomap[f2][g2+1]!=8&&twomap2[f2][g2+1]==0)
                                                 {twomap2[f2][g2+1]=1;redo2++;hit2++;}}

                               if(g2!=11){if(twomap[f2+1][g2+1]==10&&twomap2[f2+1][g2+1]==0)
                                                 {twomap2[f2+1][g2+1]=2;redo2++;hit2++;}
                                       if(bb2&&twomap[f2+1][g2+1]!=8&&twomap2[f2+1][g2+1]==0)
                                                 {twomap2[f2+1][g2+1]=1;redo2++;hit2++;}}

                         
                       }

                 else  { 

if(g2!=0&&f2!=7){if(twomap[f2][g2-1]==10&&twomap2[f2][g2-1]==0)
                                                 {twomap2[f2][g2-1]=2;redo2++;hit2++;}
                                       if(bb2&&twomap[f2][g2-1]!=8&&twomap2[f2][g2-1]==0)
                                                 {twomap2[f2][g2-1]=1;redo2++;hit2++;}}



if(g2!=0&&f2!=0){if(twomap[f2-1][g2-1]==10&&twomap2[f2-1][g2-1]==0)
                                                 {twomap2[f2-1][g2-1]=2;redo2++;hit2++;}
                                       if(bb2&&twomap[f2-1][g2-1]!=8&&twomap2[f2-1][g2-1]==0)
                                                 {twomap2[f2-1][g2-1]=1;redo2++;hit2++;}}

                         
if(f2!=0){if(twomap[f2-1][g2]==10&&twomap2[f2-1][g2]==0)
                                                 {twomap2[f2-1][g2]=2;redo2++;hit2++;}
                                       if(bb2&&twomap[f2-1][g2]!=8&&twomap2[f2-1][g2]==0)
                                                 {twomap2[f2-1][g2]=1;redo2++;hit2++;}}

if(f2!=7){if(twomap[f2+1][g2]==10&&twomap2[f2+1][g2]==0)
                                                 {twomap2[f2+1][g2]=2;redo2++;hit2++;}
                                       if(bb2&&twomap[f2+1][g2]!=8&&twomap2[f2+1][g2]==0)
                                                 {twomap2[f2+1][g2]=1;redo2++;hit2++;}}

if(g2!=11&&f2!=7){if(twomap[f2][g2+1]==10&&twomap2[f2][g2+1]==0)
                                                 {twomap2[f2][g2+1]=2;redo2++;hit2++;}
                                       if(bb2&&twomap[f2][g2+1]!=8&&twomap2[f2][g2+1]==0)
                                                 {twomap2[f2][g2+1]=1;redo2++;hit2++;}}

if(g2!=11&&f2!=0){if(twomap[f2-1][g2+1]==10&&twomap2[f2-1][g2+1]==0)
                                                 {twomap2[f2-1][g2+1]=2;redo2++;hit2++;}
                                       if(bb2&&twomap[f2-1][g2+1]!=8&&twomap2[f2-1][g2+1]==0)
                                                 {twomap2[f2-1][g2+1]=1;redo2++;hit2++;}}
                                 
                        }

                 }

                 if(redo2!=0)goto twocheckloop32;                                                





     //end check for bombs
                           play_sample(explodew,(hit2>7?255:hit2*32),twofirex/2.5,1000,0);
                           jig2=1;
                           hit2=0;
                           //exnum=0;
                           extra=1;extra2=1;
                           for(g2=0;g2<12;g2++)
                           for(f2=0;f2<7+(!(g2%2^top2));f2++)
                               if(twomap2[f2][g2]!=0){if (g2<11){
                                                 blit(sqview,screen,(16*(g2%2^top2))+(f2*32),(g2*32),43+(16*(g2%2^top2))+(f2*32),48+(g2*32),32,32);
                                                 blit(sqview,b,(16*(g2%2^top2))+(f2*32),(g2*32),43+(16*(g2%2^top2))+(f2*32),48+(g2*32),32,32);
                                                           }
                                                 else {
                                                 
                                                 blit(b,screen,43+(16*(g2%2^top2))+(f2*32),48+(g2*32),43+(16*(g2%2^top2))+(f2*32),48+(g2*32),32,32);

                                                       }

                                                   if(twomap[f2][g2]!=11)count2--;
                                                   hit2++;
                                                   if(hit2>10)jig2=2;
                                                   if(hit2>20)jig2=3;
                                                   
                                                   for(ff2=0;ff2<32;ff2+=jig2)
                                                   for(gg2=0;gg2<32;gg2+=jig2)
                                                     {pix2=getpixel(ball[twomap[f2][g2]],ff2,gg2);
                                                     if(pix2)
                                                         {
                                                          exnum++;
                                                          exx[exnum]=43+ff2+(16*(g2%2^top2))+(f2*32);
                                                          exy[exnum]=48+gg2+(g2*32);
                                                          exdx[exnum]=(random()%9)-4;
                                                          exdy[exnum]=(random()%9)-4;
                                                          if (exdx[exnum]==0&&exdy[exnum]==0)exdy[exnum]=1;
                                                          exc[exnum]=pix2;
                                                          _putpixel(screen,exx[exnum],exy[exnum],exc[exnum]);
                                                          
                                                          
                                                          }
                                                    }
                                                   if(twomap[f2][g2]<8&&gov<99){
                                                   gov++;
                                                   give[gov]=twomap[f2][g2];}
                                                   twomap[f2][g2]=8;
                                                                                                                                                
                                                  }






              for(g2=0;g2<12;g2++)for(f2=0;f2<8;f2++){twomap2[f2][g2]=0;twomap3[f2][g2]=0;
                                                if(g2==0&&twomap[f2][g2]!=8)twomap2[f2][g2]=1;
                                                if(twomap[f2][g2]==11)twomap2[f2][g2]=1;}
              
              
                           
              twocheckloop22:
              redo2=0;
              for(g2=0;g2<12;g2++)
              for(f2=0;f2<7+(!(g2%2^top2));f2++)
              if(twomap2[f2][g2]==1&&twomap3[f2][g2]==0)
                {twomap3[f2][g2]=1;
                if(g2%2^top2){  if(g2!=0&&twomap[f2][g2-1]!=8){redo2++;
                                  twomap2[f2][g2-1]=1;}
                          if(g2!=0&&twomap[f2+1][g2-1]!=8){redo2++;
                                  twomap2[f2+1][g2-1]=1;}
                          if(f2!=0&&twomap[f2-1][g2]!=8){redo2++;
                                            twomap2[f2-1][g2]=1;}
                          if(f2!=6&&twomap[f2+1][g2]!=8){redo2++;
                                             twomap2[f2+1][g2]=1;}
                          if(g2!=11&&twomap[f2][g2+1]!=8){redo2++;
                                             twomap2[f2][g2+1]=1;}
                          if(g2!=11&&twomap[f2+1][g2+1]!=8){redo2++;
                                             twomap2[f2+1][g2+1]=1;}
                       }

                 else  { if(g2!=0&&f2!=7&&twomap[f2][g2-1]!=8){redo2++;
                                                  twomap2[f2][g2-1]=1;}
                         if(g2!=0&&f2!=0&&twomap[f2-1][g2-1]!=8){redo2++;
                                                 twomap2[f2-1][g2-1]=1;}
                         if(f2!=0&&twomap[f2-1][g2]!=8){redo2++;
                                           twomap2[f2-1][g2]=1;}
                         if(f2!=7&&twomap[f2+1][g2]!=8){redo2++;
                                            twomap2[f2+1][g2]=1;}
                         if(g2!=11&&f2!=7&&twomap[f2][g2+1]!=8){redo2++;
                                                   twomap2[f2][g2+1]=1;}
                         if(g2!=11&&f2!=0&&twomap[f2-1][g2+1]!=8){redo2++;
                                                  twomap2[f2-1][g2+1]=1;}                                    
                        }

                 }

                 if(redo2!=0)goto twocheckloop22;                                                
                 
                           hit2=0;jig2=1;//dropno=0
                           for(g2=0;g2<12;g2++)
                           for(f2=0;f2<7+(!(g2%2^top2));f2++)
                               if(twomap2[f2][g2]!=1&&twomap[f2][g2]!=8)
                                                  {
                                                   if(g2<11){
                                                   //blit(view,screen,(16*(g%2^top))+(f*32),(g*32),48+(16*(g%2^top))+(f*32),48+(g*32),32,32);
                                                   blit(sqview,b,(16*(g2%2^top2))+(f2*32),(g2*32),43+(16*(g2%2^top2))+(f2*32),48+(g2*32),32,32);
                                                            }
                                                   else {
                                                 blit(b,screen,43+(16*(g2%2^top2))+(f2*32),48+(g2*32),43+(16*(g2%2^top2))+(f2*32),48+(g2*32),32,32);

                                                   }
                                                   dropno++;
                                                   if(twomap[f2][g2]!=11)count2--;
                                                   dropx[dropno]=43+(16*(g2%2^top2))+(f2*32);
                                                   dropy[dropno]=48+(g2*32);
                                                   dropc[dropno]=twomap[f2][g2];
                                                   if(twomap[f2][g2]<8&&gov<99){
                                                   gov++;
                                                   give[gov]=twomap[f2][g2];}
                                                   twomap[f2][g2]=8;
                                                  }
                                                  if(dropno!=0)dropno++;
                           //if(hit>0)play_sample(explodew,(hit>7?255:hit*32),128,1000,0);

                           }




                           


                        
                 twofirex=155;twofirey=425;
                 bf2=next2;
                 next2=bfset[bfc2];bfc2++;
                 if(bfc2==50)bfc2=0;
                 doquirk3();
                 holdit2=1;
                  gov-=(3+tog);
                 if(gov>gv)
                 {
                 gv=gov;
                 drawgive();           	 
           	 
           	 }
		 gov=gv;
                 
           }




void doaim()
{
           nolines=0;
           firex2=firex;firey2=firey;
           newx=firex2+6*fixtof(fsin(itofix(angle)));
           newy=firey2+6*fixtof(fcos(itofix(angle)));
           xx=newx-firex2;nxx=xx;
           yy=newy-firey2;
           linex[0]=firex+(xx*10)+16;liney[0]=firey+16-(yy*10);
           aim:
           firex2+=xx;
           firey2-=yy;           
           nfirex=firex2+nxx;
           nfirey=firey2-yy;
           if(nfirex<=48-4 || nfirex>=576-12)nxx=-nxx;
           if(firex2<=48-4 || firex2>=576-12){xx=-xx;
                                              nolines++;
                                              linex[nolines]=firex2+16;
                                              liney[nolines]=firey2+16;
                                              line(screen,linex[nolines-1],liney[nolines-1],linex[nolines],liney[nolines],flash);}
                                              
           ry=((firey2-48)/32);
           realy=ry;if(ry-realy>.5)realy++;
           rx=( firex2-48-  (  16* (realy %2^top))     )/32;
           realx=rx;
           if(rx-realx>.5&&realx!=(16-(realy%2^top)))realx++;
           

           nry=((nfirey-48)/32);
           nrealy=nry;if(nry-nrealy>.5)nrealy++;
           nrx=( nfirex-48-  (16*(nrealy %2^top))    )/32;
           nrealx=nrx;
           if(nrx-nrealx>.5&&nrealx!=(16-(nrealy%2^top)))nrealx++;

           if(realy<12&&realx<(17-(realy%2^top)) && map[realx][realy]==8)
            if(   (nrealy<12&&nrealx<(17-(nrealy%2^top))&&map[nrealx][nrealy]!=8)
               || (realy==0)  )
              {rect(screen,48+(16*(realy%2^top))+(realx*32),48+(realy*32),80+(16*(realy%2^top))+(realx*32),80+(realy*32),flash);
                                              nolines++;
                                              linex[nolines]=firex2+16;
                                              liney[nolines]=firey2+16;
                                              line(screen,linex[nolines-1],liney[nolines-1],linex[nolines],liney[nolines],flash);

               goto hell;}
    goto aim;
    hell:
    aim=1;
}


void doaim2()
{
           nolines=0;
           firex2=firex;firey2=firey;
           newx=firex2+6*fixtof(fsin(itofix(angle)));
           newy=firey2+6*fixtof(fcos(itofix(angle)));
           xx=newx-firex2;nxx=xx;
           yy=newy-firey2;
           linex[0]=firex+(xx*10)+16;liney[0]=firey+16-(yy*10);
           aim2:
           firex2+=xx;
           firey2-=yy;           
           nfirex=firex2+nxx;
           nfirey=firey2-yy;
           if(nfirex<=342-4 || nfirex>=582-12)nxx=-nxx;
           if(firex2<=342-4 || firex2>=582-12){xx=-xx;
                                              nolines++;
                                              linex[nolines]=firex2+16;
                                              liney[nolines]=firey2+16;
                                              line(screen,linex[nolines-1],liney[nolines-1],linex[nolines],liney[nolines],flash);}
                                              
           ry=((firey2-48)/32);
           realy=ry;if(ry-realy>.5)realy++;
           rx=( firex2-342-  (  16* (realy %2^top))     )/32;
           realx=rx;
           if(rx-realx>.5&&realx!=(7-(realy%2^top)))realx++;
           

           nry=((nfirey-48)/32);
           nrealy=nry;if(nry-nrealy>.5)nrealy++;
           nrx=( nfirex-342-  (16*(nrealy %2^top))    )/32;
           nrealx=nrx;
           if(nrx-nrealx>.5&&nrealx!=(7-(nrealy%2^top)))nrealx++;

           if(realy<12&&realx<(8-(realy%2^top)) && map[realx][realy]==8)
            if(   (nrealy<12&&nrealx<(8-(nrealy%2^top))&&map[nrealx][nrealy]!=8)
               || (realy==0)  )
              {rect(screen,342+(16*(realy%2^top))+(realx*32),48+(realy*32),374+(16*(realy%2^top))+(realx*32),80+(realy*32),flash);
                                              nolines++;
                                              linex[nolines]=firex2+16;
                                              liney[nolines]=firey2+16;
                                              line(screen,linex[nolines-1],liney[nolines-1],linex[nolines],liney[nolines],flash);

               goto hell2;}
    goto aim2;
    hell2:
    aim=1;
}



void doaim3()
{
           nolines2=0;
           twofirex2=twofirex;twofirey2=twofirey;
           newx2=twofirex2+6*fixtof(fsin(itofix(angle2)));
           newy2=twofirey2+6*fixtof(fcos(itofix(angle2)));
           xx2=newx2-twofirex2;nxx2=xx2;
           yy2=newy2-twofirey2;
           linex2[0]=twofirex+(xx2*10)+16;liney2[0]=twofirey+16-(yy2*10);
           aim3:
           twofirex2+=xx2;
           twofirey2-=yy2;           
           nfirex2=twofirex2+nxx2;
           nfirey2=twofirey2-yy2;
           if(nfirex2<=43-4 || nfirex2>=342-42-16-12)nxx2=-nxx2;
           if(twofirex2<=43-4 || twofirex2>=342-42-16-12){xx2=-xx2;
                                              nolines2++;
                                              linex2[nolines2]=twofirex2+16;
                                              liney2[nolines2]=twofirey2+16;
                                              line(screen,linex2[nolines2-1],liney2[nolines2-1],linex2[nolines2],liney2[nolines2],flash2);}
                                              
           ry2=((twofirey2-48)/32);
           realy2=ry2;if(ry2-realy2>.5)realy2++;
           rx2=( twofirex2-43-  (  16* (realy2 %2^top2))     )/32;
           realx2=rx2;
           if(rx2-realx2>.5&&realx2!=(7-(realy2%2^top2)))realx2++;
           

           nry2=((nfirey2-48)/32);
           nrealy2=nry2;if(nry2-nrealy2>.5)nrealy2++;
           nrx2=( nfirex2-43-  (16*(nrealy2 %2^top2))    )/32;
           nrealx2=nrx2;
           if(nrx2-nrealx2>.5&&nrealx2!=(7-(nrealy2%2^top2)))nrealx2++;

           if(realy2<12&&realx2<(8-(realy2%2^top2)) && twomap[realx2][realy2]==8)
            if(   (nrealy2<12&&nrealx2<(8-(nrealy2%2^top2))&&twomap[nrealx2][nrealy2]!=8)
               || (realy2==0)  )
              {rect(screen,43+(16*(realy2%2^top2))+(realx2*32),48+(realy2*32),75+(16*(realy2%2^top2))+(realx2*32),80+(realy2*32),flash2);
                                              nolines2++;
                                              linex2[nolines2]=twofirex2+16;
                                              liney2[nolines2]=twofirey2+16;
                                              line(screen,linex2[nolines2-1],liney2[nolines2-1],linex2[nolines2],liney2[nolines2],flash2);

               goto hell3;}
    goto aim3;
    hell3:
    aim2=1;
}



void llamascree(){
    fade_out(64);

    realtech=load_pcx("graf/realtech.pcx",pal);
    llama=load_pcx("graf/llama.pcx",pal);
    mummy=load_sample("wav/mummy.wav");

    draw_sprite(screen,llama,235,124);
    fade_in(pal,1);
    
    play_sample(mummy,255,128,1000,0);

    for ( f=640;f>62 ;f-=4 ) {
        blit(realtech,screen,0,0,f,415,517,65);
        }

    rest(4000);
        fade_out(3);
        clear(screen);
        destroy_bitmap(llama);
        destroy_bitmap(realtech);
        destroy_sample(mummy);
	realtech=load_pcx("graf/balldrop.pcx",pal);	
}


void mainscree(){
start=startsave;       
        set_pallete(pal2);
        text_mode(-1);
ln=0;
if(players==2)sel=1;
if(players==1)sel=(cont!=0)?9:0;
creds=fopen("misc/pf9.dat","rt");
while (!feof(creds)){fgets(credits[ln],100,creds);ln++;}
        


        exnum=10; //number of balls moving about in background
        for(f=0;f<exnum*2;f+=2){
                exx[f]=random()%640;     //centre of circle
                exy[f]=random()%480;             //""
                exx[f+1]=(random()%270)+30;   //radius of circle
                exy[f+1]=random()%256;   //current angle
                exdy[f]=random()%2;  //rotate clok or anti?
                //exdx[f]=(random()%9)-4;  //add to angle
                exc[f]=random()%8;        //colour of ball
                      }
    
    upto=0;pix=0;opt=0;ok=1;
    loopything:

    if(key[KEY_ESC]){start=999;goto retblok;}
    clear(b);
    for (f=0;f<exnum*2 ;f+=2 ) {
        
        if(exdy[f]==0)
          exy[f+1]++;
        else
          exy[f+1]--;
        h=exx[f]+exx[f+1]*fixtof(fsin(itofix(exy[f+1])));
        i=exy[f]+exx[f+1]*fixtof(fcos(itofix(exy[f+1])));

        draw_sprite(b,ball[exc[f]],h,i);


        }

     //scroller
    
    if(!key[KEY_DOWN]&&!key[KEY_UP]&&!key[KEY_SPACE]&&!key[KEY_ENTER]&&!key[KEY_RIGHT]&&!key[KEY_LEFT])ok=0;

if(opt==0){    if(upto<24){
              for(f=0;f<upto;f++){
                textout_centre(b,font,credits[f],320,480-(20*(upto-f-1))-pix,random()%256);
                   }
                     }
               else  {for(f=24-upto;f<upto+24;f++){
                textout_centre(b,font,credits[f],320,480-(20*(upto-f-1))-pix,random()%256);
                                    }

                           }

               pix++;if(pix==20){pix=0;upto++;if(upto==ln)upto=0;}
             }
else{
     textout(b,font,"ONE CREATURE VS DESTINY",100,200,254);
     textout(b,font,"ONE CREATURE VS ANOTHER SUCH CREATURE",100,230,250);     
     textout(b,font,"[RECOGNITION SCREEN]",100,260,251);
     sprintf(string,"DIFFICULTY (FOR ALL CREATURES): %s",difftext[diff]);
     textout(b,font,string,100,290,251);
     sprintf(string,"ONE CREATURE DESTINY START LEVEL: %d",start+1);
     textout(b,font,string,100,320,254);
     sprintf(string,"TWO CREATURES- INITIAL LINES: %d",il);
     textout(b,font,string,100,350,250);
     sprintf(string,"TWO CREATURES- INTERESTING BALLS: %s",yn[intballs]);
     textout(b,font,string,100,380,250);
     sprintf(string,"TWO CREATURES- NUMBER OF ROUNDS: %s",rounds[rd]);
     textout(b,font,string,100,410,250);
     sprintf(string,"TWO CREATURES- GRAPHICS: %s",gecko[gk]);
     textout(b,font,string,100,440,250);
     if(cont!=0)textout(b,font,"I am only a small creature, please let me continue.",100,470,65);
     textout(b,font,"?",80,200+(30*sel),255);
     

    if(key[KEY_UP]&&sel!=0&&ok==0){sel--;ok=1;}
    if(key[KEY_DOWN]&&(sel!=((cont==0)?8:9))&&ok==0){sel++;ok=1;}
    //if(!key[KEY_DOWN]&&!key[KEY_UP]&&!key[KEY_SPACE]&&!key[KEY_ENTER]&&!key[KEY_RIGHT])ok=0;
    if((key[KEY_SPACE]||key[KEY_ENTER])&&ok==0){ok=1;
                              if(sel==0){players=1;goto retblok;}
                              if(sel==1){players=2;goto retblok;}
                              if(sel==2){doinfo();graf1();}
                              if(sel==9){players=1;startsave=start;start=cont;goto retblok;}
                        }
    if(sel==3&&key[KEY_LEFT]&&ok==0)
       {ok=1;diff--;if(diff==-1)diff=3;}

    if(sel==3&&key[KEY_RIGHT]&&ok==0)
    {ok=1;diff++;if(diff==4)diff=0;}
    if(sel==4&&key[KEY_LEFT]&&ok==0)
     {
     ok=1;
     if(start==0)start=40;
     else
     if(start==20)start=0;
     else
     if(start==40)start=20;
     }
    if(sel==4&&key[KEY_RIGHT]&&ok==0)
     {
     ok=1;
     if(start==0)start=20;
     else
     if(start==20)start=40;
     else
     if(start==40)start=0;
     }

    if(sel==5&&key[KEY_LEFT]&&ok==0)
     {
     ok=1;
     if(il==3)il=7;
     else
     if(il==5)il=3;
     else
     if(il==7)il=5;
     }
    if(sel==5&&key[KEY_RIGHT]&&ok==0)
     {
     ok=1;
     if(il==3)il=5;
     else
     if(il==5)il=7;
     else
     if(il==7)il=3;
     }

   if(sel==6&&(key[KEY_LEFT]||key[KEY_RIGHT])&&ok==0)
    {ok=1;
    intballs=(intballs==1)?0:1;}


  if(sel==7&&key[KEY_LEFT]&&ok==0)
       {ok=1;rd--;if(rd==-1)rd=5;}

    if(sel==7&&key[KEY_RIGHT]&&ok==0)
    {ok=1;rd++;if(rd==6)rd=0;}
  


  if(sel==8&&key[KEY_LEFT]&&ok==0)
       {ok=1;gk--;if(gk==-1)gk=2;}

    if(sel==8&&key[KEY_RIGHT]&&ok==0)
    {ok=1;gk++;if(gk==3)gk=0;}



    }
             draw_sprite(b,realtech,17,0);
             

     blit(b,screen,0,0,0,0,640,480);


     if((key[KEY_SPACE]||key[KEY_ENTER])&&opt==0&&ok==0){opt=1;ok=1;}

goto loopything;

retblok:
exnum=0;ok=0;
//text_mode(0);
}


void doquirk()
{
        
        
        blit(view,wheel,212,333,0,0,120,20);
                   g=10;
                   for(f=6;f<11+(!top);f++)
                   if(map[f][g]!=8)
                    draw_sprite(wheel,ball[map[f][g]],(-212+(16*(g%2^top))+(f*32)),-13);


        
        //rotate_sprite(screen,arrow,260,381,itofix(angle));
          //      draw_sprite(screen,ball[bf],304,425);


//fix????
                blit(wheel,b,0,0,260,381,120,100);
                rotate_sprite(b,arrow,260,381,itofix(angle));
if(fire==0)            draw_sprite(b,ball[bf],firex,firey);
                
                blit(b,screen,260,401-20,260,401-20,120,100);

//fix????
}


void doquirk2()
{
        
        
                        blit(sqview,wheel,68,333,0,0,120,20);
                        
        
                   g4=10;
                   for(f4=2-top;f4<6;f4++)
                   if(map[f4][g4]!=8)
                    draw_sprite(wheel,ball[map[f4][g4]],(-68+(16*(g4%2^top))+(f4*32)),-13);


        
                blit(wheel,b,0,0,410,381,120,100);
                rotate_sprite(b,arrow,410,381,itofix(angle));
if(fire==0)                draw_sprite(b,ball[bf],firex,firey);
                
                blit(b,screen,410,401-20,410,401-20,120,100);
                


}

void doquirk3()
{
        
       
              blit(sqview,wheel2,68,333,0,0,120,20);
     
                   g4=10;
                   for(f4=2-top2;f4<6;f4++)
                   if(twomap[f4][g4]!=8)
                    draw_sprite(wheel2,ball[twomap[f4][g4]],(-68+(16*(g4%2^top2))+(f4*32)),-13);


        

                blit(wheel2,b,0,0,111,381,120,100);
                rotate_sprite(b,arrow,111,381,itofix(angle2));
if(fire2==0)                draw_sprite(b,ball[bf2],twofirex,twofirey);
                
                blit(b,screen,111,401-20,111,401-20,120,100);
            

}


void graf3()
{

        red=load_pcx("graf/30ball1.pcx",pal);
        orange=load_pcx("graf/30ball2.pcx",pal);
        yellow=load_pcx("graf/30ball3.pcx",pal);
        green=load_pcx("graf/30ball4.pcx",pal);
        blue=load_pcx("graf/30ball5.pcx",pal);
        purple=load_pcx("graf/30ball6.pcx",pal);
        white=load_pcx("graf/30ball7.pcx",pal);
        black=load_pcx("graf/30ball8.pcx",pal);
        drop=load_pcx("graf/30drop.pcx",pal);
        bomb=load_pcx("graf/30bomb.pcx",pal);
        key2=load_pcx("graf/30key.pcx",pal);
        wall=load_pcx("graf/30wall.pcx",pal);
	eye=load_pcx("graf/30eye.pcx",pal);
        title=load_pcx("graf/30title.pcx",pal);
        side=load_pcx("graf/30side.pcx",pal);

        oldwheel=load_pcx("graf/30wheel.pcx",pal);        
        clear(wheel);
        blit(oldwheel,wheel,0,0,20,0+20,80,80);
        
if(players==2){clear_to_color(wheel2,8);draw_sprite(wheel2,oldwheel,20,20);}
        destroy_bitmap(oldwheel);
        oldarrow=load_pcx("graf/30arrow.pcx",pal);
        clear(arrow);
        blit(oldarrow,arrow,0,0,48,0,24,100);
        destroy_bitmap(oldarrow);
        view=load_pcx("graf/30view.pcx",pal2);
if(players==2)stretch_blit(view,sqview,0,0,544,352,0,0,256,352);

        ball[0]=red;
        ball[1]=orange;
        ball[2]=yellow;
        ball[3]=green;
        ball[4]=blue;
        ball[5]=purple;
        ball[6]=white;
        ball[7]=black;
        ball[9]=drop;
        ball[10]=bomb;
        ball[11]=wall;
        ball[12]=key2;
	ball[13]=eye;
set_pallete(pal);
}

void graf2()
{

        red=load_pcx("graf/20red.pcx",pal);
        orange=load_pcx("graf/20oran.pcx",pal);
        yellow=load_pcx("graf/20yel.pcx",pal);
        green=load_pcx("graf/20gree.pcx",pal);
        blue=load_pcx("graf/20blue.pcx",pal);
        purple=load_pcx("graf/20purp.pcx",pal);
        white=load_pcx("graf/20white.pcx",pal);
        black=load_pcx("graf/20black.pcx",pal);
        drop=load_pcx("graf/20drop.pcx",pal);
        bomb=load_pcx("graf/20bomb.pcx",pal);
        key2=load_pcx("graf/20key.pcx",pal);
        wall=load_pcx("graf/20wall.pcx",pal);
        title=load_pcx("graf/20title.pcx",pal);
        side=load_pcx("graf/20side.pcx",pal);

        oldwheel=load_pcx("graf/20wheel.pcx",pal);        
        clear(wheel);
        blit(oldwheel,wheel,0,0,20,0+20,80,80);
        
if(players==2){clear_to_color(wheel2,8);draw_sprite(wheel2,oldwheel,20,20);}
        destroy_bitmap(oldwheel);
        oldarrow=load_pcx("graf/20arrow.pcx",pal);
        clear(arrow);
        blit(oldarrow,arrow,0,0,48,0,24,100);
        destroy_bitmap(oldarrow);
        view=load_pcx("graf/20view.pcx",pal2);
if(players==2)stretch_blit(view,sqview,0,0,544,352,0,0,256,352);

        ball[0]=red;
        ball[1]=orange;
        ball[2]=yellow;
        ball[3]=green;
        ball[4]=blue;
        ball[5]=purple;
        ball[6]=white;
        ball[7]=black;
        ball[9]=drop;
        ball[10]=bomb;
        ball[11]=wall;
        ball[12]=key2;

set_pallete(pal);
}
void graf1()
{

        red=load_pcx("graf/ball1.pcx",pal);
        orange=load_pcx("graf/ball2.pcx",pal);
        yellow=load_pcx("graf/ball3.pcx",pal);
        green=load_pcx("graf/ball4.pcx",pal);
        blue=load_pcx("graf/ball5.pcx",pal);
        purple=load_pcx("graf/ball6.pcx",pal);
        white=load_pcx("graf/ball7.pcx",pal);
        black=load_pcx("graf/ball8.pcx",pal);
        drop=load_pcx("graf/dropper.pcx",pal);
        bomb=load_pcx("graf/bomb.pcx",pal);
        wall=load_pcx("graf/wall.pcx",pal);
        title=load_pcx("graf/title.pcx",pal);
        side=load_pcx("graf/side.pcx",pal);

        oldwheel=load_pcx("graf/wheel.pcx",pal);        
        clear(wheel);
        blit(oldwheel,wheel,0,0,20,0+20,80,80);
        
        
if(players==2){clear_to_color(wheel2,8);draw_sprite(wheel2,oldwheel,20,20);}

        destroy_bitmap(oldwheel);
        oldarrow=load_pcx("graf/arrow.pcx",pal);
        clear(arrow);
        blit(oldarrow,arrow,0,0,48,0,24,100);
        destroy_bitmap(oldarrow);

        view=load_pcx("graf/view.pcx",pal2);
if(players==2)stretch_blit(view,sqview,0,0,544,352,0,0,256,352);
        ball[0]=red;
        ball[1]=orange;
        ball[2]=yellow;
        ball[3]=green;
        ball[4]=blue;
        ball[5]=purple;
        ball[6]=white;
        ball[7]=black;
        ball[9]=drop;
        ball[10]=bomb;
        ball[11]=wall;
        

set_pallete(pal);
}

void doremove()
{

            for(f=1;f<nolines+1;f++)
            do_line(0,linex[f-1],liney[f-1],linex[f],liney[f],0,doric);
            opt=48+(16*(realy%2^top))+(realx*32);
            sel=48+(realy*32);
            do_line(0,opt,sel,opt+32,sel,0,doric);
            do_line(0,opt+32,sel,opt+32,sel+32,0,doric);
            do_line(0,opt+32,sel+32,opt,sel+32,0,doric);
            do_line(0,opt,sel+32,opt,sel,0,doric);



}



void doremove2()
{

            for(f3=1;f3<nolines+1;f3++)
            do_line(0,linex[f3-1],liney[f3-1],linex[f3],liney[f3],0,doric);
            opt2=342+(16*(realy%2^top))+(realx*32);
            sel2=48+(realy*32);
            do_line(0,opt2,sel2,opt2+32,sel2,0,doric);
            do_line(0,opt2+32,sel2,opt2+32,sel2+32,0,doric);
            do_line(0,opt2+32,sel2+32,opt2,sel2+32,0,doric);
            do_line(0,opt2,sel2+32,opt2,sel2,0,doric);



}


void doremove3()
{

            for(f3=1;f3<nolines2+1;f3++)
            do_line(0,linex2[f3-1],liney2[f3-1],linex2[f3],liney2[f3],0,doric);
            opt2=43+(16*(realy2%2^top2))+(realx2*32);
            sel2=48+(realy2*32);
            do_line(0,opt2,sel2,opt2+32,sel2,0,doric);
            do_line(0,opt2+32,sel2,opt2+32,sel2+32,0,doric);
            do_line(0,opt2+32,sel2+32,opt2,sel2+32,0,doric);
            do_line(0,opt2,sel2+32,opt2,sel2,0,doric);



}



void doric(bmp,x,y,d)
{
_putpixel(screen,x,y,getpixel(b,x,y));
}


void whoo()
{
clear(mini);
textout(mini,font,string,0,0,251);
c=create_bitmap(640,480);
blit(b,c,0,0,0,0,640,480);


xx9=1; //size of pixels
readylemur:
g29=(640-((sel)*8*xx9))/2; //horiz pos.
opt=(480-(8*xx9))/2;              //vertical pos.

for(f=0;f<(sel)*8;f++)
	for(g=0;g<8;g++)
		if(getpixel(mini,f,g))rectfill(b,g29+(xx9*f),opt+(xx9*g),(g29+(xx9*f))+xx9,(opt+(xx9*g))+xx9,f29);



blit(b,screen,0,0,0,0,640,480);

blit(c,b,0,0,0,0,640,480);

xx9+=(xx9/25);
if(xx9<50)goto readylemur;

blit(c,b,0,0,0,0,640,480);
blit(c,screen,0,0,0,0,640,480);
destroy_bitmap(c);

}

void whoo2()
{
clear(mini);
textout(mini,font,string,0,0,251);
c=create_bitmap(640,480);
blit(b,c,0,0,0,0,640,480);


xx9=640/sel/8; //size of pixels

g29=(640-((sel)*8*xx9))/2; //horiz pos.
opt=(480-(8*xx9))/2;              //vertical pos.
f29=17;h9=0;
readylemur2:
for(f=0;f<(sel)*8;f++)
	for(g=0;g<8;g++)
		if(getpixel(mini,f,g))rectfill(b,g29+(xx9*f),opt+(xx9*g),(g29+(xx9*f))+xx9,(opt+(xx9*g))+xx9,f29);



blit(b,screen,0,0,0,0,640,480);

blit(c,b,0,0,0,0,640,480);

f29=(f29==17)?249:17;
h9++;
if(h9<20)goto readylemur2;

blit(c,b,0,0,0,0,640,480);
blit(c,screen,0,0,0,0,640,480);
destroy_bitmap(c);

}
void doscaw()
{
stretch_blit(side,b,0,0,48,432,0,48,43,432);
stretch_blit(side,b,0,0,48,432,598,48,43,432);
sprintf(string,"%d",scaw);
clear(mini2);
textout(mini2,font,string,0,0,255);                      
sel=1+(scaw>9);xx=2;xx2=6;
for(f=0;f<(sel)*8;f++)
	for(g=0;g<8;g++)
		if(getpixel(mini2,f,g))rectfill(b,4+(xx*f)+(8*(scaw<10)),52+(xx2*g),(4+(xx*f))+xx+(8*(scaw<10)),(52+(xx2*g))+xx2,8);

sprintf(string,"%d",scaw2);
clear(mini2);
textout(mini2,font,string,0,0,255);                      
sel=1+(scaw2>9);xx=2;xx2=6;
for(f=0;f<(sel)*8;f++)
	for(g=0;g<8;g++)
		if(getpixel(mini2,f,g))rectfill(b,604+(xx*f)+(8*(scaw2<10)),52+(xx2*g),(604+(xx*f))+xx+(8*(scaw2<10)),(52+(xx2*g))+xx2,0);

}

void drawgive2()
{

if(gv2!=0)
	{
	opt=gv2/9;
	sel=gv2%9;
	
	for(g=0;g<3;g++)
	 for(f=0;f<3;f++)
{
	 if(sel-->0){circlefill(screen,60+(12*f),440+(12*g),6,256-opt-1);circlefill(b,60+(12*f),440+(12*g),6,256-opt-1);}

else
if(opt>0)	 {circlefill(screen,60+(12*f),440+(12*g),6,256-opt);circlefill(b,60+(12*f),440+(12*g),6,256-opt);}
}			
	

	}
else {rectfill(b,53,433,91,471,8);rectfill(screen,53,433,91,471,8);}
}

void drawgive()
{

if(gv!=0)
	{
	opt=gv/9;
	sel=gv%9;
	
	for(g=0;g<3;g++)
	 for(f=0;f<3;f++)
{
if(sel-->0){circlefill(screen,360+(12*f),440+(12*g),6,256-opt-1);circlefill(b,360+(12*f),440+(12*g),6,256-opt-1);}
	else
if(opt>0){circlefill(screen,360+(12*f),440+(12*g),6,256-opt);circlefill(b,360+(12*f),440+(12*g),6,256-opt);}
				 		  	 
}}

else{rectfill(b,353,433,387+4,467+4,0);rectfill(screen,353,433,387+4,467+4,0);}
}


void doflish()
{

if(flish!=0){
	flishchex=0;
        for(flx=1;flx<flish+1;flx++)
	   	{	   
	        if(fc[flx]!=0&&map[fx[flx]][fy[flx]]!=8)
	     		{
 { if(!(fc[flx]%2)){blit(sqview,screen,(16*(fy[flx]%2^top))+(fx[flx]*32),(fy[flx]*32),342+(16*(fy[flx]%2^top))+(fx[flx]*32),48+(fy[flx]*32),32,32);
   blit(sqview,b,(16*(fy[flx]%2^top))+(fx[flx]*32),(fy[flx]*32),342+(16*(fy[flx]%2^top))+(fx[flx]*32),48+(fy[flx]*32),32,32);
                                                        }
   else {draw_sprite(b,ball[map[fx[flx]][fy[flx]]],342+(16*(fy[flx]%2^top))+(fx[flx]*32),48+(fy[flx]*32));
draw_sprite(screen,ball[map[fx[flx]][fy[flx]]],342+(16*(fy[flx]%2^top))+(fx[flx]*32),48+(fy[flx]*32));	
				      		}
				}
			
			if(--fc[flx]!=0)flishchex=1;
			}//endif	    	

	    	}//endloopblok
	    if(flishchex==0)flish=0;
	    }//endflish!=0	


if(flish2!=0){
	flishchex=0;
        for(flx=1;flx<flish2+1;flx++)
	   	{	   
	        if(fc2[flx]!=0&&twomap[fx2[flx]][fy2[flx]]!=8)
	     		{
{ if(!(fc2[flx]%2)){blit(sqview,screen,(16*(fy2[flx]%2^top2))+(fx2[flx]*32),(fy2[flx]*32),43+(16*(fy2[flx]%2^top2))+(fx2[flx]*32),48+(fy2[flx]*32),32,32);
  blit(sqview,b,(16*(fy2[flx]%2^top2))+(fx2[flx]*32),(fy2[flx]*32),43+(16*(fy2[flx]%2^top2))+(fx2[flx]*32),48+(fy2[flx]*32),32,32);
                                                        }
  else {draw_sprite(b,ball[twomap[fx2[flx]][fy2[flx]]],43+(16*(fy2[flx]%2^top2))+(fx2[flx]*32),48+(fy2[flx]*32));
draw_sprite(screen,ball[twomap[fx2[flx]][fy2[flx]]],43+(16*(fy2[flx]%2^top2))+(fx2[flx]*32),48+(fy2[flx]*32));	
				      		}
				}
			
			if(--fc2[flx]!=0)flishchex=1;
			}//endif	    	
	    	}//endloopblok
	    if(flishchex==0)flish2=0;
	    }//endflish!=0	



flishcount=0;
}


void doholditprime()
{
                 
                 
                 if(realy==11 && map[realx][realy]!=8){
                   fucked:
                   
                   play_sample(fukdw,255,128,1000,1);
                   l=0,ok=-1;clear_keybuf();
                   while(!keypressed()){
                   adjust_sample(fukdw,255,128,1000+l,1);
                   l+=ok;
                   if(l<-5000||l>4000)l==0;
                   
                   if((random()%100)>85)ok=-ok;
                   for(g=0;g<12;g++){
                   for(f=0;f<16+(!(g%2^top));f++){
                   if(map[f][g]<8)draw_sprite(screen,ball[random()%8],48+(16*(g%2^top))+(f*32),48+(g*32));}}
                            }
                   
                   l=999;return;
                   }
                 draw_sprite(screen,ball[bf],firex,firey);
                 draw_sprite(b,ball[bf],firex,firey);
                 if(diff<2)
                 {blit(ball[next],screen,0,0,492,425,32,32);
                 blit(ball[next],b,0,0,492,425,32,32);}
                
                 if(diff<2 && set==0 &&shots==todrop-2){
                       
                        set=1;whoop2=1;
                        play_sample(dangerw,255,128,1000,1);}
                 if(set==1&&shots==todrop-1){whoop2=2;set=2;adjust_sample(dangerw,255,128,2000,1);}

                 if(shots==todrop){ //wanko
                                if(set!=0){set=0;stop_sample(dangerw);set_color(0,pal2[0]);}
                                play_sample(fallw,255,128,1000,0);
                                
                                for(g=0;g<12;g++)for(f=0;f<17;f++)map2[f][g]=0;
                                shots=0;

                                for(g=0;g<12;g++)
                                        for(f=0;f<17;f++){
                                                if(g!=0)
                                                    map2[f][g]=map[f][g-1];
                                                else
                                                    map2[f][g]=11;
                                                if(f<16+(!(g%2^top))&&map[f][g]!=8)
                                                    //blit(view,screen,(16*(g%2^top))+(f*32),(g*32),48+(16*(g%2^top))+(f*32),48+(g*32),32,32);
                                                    blit(view,b,(16*(g%2^top))+(f*32),(g*32),48+(16*(g%2^top))+(f*32),48+(g*32),32,32);

                                                          }
                    

                                for(g=0;g<12;g++)
                                        for (f=0 ;f<16+(g%2^top) ;f++ )
                                                {
                                                map[f][g]=map2[f][g];
                                                if(map2[f][g]!=8&&f<16+(g%2^top)){
                                                        draw_sprite(b,ball[map2[f][g]],48+(16*(!(g%2^top)))+(f*32),48+(g*32));

                                                        if ( g==11 ){fucked=1;
                                                        draw_sprite(screen,ball[map2[f][g]],48+(16*(!(g%2^top)))+(f*32),48+(g*32));

                                                                     }
                                                        }
                                                }
                                    


                                
                                                blit(b,screen,48,48,48,48,544,352);
                                                
                                
                                top=!top;fire=0;doquirk();
                                //count+=16+(!(g%2^top));
                                if(fucked==1)goto fucked;
                               
                               }
                 if(diff==0)doaim();
                 holdit=0;
                 fire=0;
              }




void dohold1()
{

                 
                 if(realy==11 && map[realx][realy]!=8){
                   twofucked:
                   freeze=1;freeze2=1;
                   stop_sample(dangerw);
                   stop_sample(dangerw2);                  
                   scaw++;doscaw();
                   stop_sample(firew);
                   adjust_sample(fallw,70,255,1000,0);
                   play_sample(player1w,255,128,1000,0);
                   sprintf(string,"PLAYER 1 WINS!");
                   sel=14;f29=255;whoo();
                   clear_keybuf();
                   while(!keypressed())
{
		   for(g=0;g<12;g++)
                   for(f=0;f<7+(!(g%2^top));f++)
                   if(map[f][g]<8)draw_sprite(screen,ball[random()%8],342+(16*(g%2^top))+(f*32),48+(g*32));
                            
}
                   remove_int(flash);
                   rownd++;lll=1;return;
                   }
                 draw_sprite(screen,ball[bf],firex,firey);
                 draw_sprite(b,ball[bf],firex,firey);
                 if(diff<2)
                 {blit(ball[next],screen,0,0,430+120,425,32,32);
                 blit(ball[next],b,0,0,430+120,425,32,32);}
                
                 if(diff<2 && set==0 &&shots==todrop-2){
                       
                        set=1;whoop2=1;
                        play_sample(dangerw,255,255,1000,1);}
                 if(set==1&&shots==todrop-1){whoop2=2;set=2;adjust_sample(dangerw,255,255,2000,1);}

                 if(shots==todrop){ //wankolemur
                                if(set!=0){set=0;stop_sample(dangerw);set_color(0,pal2[0]);}
                                play_sample(fallw,255,255,1000,0);vr++;srandom(100*vr);
                                freeze=1;
                                for(g=0;g<12;g++)for(f=0;f<8;f++)map2[f][g]=0;
                                shots=0;

                                for(g=0;g<12;g++)
                                        for(f=0;f<8;f++){
                                                if(g!=0)
                                                    map2[f][g]=map[f][g-1];
                                                else
                                                    {map2[f][g]=random()%8;if(intballs)if(random()%16==4)map2[f][g]=(random()%3+gk)+9;if(map2[f][g]!=11)count++;}
                                                if(f<7+(!(g%2^top))&&map[f][g]!=8)
                                                    //blit(view,screen,(16*(g%2^top))+(f*32),(g*32),48+(16*(g%2^top))+(f*32),48+(g*32),32,32);
                                                    blit(sqview,b,(16*(g%2^top))+(f*32),(g*32),342+(16*(g%2^top))+(f*32),48+(g*32),32,32);

                                                          }
                    

                                for(g=0;g<12;g++)
                                        for (f=0 ;f<7+(g%2^top) ;f++ )
                                                {
                                                map[f][g]=map2[f][g];
                                                if(map2[f][g]!=8&&f<7+(g%2^top)){
                                                        draw_sprite(b,ball[map2[f][g]],342+(16*(!(g%2^top)))+(f*32),48+(g*32));

                                                        if ( g==11 ){fucked=1;
                                                        draw_sprite(screen,ball[map2[f][g]],342+(16*(!(g%2^top)))+(f*32),48+(g*32));

                                                                     }
                                                        }
                                                }
                                    


                                
                                                blit(b,screen,343,48,343,48,256,352);
                                                
                                
                                top=!top;fire=0;doquirk2();
                                //count+=16+(!(g%2^top));
                                if(fucked==1)goto twofucked;
                                freeze=0;
        
                               }
                 
                 if(helpful)doaim2();
                 holdit=0;
                 fire=0;
              
//lemur                
if(gv!=0)
{
//freeze=1;
opt=gv;sel=0;
  for(g=0;g<12;g++)
  for (f=0 ;f<7+(!(g%2^top)) ;f++ )
   	{                           
   if(map[f][g]==8){
   		    fx[opt]=f;
   		    fy[opt]=g;
   		    fc[opt]=10;
   		    map[f][g]=give[opt];if(g==11)count=901;
   		    count++;   		    
                    
   		    if(--opt==0)goto bazum;
   		    }
   	}
bazum:
play_sample(appearw,255,255,1000,0);
flish=gv;                    
gv=0;gov=0;drawgive();
if(count>900)goto twofucked;
//freeze=0;
}                 
}              
              
              
void dohold2()
{
                 
                 



                 if(realy2==11 && twomap[realx2][realy2]!=8){
                   twofucked2:
                   freeze2=1;freeze=1;
                   stop_sample(dangerw);
                   stop_sample(dangerw2);
                   scaw2++;doscaw();
                   stop_sample(firew);
                   adjust_sample(fallw,70,0,1000,0);
                   play_sample(player2w,255,128,1000,0);
                   sprintf(string,"PLAYER 2 WINS!");
                   sel=14;f29=255;whoo();
                   clear_keybuf();
                   while(!keypressed())
{
		   for(g=0;g<12;g++)
                   for(f=0;f<7+(!(g%2^top2));f++)
                   if(twomap[f][g]<8)draw_sprite(screen,ball[random()%8],43+(16*(g%2^top2))+(f*32),48+(g*32));
                            

}                   
                   remove_int(flash);
                   rownd++;lll=1;return;
                   }
                 draw_sprite(screen,ball[bf2],twofirex,twofirey);
                 draw_sprite(b,ball[bf2],twofirex,twofirey);
                 if(diff<2)  
                 {rectfill(b,251,425,251+32,425+32,8);
                 draw_sprite(b,ball[next2],251,425);
                 blit(b,screen,251,425,251,425,32,32);}
                
                 if(diff<2 && set2==0 &&shots2==todrop-2){
                       
                        set2=1;twowhoop2=1;
                        play_sample(dangerw2,255,0,1000,1);}
                 if(set2==1&&shots2==todrop-1){twowhoop2=2;set2=2;adjust_sample(dangerw2,255,0,2000,1);}

                 if(shots2==todrop){ //wanko
                                
                                if(set2!=0){set2=0;stop_sample(dangerw2);set_color(8,pal2[8]);}
                                play_sample(fallw,255,0,1000,0);vr2++;srandom(100*vr2);
                                freeze2=1;
                                for(g=0;g<12;g++)for(f=0;f<8;f++)twomap2[f][g]=0;
                                shots2=0;

                                for(g=0;g<12;g++)
                                        for(f=0;f<8;f++){
                                                if(g!=0)
                                                    twomap2[f][g]=twomap[f][g-1];
                                                else
                                                    {twomap2[f][g]=random()%8;if(intballs)if(random()%16==4)twomap2[f][g]=(random()%3+gk)+9;if(twomap2[f][g]!=11)count2++;}
                                                if(f<7+(!(g%2^top2))&&twomap[f][g]!=8)
                                                    //blit(view,screen,(16*(g%2^top))+(f*32),(g*32),48+(16*(g%2^top))+(f*32),48+(g*32),32,32);
                                                    blit(sqview,b,(16*(g%2^top2))+(f*32),(g*32),43+(16*(g%2^top2))+(f*32),48+(g*32),32,32);

                                                          }
                    

                                for(g=0;g<12;g++)
                                        for (f=0 ;f<7+(g%2^top2) ;f++ )
                                                {
                                                twomap[f][g]=twomap2[f][g];
                                                if(twomap2[f][g]!=8&&f<7+(g%2^top2)){
                                                        draw_sprite(b,ball[twomap2[f][g]],43+(16*(!(g%2^top2)))+(f*32),48+(g*32));

                                                        if ( g==11 ){fucked2=1;
                                                        draw_sprite(screen,ball[twomap2[f][g]],43+(16*(!(g%2^top2)))+(f*32),48+(g*32));

                                                                     }
                                                        }
                                                }
                                    


                                
                                                blit(b,screen,43,48,43,48,256,352);
                                                
                                
                                top2=!top2;fire2=0;doquirk3();
                                //count+=16+(!(g%2^top));
                                if(fucked2==1)goto twofucked2;
                                freeze2=0;
        
                               }
                 
                 if(helpful2)doaim3();
                 holdit2=0;
                 fire2=0;

  if(gv2!=0)
{
//freeze2=1;
opt=gv2;sel=0;
  for(g=0;g<12;g++)
  for (f=0 ;f<7+(!(g%2^top2)) ;f++ )
   	{                           
   if(twomap[f][g]==8){
   		    fx2[opt]=f;
   		    fy2[opt]=g;
   		    fc2[opt]=10;
   		    twomap[f][g]=give2[opt];if(g==11)count2=901;
   		    count2++;   		    
   		    if(--opt==0)goto bazum2;
   		    }
   	}
bazum2:
play_sample(appearw,255,0,1000,0);
flish2=gv2;		    
gv2=0;gov2=0;drawgive2();
if(count2>900)goto twofucked2;
//freeze2=0;
}  
}

void docol()
{
//return;
if(set!=0&&flashcount==1){
if(whoop>63)whoop=63;
if(whoop<0)whoop=0;           
           pal[0]->r=whoop;
           pal[0]->g=0;
           pal[0]->b=0;
           set_color(0,pal[0]);


           whoop+=whoop2;
           if((whoop>61&&whoop2>0)||(whoop<2&&whoop2<0))whoop2=-whoop2;
	   flashcount=0;
           }
}
void docol2()
{
if(set2!=0&&flashcount2==1){
if(twowhoop>63)twowhoop=63;
if(twowhoop<0)twowhoop=0;           
           
           pal[8]->r=twowhoop;
           pal[8]->g=0;
           pal[8]->b=0;
           set_color(8,pal[8]);

           twowhoop+=twowhoop2;
           if((twowhoop>61&&twowhoop2>0)||(twowhoop<2&&twowhoop2<0))twowhoop2=-twowhoop2;
           flashcount2=0;
           }
}

void doendseq()
{
smiley=load_pcx("graf/132smile.pcx",pal);
c=create_bitmap(640,480);
clear(c);
stretch_blit(smiley,c,0,0,132,132,80,0,480,480);
clear(mini);
textout(mini,font,"YOU SOLVED IT!",0,0,251);
sel=14;
xx9=640/sel/8; //size of pixels

g29=(640-((sel)*8*xx9))/2; //horiz pos.
opt=(480-(8*xx9))/2;              //vertical pos.


exnum=0;
for(f=0;f<10240;f++){exx[f]=666;exy[f]=999;}
for(f=0;f<10;f++){dropy[f]=0;}
clear_keybuf();
stalker2:
if(key[KEY_SPACE]||key[KEY_ENTER]){destroy_bitmap(c);destroy_bitmap(smiley);return;}
blit(c,b,0,0,0,0,640,480);

for(f=0;f<10;f++)
	{
	if(dropy[f]==0&&random()%1000>990)
		{dropx[f]=(random()%(640-64))+32;
		dropy[f]=480;
		dropc[f]=random()%8;
		give2[f]=random()%200;//explode height
		give[f]=(random()%30)+2;}
	
	if(dropy[f]!=0)
		{
		dropy[f]-=give[f];
		if(dropy[f]>give2[f])
			{
			draw_sprite(b,ball[dropc[f]],dropx[f],dropy[f]);
			}
		else
			{
			play_sample(explodew,255,dropx[f]/2.5,1000,0);
			doblowup();
			dropy[f]=0;
			
			}
		
		}
	}
kafireworks();              
dowinner();
blit(b,screen,0,0,0,0,640,480);
goto stalker2;              
}              
              
void dofireworks()
{
set_pallete(pal2);
clear(mini);
sprintf(string,"PLAYER %d WINS!",1+(scaw2>scaw));
textout(mini,font,string,0,0,251);
sel=14;
xx9=640/sel/8; //size of pixels

g29=(640-((sel)*8*xx9))/2; //horiz pos.
opt=(480-(8*xx9))/2;              //vertical pos.


exnum=0;
for(f=0;f<10240;f++){exx[f]=666;exy[f]=999;}
for(f=0;f<10;f++){dropy[f]=0;}
clear_keybuf();
stalker:
if(key[KEY_SPACE]||key[KEY_ENTER])return;
clear(b);

for(f=0;f<10;f++)
	{
	if(dropy[f]==0&&random()%1000>990)
		{dropx[f]=(random()%(640-64))+32;
		dropy[f]=480;
		dropc[f]=random()%8;
		give2[f]=random()%200;//explode height
		give[f]=(random()%30)+2;}
	
	if(dropy[f]!=0)
		{
		dropy[f]-=give[f];
		if(dropy[f]>give2[f])
			{
			draw_sprite(b,ball[dropc[f]],dropx[f],dropy[f]);
			}
		else
			{
			play_sample(explodew,255,dropx[f]/2.5,1000,0);
			doblowup();
			dropy[f]=0;
			
			}
		
		}
	}
kafireworks();              
dowinner();
blit(b,screen,0,0,0,0,640,480);
goto stalker;              
}              

void doblowup()
{
  exnum=1024*f;
  for(ff=0;ff<32;ff++)
  for(gg=0;gg<32;gg++)
         {pix=getpixel(ball[dropc[f]],ff,gg);
                 if(pix)
                       {
                        
                        exx[exnum]=dropx[f]+ff;
                        exy[exnum]=dropy[f]+gg;
                        exdx[exnum]=(random()%9)-4;
                        exdy[exnum]=(random()%9)-4;
                        if (exdx[exnum]==0&&exdy[exnum]==0)exdy[exnum]=1;
                        exc[exnum]=pix;
                        exnum++;
                                                                      
                                                          
                        }
           }
                                                 

}

void kafireworks()
{


for(h=1;h<10240;h++){
                   
                   
                    if(exx[h]>=0&&exx[h]<=639&&exy[h]>=0&&exy[h]<=479)

                       {
                        _putpixel(b,exx[h],exy[h],exc[h]);
                        
                         exx[h]+=exdx[h]*1.5;
                         exy[h]+=exdy[h]*1.5;

                       }
                   
                    }


}

void dowinner()
{



for(f=0;f<(sel)*8;f++)
	for(g=0;g<8;g++)
		if(getpixel(mini,f,g))rectfill(b,g29+(xx9*f),opt+(xx9*g),(g29+(xx9*f))+xx9,(opt+(xx9*g))+xx9,255);




}


void doinfo()
{
goto skop;
skup:
graf1();
skop:
clear(screen);
clear(mini);
textout(mini,font,"Levels 1-20.,255",0,0,254);
stretch_blit(mini,screen,0,0,12*8,8,0,0,12*8*4,32);
for(ff=0;ff<8;ff++)stretch_blit(ball[ff],screen,0,0,32,32,64*ff,64-16,64,64);
textout(screen,font,"Fire a ball of the same colour at a clump of 2 or more to destroy them.",0,40+16+64,255);
stretch_blit(ball[9],screen,0,0,32,32,0,(64*2)+16,64,64);
textout(screen,font,"DROPPER: Must be dropped or bombed",64+16,(64*2)+32+16,255);
stretch_blit(ball[10],screen,0,0,32,32,0,(64*3)+16,64,64);
textout(screen,font,"BOMB: Set off by any explosion. Destroys everything.",64+16,(64*3)+32+16,255);
stretch_blit(ball[11],screen,0,0,32,32,0,(64*4)+16,64,64);
textout(screen,font,"WALL: Balls will not drop if connected to a wall",64+16,(64*4)+32+16,255);
textout(screen,font,"or the top of the screen. Walls can be bombed.",64+16,(64*4)+32+16+8,255);

textout_centre(screen,font,"ARROW KEYS TO MOVE, SPACE/ENTER RETURNS TO MAIN",320,480-8,253);
clear_keybuf();
while(1){if(key[KEY_SPACE]||key[KEY_ENTER])return;
	 if(key[KEY_UP]||key[KEY_RIGHT])goto skup2;
	 if(key[KEY_DOWN]||key[KEY_LEFT])goto skup3;}
skup2:
graf2();
clear(screen);
clear(mini);
textout(mini,font,"Levels 21-40.,255",0,0,254);
stretch_blit(mini,screen,0,0,13*8,8,0,0,13*8*4,32);
for(ff=0;ff<8;ff++)stretch_blit(ball[ff],screen,0,0,32,32,64*ff,64-16,64,64);
textout(screen,font,"Fire a ball of the same colour at a clump of 2 or more to destroy them.",0,40+16+64,255);
stretch_blit(ball[9],screen,0,0,32,32,0,(64*2)+16,64,64);
textout(screen,font,"DROPPER: Must be dropped or bombed",64+16,(64*2)+32+16,255);
stretch_blit(ball[10],screen,0,0,32,32,0,(64*3)+16,64,64);
textout(screen,font,"BOMB: Set off by any explosion. Destroys everything.",64+16,(64*3)+32+16,255);
stretch_blit(ball[11],screen,0,0,32,32,0,(64*4)+16,64,64);
textout(screen,font,"WALL: Balls will not drop if connected to a wall",64+16,(64*4)+32+16,255);
textout(screen,font,"or the top of the screen. Walls can be bombed.",64+16,(64*4)+32+16+8,255);
stretch_blit(ball[12],screen,0,0,32,32,0,(64*5)+16,64,64);
textout(screen,font,"KEY BALL: Hit this to destroy all balls of the colour fired.",64+16,(64*5)+32+16,255);
textout_centre(screen,font,"ARROW KEYS TO MOVE, SPACE/ENTER RETURNS TO MAIN",320,480-8,253);
clear_keybuf();
while(1){if(key[KEY_SPACE]||key[KEY_ENTER])return;
	 if(key[KEY_UP]||key[KEY_RIGHT])goto skup3;
	 if(key[KEY_DOWN]||key[KEY_LEFT])goto skup;}
skup3:
graf3();
clear(screen);
clear(mini);
textout(mini,font,"Levels 41-50.,255",0,0,254);
stretch_blit(mini,screen,0,0,13*8,8,0,0,13*8*4,32);
for(ff=0;ff<8;ff++)stretch_blit(ball[ff],screen,0,0,32,32,64*ff,64-16,64,64);
textout(screen,font,"Fire a ball of the same colour at a clump of 2 or more to destroy them.",0,40+16+64,255);
stretch_blit(ball[9],screen,0,0,32,32,0,(64*2)+16,64,64);
textout(screen,font,"DROPPER: Must be dropped or bombed",64+16,(64*2)+32+16,255);
stretch_blit(ball[10],screen,0,0,32,32,0,(64*3)+16,64,64);
textout(screen,font,"BOMB: Set off by any explosion. Destroys everything.",64+16,(64*3)+32+16,255);
stretch_blit(ball[11],screen,0,0,32,32,0,(64*4)+16,64,64);
textout(screen,font,"WALL: Balls will not drop if connected to a wall",64+16,(64*4)+32+16,255);
textout(screen,font,"or the top of the screen. Walls can be bombed.",64+16,(64*4)+32+16+8,255);
stretch_blit(ball[12],screen,0,0,32,32,0,(64*5)+16,64,64);
textout(screen,font,"KEY BALL: Hit this to destroy all balls of the colour fired.",64+16,(64*5)+32+16,255);
stretch_blit(ball[13],screen,0,0,32,32,0,(64*6)+16,64,64);
textout(screen,font,"EYE BALL: Who can divine the mysteries of HORUS?",64+16,(64*6)+32+16,255);

textout_centre(screen,font,"ARROW KEYS TO MOVE, SPACE/ENTER RETURNS TO MAIN",320,480-8,253);
clear_keybuf();
while(1){if(key[KEY_SPACE]||key[KEY_ENTER])return;
	 if(key[KEY_UP]||key[KEY_RIGHT])goto skup;
	 if(key[KEY_DOWN]||key[KEY_LEFT])goto skup2;}

}

void doredraw()
{
blit(view,b,0,0,48,48,544,352);
for(gg=0;gg<12;gg++)
for(ff=0;ff<16+(!(gg%2^top));ff++)
if(map[ff][gg]!=8){
//blit(view,b,(16*(gg%2^top))+(ff*32),(gg*32),48+(16*(gg%2^top))+(ff*32),48+(gg*32),32,32);
draw_sprite(b,ball[map[ff][gg]],48+(16*(gg%2^top))+(ff*32),48+(gg*32));
                 }
blit(b,screen,48,48,48,48,544,352);doquirk();

}
void doredraw2()
{
for(gg=0;gg<12;gg++)
for(ff=0;ff<7+(!(gg%2^top));ff++)
if(map[ff][gg]!=8){
blit(sqview,b,(16*(gg%2^top))+(ff*32),(gg*32),342+(16*(gg%2^top))+(ff*32),48+(gg*32),32,32);
draw_sprite(b,ball[map[ff][gg]],342+(16*(gg%2^top))+(ff*32),48+(gg*32));
                 }
blit(b,screen,342,48,342,48,256,352);doquirk2();

}
void doredraw3()
{
for(gg=0;gg<12;gg++)
for(ff=0;ff<7+(!(gg%2^top2));ff++)
if(twomap[ff][gg]!=8&&ff!=realx&&gg!=realy){
blit(sqview,b,(16*(gg%2^top2))+(ff*32),(gg*32),43+(16*(gg%2^top2))+(ff*32),48+(gg*32),32,32);
draw_sprite(b,ball[twomap[ff][gg]],43+(16*(gg%2^top2))+(ff*32),48+(gg*32));
                 }
blit(b,screen,43,48,43,48,256,352);doquirk3();

}


void doflash(){


if(flishcount<2)flishcount++;
if(ballcount<1)ballcount++;
if(pointcount<1)pointcount++;
if(flashcount<1)flashcount++;
if(flashcount2<1)flashcount2++;
if(pointcount2<1)pointcount2++;
}
END_OF_FUNCTION(doflash);


void lockup()
{
//LOCK_FUNCTION(doflash);
//LOCK_VARIABLE(set);LOCK_VARIABLE(set2);
//LOCK_VARIABLE(pal);
//LOCK_VARIABLE(whoop);LOCK_VARIABLE(whoop2);
//LOCK_VARIABLE(twowhoop);LOCK_VARIABLE(twowhoop2);
LOCK_VARIABLE(flishcount);
LOCK_VARIABLE(ballcount);
LOCK_VARIABLE(flashcount);
LOCK_VARIABLE(pointcount);
LOCK_VARIABLE(flashcount2);
LOCK_VARIABLE(pointcount2);

}

