import "mod_grproc"
import "mod_key"
import "mod_map"
import "mod_video"
import "mod_text"
import "mod_proc"
import "mod_sound"

global 
	fired;
	ganaste;
	fallaste;
	fpg;
      sonido5;
      sonido1;
      sonido2;
      sonido3;
      sonido4;
      sonido0;
end

process bennu(x,y)
local
   sonido;
begin
   file = fpg;
   graph = 2;
   loop
	if (key(_up))
 		y=y-1;
	end

	if (key(_down))
 		y=y+1;
	end

	if (key(_right) && !fired)
 		fuego(x+40,y-10);
                play_wav(sonido2,0);
		fired = 1;
	end

	if (key(_esc))
	    break;           
	end
        frame;
	graph = ((graph - 1) % 2)+2;
   end
end

process fuego(x,y)
local
   posicion = 0;
   ini_y;
begin
	file = fpg;
	ini_y=y;
	graph = 4;
   loop	
	posicion = (posicion +1) % 4;
	if (posicion == 0)
		y=ini_y;
	end
	if (posicion == 1)
		y=ini_y +2;
	end
	if (posicion == 2)
		y=ini_y;
	end
	if (posicion == 3)
		y=ini_y -2;
	end
	x=x+1;
	if (x>320)
		fallaste = 1;
		break;
	end
    frame;
	
	if (key(_esc))
	    break;           
	end
	
   end 
   fired = 0;
end

process fenix(x,y)
local
   inc = 1;
   colision;
begin
   file = fpg;
   graph = 6;
   flags = 1;
   loop	
	y=y+inc;
        frame;
	graph = ((graph - 5) % 2)+6;
	if (key(_esc))
	    break;           
	end
	if (y>106)
		inc = -1;
	end
	if (y<94)
		inc = 1;
	end
        colision = collision(type fuego);
	if (colision)
           ganaste = 1;
           play_wav(sonido3,0);
           break;
	end
   end 
end

process fondo()
begin
   x=158;
   y=120;
   z= 1;
   file = fpg;
   graph = 1;
   loop	
        frame;
	if (key(_esc))
	    break;           
	end
   end 
end

function intro()
begin
   write(0,70,10,0,"LA AMENAZA AGUILAR");
   write(0,10,30,0,"Intenta eliminiar la amenaza y ganaras. Teclas: ");
   write(0,10,50,0,"flecha arriba y flecha abajo para moverse,");
   write(0,10,70,0,"flecha derecha para disparar.");
   write(0,10,90,0,"A continuacion se comprobara");
   write(0,10,110,0,"si usted no es un bot");

   write(0,100,130,0,"Pulsa c");
   play_song(sonido0,0);
   while (!key(_c))
    frame;
   end
   delete_text(0);
   write(0,100,50,0,"Pulsa r");
   while (!key(_r))
    frame;
   end
   delete_text(0);
   write(0,100,50,0,"Pulsa a");
   while (!key(_a))
    frame;
   end
   delete_text(0);
   write(0,100,50,0,"Pulsa p");
   while (!key(_p))
    frame;
   end
   delete_text(0);
   write(0,100,50,0,"Pulsa c");
   while (!key(_c))
    frame;
   end
   delete_text(0);
   write(0,100,50,0,"Pulsa o");
   while (!key(_o))
    frame;
   end
   delete_text(0);
   write(0,100,50,0,"Pulsa m");
   while (!key(_m))
    frame;
   end
   delete_text(0);
   write(0,100,50,0,"Pulsa p");
   while (!key(_p))
    frame;
   end
   delete_text(0);
   write(0,100,50,0,"Pulsa o");
   while (!key(_o))
    frame;
   end


   delete_text(0);
   write(0,100,50,0,"Pulsa t");
   while (!key(_t))
    frame;
   end
   delete_text(0);
   write(0,100,50,0,"Pulsa u");
   while (!key(_u))
    frame;
   end
   delete_text(0);
   write(0,100,50,0,"Pulsa s");
   while (!key(_s))
    frame;
   end
   delete_text(0);
   write(0,100,50,0,"Pulsa i");
   while (!key(_i))
    frame;
   end
   delete_text(0);
   write(0,100,50,0,"Pulsa q");
   while (!key(_q))
    frame;
   end
   delete_text(0);
   write(0,100,50,0,"Pulsa u");
   while (!key(_u))
    frame;
   end
   delete_text(0);
   write(0,100,50,0,"Pulsa e");
   while (!key(_e))
    frame;
   end
   delete_text(0);
   write(0,100,50,0,"Pulsa v");
   while (!key(_v))
    frame;
   end
   delete_text(0);
   write(0,100,50,0,"Pulsa a");
   while (!key(_a))
    frame;
   end
   delete_text(0);
   write(0,100,50,0,"Pulsa l");
   while (!key(_l))
    frame;
   end
   delete_text(0);
   write(0,100,50,0,"Pulsa e");
   while (!key(_e))
    frame;
   end
   delete_text(0);
   write(0,100,50,0,"Pulsa s");
   while (!key(_s))
    frame;
   end

   play_wav(sonido1,0);
   delete_text(0);
   write(0,20,10,0,"Que tio, se te ve con ganas de jugar eh");
   write(0,80,50,0,"Anda pulsa enter para empezar");
   while (!key(_enter))
    frame;
   end
   delete_text(0);
   bennu(45,200);
   fenix(260,100);
   play_song(sonido4,-1);
end

begin
   sonido1 = load_wav("1");
   sonido2 = load_wav("2");
   sonido3 = load_wav("3");
   sonido4 = load_song("4");
   sonido5 = load_wav("5");
   sonido0 = load_song("0");

   set_mode(320,240,32);
   set_fps(5,0);
   ganaste = 0;
   fallaste = 0;
   fpg = load_fpg("a");
   fondo();
   intro();
   loop
	if (key(_esc))
	    break;           
	end
        if (ganaste)
           let_me_alone();
           stop_song();
	   fondo();
	   write(0,30,40,0,"Ganaste. Fin del juego. Que esperabas?");
	   write(0,100,50,0,"Fue dificil eh.");
	   write(0,80,60,0,"Anda pulsa enter para finalizar");
	   while (!key(_enter))
	    frame;
	   end
           let_me_alone();
	   break;
        end
        if (fallaste)
           let_me_alone();
           stop_song();
           play_wav(sonido5,0);
	   fondo();
	   write(0,30,40,0,"Ains, fallaste, que se le va a hacer.");
	   write(0,100,50,0,"Fin del juego. Que esperabas?");
	   write(0,80,60,0,"Anda pulsa enter para finalizar");
	   while (!key(_enter))
	    frame;
	   end
           let_me_alone();
	   break;
        end
        frame;
   end 
   unload_fpg(fpg);
   unload_wav(sonido1);
   unload_wav(sonido2);
   unload_wav(sonido3);
   unload_song(sonido4);
   unload_wav(sonido5);
   unload_song(sonido0);

end

