task TEnemyHitboxStart(obj,n){
	ObjEnemy_SetDamageRate(obj,0,0);
	loop(n){yield;}
	ObjEnemy_SetDamageRate(obj,100,100);
	while(ObjEnemy_GetInfo(obj,INFO_LIFE)>0){
		yield;
	}
}

function angleToPlayer{
	let angle=atan2(GetPlayerY-GetEnemyY,GetPlayerX-GetEnemyX);
	return angle;
}

let objPlayer;
objPlayer=GetPlayerObjectID();

function getAtanAngle(obj,obj2){
	let angle=atan2(ObjMove_GetY(obj2)-ObjMove_GetY(obj),ObjMove_GetX(obj2)-ObjMove_GetX(obj));
	return angle;
}

function GetEnemyX{
	return ObjMove_GetX(objBoss);
}

function GetEnemyY{
	return ObjMove_GetY(objBoss);
}

function wait(n){loop(n){yield;}}

task PlayDelaySE(se,delay){
        loop(delay){yield;}
        PlaySE(se);
}

function GetClipMinX{
	return 0;
}

function GetClipMinY{
	return 0;
}

function GetClipMaxX{
	return GetStgFrameWidth;
}

function GetClipMaxY{
	return GetStgFrameHeight;
}

function ShootShape(spawnX, spawnY, v, angle, num, bside, graphic, delay) {
	ascent(i in 0..num) {
		let sx = spawnX+cos(angle+i*360/num); let sy = spawnY+sin(angle+i*360/num); let sxN = spawnX+cos(angle+(i+1)*360/num); let syN = spawnY+sin(angle+(i+1)*360/num);
		CreateShotA1(spawnX, spawnY, v*(((sx-spawnX)^2+(sy-spawnY)^2)^0.5), atan2(sy-spawnY,sx-spawnX), graphic, delay);
		ascent(j in 0..bside) {
			let toAngle = atan2(syN-sy,sxN-sx); let toDist = (((sxN-sx)^2+(syN-sy)^2)^0.5); let sx2 = sx+toDist/bside*j*cos(toAngle); let sy2 = sy+toDist/bside*j*sin(toAngle);
			CreateShotA1(spawnX, spawnY, v*(((sx2-spawnX)^2+(sy2-spawnY)^2)^0.5), atan2(sy2-spawnY,sx2-spawnX), graphic, delay);
		}
	}
}

task SetBulletTrailDelay(obj,time,delay,c,c2,alp,fade,shrink){
	let img=GCSD~"img/trail.png";
	loop(delay){ yield; }
	TObj;
	task TObj{
		while(!Obj_IsDeleted(obj)){
			let d=ObjPrim_Create(OBJ_SPRITE_2D);
			ObjRender_SetBlendType(d,BLEND_ADD_RGB);
			ObjPrim_SetTexture(d,img);
			ObjSprite2D_SetSourceRect(d,0,0,32,32);
			ObjSprite2D_SetDestCenter(d);
			ObjRender_SetPosition(d,ObjMove_GetX(obj),ObjMove_GetY(obj),0);
			SetColor(d,c,c2);
			if(fade!=true){
				ObjRender_SetAlpha(d,alp);
				}
			TAction(d);
			yield;
			}
		}
	task TAction(o){
		let scale=1;
		let s=1;
		let alpha=255;
		let a=1;
		loop(time){
			if(fade==true){
				ObjRender_SetAlpha(o,alpha);
				alpha-=(a/time);
				}
			if(shrink==true){
			ObjRender_SetScaleXYZ(o,scale,scale,0);
			scale-=(s/time);
				}
			yield;
			}
		Obj_Delete(o);
		}
	}

let sound=[];
function TLoadSounds{
//////////////////////////////0
	let se_charge=ObjSound_Create;
	ObjSound_Load(se_charge,GCSD~"se/se_ch02.wav");
	ObjSound_SetSoundDivision(se_charge,SOUND_SE);
	sound=sound~[se_charge];

//////////////////////////////1
	let se_bossdeath=ObjSound_Create;
	ObjSound_Load(se_bossdeath,GCSD~"se/se_death.wav");
	ObjSound_SetSoundDivision(se_bossdeath,SOUND_SE);
	sound=sound~[se_bossdeath];
	
//////////////////////////////2
	let se_kira01=ObjSound_Create;
	ObjSound_Load(se_kira01,GCSD~"se/se_kira00.wav");
	ObjSound_SetSoundDivision(se_kira01,SOUND_SE);
	sound=sound~[se_kira01];

//////////////////////////////3
	let se_kira02=ObjSound_Create;
	ObjSound_Load(se_kira02,GCSD~"se/se_kira01.wav");
	ObjSound_SetSoundDivision(se_kira02,SOUND_SE);
	sound=sound~[se_kira02];
	
//////////////////////////////4
	let se_kira03=ObjSound_Create;
	ObjSound_Load(se_kira03,GCSD~"se/se_kira02.wav");
	ObjSound_SetSoundDivision(se_kira03,SOUND_SE);
	sound=sound~[se_kira03];

//////////////////////////////5
	let se_laser01=ObjSound_Create;
	ObjSound_Load(se_laser01,GCSD~"se/se_lazer00.wav");
	ObjSound_SetSoundDivision(se_laser01,SOUND_SE);
	sound=sound~[se_laser01];

//////////////////////////////6
	let se_laser02=ObjSound_Create;
	ObjSound_Load(se_laser02,GCSD~"se/se_lazer01.wav");
	ObjSound_SetSoundDivision(se_laser02,SOUND_SE);
	sound=sound~[se_laser02];

//////////////////////////////7
	let se_spellstart=ObjSound_Create;
	ObjSound_Load(se_spellstart,GCSD~"se/se_spell.wav");
	ObjSound_SetSoundDivision(se_spellstart,SOUND_SE);
	sound=sound~[se_spellstart];

//////////////////////////////8
	let se_shot01=ObjSound_Create;
	ObjSound_Load(se_shot01,GCSD~"se/se_tan00.wav");
	ObjSound_SetSoundDivision(se_shot01,SOUND_SE);
	sound=sound~[se_shot01];

//////////////////////////////9
	let se_shot02=ObjSound_Create;
	ObjSound_Load(se_shot02,GCSD~"se/se_tan01.wav");
	ObjSound_SetSoundDivision(se_shot02,SOUND_SE);
	sound=sound~[se_shot02];

//////////////////////////////10
	let se_shot03=ObjSound_Create;
	ObjSound_Load(se_shot03,GCSD~"se/se_tan02.wav");
	ObjSound_SetSoundDivision(se_shot03,SOUND_SE);
	sound=sound~[se_shot03];

//////////////////////////////11
	let se_clap=ObjSound_Create;
	ObjSound_Load(se_clap,GCSD~"se/se_nice.wav");
	ObjSound_SetSoundDivision(se_clap,SOUND_SE);
	sound=sound~[se_clap];
}

task PlaySound(se,volume,w){
	loop(w){ yield; }
	if(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0){
		ObjSound_SetVolumeRate(sound[se],volume);
		ObjSound_Play(sound[se]);
	}
}

task PlaySoundNR(se,volume,w){
	loop(w){ yield; }
	ObjSound_SetVolumeRate(sound[se],volume);
	ObjSound_Play(sound[se]);
}