#TouhouDanmakufu[Single]
#Title[Third Non-Spellcard]
#Text[Third Non-Spellcard]
#BGM[.\Feast.mp3]
#PlayLevel[Normal]
#Player[FREE]
#ScriptVersion[2]


script_enemy_main{
    
    let frame = 0;
    let CSD = GetCurrentScriptDirectory;
    let imgBoss = CSD ~ "img\Koakuma.png";
    let shot = GetCurrentScriptDirectory ~ ".\sounds\se_tan00.wav";
    let lazer = GetCurrentScriptDirectory ~ ".\sounds\se_lazer01.wav";
    let charge = GetCurrentScriptDirectory ~ ".\sounds\se_ch02.wav";
    let bg = CSD ~ "img\BG.png";	

  @Initialize {
        SetLife(4000);
	SetTimer(60);
        SetMovePosition01(GetX,200,5);
	mainTask;
	LoadGraphic(imgBoss);
	LoadGraphic(bg);
	LoadSE(shot);
	LoadSE(lazer);
	LoadSE(charge);
    }

    @MainLoop {
        
	SetCollisionA(GetX,GetY,32);
	SetCollisionB(GetX,GetY,32);
	yield;
}
	 
    @DrawLoop { 

	SetTexture(imgBoss);
	SetRenderState(ALPHA);
	SetAlpha(255);
	SetGraphicScale(1,1);
	SetGraphicAngle(0,0,0);
	SetGraphicRect(0,0,132,132);
	DrawGraphic(GetX,GetY);   
	
	}

    @BackGround{ 

	SetTexture(bg);
	SetRenderState(ALPHA);
	SetAlpha(255);
	SetGraphicRect(0,0,512,512);
	SetGraphicScale(1,1);
	SetGraphicAngle(0,0,0);
	DrawGraphic(GetCenterX,GetCenterY);   
    }

    @Finalize {
	DeleteGraphic(imgBoss);
	DeleteGraphic(bg);
	DeleteSE(lazer);
	DeleteSE(shot);
	DeleteSE(charge);
    }
	
	task mainTask{
		wait(120);
		yield;
		fire;
		movement;
    }

	task movement{
		loop{	PlaySE(charge);
			SetMovePosition01(GetCenterX-40,50,3);
			wait(240);
			SetMovePosition01(GetCenterX+40,50,3);
			wait(240);
			yield;
		}
}

	task fire{
		let x = 0;
		let dir = 0;
		loop{
			while(x<36){
			PlaySE(shot);
			CreateShotA(1,GetEnemyX+10*cos(dir),GetEnemyY+10*sin(dir),50);
			SetShotDataA(1,0,0,dir,0,0,0,RED05);
			SetShotDataA(1,1,2,dir,0.0,0,0,RED31);

			dir+=360/36;

			CreateShotA(2,GetEnemyX+20*cos(dir),GetEnemyY+20*sin(dir),50);
			SetShotDataA(2,0,0,dir,0,0,0,BLUE05);
			SetShotDataA(2,1,3,dir,0.0,0,0,BLUE31);

			FireShot(1);
			FireShot(2);
			dir+=360/16;
			x++;
		}


		x = 0;
		dir = 0;
		wait(20);
			PlaySE(lazer);
			CreateLaser01(GetEnemyX,GetEnemyY,6,GetAngleToPlayer+30,100,10,RED01,1);
			wait(1);
			CreateLaser01(GetEnemyX,GetEnemyY,5,GetAngleToPlayer,100,10,BLUE01,1);
			wait(20);
			CreateLaser01(GetEnemyX,GetEnemyY,6,GetAngleToPlayer-30,100,10,RED01,1);
			wait(1);
	
			yield;

		}
}

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



	
}