Program a;

import "mod_m7";
import "mod_blendop";
import "mod_debug";
import "mod_dir";
import "mod_draw";
import "mod_file";
import "mod_grproc";
import "mod_joy";
import "mod_key";
import "mod_map";
import "mod_math";
import "mod_mouse";
import "mod_multi";
import "mod_proc";
import "mod_rand";
import "mod_regex";
import "mod_say";
import "mod_screen";
import "mod_scroll";
import "mod_sound";
import "mod_string";
import "mod_sys";
import "mod_text";
import "mod_time";
import "mod_timers";
import "mod_video";
import "mod_wm";

Global
	sonido;
	grafico;
	canal;
	puntos;
	ocasiones[10]=138,428,713,1017,1308,1897,2648;
	graph_puntos;
Begin
	set_mode(640,480,32);
	set_text_color(rgb(0,255,0));
	sonido=load_wav("1.wav");
	grafico=load_png("1.png");
	set_fps(60,9);
	x=320; y=240;
	write(0,320,100,4,"PRESS ESPACE TO KANGASKANH");
	//FRAME(6000);
	play_song(load_song("1.ogg"),0);
	write_int(0,0,0,0,&puntos);
	timer[0]=0;
	los_puntos();
	while(is_playing_song())
		if(key(_space))
			graph=grafico;
			canal=play_wav(sonido,0);
			//set_song_volume(0);
			pon_puntos(suma_puntos());
			while(key(_space) or is_playing_wav(canal)) 
				size=rand(90,120);
				angle=rand(-20,20)*1000;
				frame(1500); 
			end
			graph=0;
			stop_wav(-1);
			//set_song_volume(100);
		end
		frame;
	end
	from x=1 to 100;
		set_mode(rand(100,500),rand(100,500),32);
		frame(rand(10,500));
	end
	exit();
End

Function suma_puntos();
Private
	mispuntos;
Begin
	from x=0 to 10;
		if(timer[0]>ocasiones[x]-20 and timer[0]<ocasiones[x]+20)
			if(timer[0]>ocasiones[x])
				mispuntos=20-(timer[0]-ocasiones[x]);
			elseif(timer[0]<ocasiones[x])
				mispuntos=20-(ocasiones[x]-timer[0]);
			else
				mispuntos=30;
			end
			ocasiones[x]=0;
		end
	end
	if(mispuntos==0) mispuntos=-3; end
	puntos+=mispuntos;
	graph_puntos=write_in_map(0,puntos,4);
	return mispuntos;
End

Process pon_puntos(puntaquers);
Begin
	if(puntaquers>0)
		graph=write_in_map(0,"+"+puntaquers,0);
	else
		graph=write_in_map(0,"-"+puntaquers,0);
	end
	x=320; y=240;
	size=200;
	while(alpha>0)
		alpha--;
		size++;
		frame;
	end
End

Process los_puntos();
Begin
	x=320;
	y=400;
	size=300;
	loop
		graph=graph_puntos;
		frame;
	end
End