let musicnames=["Another World's Dream","Otherworldly Night","Renegade Machine","Tenebrous Wonder","Broken Voltage","Raindrops on a Dream","Necrofantastica","Aura of Phantomspace","Dance of the Youkai"];
let songcomments=[
"Strange, yet still familiar - perfect for the title screen. It sets the theme for the entire game, so I had to make sure it was perfect. I don't think I succeeded in that, but I still love the mood it creates, and it was fun to compose. It makes you feel like you're entering another world... because you are.",
"Stage 1 is going to be the most played, and it will also make the biggest impression on players. This is longer than a normal stage 1 song since I don't want it to get repetitive (it barely gets a chance to loop in-game). It's very relaxing, but not slow-paced, which is exactly what I was aiming for with the stage design, too. This is the song I want people to imagine when they think about this game, and it's my personal favorite.",
"Ender's battle theme. I don't know why I had to spend so much time on it for it to come out good, even though it's pretty simple and short - it went through at least three different distinct revisions before I was satisfied with it. Ender's actually fairly strong, so I still tried to convey that power in the song, even if he's the very first boss you face. It was fun to combine metal and techno, as well, but that might just be because I combine almost everything with techno...",
"Stage 2 was hard to make music for. I want it to be dark and mysterious, but if I overdo it, then it's not good shooting music at all. I reached the conclusion that players don't care too much about mood after the first minute of the stage, so I transitioned to something more upbeat. This was a very hard song to get right, and I'm still not completely satisfied... but everyone else seems to love it, so I guess I did something right.",
"Overload's battle theme: because evil lightbulb robots always need techno to accompany them. This one was probably my favorite to make, since it all flowed pretty well, and I got to use some really fun instruments. I tried to make it dark, since Overload can be very cruel, but I didn't want it to become a generic boss theme, so it also ended up melodic and fast.",
"I had two things in mind while I composed this: Mega Man and strawberries. I don't believe I need to go into any further detail.",
"Yukari's battle theme, remixed from her music in Perfect Cherry Blossom. It was hard fitting this in, since every other song is an original composition, but it ended up working pretty well. The only problem was that it flowed too nicely, so reversing the flow for the loop was hard to get right without sounding abrupt. However, I think I finally nailed it, and now it has just about my favorite loop point ever. It's almost as good as the intro!",
"Meteo's theme. I wanted it to be dark-sounding to fit the character, but having a dark and ominous tutorial song doesn't quite work. I wasn't satisfied with this at first, but the more I listen to it, the more I like it. Mission accomplished, then? I kind of just threw this song together, but it worked out well, with a nice mix of melodic parts and random techno. I think I overdo the latter on a few other songs...",
"The extra stages were a bit difficult to think of a song for - after all, it has to fit three unique characters. After a while of unsuccessfully thinking of a melody, I went with another plan: remixing one I already made. It's really catchy, but I'm worried it will be too repetitive, especially since you hear it in so many stages. I hope you don't find the song annoying after hearing it so much."
];

let musicchoice=-1;
let musicfade=1;
let redrawdescription=false;
let soundmode=0;
function MusicRoom{

	let targetmode=1;

	InMenu=6;
	musicchoice=-1;
	songnum=-1;
	let selection=0;
	let k=0;
	loop(length(musicnames)){
		SetFontStyle(0,0,0,0,0,0);
		SetFontColorNew(195,195,155,150,150,90);
		SetKerning(2);
		if(GetCommonDataDefault("Mseen"~IntString(k),false)||k==0){
			DrawTextNewObj(27,musicnames[k],imgText,20,100+k*20,0,3,3.5,8,1,255,0);
		}else{
			DrawTextNewObj(27,"???",imgText,20,100+k*20,0,3,3.5,8,1,255,0);
		}
		k++;
	}
	SoundTest(0);
	DeleteMusic(titlemusic);
	songnum=-1;
	let bgopacity=0;
	let fadeburst=0;
	let viewable=false;
	let percent=0;
	while(InMenu==6){
		fadeburst+=0.02;
		if(fadeburst>1){fadeburst=1;}
		SetCommonData("FadeBurst",fadeburst*0.8);

		bgopacity+=5;
//		DrawObject(objects[36],stgwhite,0,0,640,480,320,240,1,1,ALPHA,lower(bgopacity,150),8,0,0,0,0,0,0);
		DrawObject(objects[36],stgwhite,0,0,640,480,320,240,1,1,ALPHA,lower(bgopacity,150)*1.5,8,30,0,30,0,0,0);
		if(songnum>=0&&beatnum>=0){
			percent=(1-(beatnum+beattime)/timesig[songnum]);
			DrawObject(objects[37],"targetSparkles",0,0,512,512,320,240,1.5,1.5,ADD,lower(bgopacity,150)*((0.35+soundmode*0.65)-percent*(0.3+soundmode*0.3)*musicfade),8,255,255,255,0,0,0);
			DrawObject(objects[39],"targetSparkles",0,0,512,512,320,240,4.5-percent*3,4.5-percent*3,ADD,lower(bgopacity,150)*((0.5+soundmode*0.5)*percent*musicfade),8,255,255,255,0,0,0);
			DrawObject(objects[40],"targetSparkles",0,0,512,512,320,240,6.5-percent*5,3.5-percent*2,ADD,lower(bgopacity,150)*((soundmode*0.6)*percent*musicfade),8,255,255,255,0,0,0);
		}else{
			DrawObject(objects[37],"targetSparkles",0,0,512,512,320,240,1.5,1.5,ADD,lower(bgopacity,150)*(0.35+soundmode*0.65),8,255,255,255,0,0,0);
			DrawObject(objects[39],"targetSparkles",0,0,512,512,320,240,0,0,ADD,0,8,255,255,255,0,0,0);
			DrawObject(objects[40],"targetSparkles",0,0,512,512,320,240,0,0,ADD,0,8,255,255,255,0,0,0);
		}

		FunkyBeats(8,1);

		if(selection!=musicchoice){
			viewable=false;
			ClearTextImmediately(28);
			musicchoice=selection;
			SetFontStyle(1,4,0,360,1,10);
			SetFontColorNew(255,255,255,90,250,250);
			SetKerning(2);
			if(GetCommonDataDefault("Mseen"~IntString(musicchoice),false)||musicchoice==0){
				DrawTextNewObj(28,musicnames[musicchoice],imgText,19,99+musicchoice*20,0,3,3.5,8,1,255,1);
				viewable=true;
			}else{
				DrawTextNew(28,"???",imgText,19,99+musicchoice*20,0,3,3.5,8,1,255,1);
			}
			ClearTextImmediately(30);
			redrawdescription=true;
		}
		if(GetKeyState(VK_UP)==KEY_PUSH){
			selection--;
			selection=(selection+length(musicnames))%length(musicnames);
		}
		if(GetKeyState(VK_DOWN)==KEY_PUSH){
			selection++;
			selection%=length(musicnames);
		}
		if(GetKeyState(VK_BOMB)==KEY_PUSH||(GetKeyState(VK_SHOT)==KEY_PUSH&&songnum==selection)){
			if(songnum==-1){
				InMenu=0;
			}else{
				songnum=-1;
				lastbeat=0;
			}
			redrawdescription=true;
		}else if(GetKeyState(VK_SHOT)==KEY_PUSH&&viewable==true){
			SoundTest(musicchoice);
			redrawdescription=true;
		}else if(GetKeyState(VK_SHOT)==KEY_PUSH){
			songnum=-1;
			viewable=true;

			ClearTextImmediately(29);
			SetFontStyle(0,0,0,0,0,0);
			SetFontColorNew(255,255,255,255,0,0);
			let strings=WrapText("You haven't heard this song yet! Press the button again to listen to it anyway, but the song comments (or the song itself) might contain some spoilers. Why not play the game and hear it in context instead?",  38);
			let numstrings=length(strings)-1;
			while(numstrings>=0){		//imgText,450,130,2.8,3,8,0,
				DrawTextBoldObj(29,strings[numstrings],imgText,450,130+20*numstrings,0,3.0,3.8,8,0,255,0);
				numstrings--;
			}
			redrawdescription=true;
		}

		if(redrawdescription){
			if(songnum==-1){
				DrawDescriptionMusic("Z: Play / X: Exit / Ctrl: Brightness #/ Shift: Fade out");
			}else if(musicfade!=1){
				DrawDescriptionMusic("Z: Stop / X: Stop / Ctrl: Brightness #/ Shift: Fade out");
			}else if(selection==songnum){
				DrawDescriptionMusic("Z: Stop / X: Stop / Ctrl: Brightness / Shift: Fade out");
			}else{
				DrawDescriptionMusic("Z: Play / X: Stop / Ctrl: Brightness / Shift: Fade out");
			}
			redrawdescription=false;
		}
		if(GetKeyState(VK_SLOWMOVE)==KEY_PUSH){redrawdescription=true;}

		if(GetKeyState(VK_SKIP)==KEY_PUSH){targetmode=1-targetmode;}
		soundmode+=(targetmode-soundmode)/10;

		yield;
	}
	ClearTextImmediately(27);
	ClearText(28);
	ClearTextImmediately(29);
	ClearTextImmediately(127);
	yield;
	PlayMusic(titlemusic);
	bgopacity=150;
	ObjEffect_SetScale(objects[38],0,0);
	ObjEffect_SetScale(objects[39],0,0);
	ObjEffect_SetScale(objects[40],0,0);
	loop(50){
		bgopacity-=3;
		fadeburst-=0.02;
		if(fadeburst<0){fadeburst=0;}
		SetCommonData("FadeBurst",fadeburst*0.8);
		DrawObject(objects[36],stgwhite,0,0,640,480,320,240,1,1,ALPHA,lower(bgopacity,150)*1.5,8,30,0,30,0,0,0);
		DrawObject(objects[37],"targetSparkles",0,0,512,512,320,240,1.5,1.5,ADD,lower(bgopacity,150)*((0.35+soundmode*0.65)-percent*(0.3+soundmode*0.3)*musicfade),8,255,255,255,0,0,0);
		yield;
	}


	task DrawDescriptionMusic(string){
		ClearTextImmediately(127);
		SetFontStyle(0,0,0,0,0,0);
		SetFontColorNew(0,0,0,0,0,0);
		SetFontColorEmphasis(0,0,0,0,0,0);
		DrawTextNew(127,string,imgText,323,453,0,3,3.3,8,0,180,0);	
		SetFontColorNew(255,255,255,255,100,255);
		SetFontColorEmphasis(80,80,80,0,0,0);
		DrawTextBoldObj(127,string,imgText,320,450,0,3,3.3,8,0,255,0);	
	}

}
let lastbeat=0;
function FunkyBeats(layer,obj){
	if(songnum>=0&&beatnum>=0){
		let randx;let randy;
		let beatcolor=GetTime/20;
		if(beatspecial==1){
			beatcolor=GetTime/20;
			loop(3){
				randx=rand(0,640);
				randy=rand(0,200);
				BeatExplosion(randx,randy,1.5,beatcolor,1,layer,1,1);
				BeatExplosion(640-randx,480-randy,1.5,beatcolor,1,layer,1,1);
			}
			BeatExplosion(320+150,240,3,beatcolor,0.9,layer,1,1);
			BeatExplosion(320-150,240,3,beatcolor,0.9,layer,1,1);

			BeatExplosion(320,240,3,beatcolor,1,layer,0,1);
			BeatExplosion(320,240,2,beatcolor,1,layer,0,1);
		}else if(beatnum==0){
			if(255*(1-beattime)>lastbeat){
				beatcolor=GetTime/20;
				loop(3){
					randx=rand(0,640);
					randy=rand(0,200);
					BeatExplosion(randx,randy,1.5,beatcolor,1,layer,1,1);
					BeatExplosion(640-randx,480-randy,1.5,beatcolor,1,layer,1,1);
				}

				BeatExplosion(320+150,240,3,beatcolor,0.9,layer,1,1);
				BeatExplosion(320-150,240,3,beatcolor,0.9,layer,1,1);
			}
			if(obj==1){
				DrawObject(objects[38],stgwhite,0,0,640,480,320,240,1,1,ADD,255*(1-beattime),8,  Rainbow(0,beatcolor)*(15+soundmode*20),Rainbow(1,beatcolor)*(15+soundmode*20),Rainbow(2,beatcolor)*(15+soundmode*20),  0,0,0);
			}

		}else{
			if(255*(1-beattime)>lastbeat){
				beatcolor=GetTime/20;
				randx=rand(0,640);
				randy=rand(0,200);
				BeatExplosion(randx,randy,1,beatcolor,0.9,layer,1,1);
				BeatExplosion(640-randx,480-randy,1,beatcolor,0.9,layer,1,1);

				randx=rand(0,640);
				randy=rand(0,200);
				BeatExplosion(randx,randy,0.5,beatcolor,0.8,layer,1,1);
				BeatExplosion(640-randx,480-randy,0.5,beatcolor,0.8,layer,1,1);

				BeatExplosion(320+150,240,1.5,beatcolor,0.9,layer,1,1);
				BeatExplosion(320-150,240,1.5,beatcolor,0.9,layer,1,1);
			}

			if(obj==1){
				DrawObject(objects[38],stgwhite,0,0,640,480,320,240,1,1,ADD,255*(1-beattime),8,  Rainbow(0,beatcolor)*(8+soundmode*12),Rainbow(1,beatcolor)*(8+soundmode*12),Rainbow(2,beatcolor)*(8+soundmode*12),  0,0,0);
			}
		}
		lastbeat=255*(1-beattime);
	}else if(obj==1){
		ObjEffect_SetScale(objects[38],0,0);
	}
}
task BeatExplosion(x,y,size,color,maxalpha,layer,autocolor,tempomod){
	if(songnum>=0){
		if(autocolor==1){
			color+=atan2(y-240,x-320);
		}
		let angle=RandNew(0,360);
		let offset=RandNew(0,20);
		x+=cos(angle)*offset;
		y+=sin(angle)*offset;
		let obj=InitBeatCircle(1);
		ObjEffect_SetRenderState(obj,ADD);
		ObjEffect_SetLayer(obj,layer);
		Obj_SetPosition(obj,x,y);
		let colorarray=RainbowArray(color,140,115);
		let alpha=255;
		let rotation=RandNew(0,360);
		let scale=0.5;

		if(beatquiet==1){
			size/=2;
			scale/=2;
		}
	
		let savetempo=tempos[songnum]*tempomod;

		let frame=0;
		while(frame<=11000/savetempo){
			Obj_SetColor(obj,4,alpha*maxalpha*(0.65+soundmode*0.35)*musicfade,colorarray[0],colorarray[1],colorarray[2]);
			ObjEffect_SetScale(obj,scale,scale);
			ObjEffect_SetAngle(obj,0,0,rotation);
			Obj_SetPosition(obj,x+ScreenShakeX,y+ScreenShakeY);
			rotation+=1.5*beatspeed;

			scale+=size*savetempo*0.0002*beatspeed;

			alpha-=(255/(11000/savetempo))*beatspeed;

			yield;
			frame+=beatspeed;
		}
		Obj_Delete(obj);
	}
}

task SoundTest(num){
	let strings;
	let numstrings;
	if(songnum!=num){
		musicfade=1;
		ClearTextImmediately(29);
		SetFontStyle(0,0,0,0,0,0);
		SetFontColorNew(0,0,0,0,0,0);
		DrawTextNewObj(29,musicnames[num],imgText,450+4,100+4,0,4,4.5,8,0,155,0);
		SetFontColorNew(255,255,255,90,250,250);
		DrawTextNew(29,musicnames[num],imgText,450,100,0,4,4.5,8,0,255,0);

		SetFontStyle(0,0,0,0,0,0);
		SetFontColorNew(255,255,255,255,255,155);
		strings=WrapText(songcomments[num],  38);
		numstrings=length(strings)-1;
		while(numstrings>=0){		//imgText,450,130,2.8,3,8,0,
			DrawTextBoldObj(29,strings[numstrings],imgText,450,130+20*numstrings,0,3.0,3.8,8,0,255,0);
			numstrings--;
		}


		songnum=num;
		let musicfile=GetCurrentScriptDirectory~"..\music\"~IntString(num);
		PlayMusic(musicfile);
		songnum=num;
		mstarttime=GetTime;
		beattime=0;
		beatcheck=0;
		beatminus=0;
		beatspeed=1;
		tempo=1;
		beatquiet=0;
		while(songnum==num&&InMenu==6&&GetKeyState(VK_SLOWMOVE)!=KEY_PUSH){yield;}
		if(GetKeyState(VK_SLOWMOVE)==KEY_PUSH){
			FadeOutMusic(musicfile,10);
			loop(260){
				if(songnum==num){
					musicfade-=1/300;
					yield;
				}
			}
			if(songnum==num){
				songnum=-1;
				redrawdescription=true;
			}
		}
		DeleteMusic(musicfile);
	}
}


let beat=0;
let mstarttime=0;
let tempo=1;
let songnum=-1;
let beattime=0;
let beatnum=0;
let beatcheck=0;
let beatspecial=0;
let beatspeed=1;
let beatquiet=0;

let tempos=[140,115,180,140,170,180,170,170,135];
let startbeats=[1,1,1 ,1,1,1,1,1,1];	//how many beats before the song starts
let timesig=[3,4,4,4,4,4,4,4,4];

let bigbeats=[	//whole number is beatnumber, decimal is effect to use (1=big, 2=quiet, 6/7=halve/double expansion rate, 8/9=halve/double tempo)
[-400],
[-400],
[-400],
[-400],
[-400],
[-400],
[-400],
[-400],
[-400]
];

let stopmusic=0;
task LoadMusicNew(num){
	LoadMusic(GPSD~"music\"~IntString(num));
}
task DeleteMusicNew(num){
	DeleteMusic(GPSD~"music\"~IntString(num));
}

let newmusic=0;
task Music(num){
	drawfunk=true;
	SetCommonData("Mseen"~IntString(num),true);
	SaveCommonData;
	newmusic=1;
	let musicfile=GPSD~"music\"~IntString(num);
	PlayMusic(musicfile);
	songnum=num;
	mstarttime=GetTime;
	beattime=0;
	beatcheck=0;
	beatminus=0;
	beatspeed=1;
	tempo=1;
	beatquiet=0;
	SetFontStyle(0,0,0,0,0,0);
	SetFontColorNew(0,0,0,0,0,0);
	let obj1=DrawTextNewObj(999,"@ "~musicnames[num]~" @",imgText,GetClipMinX+3,GetClipMaxY-29,0,2.5,3.5,7,1,255,3);
	SetFontStyle(0,2,-90,-90,1,5);
	SetFontColorNew(255,255,150,150,150,100);
	let obj2=DrawTextNewObj(999,"@ "~musicnames[num]~" @",imgText,GetClipMinX,GetClipMaxY-32,0,2.5,3.5,7,1,255,3);
	let x=GetClipMinX+115;
	let xadd=1.1;
	loop(60){
		Obj_SetX(obj1,x+3);
		Obj_SetX(obj2,x);
		x-=xadd;
		xadd-=0.01;
		yield;
	}
	loop(120){
		Obj_SetX(obj1,x+3);
		Obj_SetX(obj2,x);
		x-=0.5;
		yield;
	}
	ClearText(999);
	let xadd=0.5;
	loop(60){
		Obj_SetX(obj1,x+3);
		Obj_SetX(obj2,x);
		x-=xadd;
		xadd+=0.1;
		yield;
	}
	stopmusic=0;
	newmusic=0;
	while(stopmusic==0&&newmusic==0){
		yield;
	}
	if(newmusic==0){
		FadeOutMusic(musicfile,15);
	}
}
sub StopMusic{
	stopmusic=1;
}

task BeatCircle{
	yield;
	let obj=InitBeatCircle(0);
	let obj2=InitBeatCircle(0);
	let frame=0;
	let size;
	let size2;
	let fadeframe=1;
	while(fadeframe>0){
		if(lifebarsremaining>0){
			Obj_SetPosition(obj,EnemyX2,EnemyY2);
		}else{
			fadeframe-=0.01;
		}
		if(beatnum<0){
			ObjEffect_SetScale(obj,0,0);	
			ObjEffect_SetScale(obj2,0,0);				
		}else{
			size=1.2+cos((beattime+beatnum)*(360/timesig[songnum]))*0.15;
			ObjEffect_SetScale(obj,size,size);
			ObjEffect_SetAngle(obj,0,0,frame*5.7);

			Obj_SetColor(obj,4,255*(1-beattime)*fadeframe,255,255,255);
			if(beatnum==0){
				Obj_SetPosition(obj2,EnemyX2,EnemyY2);
				Obj_SetColor(obj2,4,255*(1-beattime)*fadeframe,255,255,255);
				size2=beattime+1.35;

				ObjEffect_SetScale(obj2,size2,size2);
				ObjEffect_SetAngle(obj2,0,0,frame*5.7);
			}else if(beatnum>0){
				Obj_SetPosition(obj2,-1000,-1000);
			}else{
				Obj_SetPosition(obj,-1000,-1000);
				Obj_SetPosition(obj2,-1000,-1000);
			}
		}
		frame++;

		yield;
	}
	Obj_Delete(obj);
	Obj_Delete(obj2);

}
function InitBeatCircle(type){
	let obj=Obj_Create(OBJ_EFFECT);
	Obj_SetAutoDelete(obj,false);
	ObjEffect_SetLayer(obj,1);
	ObjEffect_CreateVertex(obj,4);
	ObjEffect_SetPrimitiveType(obj,PRIMITIVE_TRIANGLEFAN);
	ObjEffect_SetVertexXY(obj,0,-63,-63);ObjEffect_SetVertexXY(obj,1,63,-63);ObjEffect_SetVertexXY(obj,2,63,63);ObjEffect_SetVertexXY(obj,3,-63,63);
	if(type==0){
		ObjEffect_SetTexture(obj,imgEffects);
		ObjEffect_SetVertexUV(obj,0,1,129);ObjEffect_SetVertexUV(obj,1,127,129);ObjEffect_SetVertexUV(obj,2,127,255);ObjEffect_SetVertexUV(obj,3,1,255);
	}else{
		ObjEffect_SetTexture(obj,imgSoundThing);
		ObjEffect_SetRenderState(obj,ADD);
		ObjEffect_SetVertexUV(obj,0,0,0);ObjEffect_SetVertexUV(obj,1,256,0);ObjEffect_SetVertexUV(obj,2,256,256);ObjEffect_SetVertexUV(obj,3,0,256);
	}
	return obj;
}
let lastbeattime=0;
let beatminus=0;
sub HandleBeat{
	if(songnum>=0){
		beattime=((GetTime-mstarttime)/1000)*(tempos[songnum]/60)-beatminus;
		beatnum=trunc(beattime);

		if(beatnum-startbeats[songnum]>=0){
			beatnum=(beatnum-startbeats[songnum])%timesig[songnum];
		}else{
			beatnum=-1;
		}

		beatspecial=0;
		let numloops=0;
		while(trunc(beattime)-startbeats[songnum]>=absolute(trunc(bigbeats[songnum][beatcheck]))&&numloops<5000){
			if(trunc(bigbeats[songnum][beatcheck])<0){
				beatminus+=absolute(bigbeats[songnum][beatcheck]);
				beattime-=absolute(bigbeats[songnum][beatcheck]);
				beatcheck=0;
			}else{
				beatspecial=bigbeats[songnum][beatcheck];
				beatspecial=round((beatspecial-trunc(beatspecial))*10);	//get number after decimal
				beatcheck++;

				if(beatspecial==2){beatquiet=1-beatquiet;}
				if(beatspecial==6){beatspeed/=2;}
				if(beatspecial==7){beatspeed*=2;}
				if(beatspecial==8){tempo/=2;}
				if(beatspecial==9){tempo*=2;}
			}
			numloops++;
		}

		beattime=(beattime+startbeats[songnum])*tempo;
		beattime-=trunc(beattime);
	}else{
		beattime=-1;
		beatnum=-1;
	}
	SetCommonData("BeatNum",beatnum);
	SetCommonData("BeatTime",beattime);
}
let lastbeatstage=0;
sub MoreFunkyBeats{
	if(songnum>=0&&beatnum>=0&&drawbackground&&drawfunk){
		soundmode=0;
		let randx;let randy;
		let beatcolor=GetTime/5;
		if(beatspecial==1){
			loop(2){
				randx=RandNew(GetClipMinX,GetClipMaxX);
				randy=RandNew(GetClipMinY,GetCenterY-10);
				BeatExplosion(randx,randy,1.5,beatcolor,0.8,1,0,0.7);
				BeatExplosion(640-randx,480-randy,1.5,beatcolor,0.8,1,0,0.7);
			}
		}
		if(beatnum==0){
			if(255*(1-beattime)>lastbeatstage){
				loop(1){
					randx=RandNew(GetClipMinX,GetClipMaxX);
					randy=RandNew(GetClipMinY,GetCenterY-10);
					BeatExplosion(randx,randy,1.5,beatcolor,0.8,1,0,0.7);
					BeatExplosion(640-randx,480-randy,1.5,beatcolor,0.8,1,0,0.7);
				}

				BeatExplosion(GetCenterX-100,GetCenterY,3,beatcolor,0.7,1,0,0.7);
				BeatExplosion(GetCenterX+100,GetCenterY,3,beatcolor,0.7,1,0,0.7);

				BeatExplosion(GetPlayerX,GetPlayerY,3,beatcolor,0.7,1,0,0.5);
			}
		}else{
			if(255*(1-beattime)>lastbeatstage){
				randx=RandNew(GetClipMinX,GetClipMaxX);
				randy=RandNew(GetClipMinY,GetCenterY-10);
				BeatExplosion(randx,randy,1,beatcolor,0.6,1,0,0.7);
				BeatExplosion(640-randx,480-randy,1,beatcolor,0.6,1,0,0.7);

				BeatExplosion(GetCenterX-100,GetCenterY,1.5,beatcolor,0.7,1,0,0.7);
				BeatExplosion(GetCenterX+100,GetCenterY,1.5,beatcolor,0.7,1,0,0.7);
			}
		}
		lastbeatstage=255*(1-beattime);
	}
}

task CreditsMusic{
	PlayMusic(GPSD~"music\end.mp3");
	let time=GetTime;
	while(GetTime-time<30000){yield;}
	StopSE(GPSD~"music\end.mp3");
	DeleteMusic(GPSD~"music\end.mp3");
}

 let MenuSounds=["select","ok","ok2","cancel"];
 let GameSounds=[	"bomb","break","bubble","cancel","change","charge","charge2","charge3","crash","enemyexplode","exattack","explode","explode2","extend","guitar","guitar2","item","laser0","laser1","laser2",
			"laser3","laser4","laser5","light1","light2","lightning","nuke4","ok","select","shot0","shot1","shot2","shot3","shot4","slash","smallnuke","soul1","soul2","soul3","soul4"
			"timeout1","timeout2","warp"];
 let soundtypeloaded=0;

function LoadSounds(type){
	soundtypeloaded=type;
	let k=0;
	if(type==0){
		loop(length(MenuSounds)){
			LoadSE(GPSD~"se\"~MenuSounds[k]~".wav");
			k++;
		}
	}else{
		loop(length(GameSounds)){
			LoadSE(GPSD~"se\"~GameSounds[k]~".wav");
			k++;
		}
	}
}
sub DeleteSounds{
	let k=0;
	if(soundtypeloaded==0){
		loop(length(MenuSounds)){
			DeleteSE(GPSD~"se\"~MenuSounds[k]~".wav");
			k++;
		}
	}else{
		loop(length(GameSounds)){
			DeleteSE(GPSD~"se\"~GameSounds[k]~".wav");
			k++;
		}
	}
}