#TouhouDanmakufu
#Title["Spider of Miasma"]
#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 anglemov=0;
    let drawtype=0;
    let cutin=GetCurrentScriptDirectory~"img\face01ct.png";
	#include_function ".\yamameanim.txt";
task lasers{
    let angle=GetAngleToPlayer;
    drawtype=1;
    ascent(i in 0..8){
    laser(GetX, GetY, angle+i*45, 2, 100, 150);
    }
    loop(200){yield;}
    drawtype=0;
    loop(100){yield;}
    anglemov+=30;
    lasers;
}
task laser(x, y, angle, type, time, length){
    PlaySE(GetCurrentScriptDirectory~"sound\Laser1.wav");
    let counter=0;
    let obj=Obj_Create(OBJ_LASER);
    Obj_SetPosition(obj, x, y);
    Obj_SetAngle(obj, angle);
    ObjShot_SetGraphic(obj, 236);
    ObjShot_SetDelay(obj, 30);
    ObjLaser_SetLength(obj, length);
    ObjLaser_SetWidth(obj, 5);
    ObjLaser_SetSource(obj, false);
    while(Obj_BeDeleted(obj)==false){
        yield;
        counter++;
        if(counter==20 && type>0){
            laser(ObjLaser_GetEndX(obj), ObjLaser_GetEndY(obj), Obj_GetAngle(obj)+210, type-1, time-20, 125);
            laser(ObjLaser_GetEndX(obj), ObjLaser_GetEndY(obj), Obj_GetAngle(obj)+150, type-1, time-20, 125);
        }
        if(counter==time){
            wave(ObjLaser_GetEndX(obj), ObjLaser_GetEndY(obj), type, angle);
        }
        if(counter==time+100){Obj_Delete(obj); PlaySE(GetCurrentScriptDirectory~"sound\BulletWave.wav");}
    }
}
task wave(x, y, type, angle){
    ascent(i in 0..8){
        ascent(j in 1..3){
            PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
            CreateShotA(1, x+(5+i*2+j)*cos(angle+i*45+j*22.5+anglemov), y+(5+i*2+j)*sin(angle+i*45+j*22.5+anglemov), 10);
            SetShotDataA(1, 0, 0, angle+i*45+anglemov, 0, 0, 0, 77+type*2);
            SetShotDataA(1, 80-j-i*2, NULL, angle+i*45+180+j*180+anglemov, 0, 0.01, 2, 77+type*2);
            FireShot(1);
            yield;
        }
    }
}
	@Initialize
	{
		SetInvincibility(200);
		SetLife(500);
		SetDamageRate(10,10);
        LoadGraphic(cutin);

		SetMovePosition02(GetCenterX,120,20);
		Concentration01(150);
		CutIn(YOUMU, "''Spider of Miasma''",cutin,0,0,256,512);
		LoadUserShotData(GetCurrentScriptDirectory~"supershot.txt");

		SetCommonData("ONSPELL", "TRUE");
		spellbonus(10000000);
		timer;
		SetCommonData("timercount", 60*120);
        PlayMusic(GetCurrentScriptDirectory~"bgm.mp3");
        lastspell;
	}
	
	@MainLoop
	{
		SetCollisionA(GetX(),GetY(),24);
		SetCollisionB(GetX(),GetY(),24);
		frame++;
		yield;
        if(frame==100){lasers;}
}
	
	@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;
        if(drawtype==0){anim2;}else{animation;}
	}
}