#TouhouDanmakufu[Plural]
#ScriptVersion[3]
#Title["Unlikely Allies - Kisume & Parsee"]
#Text["By Lusus"]
#Background[".\Background.dnh"]

#System[".\default_system/Default_System.txt"]
#Player[".\player/Ultima's DDC Reimu B (Fixed)/ReimuH.dnh"]


@Event{
}

@Initialize{
    TPlural;
}

@MainLoop{
    yield;
}

task TPlural{
    let dir = GetCurrentScriptDirectory();
    let obj = ObjEnemyBossScene_Create();
    SetAreaCommonData("mode", "start", 0); 

    let musel =  GetAreaCommonData("mode", "music", 0);
    let bgobj = ObjSound_Create();
    if(musel == 0){
	    ObjSound_Load(bgobj, dir ~ "./se/bgm.ogg");
	    ObjSound_SetLoopEnable(bgobj, true);
	    ObjSound_SetLoopTime(bgobj, 0, 999999999);
	}
	if(musel == 1){
		ObjSound_Load(bgobj, dir ~ "./se/bgm.ogg");
	    ObjSound_SetLoopEnable(bgobj, true);
	    ObjSound_SetLoopTime(bgobj, 0, 999999999);
	}
    ObjSound_SetVolumeRate(bgobj, 85);
	ObjSound_Play(bgobj);
    TBossName;
    TMode;
    SetPlayerLife(9);

    obj = ObjEnemyBossScene_Create();
    ObjEnemyBossScene_Add(obj, 0, dir ~ "./Start.dnh");
    ObjEnemyBossScene_Add(obj, 1, dir ~ "./Non1.dnh");
    ObjEnemyBossScene_Add(obj, 1, dir ~ "./Spell1.dnh");
    ObjEnemyBossScene_Add(obj, 2, dir ~ "./Non2.dnh");
    ObjEnemyBossScene_Add(obj, 2, dir ~ "./Spell2.dnh");
    ObjEnemyBossScene_Add(obj, 3, dir ~ "./Non3.dnh");
    ObjEnemyBossScene_Add(obj, 3, dir ~ "./Spell3.dnh");
   
    ObjEnemyBossScene_LoadInThread(obj);
    ObjEnemyBossScene_Regist(obj);
    while(!Obj_IsDeleted(obj)){
        yield;
    }
    loop(30){
        yield;
    }
    CloseScript(GetOwnScriptID());
}

task TBossName(){
    let img = ObjPrim_Create(OBJ_SPRITE_2D);
    Obj_SetRenderPriority(img, 0.75);
    ObjPrim_SetTexture(img,GetCurrentScriptDirectory() ~ "img/ename.png");  
    ObjSprite2D_SetSourceRect(img, 0, 222, 160, 244);
    ObjRender_SetScaleXYZ(img, 0.6*rez, 0.6*rez, 1);
    ObjSprite2D_SetDestCenter(img);
    ObjRender_SetPosition(img, 50*rez, 11*rez, 1); 
    ObjRender_SetAlpha(img, 0);
    yield;
    let objScene = GetEnemyBossSceneObjectID();
    while(ObjEnemyBossScene_GetInfo(objScene, INFO_TIMER) > 999){yield;}
    ObjRender_SetAlpha(img, 255);
}

task TMode(){
    let diff = GetAreaCommonData("mode", "difficulty", 0);;
    diff = 1;
    let img = ObjPrim_Create(OBJ_SPRITE_2D);
    Obj_SetRenderPriority(img, 0.1);
    ObjPrim_SetTexture(img,GetCurrentScriptDirectory() ~ "img/font1.png");  
    ObjSprite2D_SetSourceRect(img, 528, 642, 659, 673);
    if(diff == 1){
        ObjSprite2D_SetSourceRect(img, 528, 674, 659, 705);
    }
    if(diff == 2){
        ObjSprite2D_SetSourceRect(img, 528, 706, 659, 737);
    }
    ObjRender_SetScaleXYZ(img, 0.75*rez, 0.75*rez, 1);
    ObjSprite2D_SetDestCenter(img);
    ObjRender_SetPosition(img, 535*rez, 33*rez, 1); 
    //834-960
    //30-75
}

let rez = GetScreenHeight()/480;