

//editor for my balls have dropped
//very userunfriendly
//always saves or loads levels.dat from current directory and
//crashes if you try to display special balls on screen if you aren't in
//the right graphic mode for them. must be run from myballs directory so that
//graf is a subdir of it with the graphics in.
//compilies with gcc -w -m486 -O3 whatever.c -lalleg

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

allegro_init();

char level[50][17][20];
char tem[17][20];
int l=0,f=0,g=0,r=0,flash=0;
int savef,saveg,savel;
FILE *gizmo;
char buffer[100];
void graf();
void graf2();
void graf3();
      BITMAP *red;
      BITMAP *orange;
      BITMAP *yellow;
      BITMAP *green;
      BITMAP *blue;
      BITMAP *purple;
      BITMAP *white;
      BITMAP *black;
      BITMAP *bomb;
      BITMAP *drop;
      BITMAP *wall;
      BITMAP *key2;
      BITMAP *eye;
      RGB *pal[256];
      BITMAP *ball[14];

void main(){

        

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

install_keyboard();
xor_mode(0);
for(l=0;l<50;l++)
for(g=0;g<11;g++)
for(f=0;f<16+(!(g%2));f++)
  level[l][f][g]=8;



l=0;
graf1();

aha:
xor_mode(0);
clear(screen);
sprintf(buffer,"Level: %d",l+1);
textout(screen,font,buffer,0,440,60);
textout(screen,font,"Arrows move,1-8=colours,W=wall,B=bomb,D=mustdrop,R=rnd,K=key,I=eye",0,460,60);
textout(screen,font,"F1=level+,F2=level-,F5/F6/F7=graphics,F9=load,F12=save",0,470,60);
for(g=0;g<11;g++)
for(f=0;f<16+(!(g%2));f++)
                {if(level[l][f][g]==8)
                 rect(screen,48+(16*(g%2))+(f*32),48+(g*32),80+(16*(g%2))+(f*32),80+(g*32),45);
                 else
                 draw_sprite(screen,ball[level[l][f][g]],48+(16*(g%2))+(f*32),48+(g*32));

                 }
delay(250);
  f=0;g=0;flash=45;

xor_mode(1);



  editloop:


  rect(screen,48+(16*(g%2))+(f*32),48+(g*32),80+(16*(g%2))+(f*32),80+(g*32),flash);
  flash=random()%256;

  
  if(key[KEY_DOWN]&&g<10){g++;if(g%2&&f==16)f=15;}
  if(key[KEY_Z]){for(f=0;f<17;f++)for(g=0;g<12;g++)
                tem[f][g]=level[46][f][g];
                 for(f=0;f<17;f++)for(g=0;g<12;g++)
                level[46][f][g]=level[49][f][g];
                for(f=0;f<17;f++)for(g=0;g<12;g++)
                level[49][f][g]=tem[f][g];}
  if(key[KEY_UP]&&g>0){g--;if(g%2&&f==16)f=15;}
  if(key[KEY_LEFT]&&f>0){f--;}
  if(key[KEY_RIGHT]&&f<16-((g%2))){f++;}

  if(key[KEY_0]||key[KEY_SPACE]){xor_mode(0);rectfill(screen,48+(16*(g%2))+(f*32),48+(g*32),80+(16*(g%2))+(f*32),80+(g*32),0);
                 xor_mode(0);
                 level[l][f][g]=8;}
  if(key[KEY_1]){draw_sprite(screen,ball[0],48+(16*(g%2))+(f*32),48+(g*32));level[l][f][g]=0;}
  if(key[KEY_2]){draw_sprite(screen,ball[1],48+(16*(g%2))+(f*32),48+(g*32));level[l][f][g]=1;}
  if(key[KEY_3]){draw_sprite(screen,ball[2],48+(16*(g%2))+(f*32),48+(g*32));level[l][f][g]=2;}
  if(key[KEY_4]){draw_sprite(screen,ball[3],48+(16*(g%2))+(f*32),48+(g*32));level[l][f][g]=3;}
  if(key[KEY_5]){draw_sprite(screen,ball[4],48+(16*(g%2))+(f*32),48+(g*32));level[l][f][g]=4;}
  if(key[KEY_6]){draw_sprite(screen,ball[5],48+(16*(g%2))+(f*32),48+(g*32));level[l][f][g]=5;}
  if(key[KEY_7]){draw_sprite(screen,ball[6],48+(16*(g%2))+(f*32),48+(g*32));level[l][f][g]=6;}
  if(key[KEY_8]){draw_sprite(screen,ball[7],48+(16*(g%2))+(f*32),48+(g*32));level[l][f][g]=7;}

   if(key[KEY_D]){draw_sprite(screen,ball[9],48+(16*(g%2))+(f*32),48+(g*32));level[l][f][g]=9;}
   if(key[KEY_B]){draw_sprite(screen,ball[10],48+(16*(g%2))+(f*32),48+(g*32));level[l][f][g]=10;}
   if(key[KEY_W]){draw_sprite(screen,ball[11],48+(16*(g%2))+(f*32),48+(g*32));level[l][f][g]=11;}
   if(key[KEY_R]){r=random()%8;draw_sprite(screen,ball[r],48+(16*(g%2))+(f*32),48+(g*32));level[l][f][g]=r;}
   if(key[KEY_K]){draw_sprite(screen,ball[12],48+(16*(g%2))+(f*32),48+(g*32));level[l][f][g]=12;}
   if(key[KEY_I]){draw_sprite(screen,ball[13],48+(16*(g%2))+(f*32),48+(g*32));level[l][f][g]=13;}

   if(key[KEY_F1]&&l>0){l--;goto aha;}
   if(key[KEY_F2]&&l<49){l++;goto aha;}

   if(key[KEY_F5]){graf1();goto aha;}
   if(key[KEY_F6]){graf2();goto aha;}
   if(key[KEY_F7]){graf3();goto aha;}

   if(key[KEY_ESC])goto end;
  if(key[KEY_F12]){gizmo=fopen("levels.dat","wb");
                        savef=f;saveg=g;savel=l;
                        for(l=0;l<50;l++)
                        for(g=0;g<11;g++)
                        for(f=0;f<16+(!(g%2));f++)
                         fputc(level[l][f][g],gizmo);
                        fclose(gizmo);
                        f=savef;g=saveg;l=savel;
                        goto aha;
                   }

  if(key[KEY_F9]){gizmo=fopen("levels.dat","rb");
                        savef=f;saveg=g;savel=l;
                        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(gizmo);
                        fclose(gizmo);
                        f=savef;g=saveg;l=savel;
                        goto aha;
                   }


  delay(100);
  goto editloop;
end:
allegro_exit();
exit(0);
}

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);


        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);

        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 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);
        wall=load_pcx("graf\30wall.pcx",pal);
        key2=load_pcx("graf\30key.pcx",pal);
        eye=load_pcx("graf\30eye.pcx",pal);
        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);
}
