#e[Player]
#ScriptVersion[2]
#Menu[[zCg@ԕ]
#Text[Xy
ԕu傫ȍ̉ԁv
]

#Image[.\LilyCutin.PNG]
#ReplayName[LilyWhite]

script_player_main{

let imgPlayer=GetCurrentScriptDirectory~".\LilyPlayer.png";
let imgCutin=GetCurrentScriptDirectory~".\LilyCutin.png";
let imgShot=GetCurrentScriptDirectory~".\LilyShot.png";
let ShotData= GetCurrentScriptDirectory~".\LilyShotData.txt";

let bShot  = false;
let bSlow  = false;
let bLeft  = false;
let bRight = false;
let bUp    = false;
let bDown  = false;
let px=GetPlayerX;
let py=GetPlayerY;
let pxP=px;
let pyP=py;

let OptionX = [-40,40,0,0, 25,-25,0,0];
let OptionY = [0,0,0,0, -25,-25,0,0];
let op = 0;

let mainshotcount=0;
let mainshotlimit=30;

@Initialize{
	LoadGraphic(imgPlayer);
	LoadGraphic(imgCutin);
	LoadGraphic(imgShot);
	LoadPlayerShotData(ShotData);
	SetInitialBombCount(3);
	SetSpeed(4.0, 1.5);
	SetItemCollectLine(145);
	SetRebirthFrame(15);
	SetRebirthFrameReduction(3);
	SetGrazeCircle(40);
        SetPlayerLifeImage(imgPlayer, 0, 0, 64, 64);

	TMain;
}

@MainLoop{
	if(OnBomb){CollectItems;}
	SetIntersectionCircle(GetPlayerX, GetPlayerY, 1.0);
	yield;
}

@Missed{yield;}

@SpellCard{
	UseSpellCard("NaturalBomb",0);
	CutIn(YOUMU,"ԕu傫ȍ̉ԁv",imgCutin);
}

@DrawLoop{
	SetTexture(imgPlayer);
        if(bLeft)       {SetGraphicRect( 64, 0, 128, 64);}
        else if(bRight) {SetGraphicRect(128, 0, 192, 64);}
        else            {SetGraphicRect(  0, 0,  64, 64);}
	DrawGraphic(px,py);

	SetTexture(imgShot);
	SetGraphicRect(0,0,23,23);
	ascent(i in 0..2){
		DrawGraphic(px+OptionX[i]+OptionX[i+4]*op,py+OptionY[i]+OptionY[i+4]*op);
	}
}

@Finalize{
	DeleteGraphic(imgPlayer);
	DeleteGraphic(imgShot);
}





task TMain{
	yield;

	TOpKeyCheck;
	TShot;
	TShot2;
	TOption;
}



task TOpKeyCheck{
	let state;
	loop{
		pxP=px;
		pyP=py;

		px=GetPlayerX;
		py=GetPlayerY;
		state=GetKeyState(VK_SHOT);
		bShot=(state==KEY_PUSH || state==KEY_HOLD);

		state=GetKeyState(VK_SLOWMOVE);
		bSlow=(state==KEY_PUSH || state==KEY_HOLD);

		state=GetKeyState(VK_LEFT);
		bLeft=(state==KEY_PUSH || state==KEY_HOLD);

		state=GetKeyState(VK_RIGHT);
		bRight=(state==KEY_PUSH || state==KEY_HOLD);

		state=GetKeyState(VK_UP);
		bUp=(state==KEY_PUSH || state==KEY_HOLD);

		state=GetKeyState(VK_DOWN);
		bDown=(state==KEY_PUSH || state==KEY_HOLD);

		yield;
	}
}



task TOption{
	loop{
		op = [0,0.1][bSlow]+(op)*0.9;
		yield;
	}
}



task TShot{
	let bShotPrev = false;
	let left = 0;   
	loop{
		if(!bShot) {
			if(bShotPrev){
			left = 10;
			}
			if(left == 0){
			while(!bShot){yield;}
			}
			else{
			left--;
			}
		}
		ascent(i in -2..3){
		CreatePlayerShot01(px, py, 10, 270+i*5, 2.25, 1, 2);
		}
	bShotPrev = bShot;
	loop(5){yield;}
	}
}



task TShot2{
	let bShotPrev=false;
	let left = 0;
	loop{
		if(!bShot){
			if(bShotPrev){
				left=2;
			}
			if(left==0){
				while(!bShot){yield;}
			}
			else{
				left--;
			}
		} 
		if(!OnMissed && !OnEvent){
			if(mainshotcount<=mainshotlimit){
				ascent(i in 0..2){
					HomingShot(px+OptionX[i]+OptionX[i+4]*op, py+OptionY[i]+OptionY[i+4]*op);
				}
			}
		}
		bShotPrev = bShot;
		loop(5){yield;}
	}
}



task HomingShot(let x,let y){
	let ang=270;
	ascent(i in EnumEnemyBegin..EnumEnemyEnd){
		let e=EnumEnemyGetID(i);
		let ex=GetEnemyInfo(e,ENEMY_X);
		let ey=GetEnemyInfo(e,ENEMY_Y);
		if(ex>GetClipMinX-32 && ex<GetClipMaxX+32 && ey>GetClipMinY-32 && ey<GetClipMaxY+32){
			ang=atan2(ey-y,ex-x);
			break;
		}
	}
	LilyShot(x,y,ang);
}



task LilyShot(let x,let y,let ang){
	mainshotcount++;
	let obj = NULL;
	obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj,x,y);
	Obj_SetAngle(obj,ang);
	Obj_SetSpeed(obj,5);
	ObjShot_SetGraphic(obj,3);
	ObjShot_SetDamage(obj,4.5);
	ObjShot_SetPenetration(obj,1);//ђʗ͕͂ʁBcĂȂƁAxђʂĂ܂c
	while( !Obj_BeDeleted(obj) )
	{
		let toAngle=atan2(GetEnemyY()-Obj_GetY(obj), GetEnemyX()-Obj_GetX(obj));
		Obj_SetAngle(obj, toAngle);
		yield;
	}
	mainshotcount--;
}



}





#include_script".\LilySpell.txt"
