#東方弾幕風
#Title[縛符「呪縛の道-Easy」]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
    let name    = "縛符「呪縛の道-Easy」";
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_komachi.png"; 
    let imgFam  = csd ~ "img\familiar.png";
    let imgBG  = csd ~ "..\img\st5bg1.png";
SetRateScoreSystemEnable(false);
    // 初期位置
    let xIni    = GetCenterX;
    let yIni    = GetClipMinY + 128;
	let wIni=60;
	let DrawY=330;
	let count=-wIni;

	#include_function ".\..\txt\SpellCardBonusDefine.txt"
	let SpellTimer=50;

	let bgx=0;
	let bgy=0;
    @Initialize {

       LoadUserShotData(GetCurrentScriptDirectory~".\..\img\ShotData.txt");
	StartSpellHistory(67);

        SetLife(900);
        SetDamageRate(1, 1);
        LoadGraphic(imgBoss);
        LoadGraphic(imgBG);
	InitializeAction();
        TMain;
    }

    @MainLoop {
	GetBossShadowPosition;
        SetCollisionA(GetX, GetY, 48);
        SetCollisionB(GetX, GetY, 8);
	Bonus=GetSpellCardBonusScore-(SpellBonus*3)/(SpellTimer*60);
        yield;
		bgx+=3;
		bgy+=3;
    }

    @DrawLoop {
	DrawBossShadow( imgBoss,150,0,255,0);
	DrawBoss( imgBoss );
	DrawSpellHistory;
    }

    @Finalize {
		DeleteGraphic(imgBoss);
		EndSpellHistory(67);
	loop(30)
	{
		ItemSet(GetX+rand(-40,40),GetY+rand(-40,40),1);
		ItemSet(GetX+rand(-40,40),GetY+rand(-40,40),2);
	}
    }
	@BackGround
	{
		SetTexture(imgBG);
		SetGraphicRect(0,0,1280+bgx,960+bgy);
		SetColor(150,150,150);
		SetAlpha(100);
		DrawGraphic(224, 240);

	}
    // メインタスク
task TMain 
{
	standBy;
	spell;
	Trate;
	Shot;
	SubShot;
	//SubShot2;
	move;
}

task Trate
{
	while(OnBomb==true){yield;}
	wait(120);
        SetDamageRate(25, 25);
}

task move
{
	loop
	{
	wait(60);
	moveToPlayer(rand(20, 30), rand(-15, 15), 15,
                     GetClipMinX + 48, GetClipMinY +  32,
                     GetClipMaxX - 48, GetClipMinY + 128);
	wait(30);
	}
}


sub standBy//初期位置へ
{
	SetAction(ACT_MOVE, wIni);
	SetMovePosition02(xIni, yIni, wIni);
	SetInvincibility(wIni);
	wait(wIni);
}

sub spell//発動モーション
{
        CutIn(YOUMU, name, "", 0, 0, 0, 0);
        SetTimer(SpellTimer);
        SetScore(SpellBonus);
	SetAction(ACT_SPELL,90);
	wait(90);
}


task Shot
{
loop
{
	snake2(1);
	wait(270);
}
}

task SubShot
{
let angle=rand(0,360);
loop
{
	ascent(let i in 0..10)
	{
	//	CreateShot01(GetX,GetY,2,angle+i*15,103,20);
		CreateShot01ToItem(GetX,GetY,2,angle+i*15,103,20);
	}
	ascent(let i in 0..10)
	{
	//	CreateShot01(GetX,GetY,2,angle+180+i*15,108,20);
		CreateShot01ToItem(GetX,GetY,2,angle+180+i*15,108,20);
	}
angle+=6;
wait(20);
}
}

task SubShot2
{
	loop
	{
		loop(5)
		{
			SetShotDirectionType(PLAYER);
			CreateShot01(rand(GetClipMinX,GetClipMaxX),GetClipMinY,3,0,46,20);
			SetShotDirectionType(ABSOLUTE);
		}
		wait(60);
	}
}

task snake2(let dir)
{
	let length=0;
	let wid=120;
	let obj= Obj_Create(OBJ_LASER);
	Obj_SetPosition(obj,GetPlayerX, GetClipMinY);
	ObjLaser_SetWidth(obj,wid);
	ObjLaser_SetLength(obj,length);
	ObjLaser_SetSource(obj,false);
        ObjShot_SetGraphic(obj,100);   
	Obj_SetAngle(obj,90);
	ObjShot_SetDelay(obj,90);
	Obj_SetAutoDelete(obj,false);
	Obj_SetCollisionToPlayer(obj,false);
	Obj_SetAlpha(obj,150);

	loop(90)
	{
		ObjLaser_SetLength(obj,length);
		length+=10;
		yield;
	}
	Obj_SetAlpha(obj,75);
	let speedhi=GetPlayerInfo(PLAYER_SPEED_HIGH);
	let speedlow=GetPlayerInfo(PLAYER_SPEED_LOW);
	loop(360)
	{
	if(GetTimeOfPlayerInvincibility==0)
	{
		if(GetPlayerX>Obj_GetX(obj)-wid/2 && GetPlayerX<Obj_GetX(obj)+wid/2)
		{
			if(GetKeyState(VK_LEFT)==KEY_PUSH || GetKeyState(VK_LEFT)==KEY_HOLD)
			{
				if(GetKeyState(VK_SLOWMOVE)==KEY_PUSH || GetKeyState(VK_SLOWMOVE)==KEY_HOLD)
				{
					if(GetKeyState(VK_UP)==KEY_PUSH || GetKeyState(VK_UP)==KEY_HOLD || GetKeyState(VK_DOWN)==KEY_PUSH || GetKeyState(VK_DOWN)==KEY_HOLD)
					{
						SetPlayerX(GetPlayerX+speedlow/(2^0.5)/2);
					}
					else
					{
						SetPlayerX(GetPlayerX+speedlow/2);
					}
				}
				else
				{
					if(GetKeyState(VK_UP)==KEY_PUSH || GetKeyState(VK_UP)==KEY_HOLD || GetKeyState(VK_DOWN)==KEY_PUSH || GetKeyState(VK_DOWN)==KEY_HOLD)
					{
						SetPlayerX(GetPlayerX+speedhi/(2^0.5)/2);
					}
					else
					{
						SetPlayerX(GetPlayerX+speedhi/2);
					}
				}
			}
			if(GetKeyState(VK_RIGHT)==KEY_PUSH || GetKeyState(VK_RIGHT)==KEY_HOLD)
			{
				if(GetKeyState(VK_SLOWMOVE)==KEY_PUSH || GetKeyState(VK_SLOWMOVE)==KEY_HOLD)
				{
					if(GetKeyState(VK_UP)==KEY_PUSH || GetKeyState(VK_UP)==KEY_HOLD || GetKeyState(VK_DOWN)==KEY_PUSH || GetKeyState(VK_DOWN)==KEY_HOLD)
					{
						SetPlayerX(GetPlayerX-speedlow/(2^0.5)/2);
					}
					else
					{
						SetPlayerX(GetPlayerX-speedlow/2);
					}
				}
				else
				{
					if(GetKeyState(VK_UP)==KEY_PUSH || GetKeyState(VK_UP)==KEY_HOLD || GetKeyState(VK_DOWN)==KEY_PUSH || GetKeyState(VK_DOWN)==KEY_HOLD)
					{
						SetPlayerX(GetPlayerX-speedhi/(2^0.5)/2);
					}
					else
					{
						SetPlayerX(GetPlayerX-speedhi/2);
					}
				}
			}
		}
	}
		yield;
	}
	loop(12)
	{
		ObjLaser_SetWidth(obj,wid);
		wid-=10;
		yield;
	}
	Obj_Delete(obj);
}

task CreateShadow(let obj)
{
		CreateShotA(0,Obj_GetX(obj),Obj_GetY(obj),60);
		SetShotDataA(0,0,0,0,0,0,0,PURPLE03);
		SetShotKillTime(0,0);
		FireShot(0);
}

function moveToPlayer(xMove, yAdd, frame, left, top, right, bottom)
{
	let x;
	let y;

	if(GetPlayerX < GetX)
	{
		x = GetX - xMove;
		if(x < left)
		{
		x = GetX + xMove;
		}
	}
	else
	{
		x = GetX + xMove;
		if(right < x)
		{
			x = GetX - xMove;
		}
	}

	y = GetY + yAdd;
	if(y < top)
	{
		y = top;
	}
	else if(bottom < y)
	{
		y = bottom;
        }

        SetMovePosition02(x, y, frame);
	SetAction(ACT_MOVE,60);
}

#include_function ".\..\txt\data.txt"
#include_function ".\..\txt\Spelldata.txt"
#include_function ".\..\lib/lib_anime_Komachi.txt"
}
