#TouhouDanmakufu
#Title[Contest spell 2]
#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 = 360/36;
	let angle1 = 360/36;
	let timer1 = 0;
	let speed = 1;
	let angle2 = 360/5;
	let angle3 = 360/7;
	let angle4 = 360/12;
	
	@Initialize{
		
		SetLife(800);
		SetDamageRate(10, 10);
                SetTimer(90);
		SetInvincibility(240);
                SetScore(200000);
		SetMovePosition01(GetCenterX,180,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," Divine garden - Butterflyes in the shrine ",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);
		attack;
		attack2;
		countdown1;
		
	}

	task attack{
		loop{
			fire;
			}
			}

	task attack2{
		loop{
			stream;
			}
			}

	function stream{
			wait(240);
			loop(6){PlaySE(CSD ~ "SE\se_tan00.wav");
			CreateShot01( GetEnemyX, GetEnemyY, 3.5 , GetAngleToPlayer , 95 , 10);
			CreateShot01( GetEnemyX,GetEnemyY, 3.5 , GetAngleToPlayer + 30 , 95 , 10);
			CreateShot01( GetEnemyX, GetEnemyY, 3.5 , GetAngleToPlayer - 30 , 95 , 10);
			CreateShot01( GetEnemyX, GetEnemyY, 3.5 , GetAngleToPlayer + 60 , 95 , 10);
			CreateShot01( GetEnemyX, GetEnemyY, 3.5 , GetAngleToPlayer - 60 , 95 , 10);
			CreateShot01( GetEnemyX, GetEnemyY, 3.5 , GetAngleToPlayer + 150 , 95 , 10);
			CreateShot01( GetEnemyX, GetEnemyY, 3.5, GetAngleToPlayer + 210 , 95 , 10);
			wait(20);
			}
			}

	function fire{
		
		
		
		loop(36){
		CreateShotA( 1 , GetEnemyX + 80*cos(0) , GetEnemyY + 20*sin(90), 10 );
		SetShotDataA( 1 , 0 , 2 , angle , 0.3 , 0.08 , 4 , 95 );
		SetShotDataA( 1 , 30 , 4.8 , -angle , 0.3 , -0.5 , 2 , 95 );
		SetShotDataA( 1 , 90 , 2 , angle , 0 , +0.5 , 3 , 210 );
		CreateShotA( 2 , GetX + 60*cos(0) , GetY + 60*sin(90), 10 );
		SetShotDataA( 2 , 0 , 2 , angle , 0.3 , 0.08 , 4 , 95 );
		SetShotDataA( 2 , 30 , 4.8 , -angle , 0.3 , -0.5 , 2 , 95 );
		SetShotDataA( 2 , 90 , 2 , angle , 0 , +0.5 , 3 , 210 );
		CreateShotA( 3 , GetX + 40*cos(0) , GetY + 40*sin(90), 10 );
		SetShotDataA( 3 , 0 , 2 , angle , 0.3 , 0.08 , 4 , 95 );
		SetShotDataA( 3 , 30 , 4.8 , -angle , 0.3 , -0.5 , 2 , 95 );
		SetShotDataA( 3 , 90 , 2 , angle , 0, +0.5 , 3 , 210 );
		CreateShotA( 4 , GetEnemyX - 80*cos(0) , GetEnemyY + 20*sin(90), 10 );
		SetShotDataA( 4 , 0 , 2 , angle , 0.3 , 0.08 , 4 , 95 );
		SetShotDataA( 4 , 30 , 4.8 , -angle , 0.3 , -0.5 , 2 , 95 );
		SetShotDataA( 4 , 90 , 2 , angle , 0 , +0.5 , 3 , 210 );
		CreateShotA( 5 , GetX - 60*cos(0) , GetY + 40*sin(90), 10 );
		SetShotDataA( 5 , 0 , 2 , angle , 0.3 , 0.08 , 4 , 95 );
		SetShotDataA( 5 , 30 , 4.8 , -angle , 0.3 , -0.5 , 2 , 95 );
		SetShotDataA( 5 , 90 , 2 , angle , 0 , +0.5 , 3 , 210 );
		CreateShotA( 6 , GetX - 40*cos(0) , GetY + 60*sin(90), 10 );
		SetShotDataA( 6 , 0 , 2 , angle , 0.3 , 0.08 , 4 , 95 );
		SetShotDataA( 6 , 30 , 4.8 , -angle , 0.3 , -0.5 , 2 , 95 );
		SetShotDataA( 6 , 90 , 2 , angle , 0 , +0.5 , 3 , 210 );
		CreateShotA( 7 , GetEnemyX + 80*cos(0) , GetEnemyY - 80*sin(90), 10 );
		SetShotDataA( 7 , 0 , 2 , angle , 0.3 , 0.08 , 4 , 95 );
		SetShotDataA( 7 , 30 , 4.8 , -angle , 0.3 , -0.5 , 2 , 95 );
		SetShotDataA( 7 , 90 , 2 , angle , -0.5 , +0.5 , 3 , 210 );
		CreateShotA( 8 , GetX + 60*cos(0) , GetY - 60*sin(90), 10 );
		SetShotDataA( 8 , 0 , 2 , angle , 0.3 , 0.08 , 4 , 95 );
		SetShotDataA( 8 , 30 , 4.8 , -angle , 0.3 , -0.5 , 2 , 95 );
		SetShotDataA( 8 , 90 , 2 , angle , -0.5 , +0.5 , 3 , 210 );
		CreateShotA( 9 , GetX + 40*cos(0) , GetY - 40*sin(90), 10 );
		SetShotDataA( 9 , 0 , 2 , angle , 0.3 , 0.08 , 4 , 95 );
		SetShotDataA( 9 , 30 , 4.8 , -angle , 0.3 , -0.5 , 2 , 95 );
		SetShotDataA( 9 , 90 , 2 , angle , -0.5 , +0.5 , 3 , 210 );
		CreateShotA( 10 , GetEnemyX - 80*cos(0) , GetEnemyY - 80*sin(90), 10 );
		SetShotDataA( 10 , 0 , 2 , angle , 0.3 , 0.08 , 4 , 95 );
		SetShotDataA( 10 , 30 , 4.8 , -angle , 0.3 , -0.5 , 2 , 95 );
		SetShotDataA( 10 , 90 , 2 , angle , -0.5 , +0.5 , 3 , 210 );
		CreateShotA( 11 , GetX - 60*cos(0) , GetY - 60*sin(90), 10 );
		SetShotDataA( 11 , 0 , 2 , angle , 0.3 , 0.08 , 4 , 95 );
		SetShotDataA( 11 , 30 , 4.8 , -angle , 0.3 , -0.5 , 2 , 95 );
		SetShotDataA( 11 , 90 , 2 , angle , -0.5 , +0.5 , 3 , 210 );
		CreateShotA( 12 , GetX - 40*cos(0) , GetY - 40*sin(90), 10 );
		SetShotDataA( 12 , 0 , 2 , angle , 0.3 , 0.08 , 4 , 95 );
		SetShotDataA( 12 , 30 , 4.8 , -angle , 0.3 , -0.5 , 2 , 95 );
		SetShotDataA( 12 , 90 , 2 , angle , -0.5 , +0.5 , 3 , 210 );
		
		angle += 10;
		PlaySE(CSD ~ "SE\se_tan00.wav");
		FireShot(1);
		FireShot(2);
		FireShot(3);
		FireShot(4);
		FireShot(5);
		FireShot(6);
		FireShot(7);
		FireShot(8);
		FireShot(9);
		FireShot(10);
		FireShot(11);
		FireShot(12);
		}
		wait(190);
		loop(2){PlaySE(CSD ~ "SE\se_tan00.wav");
		ascent(i in -8..9){
		CreateShot01( GetEnemyX, GetEnemyY, 2 , GetAngleToPlayer +10*i , 74 , 10);
		}
		ascent(i in -1..10){
		CreateShot01( 32, 464, 2 , -90 +10*i , 212 , 10);
		CreateShot01( 416, 464, 2 , -90 -10*i , 213 , 10);
		CreateShot01( 416, 16, 2 , 90 +10*i , 213 , 10);
		CreateShot01( 32, 16, 2 , 90 -10*i , 212 , 10);
		}
		wait(30);
		}
		SetMovePosition01(GetCenterX + 100,130,2);
		wait(60);
		let angle10 = 0;
let spee = 2;
loop(10){
 loop(36){
  CreateShotA( 1 , GetEnemyX + 50*cos(0) , GetEnemyY + 50*sin(90), 10 );
  SetShotDataA( 1 , 0 , 2 , angle10 , 0.3 , 0.08 , 4 , 95 );
  SetShotDataA( 1 , 30 , 0 , NULL , 0 , -0.5 , -1 , 95 );
  SetShotDataA( 1 , 90 , spee , NULL , 0.3 , 0 , 0 , 210 );
  angle10 += 10;
  FireShot(1);PlaySE(CSD ~ "SE\se_tan00.wav");
  }
  spee+=0.2;}
		loop(36){
		CreateShotA( 1 , GetEnemyX + 50*cos(0) , GetEnemyY + 50*sin(90), 10 );
		SetShotDataA( 1 , 0 , 2 , angle , 0.3 , 0.08 , 4 , 95 );
		SetShotDataA( 1 , 30 , 4.8 , -angle , 0.3 , -0.5 , 2 , 95 );
		SetShotDataA( 1 , 90 , 2 , angle , 0.3 , +0.5 , 5 , 210 );
		CreateShotA( 2 , GetEnemyX - 50*cos(0) , GetEnemyY + 50*sin(90), 10 );
		SetShotDataA( 2 , 0 , 2 , angle , 0.3 , 0.08 , 4 , 95 );
		SetShotDataA(2 , 30 , 4.8 , -angle , 0.3 , -0.5 , 2 , 95 );
		SetShotDataA( 2 , 90 , 2 , angle , 0.3 , +0.5 , 5 , 210 );
		CreateShotA( 3 , GetEnemyX + 50*cos(0) , (GetEnemyY + 50*sin(90))-50, 10 );
		SetShotDataA( 3 , 0 , 2 , angle , 0.3 , 0.08 , 4 , 95 );
		SetShotDataA( 3 , 30 , 4.8 , -angle , 0.3 , -0.5 , 2 , 95 );
		SetShotDataA( 3 , 90 , 2 , angle , 0.3 , +0.5 , 5 , 210 );
		CreateShotA( 4 , GetEnemyX - 50*cos(0) , (GetEnemyY + 50*sin(90))-50, 10 );
		SetShotDataA( 4 , 0 , 2 , angle , 0.3 , 0.08 , 4 , 95 );
		SetShotDataA( 4 , 30 , 4.8 , -angle , 0.3 , -0.5 , 2 , 95 );
		SetShotDataA( 4 , 90 , 2 , angle , 0.3 , +0.5 , 5 , 210 );
		angle += 10;
		FireShot(1);
		FireShot(2);
		FireShot(3);
		FireShot(4);
		PlaySE(CSD ~ "SE\se_tan00.wav");
		}
		SetMovePosition01(GetCenterX,180,2);
		wait(90);
		loop(2){
		loop(16){PlaySE(CSD ~ "SE\se_tan00.wav");
		ascent(i in -8..9){
		CreateShot01( GetClipMinX+ rand(0,520), GetClipMinY, 2 , GetAngleToPlayer +i*10 , 212 , 10);
		}
		wait(25);
		}
		}
		SetMovePosition01(GetCenterX,180,5);
		wait(120);
		let speed = 0;
		loop(6){PlaySE(CSD ~ "SE\se_tan00.wav");
		ascent(i in -8..9){
		CreateShot01( GetEnemyX, GetEnemyY, 3 + speed , GetAngleToPlayer +10*i , 74 , 10);
		}
		wait(30);
		speed += 0.5;
		}
		SetColor(255,255,255);
		Concentration01(120);
		PlaySE(CSD ~ "SE\se_ch00.wav");
		wait(120);
		loop(70){PlaySE(CSD ~ "SE\se_tan00.wav");
		CreateShot01( GetClipMinX+ rand(0,520), GetClipMinY, 1.5 , 90 , 97 , 10);
		CreateShot01( GetClipMinX+ rand(0,520), GetClipMaxY, 1.5 , -90 , 99 , 10);
		CreateShot01( GetClipMinX, GetClipMaxY - rand(0,520), 1.5 , 0 , 97 , 10);
		CreateShot01( GetClipMaxX, GetClipMinY + rand(0,520), 1.5 , 180 , 99 , 10);
		CreateShot01( GetClipMinX+ rand(0,520), GetClipMinY, 1.5 , 90 , 97 , 10);
		CreateShot01( GetClipMinX+ rand(0,520), GetClipMaxY, 1.5 , -90 , 99 , 10);
		CreateShot01( GetClipMinX, GetClipMaxY - rand(0,520), 1.5 , 0 , 97 , 10);
		CreateShot01( GetClipMaxX, GetClipMinY + rand(0,520), 1.5 , 180 , 99 , 10);
		wait(35);
		
		}
		}

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

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

	

	
		
}