#e[Player]
#ScriptVersion[2]
#Menu[\Z@zV]
#Text[



@@ver1.22
]
#Image[.\img\select.png]
#ReplayName[SAKU_HST]

script_player_main{
#include_function ".\txt\System.dnh"

@Initialize{

	SetPlayerLifeImage( imgPlayer, 0, 0, 48, 48 );
	ascent( let i in 0..length(ListImg) ){ LoadGraphic( ListImg[i] ); }
	ascent( let i in 0..length(SE) ){ LoadSE( SE[i] ); }

	SetSpeed(HighSpeed, LowSpeed);
	LoadPlayerShotData( current~"txt\ShotData.dnh" );

	SetItemCollectLine(140);
	SetRebirthFrame(0);
	SetRebirthFrameReduction(0);
	SetGrazeCircle(64);
	SetAutoEffect(false);
	SetInitialBombCount(3);

	Initialize_System;
}

let n_anime_state = 0;

@MainLoop{
	n_Timer++;
	n_PlayerX = GetPlayerX;
	n_PlayerY = GetPlayerY;

	KeyCheck;

	rect_DrawPlayer[0] = 48*(int(n_Timer/10)%5);

	if( KeyState_Hold[K_RIGHT] ){
		if(n_anime_state < 0){ n_anime_state+= 2;}
		else if(n_anime_state < 20){ n_anime_state++; }
	}
	else if( KeyState_Hold[K_LEFT] ){
		if(n_anime_state > 0){ n_anime_state-= 2;}
		else if(n_anime_state > -20){ n_anime_state--; }
	}
	else{
		if(n_anime_state > 0){ n_anime_state--;}
		else if(n_anime_state < 0){ n_anime_state++; }
	}
	
	if(n_anime_state == 0){
		rect_DrawPlayer[1] = 0;
	}
	else{
		if(n_anime_state < 0){
			rect_DrawPlayer[1] = 96;
		}
		else{
			rect_DrawPlayer[1] = 48;
		}
		rect_DrawPlayer[0] = 48*int((absolute(n_anime_state)-3)/6);
	}

	if( !KeyState_Hold[K_SLOW] ){ n_slow = 0; }
	n_slow++;

	if( KeyState_Hold[K_SLOW] ){
		if( n_SlowEffectAlpha < 20 ){ n_SlowEffectAlpha++; }
	}
	else if( n_SlowEffectAlpha > 0 ){ n_SlowEffectAlpha-=2; }

	SetIntersectionCircle( n_PlayerX, n_PlayerY, 0 );
	
	
	
	ascent(let i in 0..4){
		optXDef[i] = n_PlayerX;
		optYDef[i] = n_PlayerY;
	}
//	optN = MIN(MAX(5-GetPlayerBomb,2),4);
	optN = 4;
	if(KeyState_Hold[K_SLOW]){optAng = 270;}
	else{
		if((!KeyState_Hold[K_SHOT] && !KeyState_Hold[K_USER]) || (KeyState_Hold[K_SHOT] && KeyState_Hold[K_USER])){
			if(KeyState_Hold[K_RIGHT]){
				optAng += 4;
				if(optAng > 316){optAng = 316;}
			}
			else if(KeyState_Hold[K_LEFT]){
				optAng -= 4;
				if(optAng < 224){optAng = 224;}
			}
			else if(absolute(optAng-270) < 4){optAng=270;}
			else if(optAng < 270){optAng+=4;}
			else if(optAng > 270){optAng-=4;}
		}
	}
	alternative(optN)
	case(1){
		let nR = [32,20][KeyState_Hold[K_SLOW]];
		optXDef[0] = n_PlayerX+nR*cos(optAng);
		optYDef[0] = n_PlayerY+nR*sin(optAng);
	}
	case(2){
		let nR = [32,20][KeyState_Hold[K_SLOW]];
		optXDef[0] = n_PlayerX+nR*cos(optAng-110);
		optXDef[1] = n_PlayerX+nR*cos(optAng+110);
		optYDef[0] = n_PlayerY+nR*sin(optAng-110);
		optYDef[1] = n_PlayerY+nR*sin(optAng+110);
	}
	case(3){
		let nR = [32,20][KeyState_Hold[K_SLOW]];
		optXDef[0] = n_PlayerX+nR*cos(optAng-110);
		optXDef[1] = n_PlayerX+nR*cos(optAng+110);
		optYDef[0] = n_PlayerY+nR*sin(optAng-110);
		optYDef[1] = n_PlayerY+nR*sin(optAng+110);
		optXDef[2] = n_PlayerX+nR*cos(optAng);
		optYDef[2] = n_PlayerY+nR*sin(optAng);
	}
	case(4){
		let nR = [24,16][KeyState_Hold[K_SLOW]];
		optXDef[0] = n_PlayerX+nR*cos(optAng-110);
		optXDef[1] = n_PlayerX+nR*cos(optAng+110);
		optYDef[0] = n_PlayerY+nR*sin(optAng-110);
		optYDef[1] = n_PlayerY+nR*sin(optAng+110);
		optXDef[2] = n_PlayerX+nR*cos(optAng-110)*2;
		optXDef[3] = n_PlayerX+nR*cos(optAng+110)*2;
		optYDef[2] = n_PlayerY+nR*sin(optAng-110)*2;
		optYDef[3] = n_PlayerY+nR*sin(optAng+110)*2;
	}

	ascent(let i in 0..4){
		optX[i] = optX[i]+(optXDef[i]-optX[i])*0.2;
		optY[i] = optY[i]+(optYDef[i]-optY[i])*0.2;
	}
	
	if(GetKeyState(VK_SLOWMOVE) != KEY_HOLD || OnMissed){optTGT = [];}
	
	if(n_chargeshotcounter >= 60){
		if(GetKeyState(VK_SHOT) == KEY_PUSH && !OnBomb){
			if(!OnMissed){
				if(GetKeyState(VK_SLOWMOVE) == KEY_HOLD){Use_Charge02;}
				else{Use_Charge01;}
			}
		}
	}
	yield;
}

@Missed{MainLoop}

let N_PLAYER_ALPHA = 255;

@DrawLoop{

	SetTexture(imgBorder);
	SetRenderState(ADD);
	SetGraphicRect( 193, 1, 255, 63 );
	SetGraphicScale(1, 1);
	SetColor(63,0,255);
	ascent(let i in 0..length(optTGT)){
		DrawGraphic(GetEnemyInfo(optTGT[i], ENEMY_X),GetEnemyInfo(optTGT[i], ENEMY_Y));
	}

	SetRenderState(ALPHA);
	SetColor(255,255,255);
	SetGraphicRect( 129, 1, 191, 63 );
	SetGraphicScale(0.25, 0.25);
	SetAlpha(N_PLAYER_ALPHA);
	ascent(let i in 0..optN){
		DrawGraphic(optX[i], optY[i]);
	}

	SetTexture(imgPlayer);
	SetGraphicRect( rect_DrawPlayer[0], rect_DrawPlayer[1], 48+rect_DrawPlayer[0], 48+rect_DrawPlayer[1] );
	SetGraphicAngle( 0, 0, 0 );
	SetGraphicScale( 1.1, 1.1 );
	SetColor(255,255,255);
	DrawGraphic( n_PlayerX, n_PlayerY );

	SetTexture(imgBorder);
	if( n_SlowEffectAlpha > 0 ){
		SetRenderState(ALPHA);
		SetColor(255,255,255);
		SetAlpha( N_PLAYER_ALPHA*n_SlowEffectAlpha/20 );
		SetGraphicRect( 1, 1, 63, 63 );
		SetGraphicAngle( 0, 0, 0 );
		SetGraphicScale( n_SlowEffectAlpha/20, n_SlowEffectAlpha/20 );
		DrawGraphic( n_PlayerX, n_PlayerY );

		SetGraphicScale( (45-n_SlowEffectAlpha)/20, (45-n_SlowEffectAlpha)/20 );
		SetGraphicRect( 65, 1, 127, 63 );
		SetGraphicAngle( 0, 0, n_Timer*2 );
		DrawGraphic( n_PlayerX, n_PlayerY );
		SetGraphicAngle( 0, 0, -n_Timer*2 );
		DrawGraphic( n_PlayerX, n_PlayerY );
	}
	
}

@Finalize{
	ascent( let i in 0..length(ListImg) ){ DeleteGraphic( ListImg[i] ); }
	ascent( let i in 0..length(SE) ){ DeleteSE( SE[i] ); }
}

@SpellCard{
	PlaySE(SE[2]);
	
	
	if(b_LastSpell || OnMissed){
		CollectItemRemain(180);
		SetPlayerInvincibility(240);
		UseSpellCard( "Spell_Slash", 0 );
		AddBomb(-10);
	}
	else{
		if(n_chargeshotcounter<60){
			CollectItemRemain(60);
			SetPlayerInvincibility(60);
			UseSpellCard( "dummy", 0 );
			Spell01;
		}
		else{
			CollectItemRemain(180);
			SetPlayerInvincibility(180);
			UseSpellCard("stopwatch",0);
			Spell02;
		}
	}
	b_LastSpell = false;
}


}
/*
include_script ".\txt\Spell_Red.dnh"
include_script ".\txt\Spell_Scarlet.dnh"
include_script ".\txt\Spell_HeartBreak.dnh"
include_script ".\txt\Spell_Gungnir.dnh"
include_script ".\txt\Spell_Fate.dnh"
include_script ".\txt\Spell_Fate2.dnh"
*/
#include_script ".\txt\Spell_stopwatch.dnh"
#include_script ".\txt\Spell_dummy.dnh"
#include_script ".\txt\Spell_F.dnh"



