#TouhouDanmakufu[Single]
#Title[Koishi - Spell #5]
#BackGround[User(.\bgNon.png, 0, 0)]
#BGM[.\music0.mp3]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main {

	#include_function ".\Include.~ath"

	task codeInit {
		SetLife(10000); SetTimer(62);
		SetMovePosition03(GetCenterX, GetCenterY/2, 10, 4);
		cutin("Response "\""Baseline Test"\",imgBossCut,0,0,255,511); SetScore(1000000);
		SetInvincibility(120);
		wait(120);
		LoadUserShotData(GCSD ~ "ShotDefine2.~ath");
		MoveAroundEasy;
		attack1;
		attack2;
	}
	task MoveAroundEasy {
		let obj = Obj_Create(OBJ_EFFECT);
		Obj_SetPosition(obj, 640-112, 240+128);
		ObjEffect_SetTexture(obj, imgMoveEasy);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetLayer(obj, 8);
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -96, -96);
		ObjEffect_SetVertexXY(obj, 1, 96, -96);
		ObjEffect_SetVertexXY(obj, 2, 96, 96);
		ObjEffect_SetVertexXY(obj, 3, -96, 96);
		ObjEffect_SetVertexUV(obj, 0, 0, 0);
		ObjEffect_SetVertexUV(obj, 1, 192, 0);
		ObjEffect_SetVertexUV(obj, 2, 192, 192);
		ObjEffect_SetVertexUV(obj, 3, 0, 192);
		ascent(i in 0..360) {
			ascent(j in 0..4) { ObjEffect_SetVertexColor(obj, j, 255*sin(i/2), 255, 255, 255); }
			yield;
		}
	}
	task attack1 {
		let arg = 0;
		loop {
			Laser(arg); arg+=1; arg%=8;
			wait(150);
		}
	}
	task attack2 {
		loop {
			SetMovePosition03(GetPlayerX, GetCenterY/2+rand(-50,50), 12, 6); 
			wait(150);
		}
	}
	task Laser(arg) {
		PlaySE2("se_shot_laser");
		let gra = [RED11, BLUE11][(arg+[0,1][arg>=4])%2];
		let ang = [0, 90, 180, 270][arg%4];
		let ang2 = ang+90;
		let x = [GetClipMinX, GetClipMaxX, GetClipMaxX, GetClipMinX][arg%4];
		let y = [GetClipMinX, GetClipMinY, GetClipMaxY, GetClipMaxY][arg%4];
		let obj = Obj_Create(OBJ_LASER);
		Obj_SetPosition(obj, x, y); ObjShot_SetGraphic(obj, gra);
		Obj_SetAngle(obj, ang); ObjLaser_SetLength(obj, 500);
		ObjLaser_SetWidth(obj, 10); ObjLaser_SetSource(obj, false);
		Obj_SetCollisionToPlayer(obj, false); Obj_SetAlpha(obj, 155);
		while(!Obj_BeDeleted(obj)) {
			PlaySE2("se_shot_tan");
			alternative(arg)
			case(0) {
				ascent(i in 0..2) { CreateShot01(GetClipMaxX-GetPlayerX, Obj_GetY(obj), 2, 0+i*360/2, RED23, 5); }
			}
			case(1) {
				ascent(i in 0..2) { CreateShot01(Obj_GetX(obj), GetClipMaxY-GetPlayerY, 2, 90+i*360/2, DBLUE23, 5); }
			}
			case(2) {
				ascent(i in 0..2) { CreateShot01(GetPlayerX+75, Obj_GetY(obj), 2, 0+i*360/2, RED23, 5); }
			}
			case(3) {
				ascent(i in 0..2) { CreateShot01(Obj_GetX(obj), GetPlayerY-75, 2, 0+i*360/2, DBLUE23, 5); }
			}
			case(4) {
				ascent(i in 0..2) { CreateShot01(GetClipMaxX-GetPlayerX, Obj_GetY(obj), 2, 0+i*360/2, DBLUE23, 5); }
			}
			case(5) {
				ascent(i in 0..2) { CreateShot01(Obj_GetX(obj), GetClipMaxY-GetPlayerY, 2, 90+i*360/2, RED23, 5); }
			}
			case(6) {
				ascent(i in 0..2) { CreateShot01(GetPlayerX-75, Obj_GetY(obj), 2, 0+i*360/2, DBLUE23, 5); }
			}
			case(7) {
				ascent(i in 0..2) { CreateShot01(Obj_GetX(obj), GetPlayerY-75, 2, 0+i*360/2, RED23, 5); }
			}
			loop(8) {
				wait(1);
				Obj_SetPosition(obj, Obj_GetX(obj)+pi/5*cos(ang2), Obj_GetY(obj)+pi/5*sin(ang2));
			}
		}
	}
}