#TouhouDanmakufu
#Title[Contest nonspell 2]
#Text[reimuuuu]
#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 = 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(150);
		SetDamageRate(10, 10);
                SetTimer(30);
		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);

		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(2){PlaySE(CSD ~ "SE\se_tan00.wav");
		ascent(i in -8..9){
		CreateShot01( GetEnemyX, GetEnemyY, 3 , 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,5);
		}
task attack2{
	loop{
	fire;
	wait(120);
	fire2;
	}
}

function fire{
	let speed = 1;
	let n = [-1,1];
	let p = [96,99];
	let s = 0;
	loop(20){
	ascent(i in -20..21){
	CreateShotA(0,GetX,GetY,10);
	SetShotDataA(0,0,1,GetAngleToPlayer+i*10,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.2; s++; s%=length(n);}
	
}

function fire2{
	let angle = 0;
	let dir = 0;
	let s = 0;
	let p = [102,100];
	loop(40){PlaySE(CSD ~ "SE\se_tan00.wav");
	ascent(i in 0..9){
	CreateShot01(GetX+70*cos(angle+i*360/8),GetY+30*sin(angle+i*360/8),3,dir,p[s],10);
	angle+=i*360/8+1;
	dir+=i*360/8+1;}
	s++; s%=length(p);
	wait(2);}
}
	
	
	


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

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

	

	
		
}