#TouhouDanmakufu
#Title[Contest spell 3]
#Text[reimuuuuuu]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main{

        let CSD = GetCurrentScriptDirectory;
	#include_function ".\AnimationLib.dnh";
	let spritereimu = CSD ~ ".\Reimu2.png";
	let ShotData = CSD ~ "lib\supershot.txt";
        let imgBoss = CSD ~ "img\Sprite.png";
        let cut = CSD ~ "img\Swr_reimu.jpg";
        let bg = CSD ~ "img\raging_inferno.jpg";
        let bgm = CSD ~ "bmg\09 - Maiden's Capriccio ~ Dream Battle";
	let shot3 = CSD ~"SE\shot3.wav";
	let Laser3 = CSD ~"SE\Laser3.wav";
	let frame = 0;	
	let angle = 0;
	let angle1 = 360/36;
	let timer1 = 0;
	let speed = 1;
	let angle2 = 360/5;
	let angle3 = 360/7;
	let angle4 = 360/12;
	
	@Initialize{
		
		SetLife(300);
		SetDamageRate(10, 10);
                SetTimer(40);
		SetInvincibility(240);
                SetScore(200000);
		SetMovePosition01(GetCenterX,120,5);
		SetEnemyMarker(true);
        	SetDurableSpellCard;
		Concentration01(120);
		MagicCircle(true);
		SetEffectForZeroLife(180, 100, 1);
                LoadGraphic(imgBoss);
                LoadGraphic(cut);
                LoadGraphic(bg);
                LoadMusic(bgm);
                PlayMusic(bgm);
		LoadSE(shot3);
		LoadSE(Laser3);
		LoadUserShotData(ShotData);
		LoadGraphic(spritereimu);
CutIn(YOUMU,"Holy Inquisition - Consumed by fire",cut,0,0,128,128);
		CreateAnimation("reimu", "idle", 4);
  SetAnimationFrame("reimu", "idle", 0, spritereimu, 10, 0, 0, 64, 76);
  SetAnimationFrame("reimu", "idle", 1, spritereimu, 10, 64, 0, 128, 76);
  SetAnimationFrame("reimu", "idle", 2, spritereimu, 10, 128, 0, 192, 76);
  SetAnimationFrame("reimu", "idle", 3, spritereimu, 10, 192, 0, 256, 76);

  CreateAnimation("reimu", "move left", 4);
  SetAnimationFrame("reimu", "move left", 0, spritereimu, 6, 0, 78, 64, 152);
  SetAnimationFrame("reimu", "move left", 1, spritereimu, 6, 64, 78, 128, 151);
  SetAnimationFrame("reimu", "move left", 2, spritereimu, 6, 128, 78, 192, 150);
  SetAnimationFrame("reimu", "move left", 3, spritereimu, 6, 192, 78, 256, 148);
  
  CreateAnimation("reimu", "shoot", 4);
  SetAnimationFrame("reimu", "shoot", 0, spritereimu, 12, 0, 158, 64, 250);
  SetAnimationFrame("reimu", "shoot", 1, spritereimu, 12, 64, 158, 128, 250);
  SetAnimationFrame("reimu", "shoot", 2, spritereimu, 12, 128, 158, 192, 250);
  SetAnimationFrame("reimu", "shoot", 3, spritereimu, 12, 192, 158, 256, 250);
  
  Animate("reimu", "idle", true);
                
 		Maintask;
		
	}

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

	@DrawLoop{
		let float = 0;
                
                SetRenderState(ALPHA);
                SetAlpha(255);
                SetGraphicRect(0,0,110,110);
                SetGraphicScale(1,1);
                SetGraphicAngle(0,0,0);
                DrawGraphic(GetX,GetY);
		SetTexture(spritereimu);
  SetRenderState(ALPHA);
  SetAlpha(255);
  SetGraphicScale(1,1);
  SetGraphicAngle(0,0,0);
   if(GetSpeedX<0){
   SetGraphicAngle(180,0,0);
   }
  
   DrawAnimatedSprite("reimu",GetX,GetY+5*sin(float));

  float+=7;
	}

	@BackGround{

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

	}

	@Finalize{
	        
                DeleteGraphic(imgBoss);
                DeleteGraphic(cut);
                DeleteGraphic(bg);

	}

	task Maintask {
		SetColor(255,255,255);
		Concentration01(120);
		PlaySE(CSD ~ "SE\se_ch00.wav");
		wait(120);
		attack;
		attack2;
		wait(60);
		attack3;
		countdown1;
	}

task attack{
	loop{
		fire;
		wait(60);
		fire2;
		}
}

task attack3{
	loop{
	fire3;
	wait(120);
	}
}

task attack2{
           loop{
		fire2;
		wait(3);
		}
		}
function fire{
	CreateShotA(1, GetX, GetY, 10);
	SetShotDataA(1, 0, 3.5, 180, 0, 0, 0, RED03);
	SetShotDataA(1, 60, 3.5, 90, -1.9, 0.5, 3, RED03);
	SetShotDataA(1, 150, 3.5, -45, 0, 0.5, 3, RED03);
	ascent(i in 1..450){
    		CreateShotA(2, 0, 0, 30);
    		SetShotDataA_XY(2, 10, rand(-3, 2), rand(-1, -4), 0, +0.05, 0, 2, 237);
    		AddShot(i*8, 1, 2, 0);}
	CreateShotA(3, GetX, GetY, 10);
	SetShotDataA(3, 0, 3.5, 0, 0, 0, 0, RED03);
	SetShotDataA(3, 60, 3.5, 90, +1.9, 0.5, 3, RED03);
	SetShotDataA(3, 150, 3.5, -135, 0, 0.5, 3, RED03);
	ascent(i in 1..450){
    		CreateShotA(4, 0, 0, 30);
    		SetShotDataA_XY(4, 10, rand(-3, 2), rand(-1, -4), 0, +0.05, 0, 2, 237);
    		AddShot(i*8, 3, 4, 0);}
		CreateShotA(5, GetX, GetY, 10);
		SetShotDataA(5, 0, 3.5, 135, 0, 0, 3.5, BLUE03);
		ascent(i in 1..450){
    		CreateShotA(6, 0, 0, 30);
    		SetShotDataA_XY(6, 10, rand(-3, 2), rand(-1, -4), 0, +0.05, 0, 3, 238);
    		AddShot(i*8, 5, 6, 0);}
		CreateShotA(7, GetX, GetY, 10);
		SetShotDataA(7, 0, 3.5, 45, 0, 0, 3.5, BLUE03);
		ascent(i in 1..450){
    		CreateShotA(8, 0, 0, 30);
    		SetShotDataA_XY(8, 10, rand(-3, 2), rand(-1, -4), 0, +0.05, 0, 3, 238);
    		AddShot(i*8, 7, 8, 0);}
PlaySE(CSD ~ "SE\se_tan00.wav");
FireShot(1);
FireShot(3);
FireShot(5);
FireShot(7);
wait(120);
}

function fire2{
		
		CreateShot01(GetClipMaxX-rand(0,512),GetClipMinY,rand(2,3),rand(0,180),83,10);
		PlaySE(CSD ~ "SE\se_tan00.wav");
		}

function fire3{
	loop(2){PlaySE(CSD ~ "SE\se_tan00.wav");
		Bullet(GetClipMinX+5,GetClipMinY,3,90,231,10,0);
		wait(180);
		Bullet(GetClipMaxX-5,GetClipMinY,3,90,231,10,1);
	}
}

task countdown1{
 loop{
  if(GetTimer<11){
   wait(60);
   PlaySE(CSD ~ "SE\se_timeout.wav");
    }
  yield;}
 }
task Bullet(x,y,v,dir,graphic,delay,arg){
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, x, y);
	Obj_SetSpeed(obj, v);
	Obj_SetAngle(obj, dir);
	ObjShot_SetGraphic(obj, graphic);
	ObjShot_SetDelay(obj, delay);
		wait(30);
		
		loop(20){let z = Obj_GetX(obj) + rand(-20,20);
		let zx = Obj_GetY(obj) + rand(-20,20);
		CreateShot01(z,zx,2,atan2(GetPlayerY-zx,GetPlayerX-z),95,10);
		wait(3);}
	while(!Obj_BeDeleted(obj)){
		yield;
		}
}


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

	

	
		
}