//#TouhouDanmakufu
#ScriptVersion[3]
#Title["Mima Dialo"]
#Text["Bullets"]


#include"./lib/SHOT_REPLACE/shot_replace.dnh"
#include"./Kogasainclude.txt"

let objEnemy;
let duration = 0;
let stopstuff = false;
let angle = 0;
let angle2 = 0;
let animframe = 0;
let frame = 0;
let GetSpeedX = 0;
let variable = 0;
let n = 0;
let illumima = GetCurrentScriptDirectory~"sfx/illumima.mp3";
@Event{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
	SetScriptResult(1);
	}
	case(EV_REQUEST_TIMER){
	SetScriptResult(999);
	}
}


@Initialize{
	//Resource Loading
	shotinit;
	InstallFont("./fontSEI.ttf");
	LoadSound(shot);
	LoadSound(shot3);
	LoadSound(illumima);
	LoadSound(charge2);
	objEnemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objEnemy);
	Invuln(180000000, 120, 75);
	SetCommonData("alive", true);
	let Mima = GetCurrentScriptDirectory~"sprites/mima real.png";
	ObjPrim_SetTexture(objEnemy, Mima); 
	ObjSprite2D_SetSourceRect(objEnemy, 0, 1, 142, 112);
	
	ObjSprite2D_SetDestCenter(objEnemy); 
	//BottomEnemyMarker(objEnemy, objEnemy);
	ObjMove_SetPosition(objEnemy, GetCenterX, -100);
		ObjMove_SetDestAtFrame(objEnemy, GetCenterX, 120, 120);
		

	
	attack1;
	SetShotAutoDeleteClip(100, 70, 100, 40);
	
	
}



task CheckForFlip{
yield;
loop{
if(CheckDirectionAL1(objEnemy, "left")){
SetCommonData("flipsprite", true);
}
else if(CheckDirectionAL1(objEnemy, "right")){
SetCommonData("flipsprite", false);
}
if(GetCommonData("flipsprite", false)==true && CheckDirectionAL1(objEnemy, "none")){ ObjRender_SetScaleX(objEnemy, -1)}
else{ ObjRender_SetScaleX(objEnemy, 1); }


yield;
}
}



@MainLoop{
	
	
	if(ObjEnemy_GetInfo(objEnemy, INFO_LIFE) <=0 && stopstuff==false){stopstuff=true;}

	GetEnemyX = ObjMove_GetX(objEnemy);
	GetEnemyY = ObjMove_GetY(objEnemy);
	//ObjEnemy_SetIntersectionCircleToShot(objEnemy, GetEnemyX, GetEnemyY, 23);//当たり判定(自機弾用)登録
	//ObjEnemy_SetIntersectionCircleToPlayer(objEnemy, GetEnemyX, GetEnemyY, 17);//当たり判定(体当たり用)登録

	frame++;
	yield;
	GetSpeedX = ObjMove_GetSpeed(objEnemy)*cos(ObjMove_GetAngle(objEnemy));
	SetCommonData("kogasax", ObjMove_GetX(objEnemy));
	SetCommonData("kogasay", ObjMove_GetY(objEnemy));



if(stopstuff==true && popped==false){
DestroyBoss;
}	
	
}

task DestroyBoss{
popped=true;
SetCommonData("alive", false);
loop(10){ yield; }
Obj_Delete(objEnemy);
loop(20){ yield; }
		CloseScript(GetOwnScriptID());
		return;
}



task attack1{
PlaySE(illumima);
let one = -1;
let blah = false;
let circlemade = false;
wait(120);
loop(4){
ObjRender_SetScaleX(objEnemy, one);
one*=-1;
wait(40);
}
wait(15);
ObjMove_SetDestAtFrame(objEnemy, -140, 120, 120);
wait(180);			
ObjEnemy_SetLife(objEnemy, 0);
}
