//#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["nonTogether"]
#include "./../ZUNShot/ZUNShot_Const.txt"
#include "./sharedFuncDave.dnh"



let objBoss;
let width = 384;
let height = 448;
let life = 1;
let scene = GetEnemyBossSceneObjectID();


@Event{
    alternative(GetEventType())
    case(EV_REQUEST_LIFE){
        SetScriptResult(life);
    }
}


@Initialize{
    objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
    ObjEnemy_Regist(objBoss);
	SetCommonData("non1", "no");
	
	animNon(objBoss);
	TFinalize(objBoss);
	
	
    ObjMove_SetDestAtFrame(objBoss, width/2, height/5, 60);
	Main;
}

@MainLoop{
    ObjEnemy_SetIntersectionCircleToShot(objBoss, ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 32); 
    ObjEnemy_SetIntersectionCircleToPlayer(objBoss, ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 28);
    yield;
}


task Main{
    Name(1, objBoss);
	skip(objBoss);
    SetForbidPlayerShot(true);
	ObjEnemy_SetDamageRate(objBoss, 0,0);
    Indicator(objBoss, 1);
	let time = 150;
	wait(90);
	let t=0;
	let text = speak(true, "You are being[r]a royal pain.");
	while(t<time){
	    if(GetVirtualKeyState(VK_OK) == KEY_PUSH){t=time;}
		t++; yield;
	}
	Obj_Delete(text);
	t=0;
	text = speak(true, "Well, so be it.");
	while(t<time){
	    if(GetVirtualKeyState(VK_OK) == KEY_PUSH){t=time;}
		t++; yield;
	}
	Obj_Delete(text);
	t=0;
	text = speak(true, "Mario, James...[r]Come to my aid!");
	while(t<time){
	    if(GetVirtualKeyState(VK_OK) == KEY_PUSH){t=time;}
		t++; yield;
	}
	Obj_Delete(text);
	
	NotifyEventAll(EV_USER_STAGE+6, 0);
	wait(60);
	Mario; James;
	wait(300);
	ObjEnemy_SetLife(objBoss, 0);

}

task drawMario(enemy1){
    let img = GetCurrentScriptDirectory() ~ "../img/nonMario.png";
	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE)>0){
		ObjPrim_SetTexture(enemy1, img);
		ObjSprite2D_SetSourceRect(enemy1, 166, 250, 340, 770);
		ObjSprite2D_SetDestRect(enemy1, -30, -60, 30, 60);
		yield;
	}
	ObjRender_SetPosition(enemy1, width/4, -300, 1);
}

task Mario{
    let enemy1 = ObjPrim_Create(OBJ_SPRITE_2D);
	drawMario(enemy1);
	ObjRender_SetPosition(enemy1, width/4, -70, 1);
	ascent(i in 0..240){ObjRender_SetY(enemy1, -70+0.85*i); yield;}
}


task drawJames(enemy2){
    let img = GetCurrentScriptDirectory() ~ "../img/NonSpell.png";
	let i=0;
	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE)>0){
		ObjPrim_SetTexture(enemy2, img);
		ObjSprite2D_SetSourceRect(enemy2, 316, 70, 436, 410); 
		ObjSprite2D_SetDestRect(enemy2, -25, -70, 25, 70);
		yield;
	}
	ObjRender_SetPosition(enemy2, width/4, -300, 1);
}

task James{
    let enemy2 = ObjPrim_Create(OBJ_SPRITE_2D);
	drawJames(enemy2);
	ObjRender_SetPosition(enemy2, 3*width/4, -70, 1);
	ascent(i in 0..240){ObjRender_SetY(enemy2, -70+0.85*i); yield;}
}



