#TouhouDanmakufu
#Title[Halloween 2009 - Horror in the Night (Hard)]
#Text[Fear can make things look different, but Reimu is not affraid. She is just annoyed.]
#Player[FREE]
#ScriptVersion[2]
#Image[.\system\afro01.png]
#BGM[.\Music\spook.mp3]

script_enemy_main {
    let CSD        = GetCurrentScriptDirectory;

    let ImgBoss = CSD ~ "system\spook.png";
    let ShotData   = CSD ~ "system\supershot.txt";

    let cut = CSD ~ "system\spookcut.png";
    let bg = CSD ~ "system\bg.png";
    let bg2 = CSD ~ "system\bg2.png";
    let bg3 = CSD ~ "system\bg3.png";
    let bg4 = CSD ~ "system\bg4.png";
    let bg5 = CSD ~ "system\bg5.png";
    let lay = CSD ~ "system\lay.png";

    let schijn = 0;    
    let schijn2 = 0;
    let schijn3 = 0;
    let schijn4 = 0;
    let schijn5 = 0;
    let schuif = 0;
    let framer = 1;
    let alph = 255;

    let spoken = 1;
    let verdwijn = 0;
    let moving = 0;

    @Initialize {
        SetLife(500);
        SetTimer(130);
	SetScore(350000);
	SetDamageRateEx(10,4,5,5);
	MagicCircle(false);
        SetInvincibility(240);
	SetMovePosition01(GetCenterX,GetCenterY-100,5);

        LoadGraphic(ImgBoss);
        LoadGraphic(bg);
	LoadGraphic(bg2);
	LoadGraphic(bg3);
	LoadGraphic(bg4);
	LoadGraphic(bg5);
	LoadGraphic(lay);
	LoadGraphic(cut);

	LoadUserShotData(ShotData);

	CutIn(YOUMU,"Horror in the night",cut,0,0,0,0);
	cutin("KANAKO",cut,0,0,350,348);
	ConcentrationX;
	hitboxer;
	Hoofd;	
    }

    @MainLoop {
	if(verdwijn==1){}
	if(verdwijn==0){
		SetCollisionA(GetX, GetY, 32);
        	SetCollisionB(GetX, GetY, 32);
	}
	yield;
    }

    @DrawLoop {

	if(verdwijn==1){ if(alph>=0){alph-=10;} alph = 0;}
	if(verdwijn==0){ DiscoCircle; if(alph<250){alph+=10;} }

	SetTexture(ImgBoss);
	SetAlpha(alph);
	SetGraphicAngle(0,0,0);
	SetGraphicScale(0.7,0.7);
	SetRenderState(ALPHA);
	SetGraphicRect(0,0,128,128);
       	DrawGraphic(GetX, GetY);

	// Focus anim
	Focus;

	DrawText("Unknown Spirit",35,30,12,255);
    }

    @BackGround{
	SetTexture(bg);
	SetGraphicRect(0,0,768,768);
	SetGraphicAngle(0,0,0);
	SetGraphicScale(0.7,0.7);
	SetRenderState(ALPHA);
	SetAlpha(schijn);
        DrawGraphic(GetCenterX, GetCenterY);

	SetTexture(bg2);
	SetGraphicRect(0,0,768,768);
	SetGraphicAngle(0,0,0);
	SetGraphicScale(0.7,0.7);
	SetRenderState(ALPHA);
	SetAlpha(schijn2);
        DrawGraphic(GetCenterX, GetCenterY);

	SetTexture(bg3);
	SetGraphicRect(0,0,768,768);
	SetGraphicAngle(0,0,0);
	SetGraphicScale(0.7,0.7);
	SetRenderState(ALPHA);
	SetAlpha(schijn3);
        DrawGraphic(GetCenterX, GetCenterY);

	SetTexture(bg4);
	SetGraphicRect(0,0,768,768);
	SetGraphicAngle(0,0,0);
	SetGraphicScale(0.7,0.7);
	SetRenderState(ALPHA);
	SetAlpha(schijn4);
        DrawGraphic(GetCenterX, GetCenterY);

	SetTexture(bg5);
	SetGraphicRect(0,0,768,768);
	SetGraphicAngle(0,0,0);
	SetGraphicScale(0.7,0.7);
	SetRenderState(ALPHA);
	SetAlpha(schijn5);
        DrawGraphic(GetCenterX, GetCenterY);

	if(framer==1){
		if(schijn<250){schijn+=5;}
		if(schijn==250){framer++;}
	}
	if(framer==2){
		if(schijn<250){schijn+=5; schijn5-=5;}
		if(schijn==250){framer++;}
	}
	if(framer==3){
		if(schijn2<250){schijn2+=5; schijn-=5;}
		if(schijn2==250){framer++;}
	}
	if(framer==4){
		if(schijn3<250){schijn3+=5; schijn2-=5;}
		if(schijn3==250){framer++;}
	}
	if(framer==5){
		if(schijn4<250){schijn4+=5; schijn3-=5;}
		if(schijn4==250){framer++;}
	}
	if(framer==6){
		if(schijn5<250){schijn5+=5; schijn4-=5;}
		if(schijn5==250){framer=2;}
	}

	SetTexture(lay);
	SetGraphicRect(0,0,256,20000);
	SetGraphicAngle(0,0,0);
	SetGraphicScale(2,2);
	SetRenderState(ALPHA);
	SetAlpha(85);
        DrawGraphic(GetCenterX, GetCenterY+schuif);

	SetTexture(lay);
	SetGraphicRect(0,0,20000,256);
	SetGraphicAngle(0,0,0);
	SetGraphicScale(2,2);
	SetRenderState(ALPHA);
	SetAlpha(85);
        DrawGraphic(GetCenterX+schuif, GetCenterY);

	schuif+=2;
    }

    @Finalize {	
	PlaySE(CSD ~"SFX\se_spookau.wav");
	if(GotSpellCardBonus){
                PlaySE(CSD ~ "SFX\se_cardget.wav");
        }
    }

    task Hoofd{
	wait(120);
	ConcentrationH;
	floating;
	ghosts;
	halloween;
	pijn;
	tijd;
	yield;
    }

    task halloween{
	loop{
		// voorbereiding
		wait(120);
		moving = 1;
		spoken = 0;
		wait(80);
		PlaySE(CSD ~"SFX\se_spookshift.wav");		
		verdwijn = 1;
		wait(60);

		// spoken
		regel;
		PlaySE(CSD ~"SFX\se_spookshift.wav");	
		verdwijn = 0;
		moving = 0;

		// wachten
		wait(200);
		PlaySE(CSD ~"SFX\se_spooklaugh.wav");
		spoken = 1;
		wait(60);
		vuur;
		vuur2;
		wait(160);
		yield;
	}

    }

    task vuur { 
	let dir = 0;
	let x = 0;
	loop(8){
		while(x<36){
			PlaySE(CSD ~"SFX\se_tan00.wav");
			CreateShotA(1,GetEnemyX,GetEnemyY,30);
			SetShotDataA(1,0,1,dir,0,0,0,243);
			SetShotDataA(1,30,0,NULL,0,0,0,246);
			SetShotDataA(1,60,1,NULL,-0.3,0.050,2,244);
			FireShot(1);	
			dir+=360/36;
			x++;
		}
		x = 0;
		wait(30);
		yield;
	}
    }

    task vuur2{ 
	let dir = 0;
	let x = 0;
	while(x<72){
		wait(3);
		PlaySE(CSD ~"SFX\se_tan00.wav");
		spookshot(GetEnemyX+60*cos(dir),GetEnemyY+60*sin(dir),0.5,dir,221,30);
		dir+=360/36;
		x++;
		if(dir==360){dir=0;}
	}
	x = 0;
	while(x<12){
		wait(10);
		PlaySE(CSD ~"SFX\se_kira00.wav");
		CreateShot01(GetEnemyX,GetEnemyY,4,GetAngleToPlayer-40,235,0);
		CreateShot01(GetEnemyX,GetEnemyY,4,GetAngleToPlayer-20,235,0);
		CreateShot01(GetEnemyX,GetEnemyY,4,GetAngleToPlayer,235,0);
		CreateShot01(GetEnemyX,GetEnemyY,4,GetAngleToPlayer+20,235,0);
		CreateShot01(GetEnemyX,GetEnemyY,4,GetAngleToPlayer+40,235,0);
		x++;
	}
	x = 0;
    }

    task vuur3{
	let dir = 0;
	let kleur = 1;
	let x = 0;
	loop(8){
		PlaySE(CSD ~"SFX\se_lazer01.wav");
		CreateLaserB(1,800,15,kleur,30);
		SetLaserDataB(1,0,0,0,0,0,0,GetAngleToPlayer,0);
		SetShotKillTime(1,60);
		FireShot(1);
		kleur++;
		if(kleur==8){kleur=1;}
		wait(15);
	}
    }

    task spookshot(x,y,v,angle,kleur,delay){
	let obj = Obj_Create(OBJ_SHOT);

	Obj_SetPosition(obj,x,y);
	Obj_SetSpeed(obj,v);
	ObjShot_SetGraphic(obj,kleur);
	ObjShot_SetDelay(obj,delay);    
	Obj_SetAngle(obj,angle);

	Obj_SetAngle(obj,atan2(GetPlayerY - Obj_GetY(obj), GetPlayerX - Obj_GetX(obj)));

	wait(80);
	Obj_SetAngle(obj,atan2(GetPlayerY - Obj_GetY(obj), GetPlayerX - Obj_GetX(obj)));

	Obj_SetSpeed(obj,5);

    }

    sub regel{ 
	let random = rand_int(1,7);
	if(random==1){
		SetMovePosition03(GetCenterX+80,GetCenterY,10,60);
		wait(60);
		ConcentrationJ;
		CreateEnemyFromScript("cloonspook",GetCenterX,80,0,0,0);
		CreateEnemyFromScript("cloonspook",GetCenterX-150,140,0,0,0);
		CreateEnemyFromScript("cloonspook",GetCenterX-40,170,0,0,0);
		CreateEnemyFromScript("cloonspook",GetCenterX+120,120,0,0,0);
		vuur3;
	}

	if(random==2){
		SetMovePosition03(GetCenterX-150,140,10,60);
		wait(60);
		ConcentrationJ;
		CreateEnemyFromScript("cloonspook",GetCenterX,80,0,0,0);
		CreateEnemyFromScript("cloonspook",GetCenterX+80,GetCenterY,0,0,0);
		CreateEnemyFromScript("cloonspook",GetCenterX-40,170,0,0,0);
		CreateEnemyFromScript("cloonspook",GetCenterX+120,120,0,0,0);
		vuur3;
	}

	if(random==3){
		SetMovePosition03(GetCenterX-80,GetCenterY-100,10,60);
		wait(60);
		ConcentrationJ;
		CreateEnemyFromScript("cloonspook",GetCenterX,80,0,0,0);
		CreateEnemyFromScript("cloonspook",GetCenterX-100,GetCenterY+40,0,0,0);
		CreateEnemyFromScript("cloonspook",GetCenterX+100,170,0,0,0);
		CreateEnemyFromScript("cloonspook",GetCenterX+150,120,0,0,0);
		vuur3;
	}

	if(random==4){
		SetMovePosition03(GetCenterX+100,170,10,60);
		wait(60);
		ConcentrationJ;
		CreateEnemyFromScript("cloonspook",GetCenterX,80,0,0,0);
		CreateEnemyFromScript("cloonspook",GetCenterX-100,GetCenterY+40,0,0,0);
		CreateEnemyFromScript("cloonspook",GetCenterX-80,GetCenterY-100,0,0,0);
		CreateEnemyFromScript("cloonspook",GetCenterX+150,120,0,0,0);
		vuur3;
	}

	if(random==5){
		SetMovePosition03(GetCenterX+150,GetCenterY-50,10,60);
		wait(60);
		ConcentrationJ;
		CreateEnemyFromScript("cloonspook",GetCenterX-150,80,0,0,0);
		CreateEnemyFromScript("cloonspook",GetCenterX-100,GetCenterY+20,0,0,0);
		CreateEnemyFromScript("cloonspook",GetCenterX+70,GetCenterY-120,0,0,0);
		CreateEnemyFromScript("cloonspook",GetCenterX,GetCenterY-20,0,0,0);
		vuur3;
	}

	if(random==6){
		SetMovePosition03(GetCenterX,GetCenterY-20,10,60);
		wait(60);
		ConcentrationJ;
		CreateEnemyFromScript("cloonspook",GetCenterX-150,80,0,0,0);
		CreateEnemyFromScript("cloonspook",GetCenterX-100,GetCenterY+20,0,0,0);
		CreateEnemyFromScript("cloonspook",GetCenterX+70,GetCenterY-120,0,0,0);
		CreateEnemyFromScript("cloonspook",GetCenterX+150,GetCenterY-50,0,0,0);
		vuur3;
	}

	if(random==7){
		SetMovePosition03(GetCenterX+70,GetCenterY-120,10,60);
		wait(60);
		ConcentrationJ;
		CreateEnemyFromScript("cloonspook",GetCenterX-150,80,0,0,0);
		CreateEnemyFromScript("cloonspook",GetCenterX-100,GetCenterY+20,0,0,0);
		CreateEnemyFromScript("cloonspook",GetCenterX,GetCenterY-20,0,0,0);
		CreateEnemyFromScript("cloonspook",GetCenterX+150,GetCenterY-50,0,0,0);
		vuur3;
	}
    }

    task floating{
	wait(120);
	loop{
		if(moving==1){yield;}
		if(moving==0){
			loop(18){ wait(2); SetY(GetY-1.2); }
			wait(10);
			loop(18){ wait(2); SetY(GetY+1.2); }	
		}	
		yield;
	}
    }

    task ghosts{
	let r = 0;
	let s = 0;
	let dir = 0;
	let x = 0;
	let t = 0;

	loop{
		if(spoken==0){yield;}
			if(spoken==1){
			while(x<36){
				wait(4);
				CreateShotA(97,GetEnemyX+r*cos(dir),GetEnemyY+r*sin(dir-45),30);
				SetShotDataA(97,0,0,dir,0,0,0,WHITE01);
				SetShotKillTime(97,0);
				FireShot(97);

				CreateShotA(98,GetEnemyX+r*cos(dir-180),GetEnemyY+r*sin(dir),30);
				SetShotDataA(98,0,0,dir,0,0,0,WHITE01);
				SetShotKillTime(98,0);
				FireShot(98);

				CreateShotA(99,GetEnemyX+r*cos(-dir+45),GetEnemyY+r*sin(dir+180),30);
				SetShotDataA(99,0,0,-dir,0,0,0,WHITE01);
				SetShotKillTime(99,0);
				FireShot(99);

				if(s==0){r+=10; if(r==80){s=1;}}
				if(s==1){r-=1; if(r==40){s=2;}}
				if(s==2){r+=1; if(r==120){s=1;}}

				dir+=360/36;
				x++;
			}
			x = 0;
			dir = 0;
		}
		yield;
	}
    }

    // brr geluid
    task pijn{	
    let brr = GetEnemyLife / 100 * 7;	
    	loop{
   		let hp = GetEnemyLife;
		wait(3.3);
		let nhp = GetEnemyLife;
		if(nhp<hp && nhp>brr){PlaySE(GetCurrentScriptDirectory~"SFX\se_damage00.wav");}
		if(nhp<hp && nhp<brr){PlaySE(GetCurrentScriptDirectory~"SFX\se_damage01.wav");}
		yield;
 	}
    }
 
    // timeout sfx
    task tijd{
	loop{
		wait(60);
		if(GetTimer<=10){PlaySE(CSD~"SFX\se_timeout.wav");}
		if(GetTimer<=5){PlaySE(CSD~"SFX\se_timeout2.wav");}
		yield;
	}

    }

    #include_function ".\hitboxer.txt"
    #include_function ".\spellcircle.txt"
    #include_function ".\Hwfunctions.txt"
    #include_function ".\cutin.txt"
}

script_enemy cloonspook {

    let CSD        = GetCurrentScriptDirectory;

    let spookimg = CSD ~ "system\spook.png";



    let dir = 0;
    let r = 0;
    let a = 0;

    @Initialize { 
	SetDamageRateEx(10,4,5,5);

        LoadGraphic(spookimg);
        SetLife(1000);
	PlaySE(CSD ~"SFX\se_spook3.wav");
	ConcentrationJ;
	Hoofd;
    }

    @MainLoop {
	SetCollisionA(GetX, GetY, 32);
	SetCollisionB(GetX, GetY, 16);
        yield;
    }

    @DrawLoop {
	DiscoCircle;

	SetTexture(spookimg);
	SetAlpha(a);
	SetGraphicAngle(0,0,0);
	SetGraphicScale(0.7,0.7);
	SetRenderState(ALPHA);
	SetGraphicRect(0,0,128,128);
        DrawGraphic(GetX, GetY);

	if(a<250){a+=5;}
    }

    @Finalize {
	PlaySE(CSD ~"SFX\se_gun00.wav");
	let x = 0;
	while(x<16){
		CreateShot01(GetX,GetY,2,GetAngleToPlayer+dir,236,0);
		dir+=360/16;
		x++;
	}	
    }

    task Hoofd{
	yield;
	floating;
	vuur;
	die;
	pijn;
    }

    task vuur {
	let dir = 0;
	let kleur = 1;
	let x = 0;

	loop(8){
		PlaySE(CSD ~"SFX\se_lazer01.wav");
		CreateLaserB(1,800,15,kleur,30);
		SetLaserDataB(1,0,0,0,0,0,0,GetAngleToPlayer,0);
		SetShotKillTime(1,60);
		FireShot(1);
		kleur++;
		if(kleur==8){kleur=1;}
		wait(15);
	}
	PlaySE(CSD ~"SFX\se_lazer00.wav");
	while(x<12){
		let laserkleur = [RED01, BLUE01, GREEN01, YELLOW01, PURPLE01, ORANGE01, AQUA01][rand_int(0,6)];
		CreateLaser01(GetX+50*cos(dir),GetY+50*sin(dir),4,dir,300,10,laserkleur,10);
		dir+=360/12;
		x++;
	}
	x = 0;	
    }

    sub die{
	wait(200);
	VanishEnemy;
    }

    task floating{
	loop{
		loop(18){
			wait(2);
			SetY(GetY-1.2);
		}
		wait(10);
		loop(18){
			wait(2);
			SetY(GetY+1.2);
		}	
		yield;
	}
    }

    // brr geluid
    task pijn{	
    let brr = GetEnemyLife / 100 * 7;	
    	loop{
   		let hp = GetEnemyLife;
		wait(3.3);
		let nhp = GetEnemyLife;
		if(nhp<hp && nhp>brr){PlaySE(GetCurrentScriptDirectory~"SFX\se_damage00.wav");}
		if(nhp<hp && nhp<brr){PlaySE(GetCurrentScriptDirectory~"SFX\se_damage01.wav");}
		yield;
 	}
    }
 
    #include_function ".\spellcircle.txt"
    #include_function ".\Hwfunctions.txt"
}