#東方弾幕風[Single]
#ScriptVersion[3]
#Title["SP2"]
#Text["Blep"]
#System["./default_system/Default_System.txt"]
#include "./default_system/MS_Index.txt"

let objBoss;
let BossX;
let BossY;

@Initialize {
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	
	HitSound(objBoss, 50, 450);
	RenderCharacter(objBoss);
	DamageReduction(objBoss, 120);
	EnemyMarker(objBoss);
	
	
	SetCommonData("ForceLifebar", 0);
	
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/2-100, 5, 4);
	
	if(GetCommonData("IsStage", false)==false){
	LoadAssets;}
	
	Main;
	end;
} 

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(4000);
     	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(45);
	}
	/*case(EV_REQUEST_SPELL_SCORE){
		SetScriptResult(1000000);
	}*/
} 

@MainLoop {
	BossX = ObjMove_GetX(objBoss);
	BossY = ObjMove_GetY(objBoss);
	ObjEnemy_SetIntersectionCircleToShot(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),21);
	ObjEnemy_SetIntersectionCircleToPlayer(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),24);
	yield;
} 

@Finalize {
} 

task Main { 
wait(120);

let path = GetCurrentScriptDirectory ~ "./default_system/img/Ingame/mam1.png";
let path2 = GetCurrentScriptDirectory ~ "./default_system/img/Ingame/mam2.png";
SpellCard(160, "New Duel &quot;Feline Danmaku Transformation&quot;", [255, 60, 60], path, path2, 5, 150, 0.4, "Mamizou");

let a = 0;
	loop{
	let hp = ObjEnemy_GetInfo(objBoss, INFO_LIFE)/120;
	let obj = Leaf(GetPlayerX, -10, 3, 90, 0.5, objBoss, 0);
	//ObjShot_SetDeleteFrame(obj, 260-hp*5);
	Cat(obj, a);
	PlaySound(GetCurrentScriptDirectory ~ "default_system/se/smbullet.wav", 65, 0);
	wait(15+hp);
	a++;
	let obj2 = Leaf(GetPlayerX, -10, 3, 90, 0.5, objBoss, 0);
	//ObjShot_SetDeleteFrame(obj2, 260-hp*5);
	Cat2(obj2, a);
	PlaySound(GetCurrentScriptDirectory ~ "default_system/se/smbullet.wav", 65, 0);
	wait(15+hp);
	a++;
	}
}

task Cat(obj, a){
let X = 0;
let Y = 0;
let angle = 0;
let wai = 0;
while(!Obj_IsDeleted(obj)){
 angle = ObjMove_GetAngle(obj);
 X = GetX(obj);
 Y = GetY(obj);
 wai = 50+a*20;
 if(wai > GetStageDown){wai = GetStageDown}
  if(Y > wai){Obj_Delete(obj);}
yield;
}
PlaySound(GetCurrentScriptDirectory ~ "default_system/se/spirit.wav", 65, 0);
PlaySound(GetCurrentScriptDirectory ~ "default_system/se/barrage2.wav", 65, 0);
MamiSmoke(X, Y, rand(0, 1), rand(0,360), 0.35, 0, 10, 0);
	if(Y < GetPlayerY){
		ascent(i in 0..4){
		let shot = CreateShotB2(X, Y, 0.5*i, 0, 0, 0.02, 10, 10, 2006, 1);
		ObjShot_SetSpellResist(shot, true);
		ObjRender_SetAngleZ(shot, -90);
		}
	}
	else{
		ascent(i in 0..4){
		let shot = CreateShotB2(X, Y, 0.5*i, 0, 0, -0.02, 10, -10, 2007, 1);
		ObjShot_SetSpellResist(shot, true);
		ObjRender_SetAngleZ(shot, 90);
		}
	}
}


task Cat2(obj, a){
let X = 0;
let Y = 0;
let angle = 0;
let wai = 0;
while(!Obj_IsDeleted(obj)){
 angle = ObjMove_GetAngle(obj);
 X = GetX(obj);
 Y = GetY(obj);
 wai = 50+a*20;
 if(wai > GetStageDown){wai = GetStageDown}
  if(Y > wai){Obj_Delete(obj);}
yield;
}
PlaySound(GetCurrentScriptDirectory ~ "default_system/se/spirit.wav", 65, 0);
PlaySound(GetCurrentScriptDirectory ~ "default_system/se/barrage2.wav", 65, 0);
MamiSmoke(X, Y, rand(0, 1), rand(0,360), 0.35, 0, 10, 0);
	if(Y < GetPlayerY){
		ascent(i in 0..4){
		let shot = CreateShotB2(X, Y, -0.5*i, 0, 0, 0.02, 10, 10, 2007, 1);
		ObjShot_SetSpellResist(shot, true);
		ObjRender_SetAngleZ(shot, 90);
		}
	}
	else{
		ascent(i in 0..4){
		let shot = CreateShotB2(X, Y, -0.5*i, 0, 0, -0.02, 10, -10, 2006, 1);
		ObjShot_SetSpellResist(shot, true);
		ObjRender_SetAngleZ(shot, -90);
		}
	}
}

task end{
	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){yield;}
	SetCommonData("bossx", BossX);
	SetCommonData("bossy", BossY);
	SetCommonData("RipSpell", 1);
    Obj_Delete(objBoss);
    DeleteShotAll(TYPE_ALL, TYPE_ITEM);
    SetAutoDeleteObject(true);
    CloseScript(GetOwnScriptID());
	
} 


