#TouhouDanmakufu
#Title[Contest spell 5]
#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 = 360/36;
	let angle1 = 360/36;
	let timer1 = 0;
	let angle2 = 360/5;
	let angle3 = 360/7;
	let angle4 = 360/12;
	
	@Initialize{
		
		SetLife(1000);
		SetDamageRate(10, 10);
                SetTimer(80);
		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," Deus Irae - Forbidden 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{
               
		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(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;
		countdown1;
		
	}

	task attack{
		loop{
			fire;
			}
			}

	task attack2{
			stream2;
			wait(2200);
			stream;
			wait(9000);
			
			}

	

	function stream{
			loop(130){PlaySE(CSD ~ "SE\se_tan00.wav");
		CreateShot01( GetClipMinX+ rand(0,520), GetClipMinY, rand(0.8,2) , 90 , 97 , 10);
		CreateShot01( GetClipMinX+ rand(0,520), GetClipMaxY, rand(0.8,2) , -90 , 99 , 10);
		CreateShot01( GetClipMinX, GetClipMaxY - rand(0,520), rand(0.8,2) , 0 , 97 , 10);
		CreateShot01( GetClipMaxX, GetClipMinY + rand(0,520), rand(0.8,2) , 180 , 99 , 10);
		CreateShot01( GetClipMinX+ rand(0,520), GetClipMinY, 1.2 , 90 , 97 , 10);
		CreateShot01( GetClipMinX+ rand(0,520), GetClipMaxY, 1.2 , -90 , 99 , 10);
		CreateShot01( GetClipMinX, GetClipMaxY - rand(0,520), 1 , 0 , 97 , 10);
		CreateShot01( GetClipMaxX, GetClipMinY + rand(0,520), 1 , 180 , 99 , 10);
		wait(22);
		
		}
			}

	function stream2{
			loop(40){PlaySE(CSD ~ "SE\se_tan00.wav");
		CreateShot01( GetClipMinX+ rand(0,520), GetClipMinY, rand(0.5,1.5) , 90 , 97 , 10);
		CreateShot01( GetClipMinX+ rand(0,520), GetClipMaxY, rand(0.5,1.5) , -90 , 99 , 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);
		CreateShot01( GetClipMinX+ rand(0,520), GetClipMinY, 1 , 90 , 97 , 10);
		CreateShot01( GetClipMinX+ rand(0,520), GetClipMaxY, 1 , -90 , 99 , 10);
		CreateShot01( GetClipMinX, GetClipMaxY - rand(0,520), 1 , 0 , 97 , 10);
		CreateShot01( GetClipMaxX, GetClipMinY + rand(0,520), 1 , 180 , 99 , 10);
		wait(40);
		
		}
			}


	function fire{
		loop(5){
		loop(10){PlaySE(CSD ~ "SE\se_tan00.wav");
		ascent(i in -8..9){
		CreateShot01( GetClipMinX+ rand(0,520), GetClipMinY, 2 , GetAngleToPlayer +i*10 , 67 , 10);
		CreateShot01( GetClipMinX+ rand(0,520), GetClipMinY, 2 , i*rand(0,180) , 67 , 10);
		}
		wait(30);
		}
		}
		wait(180);
		let angle20 = 0;
let speed = 2;
let n = [+20, 10];
let p = [208,212];
let s = 0;
loop(15){
loop(24){
 
  CreateShotA( 2 , GetEnemyX, GetEnemyY, 10 );
  SetShotDataA( 2 , 0 , 2 , angle20 , 0 , 0 , 0 , 95 );
  SetShotDataA( 2 , 60 , 0 , NULL , n[s] , 0 , -1 , 95 );
  SetShotDataA( 2 , 90 , speed , NULL , 0 , 0 , 0 , p[s] );
  angle20 += 15;
  FireShot(2);
	PlaySE(CSD ~ "SE\se_tan00.wav");
  }
  speed+=0.2; s++; s%=length(n);}
let angle20 = 0;
let speed = 2;
let n = [-20, -10];
let p = [209,211];
let s = 0;
loop(15){
loop(24){
 
  CreateShotA( 2 , GetEnemyX, GetEnemyY, 10 );
  SetShotDataA( 2 , 0 , 2 , angle20 , 0 , 0 , 0 , 95 );
  SetShotDataA( 2 , 60 , 0 , NULL , n[s] , 0 , -1 , 95 );
  SetShotDataA( 2 , 90 , speed , NULL , 0 , 0 , 0 , p[s] );
  angle20 += 15;
  FireShot(2);
PlaySE(CSD ~ "SE\se_tan00.wav");
  }
  speed+=0.2; s++; s%=length(n);}
	wait(180);
let angle20 = 0;
let speed = 2;
let n = [+20, 180];
let p = [208,212];
let s = 0;
loop(15){
loop(24){
 
  CreateShotA( 2 , GetEnemyX, GetEnemyY, 10 );
  SetShotDataA( 2 , 0 , 2 , angle20 , 0 , 0 , 0 , 95 );
  SetShotDataA( 2 , 60 , 0 , NULL , n[s] , 0 , -1 , 95 );
  SetShotDataA( 2 , 90 , speed , NULL , 0 , 0 , 0 , p[s] );
  angle20 += 15;
  FireShot(2);
PlaySE(CSD ~ "SE\se_tan00.wav");
  }
  speed+=0.2; s++; s%=length(n);}
let angle20 = 0;
let speed = 2;
let n = [-20, -180];
let p = [209,211];
let s = 0;
loop(15){
loop(24){
 
  CreateShotA( 2 , GetEnemyX, GetEnemyY, 10 );
  SetShotDataA( 2 , 0 , 2 , angle20 , 0 , 0 , 0 , 95 );
  SetShotDataA( 2 , 60 , 0 , NULL , n[s] , 0 , -1 , 95 );
  SetShotDataA( 2 , 90 , speed , NULL , 0 , 0 , 0 , p[s] );
  angle20 += 15;
  FireShot(2);
PlaySE(CSD ~ "SE\se_tan00.wav");
  }
  speed+=0.2; s++; s%=length(n);}
		wait(60);
		let angle20 = 0;
let speed = 2;
let n = [+20, 90];
let p = [208,212];
let s = 0;
loop(15){
loop(24){
 
  CreateShotA( 2 , GetEnemyX, GetEnemyY, 10 );
  SetShotDataA( 2 , 0 , 2 , angle20 , 0 , 0 , 0 , 95 );
  SetShotDataA( 2 , 60 , 0 , NULL , n[s] , 0 , -1 , 95 );
  SetShotDataA( 2 , 90 , speed , NULL , 0 , 0 , 0 , p[s] );
  angle20 += 15;
  FireShot(2);
PlaySE(CSD ~ "SE\se_tan00.wav");
  }
  speed+=0.2; s++; s%=length(n);}
let angle20 = 0;
let speed = 2;
let n = [-20, -90];
let p = [209,211];
let s = 0;
loop(15){
loop(24){
 
  CreateShotA( 2 , GetEnemyX, GetEnemyY, 10 );
  SetShotDataA( 2 , 0 , 2 , angle20 , 0 , 0 , 0 , 95 );
  SetShotDataA( 2 , 60 , 0 , NULL , n[s] , 0 , -1 , 95 );
  SetShotDataA( 2 , 90 , speed , NULL , 0 , 0 , 0 , p[s] );
  angle20 += 15;
  FireShot(2);
PlaySE(CSD ~ "SE\se_tan00.wav");
  }
  speed+=0.2; s++; s%=length(n);}
		wait(180);
		let angle20 = 0;
let speed = 2;
let n = [+20, 60];
let p = [208,212];
let s = 0;
loop(15){
loop(24){
 
  CreateShotA( 2 , GetEnemyX, GetEnemyY, 10 );
  SetShotDataA( 2 , 0 , 2 , angle20 , 0 , 0 , 0 , 95 );
  SetShotDataA( 2 , 60 , 0 , NULL , n[s] , 0 , -1 , 95 );
  SetShotDataA( 2 , 90 , speed , NULL , 0 , 0 , 0 , p[s] );
  angle20 += 15;
  FireShot(2);
PlaySE(CSD ~ "SE\se_tan00.wav");
  }
  speed+=0.2; s++; s%=length(n);}
let angle20 = 0;
let speed = 2;
let n = [-20, -60];
let p = [209,211];
let s = 0;
loop(15){
loop(24){
 
  CreateShotA( 2 , GetEnemyX, GetEnemyY, 10 );
  SetShotDataA( 2 , 0 , 2 , angle20 , 0 , 0 , 0 , 95 );
  SetShotDataA( 2 , 60 , 0 , NULL , n[s] , 0 , -1 , 95 );
  SetShotDataA( 2 , 90 , speed , NULL , 0 , 0 , 0 , p[s] );
  angle20 += 15;
  FireShot(2);
PlaySE(CSD ~ "SE\se_tan00.wav");
  }
  speed+=0.2; s++; s%=length(n);}
		wait(180);
		
		let angle20 = 0;
let speed = 2;
let n = [-10,10, 5 ,-5 , 17, -17];
let s = 0;
loop(10){
loop(36){
 
  CreateShotA( 1 , GetEnemyX, GetEnemyY, 10 );
  SetShotDataA( 1 , 0 , 2 , angle20 , n[s] , 0 , 0 , 95 );
  SetShotDataA( 1 , 60 , 0 , NULL , 0 , -1/20 , -1 , 95 );
  SetShotDataA( 1 , 120 , speed , NULL , 0 , 0 , 0 , 210 );
  angle20 += 10;
  FireShot(1);
PlaySE(CSD ~ "SE\se_tan00.wav");
  }
  speed+=0.2; s++; s%=length(n);}
		wait(150);
		let angle20 = 0;
let speed = 2;
let n = [-2];
let s = 0;
loop(15){
loop(36){
 
  CreateShotA( 1 , GetEnemyX, GetEnemyY, 10 );
  SetShotDataA( 1 , 0 , 2 , angle20 , n[s] , 0 , 0 , 95 );
  SetShotDataA( 1 , 60 , 0 , NULL , 0 , -1/20 , -1 , 95 );
  SetShotDataA( 1 , 120 , speed , NULL , 0 , 0 , 0 , 210 );
  angle20 += 10;
  FireShot(1);
PlaySE(CSD ~ "SE\se_tan00.wav");
  }
  speed+=0.2; s++; s%=length(n);}
	wait(70);
let angle20 = 0;
let speed = 2;
let n = [+2];
let s = 0;
loop(15){
loop(36){
 
  CreateShotA( 1 , GetEnemyX, GetEnemyY, 10 );
  SetShotDataA( 1 , 0 , 2 , angle20 , n[s] , 0 , 0 , 95 );
  SetShotDataA( 1 , 60 , 0 , NULL , 0 , -1/20 , -1 , 95 );
  SetShotDataA( 1 , 120 , speed , NULL , 0 , 0 , 0 , 210 );
  angle20 += 10;
  FireShot(1);
PlaySE(CSD ~ "SE\se_tan00.wav");
  }
  speed+=0.2; s++; s%=length(n);}
		wait(200);
let angle20 = 0;
let speed = 2;
let n = [+10];
let s = 0;
loop(15){
loop(36){
 
  CreateShotA( 1 , GetEnemyX, GetEnemyY, 10 );
  SetShotDataA( 1 , 0 , 2 , angle20 , n[s] , 0 , 0 , 95 );
  SetShotDataA( 1 , 60 , 0 , NULL , 0 , 0 , -1 , 95 );
  SetShotDataA( 1 , 90 , speed , NULL , 0 , 0 , 0 , 214 );
  angle20 += 10;
  FireShot(1);
PlaySE(CSD ~ "SE\se_tan00.wav");
  }
  speed+=0.2; s++; s%=length(n);}
let angle20 = 0;
let speed = 2;
let n = [-10];
let s = 0;
loop(15){
loop(36){
 
  CreateShotA( 1 , GetEnemyX, GetEnemyY, 10 );
  SetShotDataA( 1 , 0 , 2 , angle20 , n[s] , 0 , 0 , 95 );
  SetShotDataA( 1 , 60 , 0 , NULL , 0 , 0 , -1 , 95 );
  SetShotDataA( 1 , 90 , speed , NULL , 0 , 0 , 0 , 214 );
  angle20 += 10;
  FireShot(1);
PlaySE(CSD ~ "SE\se_tan00.wav");
  }
  speed+=0.2; s++; s%=length(n);}
	wait(180);
let angle20 = 0;
let speed = 2;
let n = [+2];
let s = 0;
loop(15){
loop(36){
 
  CreateShotA( 1 , GetEnemyX, GetEnemyY, 10 );
  SetShotDataA( 1 , 0 , 2 , angle20 , 0 , 0 , 0 , 95 );
  SetShotDataA( 1 , 60 , 0 , NULL , n[s] , 0 , -1 , 95 );
  SetShotDataA( 1 , 90 , speed , NULL , 0 , 0 , 0 , 213 );
  angle20 += 15;
  FireShot(1);
PlaySE(CSD ~ "SE\se_tan00.wav");
  }
  speed+=0.2; s++; s%=length(n);}
let angle20 = 0;
let speed = 2;
let n = [-2];
let s = 0;
loop(15){
loop(36){
 
  CreateShotA( 1 , GetEnemyX, GetEnemyY, 10 );
  SetShotDataA( 1 , 0 , 2 , angle20 , 0 , 0 , 0 , 95 );
  SetShotDataA( 1 , 60 , 0 , NULL , n[s] , 0 , -1 , 95 );
  SetShotDataA( 1 , 90 , speed , NULL , 0 , 0 , 0 , 213 );
  angle20 += 15;
  FireShot(1);
PlaySE(CSD ~ "SE\se_tan00.wav");
  }
  speed+=0.2; s++; s%=length(n);}
let angle20 = 0;
let speed = 2;
let n = [+10, 5];
let s = 0;
loop(15){
loop(24){
 
  CreateShotA( 2 , GetEnemyX, GetEnemyY, 10 );
  SetShotDataA( 2 , 0 , 2 , angle20 , 0 , 0 , 0 , 95 );
  SetShotDataA( 2 , 60 , 0 , NULL , n[s] , 0 , -1 , 95 );
  SetShotDataA( 2 , 90 , speed , NULL , 0 , 0 , 0 , 208 );
  angle20 += 15;
  FireShot(2);
PlaySE(CSD ~ "SE\se_tan00.wav");
  }
  speed+=0.2; s++; s%=length(n);}
let angle20 = 0;
let speed = 2;
let n = [-10, -5];
let s = 0;
loop(15){
loop(24){
 
  CreateShotA( 2 , GetEnemyX, GetEnemyY, 10 );
  SetShotDataA( 2 , 0 , 2 , angle20 , 0 , 0 , 0 , 95 );
  SetShotDataA( 2 , 60 , 0 , NULL , n[s] , 0 , -1 , 95 );
  SetShotDataA( 2 , 90 , speed , NULL , 0 , 0 , 0 , 208 );
  angle20 += 15;
  FireShot(2);
PlaySE(CSD ~ "SE\se_tan00.wav");
  }
  speed+=0.2; s++; s%=length(n);}
		wait(120);
let angle20 = 0;
let speed = 2;
let n = [+10, 5, 25, 45];
let s = 0;
loop(15){
loop(24){
 
  CreateShotA( 2 , GetEnemyX, GetEnemyY, 10 );
  SetShotDataA( 2 , 0 , 2 , angle20 , 0 , 0 , 0 , 95 );
  SetShotDataA( 2 , 60 , 0 , NULL , n[s] , 0 , -1 , 95 );
  SetShotDataA( 2 , 90 , speed , NULL , 0 , 0 , 0 , 211 );
  angle20 += 15;
  FireShot(2);
PlaySE(CSD ~ "SE\se_tan00.wav");
  }
  speed+=0.2; s++; s%=length(n);}
let angle20 = 0;
let speed = 2;
let n = [-10, -5, -25, -45];
let s = 0;
loop(15){
loop(24){
 
  CreateShotA( 2 , GetEnemyX, GetEnemyY, 10 );
  SetShotDataA( 2 , 0 , 2 , angle20 , 0 , 0 , 0 , 95 );
  SetShotDataA( 2 , 60 , 0 , NULL , n[s] , 0 , -1 , 95 );
  SetShotDataA( 2 , 90 , speed , NULL , 0 , 0 , 0 , 211 );
  angle20 += 15;
  FireShot(2);
PlaySE(CSD ~ "SE\se_tan00.wav");
  }
  speed+=0.2; s++; s%=length(n);}
		wait(120);
let speed = 1;
	let n = [-1,1];
	let p = [96,99];
	let s = 0;
	loop(40){
	ascent(i in -10..11){
	CreateShotA(0,GetX,GetY,10);
	SetShotDataA(0,0,1,GetAngleToPlayer+i*20,0,0,0,p[s]);
	SetShotDataA(0,60,1,NULL,n[s],0,0,p[s]);
	SetShotDataA(0,120,speed,NULL,0,0,0,p[s]);
	FireShot(0);PlaySE(CSD ~ "SE\se_tan00.wav");}speed+=0.1; s++; s%=length(n);}
		wait(60);
		loop(10){
		let angle20 = 0;
let speed = 2;
let n = [+10, 5];
let s = 0;
loop(15){
loop(24){
 
  CreateShotA( 2 , GetEnemyX, GetEnemyY, 10 );
  SetShotDataA( 2 , 0 , 2 , angle20 , 0 , 0 , 0 , 95 );
  SetShotDataA( 2 , 60 , 0 , NULL , n[s] , 0 , -1 , 95 );
  SetShotDataA( 2 , 90 , speed , NULL , 0 , 0 , 0 , 208 );
  angle20 += 15;
  FireShot(2);
PlaySE(CSD ~ "SE\se_tan00.wav");
  }
  speed+=0.2; s++; s%=length(n);}
let angle20 = 0;
let speed = 2;
let n = [-10, -5];
let s = 0;
loop(15){
loop(24){
 
  CreateShotA( 2 , GetEnemyX, GetEnemyY, 10 );
  SetShotDataA( 2 , 0 , 2 , angle20 , 0 , 0 , 0 , 95 );
  SetShotDataA( 2 , 60 , 0 , NULL , n[s] , 0 , -1 , 95 );
  SetShotDataA( 2 , 90 , speed , NULL , 0 , 0 , 0 , 208 );
  angle20 += 15;
  FireShot(2);
PlaySE(CSD ~ "SE\se_tan00.wav");
  }
  speed+=0.2; s++; s%=length(n);}
	wait(30);
		}
	wait(60);
loop(90){
		let angle20 = 0;
let speed = 2;
let n = [+20, 10];
let p = [208,212];
let s = 0;
loop(15){
loop(24){
 
  CreateShotA( 2 , GetEnemyX, GetEnemyY, 10 );
  SetShotDataA( 2 , 0 , 2 , angle20 , 0 , 0 , 0 , 95 );
  SetShotDataA( 2 , 60 , 0 , NULL , n[s] , 0 , -1 , 95 );
  SetShotDataA( 2 , 90 , speed , NULL , 0 , 0 , 0 , p[s] );
  angle20 += 15;
  FireShot(2);
PlaySE(CSD ~ "SE\se_tan00.wav");
  }
  speed+=0.2; s++; s%=length(n);}
let angle20 = 0;
let speed = 2;
let n = [-20, -10];
let p = [209,211];
let s = 0;
loop(15){
loop(24){
 
  CreateShotA( 2 , GetEnemyX, GetEnemyY, 10 );
  SetShotDataA( 2 , 0 , 2 , angle20 , 0 , 0 , 0 , 95 );
  SetShotDataA( 2 , 60 , 0 , NULL , n[s] , 0 , -1 , 95 );
  SetShotDataA( 2 , 90 , speed , NULL , 0 , 0 , 0 , p[s] );
  angle20 += 15;
  FireShot(2);
PlaySE(CSD ~ "SE\se_tan00.wav");
  }
  speed+=0.2; s++; s%=length(n);}
	wait(30);
		}
		}


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

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

	

	
		
}