#TouhouDanmakufu
#Title[Contest spell 6]
#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\sta72572.jpg";
        let bgm = CSD ~ "bmg\16 - Voyage 1970";
	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 angle2 = 0;
	let angle3 = 360/7;
	let angle4 = 360/12;
	
	@Initialize{
		
		SetLife(1000);
		SetDamageRate(10, 10);
                SetTimer(90);
		SetInvincibility(240);
                SetScore(200000);
		SetMovePosition01(GetCenterX,140,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," Shinigami's pact - A donation for a Soul ",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{
               
		yield;
	}

	let float = 0;
	@DrawLoop{
		SetTexture(spritereimu);
		SetRenderState(ALPHA);
		SetAlpha(100);
		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(100);
                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;
		countdown1;
		
	}

	task attack{
		loop{
			fire;
			}
			}

	task attack2{
		loop{
			wait(360);
			side;
			wait(1660);
			stream;
			wait(9999999);
			}
			}
			
	

	function side{
			loop(50){PlaySE(CSD ~ "SE\se_tan00.wav");
			CreateShot01( GetClipMinX+ rand(0,520), GetClipMinY, rand(0.5,1.5) , 90 , 97 , 10);
		
		CreateShot01( GetClipMinX, GetClipMaxY - rand(0,520), rand(0.5,1.5) , 0 , 97 , 10);
		CreateShot01( GetClipMaxX, GetClipMinY + rand(0,520), rand(0.5,1.5) , 180 , 99 , 10);
		wait(35);
		}
		}

	function stream{
			loop(50){PlaySE(CSD ~ "SE\se_tan00.wav");
			CreateShot01( GetEnemyX, GetEnemyY, 3 , GetAngleToPlayer , 97 , 10);
		
		CreateShot01( GetEnemyX, GetEnemyY, 3 , GetAngleToPlayer , 97 , 10);
		CreateShot01( GetEnemyX, GetEnemyY, 3 , GetAngleToPlayer , 99 , 10);
		CreateShot01( GetClipMinX, GetClipMaxY - rand(0,520), rand(0.5,1.5) , 0 , 212 , 10);
		CreateShot01( GetClipMaxX, GetClipMinY + rand(0,520), rand(0.5,1.5) , 180 , 211 , 10);
		wait(35);
		}
		}
	function fire{
			loop(40){
			descent(i in 5..9){
			ascent(j in 0..8){
			CreateShotA( 1 , GetX , GetY , 0 );
			SetShotDataA( 1 , 1 , (9-i)+0.5 ,   GetAngleToPlayer - j*angle , 0 , 0 , 0 , 99);
					CreateShotA( 2 , GetX , GetY , 0 );
			SetShotDataA( 2 , 1 , (9-i)+0.5 ,   GetAngleToPlayer - angle , 0 , 0 , 0 , 99);
			FireShot(1);					
			FireShot(2);
			PlaySE(CSD ~ "SE\se_tan00.wav");	
			angle += 5;
			}
			}
			wait(30);
			descent(i in 6..9){
			ascent(j in 0..5){
			CreateShotA( 1 , GetX , GetY , 0 );
			SetShotDataA( 1 , 1 , (9-i)+0.5 ,   GetAngleToPlayer + j*angle2 , 0 , 0 , 0 , 102);
				CreateShotA( 2 , GetX , GetY , 0 );
			SetShotDataA( 2 , 1 , (9-i)+0.5 ,   GetAngleToPlayer + angle2 , 0 , 0 , 0 , 102);	
			FireShot(1);
			FireShot(2);					
			PlaySE(CSD ~ "SE\se_tan00.wav");
			angle2 += 15;
			}
			}
			wait(30);
			}
			wait(120);

			
			loop(15){
			loop(36){
			ascent(i in -2..6){
			CreateShotA( 1 , GetClipMinX, GetClipMaxY - rand(0,520), 10 );
			SetShotDataA( 1 , 0 , 0 , angle , 0 , 0 , 0 , 95 );
			SetShotDataA( 1 , 60 , 1 , -angle , 0.3 , 0.08 , 2 , 95 );
			SetShotDataA( 1 , 120 , 2 , GetAngleToPlayer , 0.3 , 0 , 0 , 95 );
			SetShotDataA( 1 , 200 , 2 , +angle , 0.3 , 0 , 0 , 95 );
			SetShotDataA( 1 , 230 , 2 , GetAngleToPlayer + 2*i , -0.3 , 0 , 0 , 216 );
			CreateShotA( 6 , GetClipMinX, GetClipMaxY - rand(0,520), 10 );
			SetShotDataA( 6 , 0 , 0 , angle , 0 , 0 , 0 , 95 );
			SetShotDataA( 6 , 60 , 1 , -angle , 0.3 , 0.08 , 2 , 95 );
			SetShotDataA( 6 , 120 , 2 , GetAngleToPlayer , 0.3 , 0 , 0 , 95 );
			SetShotDataA( 6 , 200 , 2 , +angle , 0.3 , 0 , 0 , 95 );
			SetShotDataA( 6 , 230 , 2 , GetAngleToPlayer + 2*i , -0.3 , 0 , 0 , 221 );
			
			
			CreateShotA( 2 , GetClipMinX+ rand(0,520), GetClipMinY,  10 );
			CreateShotA( 3 , GetClipMinX+ rand(0,520), GetClipMinY,  10 );
			CreateShotA( 4 , GetClipMaxX, GetClipMaxY - rand(0,520), 10 );
			CreateShotA( 5 , GetClipMaxX, GetClipMaxY- rand(0,520),  10 );
			SetShotDataA( 2 , 0 , 0 , angle , 0 , 0 , 0 , 95 );
			SetShotDataA( 2 , 60 , 1 , -angle , 0.3 , 0.08 , 2 , 95 );
			SetShotDataA( 2 , 120 , 2 , GetAngleToPlayer , 0.3 , 0 , 0 , 95 );
			SetShotDataA( 2 , 180 , 2 , -angle , 0.3 , 0 , 0 , 95 );
			SetShotDataA( 2 , 210 , 2 , GetAngleToPlayer+ 2*i , 0.3 , 0 , 0 , 217 );
			SetShotDataA( 3 , 0 , 0 , angle , 0 , 0 , 0 , 95 );
			SetShotDataA( 3 , 60 , 1 , -angle , 0.3 , 0.08 , 2 , 95 );
			SetShotDataA( 3 , 120 , 2 , GetAngleToPlayer , 0.3 , 0 , 0 , 95 );
			SetShotDataA( 3 , 180 , 2 , -angle , 0.3 , 0 , 0 , 95 );
			SetShotDataA( 3 , 210 , 2 , GetAngleToPlayer+ 2*i , 0.3 , 0 , 0 , 218 );
			SetShotDataA( 4 , 0 , 0 , angle , 0 , 0 , 0 , 95 );
			SetShotDataA( 4 , 60 , 1 , -angle , 0.3 , 0.08 , 2 , 95 );
			SetShotDataA( 4 , 120 , 2 , GetAngleToPlayer , 0.3 , 0 , 0 , 95 );
			SetShotDataA( 4 , 180 , 2 , -angle , 0.3 , 0 , 0 , 95 );
			SetShotDataA( 4 , 210 , 2 , GetAngleToPlayer+ 2*i , 0.3 , 0 , 0 , 219 );
			SetShotDataA( 5 , 0 , 0 , angle , 0 , 0 , 0 , 95 );
			SetShotDataA( 5 , 60 , 1 , -angle , 0.3 , 0.08 , 2 , 95 );
			SetShotDataA( 5 , 120 , 2 , GetAngleToPlayer , 0.3 , 0 , 0 , 95 );
			SetShotDataA( 5 , 180 , 2 , -angle , 0.3 , 0 , 0 , 95 );
			SetShotDataA( 5 , 210 , 2 , GetAngleToPlayer+ 2*i , 0.3 , 0 , 0 , 220 );
			}
			angle += 10;
		FireShot(1);
		FireShot(2);
		FireShot(3);
		FireShot(4);
		FireShot(5);
		FireShot(6);
		PlaySE(CSD ~ "SE\se_tan00.wav");
		wait(15);
			
		}
		
		}
		wait(120);
		
		}


task countdown1{
 loop{
  if(GetTimer<11){
   wait(60);
   PlaySE(CSD ~ "SE\se_timeout.wav");
    }
  yield;}
 }

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

	

	
		
}