#TouhouDanmakufu
#Title["Hordes of Abaddon"]
#Text[]
#Image[]
#BackGround[Default]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main
{
	#include_function ".\spellcard.txt";
	let type=0;
	let frame=0;
    let cutin=GetCurrentScriptDirectory~"img\face05ct.png";
	#include_function ".\orinanim.txt";

task fairies{
    CreateEnemyFromScript("fairy", GetX, GetY, 0, 0, -30);
    CreateEnemyFromScript("fairy", GetX, GetY, 0, 0, 0);
    CreateEnemyFromScript("fairy", GetX, GetY, 0, 0, 30);
    CreateEnemyFromScript("fairy", GetX, GetY, 0, 0, 150);
    CreateEnemyFromScript("fairy", GetX, GetY, 0, 0, 180);
    CreateEnemyFromScript("fairy", GetX, GetY, 0, 0, 210);
}

task bullets{
    let angle=0;
    loop{
        loop(4){
            ascent(i in 0..4){
                CreateShot01(GetX, GetY, rand(5, 6), angle+i*90+rand(-10, 10), 173, 10);
            }
            yield;
        }
        loop(4){yield;}
        angle+=rand(2, 4);
    }
}

	@Initialize
	{
		SetInvincibility(200);
		SetLife(500);
		SetDamageRate(10,10);
        LoadGraphic(cutin);

		SetMovePosition02(GetCenterX,GetCenterY-100,20);
		Concentration01(150);
		CutIn(YOUMU, "''Hordes of Abaddon''",cutin,0,0,402,512);
		LoadUserShotData(GetCurrentScriptDirectory~"supershot.txt");

		SetCommonData("ONSPELL", "TRUE");
		spellbonus(10000000);
		timer;
		SetCommonData("timercount", 60*120);
        lastspell;
        PlayMusic(GetCurrentScriptDirectory~"bgm.mp3");
	}
	
	@MainLoop
	{
		SetCollisionA(GetX(),GetY(),24);
		SetCollisionB(GetX(),GetY(),24);
        survival=1;
		frame++;
		yield;
        if(frame>150 && frame%200==0){fairies;}
        if(frame==250){bullets;}
}
	
	@Finalize
	{
		AddScore(spellbonustotal);
		if(spellbonustotal>0)
		{
		PlaySE(GetCurrentScriptDirectory~"sound\se_cardget.wav");
		loop(50)
		{
			CreateItem(ITEM_SCORE,GetX+rand(-100,100),GetY+rand(20,100));
		}
		}else{
		loop(15)
		{
			CreateItem(ITEM_SCORE,GetX+rand(-100,100),GetY+rand(20,100));
		}
		}
		SetCommonData("ONSPELL", "FALSE");
        if(spellbonustotal==0){SetCommonData("REDO", "TRUE");}
	}
	
	@DrawLoop
	{
        bg;
        anim2;
	}
}

script_enemy fairy{
    #include_function ".\orinanim.txt"
    let drawtype=0;
    let frame=0;
    let counter=0;
    
task movement{
    let counterb=0;
    SetMovePosition01(GetEnemyX+200*cos(GetArgument), GetEnemyY+200*sin(GetArgument), 2);
    while(GetSpeed!=0){
        yield;
        counter++;
        if(counter%3==0){bullets;}
    }
    counter++;
    movementb;
}
task movementb{
    SetMovePosition01(GetPlayerX, GetPlayerY, 6);
    while(GetSpeed!=0){yield;}
    counter++;
    death;
    loop(5){yield;}
    VanishEnemy;
}
task death{
    PlaySE(GetCurrentScriptDirectory~"sound\BulletWave.wav");
    ascent(i in 0..6){
    CreateShot01(GetX, GetY, 8, GetAngleToPlayer+i*60, 229, 30);
    CreateShot01(GetX, GetY, 6, GetAngleToPlayer+i*60+30, 229, 30);
    }
}
task bullets{
    PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
    CreateShot01(GetX, GetY, 8, GetAngleToPlayer, 47, 10);
}
    
    @Initialize{
		SetInvincibility(0);
        SetLife(1000);
        SetDamageRate(50, 50);
        movement;
    }
    
    @MainLoop{
		yield;
        if(GetLife<900){
            SetX(GetX);
            SetY(GetY);
            frame++;
            if(drawtype==0){
                death;
                SetMovePosition03(GetX+rand(-50, 50), GetY+rand(-50, 50), 10, 4);
                drawtype=1;
            }
        }else{
		SetCollisionA(GetX(),GetY(),8);
		SetCollisionB(GetX(),GetY(),8);
        }
        if(frame==100){
            frame=0;
            AddLife(1000-GetLife);
            drawtype=0;
            if(counter==0){movement;}else{movementb;}
        }
    }
    
    @Finalize{
    }
    
    @DrawLoop{
    if(drawtype==1){fairydead;}else{fairy;}
    }
}