#TouhouDanmakufu
#Title["'Gassing Wall'"[Lunatic]]
#Text[The bullets come through the walls! How amazing ! Anyway,Please dodge carefully....if you don't want to die.]
#Image[.\img\spellcard0103.jpg]
#PlayLevel[Lunatic]
#ScriptVersion[2]

script_enemy_main
{
#include_function ".\system\Effects.txt";
#include_function ".\cutin.txt";
#include_function ".\MediEffect.txt";
#include_function ".\draweverything.txt";
let CSD = GetCurrentScriptDirectory;
let frame = 0;
let angle = 0;
let r = 0;
let switch = 1;
let cx = GetCenterX();
SetCommonData("back",1);
@Initialize
{
SetLife(800);
SetDamageRate(20,10);
SetTimer(60);
mainTask;
MediStart;
SetMovePosition03(GetCenterX, 120, 10, 4);
MagicCircle(false);
Aura;
}

//---------------------------------------------------------------

@MainLoop 
{

SetCollisionA(GetX, GetY, 32);
SetCollisionB(GetX, GetY, 16);
SetGraphicScale(1.2,1.2);
frame++;

yield;

}

//---------------------------------------------------------------

@DrawLoop
{
	drawall;
}
//---------------------------------------------------------------

@BackGround
{
	draw2;
}	

//---------------------------------------------------------------

@Finalize
{
DeleteGraphic(ImgBoss);
}

// main task
task mainTask{
	checkmove;
	wait(60);
	Border();
	drawcc(GetX,GetY+120,0,0);
	PlaySE(GetCurrentScriptDirectory~"cardcall.wav");
	SetScore(500000);
	cutin("KANAKO", "'Gassing Wall'", Cut, 0, 0, 205, 410);
	spellcardattack;
	wait(90);
	fire;
}

task fire{
	loop(2){
	r = 100;
	ascent(n in 0..40){
	PlaySE(CSD~"sound\shot6.wav");
	Bullet(GetX+r*cos(angle), GetY+r*sin(angle), 2.5, n*13*switch, 207, 20,0);
	Bullet(GetX+r*cos(angle+180), GetY+r*sin(angle+180), 2.5, n*13*switch+180, 207, 20,0);
	r -= 5;
	angle += 7*switch;
	wait(2);
	}
	switch = -switch;
	SetMovePositionRandom01(rand(20,50),0,2,GetClipMinX+100,rand(150,160),GetClipMaxX-100,rand(100,150));
	checkmove;
	wait(60);
	}
	wait(90);
	fire2;
	}

task fire2{
	r = 17;
	angle = 0;
	Concentration01(120);
	PlaySE(CSD~"sound\Charge.wav");
	wait(120);
	ascent(n in 0..10){
	PlaySE(CSD~"sound\shot4.wav");
	ascent(a in 0..6){
	CreateShot01(GetX+r*cos(angle+180),GetY+r*sin(angle+180),1+a/3,SetShotDirectionType(PLAYER),43,10);
	CreateShot01(GetX+r*cos(-angle),GetY+r*sin(-angle),1+a/3,SetShotDirectionType(PLAYER),43,10);
	}
	SetShotDirectionType(ABSOLUTE);
	angle += 20;
	r += 17;
	wait(5);
	}
	/////////////////////
	ascent(n in 0..10){
	PlaySE(CSD~"sound\shot4.wav");
	ascent(a in 0..6){
	CreateShot01(GetX+r*cos(angle+180),GetY+r*sin(angle+180),1+a/3,SetShotDirectionType(PLAYER),43,10);
	CreateShot01(GetX+r*cos(-angle),GetY+r*sin(-angle),1+a/3,SetShotDirectionType(PLAYER),43,10);
	}
	SetShotDirectionType(ABSOLUTE);
	angle += 20;
	r -= 17;
	wait(5);
	}
	wait(60);
	fire;
	}

task Bullet(x, y, v, dir, graphic, delay,check) 
	{
    	 let obj = Obj_Create(OBJ_SHOT);
	 let c = 0;
    	 Obj_SetPosition   (obj, x, y);
    	 Obj_SetSpeed      (obj, v);
    	 Obj_SetAngle      (obj, dir);
    	 ObjShot_SetGraphic(obj, graphic);
    	 ObjShot_SetDelay  (obj, delay);
	 task bulletp{
	 let x = Obj_GetX(obj);
	  let y = Obj_GetY(obj);
	  let ao = Obj_GetAngle(obj);
	 loop(20){
		CreateShotA(0,x,y,30);
		SetShotDataA(0,0,0,0,0,0,0,58);
		SetShotKillTime(0,0);
		FireShot(0);
		wait(5);
		}
		PlaySE(CSD~"sound\shot1.wav");
		ascent(i in 0..9){
		CreateShotA(0,x,y,20);
		SetShotDataA(0,0,4,i*40,0,-0.1,0.8,58);
		FireShot(0);
		}
	}
		 while(! Obj_BeDeleted(obj)) 
		{
		if(Obj_GetX(obj)<GetClipMinX || Obj_GetX(obj)>GetClipMaxX){
		PlaySE(CSD~"sound\shot5.wav");
		bulletp;
		Obj_Delete(obj);
		}
		 yield;
		}
	}

	function Obj_GetAngleToPlayer(obj) {
	return atan2(GetPlayerY - Obj_GetY(obj), GetPlayerX - Obj_GetX(obj));
	}

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