#東方弾幕風[Single]
#ScriptVersion[3]
#Title["SP3"]
#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);
	
	EnemyMarker(objBoss);
	HitSound(objBoss, 50, 450);
	RenderCharacter(objBoss);
	DamageReduction(objBoss, 320);
	
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/2-56, 10, 4);
	
	if(GetCommonData("IsStage", false)==false){
	LoadAssets;}
	
	Main;
	end;
} 

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(5000);
     	}
	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 { 
	let path = GetCurrentScriptDirectory ~ "./default_system/img/Ingame/cutin.png";
	SpellCard(210, "", [255, 60, 60], path, path, 20, 0.75, "Okina");
	
	Lasers;
	Potato;
}

task Lasers{
let a = 60;
loop{
let obj = CreateCurveLaserA1(-200, rand(0,100), 10, rand(0, 0-22), 10, 15, LASER_C_RED, 10);
ObjMove_SetAngularVelocity(obj, 0.5);
Del(obj);
ObjCrLaser_SetTipDecrement(obj, 0);
let obj2 = CreateCurveLaserA1(GetStgFrameWidth+200, rand(0,100), 10, rand(180, 180+22), 10, 15, LASER_C_RED, 10);
Del(obj2);
ObjCrLaser_SetTipDecrement(obj2, 0);
ObjMove_SetAngularVelocity(obj2, -0.5);

Shoot(obj);
Shoot(obj2);

if(a>20){a-=2;}
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/slash.wav", 90, 20);
wait(a);
}

	task Del(obj){
	ObjShot_SetAutoDelete(obj, 0);
	while(IsObjInsideBox(obj)==false){yield;}
	ObjShot_SetAutoDelete(obj, 1);
	}
	
	task Shoot(obj){
	while(!Obj_IsDeleted(obj)){
		ascent(i in 0..2){
		FireShotA1(GetX(obj), GetY(obj), 2, ObjMove_GetAngle(obj)+90+i*180, SCALE_RED, 10);
		}
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/smbullet.wav", 90, 0);
	wait(6);
	}
	}
}

task Potato{
loop{
let ang = GetAngleToPlayer(objBoss);
ascent(j in 0..32){
	ascent(k in 0..8){
	FireShotA1(BossX, BossY, 2+j/2, ang+k*360/8, KUNAI_ORANGE, 10);
	}
PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/spirit.wav", 70, 0);
	wait(3);
}
wait(180);
}
}


task end{
    while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){yield;}
    Obj_Delete(objBoss);
    DeleteShotAll(TYPE_ALL, TYPE_ITEM);
    SetAutoDeleteObject(true);
    CloseScript(GetOwnScriptID());
} 


