#e[Player]	
#ScriptVersion[2]
#Menu[Start]

#Image[.\Select.png]
#ReplayName[Yamato]

script_player_main{
	let current = GetCurrentScriptDirectory;
	let Img = [//摜
			current~".\Yamato.png",//@
			current~".\ObjImg.png",
			];
	let SE = [
			current~".\se.wav",
			];
	let SideLife =10;
	let counter = 0;
	let KeyHold = 0;
	let n= 85;
	let	Life = 200;
	let UnitLife =300;

	@Initialize{
		ascent(n in 0..length(Img)){LoadGraphic(Img[n]);}
		ascent(n in 0..length(SE)){LoadSE(SE[n]);}
		SetPlayerLifeImage(Img[0],x[0],x[0],x[1],x[1]);
		LoadPlayerShotData(current~".\ShotData.txt");
		LoadSE(SE[0]);
		
		SetSpeed(5,2.5);
		SetGrazeCircle(80);
		SetAutoEffect(false);
		ForbidBomb(false);
		KeyCheck;
	}
	@MainLoop{
		Clock;
		GetPain;
		if(UnitLife>0){
			if(RapShot){
				if(counter%20==0){
				let angle = 5;
				loop(18){
					CreatePlayerShot01(GetPlayerX, GetPlayerY-5, 10, angle, 5, 5, 91);
					angle+=10;
					}
				PlaySE(SE[0]);
				}
			}
		}
		else if(UnitLife==0){
			if(RapShot){
				if(counter%10==0){
				let Way= 85;
					loop(3){
						CreatePlayerShot01(GetPlayerX+10, GetPlayerY-10, 15, Way, 5, 5, 91);
						Way+=5;
					}
				PlaySE(SE[0]);
				}
			}
		}	
		if(UnitLife>0){
			UnitPain(GetPlayerX,GetPlayerY);
		}
		counter++;
		yield;
	}
	@Missed{MainLoop;}
	
	@SpellCard{}
	
	@DrawLoop{
		if(UnitLife>0){
			if(RapShot){
				ImgEffect(Img[0],GetPlayerX, GetPlayerY,3,x[2],x[0],x[3],x[1],2);
				PlayerImg(x[1],x[0],x[2],x[1]);
			}
			else{
				ImgEffect(Img[0],GetPlayerX, GetPlayerY,3,x[2],x[1],x[3],x[2],2);
				PlayerImg(x[0],x[0],x[1],x[1]);
			}
		}
		else if(UnitLife==0){
			if(RapShot){
				PlayerImg(x[1],x[0],x[2],x[1]);
			}
			else if(Right){
				PlayerImg(x[1],x[1],x[2],x[2]);
			}
			else if(Left){
				PlayerImg(x[0],x[1],x[1],x[2]);
			}
			else{
				PlayerImg(x[0],x[0],x[1],x[1]);
			}
		}
		yield;
		LifeDraw(500);
	}
	
	@Finalize{
		ascent(n in 0..length(SE)){DeleteSE(SE[n]);}
		ascent(n in 0..length(Img)){DeleteGraphic(Img[n]);}
	}
	
	task GetPain{//Q
	if(Life==0){
		SetIntersectionCircle(GetPlayerX,GetPlayerY,5);
		}
		else if(Life>0&&GetEnemyShotCountEx(GetPlayerX,GetPlayerY,30,ALL)>=1){
			Life=Life-GetEnemyShotCountEx(GetPlayerX,GetPlayerY,20,ALL);
			DeleteEnemyShotImmediatelyInCircle(SHOT,GetPlayerX,GetPlayerY,20);
		}
		if(Life>200){Life=200;}
		if(Life<0){Life=0;}
		yield;
	}	
	
	task UnitPain(Xobj,Yobj){
		if(UnitLife>0&&GetEnemyShotCountEx(Xobj,Yobj,60,ALL)>=1){
			UnitLife=UnitLife-GetEnemyShotCountEx(Xobj,Yobj,50,ALL);
			DeleteEnemyShotImmediatelyInCircle(SHOT,Xobj,Yobj,50);
		}
		if(UnitLife>300){UnitLife=300;}
		if(UnitLife<0){UnitLife=0;}
		yield;
	}
	
	task LifeDraw(MaxHp){
		let Hp=((Life+UnitLife)/MaxHp)*308;
		ObjImg(GetCenterX+2,GetClipMinY+15,0,0,308,20);
		ObjImg((GetCenterX+Hp)/2-40,GetClipMinY+15.5,0,21,Hp,40);
	yield;
	}
#include_function ".\ImageObj.txt"
#include_function ".\KeyObj.txt"
}