#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["SampleB03"]
#Text["SampleB03: ObjPatternShot Transforms 2 : Transform Harder"]

#include "script/default_system/Default_ShotConst.txt"

let objEnemy;
let frame = 0;

@Event {
	alternative(GetEventType())
	case(EV_REQUEST_LIFE) {
		SetScriptResult(500);
	}
}

@Initialize {
	objEnemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objEnemy);

	let imgExRumia = GetCurrentScriptDirectory ~ "ExRumia.png";
	ObjPrim_SetTexture(objEnemy, imgExRumia);
	ObjSprite2D_SetSourceRect(objEnemy, 64, 1, 127, 64);
	ObjSprite2D_SetDestCenter(objEnemy);

	let cx = GetStgFrameWidth() / 2;
	ObjMove_SetDestAtFrame(objEnemy, cx, 120, 60);
	
	SetPlayerInvincibilityFrame(600000);
	
	TShot();
}

@MainLoop {
	let ex = ObjMove_GetX(objEnemy);
	let ey = ObjMove_GetY(objEnemy);

	ObjEnemy_SetIntersectionCircleToShot(objEnemy, ex, ey, 32);
	ObjEnemy_SetIntersectionCircleToPlayer(objEnemy, ex, ey, 24);
	
	yield;

	if (ObjEnemy_GetInfo(objEnemy, INFO_LIFE) <= 0) {
		Obj_Delete(objEnemy);
		CloseScript(GetOwnScriptID());
		return;
	}
}

task TShot() {
	let objPattern = ObjPatternShot_Create();
	
	ObjPatternShot_SetParentObject(objPattern, objEnemy);
	ObjPatternShot_SetPatternType(objPattern, PATTERN_RING);
	
	ObjPatternShot_SetDelay(objPattern, 12);
	ObjPatternShot_SetGraphic(objPattern, DS_BALL_S_RED);
	
	ObjPatternShot_SetSpeed(objPattern, 2, 1.2);
	
	ObjPatternShot_SetShotCount(objPattern, 16, 1);
	ObjPatternShot_SetInitialBlendMode(objPattern, BLEND_ADD_ARGB);
	
	ObjPatternShot_AddTransform(objPattern, TRANSFORM_WAIT, 20, 0, 0, 0, 0, 0);
	ObjPatternShot_AddTransform(objPattern, TRANSFORM_N_DECEL_CHANGE, 25, 5, 1, 2.7, 10.12, 0);
	ObjPatternShot_AddTransform(objPattern, TRANSFORM_TO_SPEED_ANGLE, 1, 0, 0, 0.001, NO_CHANGE, 0);
	ObjPatternShot_AddTransform(objPattern, TRANSFORM_WAIT, 60, 0, 0, 0, 0, 0);
	ObjPatternShot_AddTransform(objPattern, TRANSFORM_BLEND_CHANGE, BLEND_ALPHA, 0, 0, 0, 0, 0);
	ObjPatternShot_AddTransform(objPattern, TRANSFORM_GRAPHIC_CHANGE, DS_RICE_S_RED, 0, 0, 0, 0, 0);
	ObjPatternShot_AddTransform(objPattern, TRANSFORM_TO_SPEED_ANGLE, 60, 0, 0, 1.8, NO_CHANGE, 0);
	
	wait(60);
	
	let frame = 0;
	while (ObjEnemy_GetInfo(objEnemy, INFO_LIFE) > 0) {
		ObjPatternShot_SetAngle(objPattern, rand(0, 360), 0);
		
		ObjPatternShot_SetTransform(objPattern, 1, TRANSFORM_N_DECEL_CHANGE, 25, 5, 1, 2.7, 10.4 * sin(frame * 5.212), 0);
		
		ObjPatternShot_Fire(objPattern);
		
		frame++;
		wait(8);
	}
	
	Obj_Delete(objPattern);
}