#TouhouDanmakufu
#Title[Contest spell 4]
#Text[reimuuuuu]
#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\IMG_0517-520x520.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 = 150;
	let angle2 = -30;
	let angle3 = 210;
	let angle4 = 30;
	let angle5 = 210;
	let angle6 = -50;
	let angle7 = 230;
	let angle8 = -70;
	
	@Initialize{
		
		SetLife(900);
		SetDamageRate(10, 10);
                SetTimer(90);
		SetInvincibility(240);
                SetScore(200000);
		SetMovePosition01(GetCenterX,160,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," Exorcism - Imperishable Seal",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;
	}

	let float = 0;
	@DrawLoop{
		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+=5;
	}
	

	@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);
		aimed;
		attack;
		attack2;
		attack3;
		attack4;
		countdown1;
	}

task aimed{
	loop{
		aim;
		
		}
}

task attack{
	loop{
		fire;
		
		}
}

task attack2{
	loop{
		fire2;
		
		}
}

task attack3{
	loop{
		fire3;
		
		}
}

task attack4{
	loop{
		fire4;
		
		}
}

function aim{
		wait(180);
		SetColor(255,255,255);
		Concentration01(120);
		PlaySE(CSD ~ "SE\se_ch00.wav");
		wait(120);
		loop(45){
		PlaySE(CSD ~ "SE\se_tan00.wav");
		CreateShot01( GetEnemyX, GetEnemyY, 3 , GetAngleToPlayer , 102 , 10);
		CreateShot01( GetEnemyX, GetEnemyY, 3 , GetAngleToPlayer-30 , 102 , 10);
		CreateShot01( GetEnemyX, GetEnemyY, 3 , GetAngleToPlayer+30 , 102 , 10);
		wait(20);
		}
		wait(120);
		loop(35){PlaySE(CSD ~ "SE\se_tan00.wav");
		CreateShot01( GetEnemyX, GetEnemyY, 2 , GetAngleToPlayer-15 , 99 , 10);
		CreateShot01( GetEnemyX, GetEnemyY, 2 , GetAngleToPlayer+15 , 99 , 10);
		CreateShot01( GetEnemyX, GetEnemyY, 2 , GetAngleToPlayer-30 , 99 , 10);
		CreateShot01( GetEnemyX, GetEnemyY, 2 , GetAngleToPlayer+30 , 99 , 10);
		wait(15);
		}
		}

function fire{
		loop(15){PlaySE(CSD ~ "SE\se_tan00.wav");
	ascent( i in 3..9){
	CreateShot01( GetEnemyX, GetEnemyY, i , angle , 97 , 10);
	CreateShot01( GetEnemyX, GetEnemyY, i , angle2 , 97 , 10);
	CreateShot01( GetEnemyX, GetEnemyY, i , angle3 , 98 , 10);
	CreateShot01( GetEnemyX, GetEnemyY, i , angle4 , 98 , 10);
	CreateShot01( GetEnemyX, GetEnemyY, i/2 , 0 , 95 , 10);
	CreateShot01( GetEnemyX, GetEnemyY, i/2 , 180 , 95 , 10);
	
	}
	angle += 5;
	angle2 += 5;
	angle3 -= 5;
	angle4 -= 5;
	
	wait(7);
}
angle = 150;
angle2 = -30;
angle3 = 210;
angle4 = 30;

}

function fire2{PlaySE(CSD ~ "SE\se_tan00.wav");
		CreateShot01(GetClipMinX,GetClipMinY+rand(0,512),rand(1,2),0,98,10);
		CreateShot01(GetClipMaxX,GetClipMinY+rand(0,512),rand(1,2),180,97,10);
		CreateShot01(GetClipMinX,GetClipMinY+rand(0,512),rand(1,2),0,98,10);
		CreateShot01(GetClipMaxX,GetClipMinY+rand(0,512),rand(1,2),180,97,10);
		wait(25);
		}

function fire3{
		
		let angle9 = 0;
		loop(20){
		loop(16){PlaySE(CSD ~ "SE\se_tan00.wav");
		CreateShot01(32, 464, 2 ,  angle9 , 95 , 10);
		CreateShot01(32, 464, 2 ,  angle9 , 95 , 10);
		CreateShot01(416, 464, 2 ,  angle9 , 95 , 10);
		CreateShot01(416, 464, 2 ,  angle9 , 95 , 10);
		angle9 += 360/16;
		}
		 wait(120);
		}

		
		}

function fire4{
		loop(60){PlaySE(CSD ~ "SE\se_tan00.wav");
		CreateShot01( GetEnemyX, GetEnemyY, 4 , -45 , 149 , 10);
		CreateShot01( GetEnemyX, GetEnemyY, 4 , 225 , 149 , 10);
		CreateShot01( GetEnemyX, GetEnemyY, 4 , -70 , 149 , 10);
		CreateShot01( GetEnemyX, GetEnemyY, 4 , -110 , 149 , 10);
		CreateShot01( GetEnemyX, GetEnemyY, 4 , -90 , 149 , 10);
		
		wait(10);
		}
		loop(90){PlaySE(CSD ~ "SE\se_tan00.wav");
		CreateShot01(GetClipMinX + rand(32,416),GetClipMinY- 10,rand(2,3),rand(0,180),149,10);
		CreateShot01(GetClipMinX + rand(32,416),GetClipMinY- 10,rand(2,3),rand(30,150) + 30,149,10);
		CreateShot01(GetClipMinX + rand(32,416),GetClipMinY- 10,rand(2,3),rand(30,150) - 30,149,10);
		wait(14);
		}
		wait(180);
		}

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;}
	}

	

	
		
}