#TouhouDanmakufu
#Title["Demon Bucket-Monster"]
#Text[]
#Image[]
#BackGround[Default]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main
{
	#include_function ".\spellcard.txt";
	let type=0;
	let frame=0;
	let move_count=0;
    let cutin=GetCurrentScriptDirectory~"img\face01mct.png";
	#include_function ".\kisumeanim.txt";
task lasers{
    SetMovePosition02(GetPlayerX+rand(-50, 50), GetClipMinY+rand(75, 120), 30);
    loop(30){yield;}
    PlaySE(GetCurrentScriptDirectory~"sound\Laser1.wav");
    ascent(i in -2..3){
    laser(GetX, GetY, 90+i*30);
    }
    loop(20){yield;}
    lasers;
}
task laser(x, y, angle){
    let length=0;
    let counter=0;
    let obj=Obj_Create(OBJ_LASER);
    Obj_SetPosition(obj, x, y);
    Obj_SetAngle(obj, angle);
    ObjShot_SetGraphic(obj, 236);
    ObjLaser_SetLength(obj, length);
    ObjLaser_SetWidth(obj, 60);
    ObjLaser_SetSource(obj, false);
    while(Obj_BeDeleted(obj)==false){
        yield;
        if(length<125){length+=5;}else{Obj_SetPosition(obj, Obj_GetX(obj)+5*cos(angle), Obj_GetY(obj)+5*sin(angle));}
        ObjLaser_SetLength(obj, length);
        counter++;
        if(counter==20 && counter<35){ascent(i in -1..2){shot(Obj_GetX(obj)+rand(-60, 60)*cos(rand(0, 359)), Obj_GetY(obj)+rand(-60, 60)*sin(rand(0, 359)));}}
    }
}
task shot(x, y){
    CreateShot02(x, y, 0, rand(85, 95), 0.05, 3, 204, rand_int(5, 50));
    loop(30){yield;}
    PlaySE(GetCurrentScriptDirectory~"sound\BulletWave.wav");
}
task shots{
    let angle=rand(0, 359);
    loop{
        PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
        ascent(i in 0..5){
            ascent(j in 1..3){
                CreateShot01(GetX, GetY, 2+j, angle+i*72, 1+j, j*5);
            }
        loop(2){yield;}
        }
        angle+=rand(27, 37);
    }
}
	@Initialize
	{
		SetInvincibility(200);
		SetLife(500);
		SetDamageRate(10,10);
        LoadGraphic(cutin);

		SetMovePosition02(GetCenterX,120,20);
		Concentration01(150);
		CutIn(YOUMU, "''Demon Bucket-Monster''",cutin,0,0,256,512);
		LoadUserShotData(GetCurrentScriptDirectory~"supershot.txt");

		SetCommonData("ONSPELL", "TRUE");
		spellbonus(10000000);
		timer;
		SetCommonData("timercount", 60*120);
        lastspell;
        PlayMusic(GetCurrentScriptDirectory~"bgm.mp3");
	}
	
	@MainLoop
	{
		SetCollisionA(GetX(),GetY(),24);
		SetCollisionB(GetX(),GetY(),24);
		frame++;
		yield;
        if(frame==100){lasers;}
        if(frame==150){shots;}
}
	
	@Finalize
	{
		AddScore(spellbonustotal);
		if(spellbonustotal>0)
		{
		PlaySE(GetCurrentScriptDirectory~"sound\se_cardget.wav");
		loop(50)
		{
			CreateItem(ITEM_SCORE,GetX+rand(-100,100),GetY+rand(20,100));
		}
		}else{
		loop(15)
		{
			CreateItem(ITEM_SCORE,GetX+rand(-100,100),GetY+rand(20,100));
		}
		}
		SetCommonData("ONSPELL", "FALSE");
        if(spellbonustotal==0){SetCommonData("REDO", "TRUE");}
	}
	
	@DrawLoop
	{
        bg;
        anim2;
	}
}