#include <allegro.h> 
#include <iostream.h>


BITMAP *maze1,*bullet,*laser;
BITMAP *test;
int x=7;
int y=0;
int color,color2,color3;
int face;
int bx=7;
int by=0;

bool bulleet;






    void prosses()
{
     

     if(bulleet==true)
     {
                      clear(bullet);
                      
                      if(face==1)bx+=2; color2=getpixel(maze1,bx+1,by); 
                      if(face==2)bx-=2; color2=getpixel(maze1,bx-1,by); 
                      if(face==3)by-=2; color2=getpixel(maze1,bx,by-1); 
                      if(face==4)by+=2; color2=getpixel(maze1,bx,by+1);
                       if(color2==0){bx=x; by=y; clear(bullet); bulleet=false; goto end;}
                      blit(test, bullet, 0, 0, 0, 0, test->w, test->h);
                      rest(10);
                      
                      
                      circlefill(bullet,bx,by,2,makecol( 255, 255, 0   ));
                       blit(bullet, screen, 0, 0, 0, 0, test->w, test->h);
     }
end:;
}      
    
    
    
    
    
    
    
    
    


int drawmaze1()

{
      maze1 = load_bitmap( "maze1.bmp", NULL);
      circlefill(test,x,y,8,makecol( 255, 255, 0   ));
      draw_sprite( screen, maze1, 0, 0);
}         
END_OF_FUNCTION(drawmaze1);








void setup()
{
     drawmaze1();
     
     
}
END_OF_FUNCTION(setup);


void input()
{
if(key[KEY_RIGHT])
{
                  if(bulleet==true)
     {
prosses();
     }  
              clear(test);
              color=getpixel(maze1,x+8,y);
               if(color!=0)
              {
              if(bulleet==true){x++;}
              else
              {
              x++;
              bx++;
              }
              next:
              blit(maze1, test, 0, 0, 0, 0, test->w, test->h);
              rest(10);
            
              circlefill(test,x,y,7,makecol( 255, 255, 0   ));
              if(bulleet==false)face=1;
              blit(test, screen, 0, 0, 0, 0, test->w, test->h);
              }
                                if(bulleet==true)
     {
prosses();
     }
}
if(key[KEY_LEFT])
{
                  if(bulleet==true)
     {
prosses();
     }
              clear(test);
              color=getpixel(maze1,x-8,y);
               if(color==0)goto end;
              
              if(bulleet==true){x--;}
              else
              {
                  x--;
              bx--;
              }
              next2:
              blit(maze1, test, 0, 0, 0, 0, maze1->w, maze1->h);
              rest(10);
             
              circlefill(test,x,y,7,makecol( 255, 255, 0   ));
              if(bulleet==false)face=2;
              blit(test, screen, 0, 0, 0, 0, test->w, test->h);
             
                                if(bulleet==true)
     {
prosses();
     }
}
if(key[KEY_UP])
{
                  if(bulleet==true)
     {
prosses();
     }
     
              clear(test);
              color=getpixel(maze1,x,y-8);
               if(color!=0)
              {
              if(bulleet==true){y--;}
              else{y--;
              by--;
              }
              next3:
              blit(maze1, test, 0, 0, 0, 0, maze1->w, maze1->h);
              rest(10);
          
              circlefill(test,x,y,7,makecol( 255, 255, 0   ));
              if(bulleet==false)face=3;
              blit(test, screen, 0, 0, 0, 0, test->w, test->h);
              }
                                if(bulleet==true)
     {
prosses();
     }
}
if(key[KEY_DOWN])
{
                  if(bulleet==true)
     {
  prosses();
     }
              clear(test);
              color=getpixel(maze1,x,y+8);
              if (color==0)goto end;
              if(bulleet==true){y++;}
              else{
              y++;
              by++;
              }
              next4:
              blit(maze1, test, 0, 0, 0, 0, maze1->w, maze1->h);
              rest(10);
              
              
              circlefill(test,x,y,7,makecol( 255, 255, 0   ));
              if(bulleet==false)face=4;
              
              blit(test, bullet, 0, 0, 0, 0, test->w, test->h);
              blit(bullet, screen, 0, 0, 0, 0, test->w, test->h);
       
                                if(bulleet==true)
     {
                      prosses();
     }
   
              
}
if(key[KEY_A])
{
              
                    if(face==1) color3=getpixel(maze1,bx+8,bx); 
                      if(face==2) color3=getpixel(maze1,bx-8,bx); 
                      if(face==3) color3=getpixel(maze1,bx,by-8); 
                           if(face==4) color3=getpixel(maze1,bx,by+8);
                           if (color3!=0)bulleet=true;
             
}
             
end:;
}
END_OF_FUNCTION(input);






int main(){ 

allegro_init(); 
install_mouse(); 
install_keyboard(); 
install_timer();
set_color_depth(16); 

set_gfx_mode( GFX_AUTODETECT, 800, 600, 0, 0); 




test=create_bitmap(800,600);
bullet=create_bitmap(800,600);

setup();


while ( !key[KEY_ESC])
{ 
    blit(maze1, test, 0, 0, 0, 0, maze1->w, maze1->h);             
              circlefill(test,x,y,7,makecol( 255, 255, 0   ));            
              blit(test, screen, 0, 0, 0, 0, test->w, test->h);    
                    
              
input();
prosses();

}





} 

END_OF_MAIN();
