#include_function ".\variables.txt"
let drawidle = 0;
let drawidle2 = 0;
let drawmove = 0;
let drawframe = 0;
let drawblend = ALPHA;
let exbound = 96;
@Initialize {
	SetLife(5000);
	LoadUserShotData(GCSD ~ "shots.txt");
	TMain;
}
@Finalize {
	SetCommonData("Dead Satori", true);
}
@MainLoop {
	SetCommonData("X Satori", GetX);
	SetCommonData("Y Satori", GetY);
	SetCommonData("Life Satori", GetCommonData("Life Satori")+5000-GetLife);
	SetCommonData("Lower Life", 0);
	AddLife(5000-GetLife);
	if(GetCommonData("Dead Satori") || GetCommonData("Dead Koishi")) { AddLife(-GetLife); }
	if(drawframe == 0) {
		if(GetSpeedX == 0) {
			drawidle++; drawidle%=4;
			if(drawmove > 0) { drawmove--; }
			if(drawidle==0) { drawidle2++; drawidle2%=2; }
		} else {
			drawidle = 0;
			if(drawmove < 3) { drawmove++; }
		}
	}
	drawframe++; drawframe%=8;
	yield;
}
@DrawLoop {
	SetTexture(spriteSatori);
	if(drawmove == 0) {
		SetGraphicRect(0+48*drawidle, 0+64*drawidle2, 48+48*drawidle, 64+64*drawidle2);
	} else {
		SetGraphicRect(0+48*drawmove, 0+64*2, 48+48*drawmove, 64+64*2);
		if(GetSpeedX > 0) {
			SetGraphicScale(1, 1);
		} else if(GetSpeedX < 0) {
			SetGraphicScale(-1, 1);
		}
	}
	SetGraphicAngle(0, 0, 0);
	SetRenderState(drawblend);
	SetAlpha(255);
	SetColor(255, 255, 255);
	DrawGraphic(GetX, GetY);
}
function wait(let frames) { loop(frames) { yield; } }
function PlaySE2(sfxname) { PlaySE(GCSD ~ "se_" ~ sfxname ~ ".wav"); }
function ExMove01_(nBaseHeight, nHorizontal, nAddHeight, nVelocity) {
	if(GetPlayerX < GetX) {
		if(GetX - nHorizontal <= GetClipMinX+exbound) {
			SetMovePosition01(GetX+nHorizontal, nBaseHeight+rand(-nAddHeight, nAddHeight), nVelocity);
		} else {
			SetMovePosition01(GetX-nHorizontal, nBaseHeight+rand(-nAddHeight, nAddHeight), nVelocity);
		}
	} else {
		if(GetX + nHorizontal >= GetClipMaxX-exbound) {
			SetMovePosition01(GetX-nHorizontal, nBaseHeight+rand(-nAddHeight, nAddHeight), nVelocity);
		} else {
			SetMovePosition01(GetX+nHorizontal, nBaseHeight+rand(-nAddHeight, nAddHeight), nVelocity);
		}
	}
}
function ExMove02_(nBaseHeight, nHorizontal, nAddHeight, nFrame) {
	if(GetPlayerX < GetX) {
		if(GetX - nHorizontal <= GetClipMinX+exbound) {
			SetMovePosition02(GetX+nHorizontal, nBaseHeight+rand(-nAddHeight, nAddHeight), nFrame);
		} else {
			SetMovePosition02(GetX-nHorizontal, nBaseHeight+rand(-nAddHeight, nAddHeight), nFrame);
		}
	} else {
		if(GetX + nHorizontal >= GetClipMaxX-exbound) {
			SetMovePosition02(GetX-nHorizontal, nBaseHeight+rand(-nAddHeight, nAddHeight), nFrame);
		} else {
			SetMovePosition02(GetX+nHorizontal, nBaseHeight+rand(-nAddHeight, nAddHeight), nFrame);
		}
	}
}
function ExMove03_(nBaseHeight, nHorizontal, nAddHeight, nWeight, nVelocity) {
	if(GetPlayerX < GetX) {
		if(GetX - nHorizontal <= GetClipMinX+exbound) {
			SetMovePosition03(GetX+nHorizontal, nBaseHeight+rand(-nAddHeight, nAddHeight), nWeight, nVelocity);
		} else {
			SetMovePosition03(GetX-nHorizontal, nBaseHeight+rand(-nAddHeight, nAddHeight), nWeight, nVelocity);
		}
	} else {
		if(GetX + nHorizontal >= GetClipMaxX-exbound) {
			SetMovePosition03(GetX-nHorizontal, nBaseHeight+rand(-nAddHeight, nAddHeight), nWeight, nVelocity);
		} else {
			SetMovePosition03(GetX+nHorizontal, nBaseHeight+rand(-nAddHeight, nAddHeight), nWeight, nVelocity);
		}
	}
}
sub ExMove01 { ExMove01_(GetCenterY-100, rand(15, 50), 30, 1); }
sub ExMove01Slow { ExMove01_(GetCenterY-100, rand(5, 30), 10, 1/2); }
sub ExMove02 { ExMove02_(GetCenterY-100, rand(15, 50), 30, 60); }
sub ExMove02B { ExMove02_(GetCenterY-100, rand(30, 50), 50, 60); }
sub ExMove02Slow { ExMove02_(GetCenterY-100, rand(5, 30), 10, 90); }
sub ExMove03 { ExMove03_(GetCenterY-100, rand(15, 50), 30, 10, 2); }
sub ExMove03Slow { ExMove03_(GetCenterY-100, rand(5, 30), 10, 15, 1); }
sub ExMove { ExMove03; }
sub ExMoveSlow { ExMove03Slow; }

task TCharge(let nX, let nY) {
	CreateChargeEffectCircle(nX, nY);
	loop(30) {
		loop(1) { CreateChargeEffectMaple(nX, nY); }
		loop(1) { yield; }
	}
}
task TExplode(let nX, let nY) {
	loop(50) { CreateExplodeEffectMaple(nX, nY); }
}
task CreateChargeEffectMaple(let nX, let nY) {
	let obj = Obj_Create(OBJ_EFFECT);
	ObjEffect_SetTexture(obj, hudenemy);
	ObjEffect_SetLayer(obj, 3);
	ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	ObjEffect_CreateVertex(obj, 4);
	ObjEffect_SetRenderState(obj, ADD);
	ObjEffect_SetVertexUV(obj, 0, 224, 0);
	ObjEffect_SetVertexUV(obj, 1, 256, 0);
	ObjEffect_SetVertexUV(obj, 2, 256, 32);
	ObjEffect_SetVertexUV(obj, 3, 224, 32);
	ObjEffect_SetVertexXY(obj, 0, -16, -16);
	ObjEffect_SetVertexXY(obj, 1, 16, -16);
	ObjEffect_SetVertexXY(obj, 2, 16, 16);
	ObjEffect_SetVertexXY(obj, 3, -16, 16);
	let radius = 125+rand(-25, 25);
	let angle = rand(0,360);
	let angle2 = rand(0,360); let angle2spin = rand(2, 5)*((-1)^rand_int(0,1));
	let num = 30;
	descent(i in 0..num) {
		Obj_SetPosition(obj, nX+radius*i/num*cos(angle), nY+radius*i/num*sin(angle));
		ObjEffect_SetScale(obj, i/num*4, i/num*4);
		ascent(j in 0..4) { ObjEffect_SetVertexColor(obj, j, 255, (num-i)/num*255, (num-i)/num*255, (num-i)/num*255); }
		ObjEffect_SetAngle(obj, 0, 0, angle2); angle2+=angle2spin; angle2%=360;
		yield;
	}
	Obj_Delete(obj);
}
task CreateChargeEffectCircle(let nX, let nY) {
	let obj = Obj_Create(OBJ_EFFECT);
	ObjEffect_SetTexture(obj, chargeCircle);
	ObjEffect_SetLayer(obj, 3);
	ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	ObjEffect_CreateVertex(obj, 4);
	ObjEffect_SetRenderState(obj, ADD);
	ObjEffect_SetVertexUV(obj, 0, 0, 0);
	ObjEffect_SetVertexUV(obj, 1, 512, 0);
	ObjEffect_SetVertexUV(obj, 2, 512, 512);
	ObjEffect_SetVertexUV(obj, 3, 0, 512);
	ObjEffect_SetVertexXY(obj, 0, -256, -256);
	ObjEffect_SetVertexXY(obj, 1, 256, -256);
	ObjEffect_SetVertexXY(obj, 2, 256, 256);
	ObjEffect_SetVertexXY(obj, 3, -256, 256);
	Obj_SetPosition(obj, nX, nY);
	let num = 60; let alpha = 1/2;
	descent(i in 0..num) {
		ObjEffect_SetScale(obj, i/num*7/8, i/num*7/8);
		ascent(j in 0..4) { ObjEffect_SetVertexColor(obj, j, 255, (num-i)/num*155*alpha, (num-i)/num*0*alpha, (num-i)/num*155*alpha); }
		yield;
	}
	Obj_Delete(obj);
}
task CreateExplodeEffectMaple(let nX, let nY) {
	let obj = Obj_Create(OBJ_EFFECT);
	ObjEffect_SetTexture(obj, hudenemy);
	ObjEffect_SetLayer(obj, 3);
	ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	ObjEffect_CreateVertex(obj, 4);
	ObjEffect_SetRenderState(obj, ADD);
	ObjEffect_SetVertexUV(obj, 0, 224, 0);
	ObjEffect_SetVertexUV(obj, 1, 256, 0);
	ObjEffect_SetVertexUV(obj, 2, 256, 32);
	ObjEffect_SetVertexUV(obj, 3, 224, 32);
	ObjEffect_SetVertexXY(obj, 0, -16, -16);
	ObjEffect_SetVertexXY(obj, 1, 16, -16);
	ObjEffect_SetVertexXY(obj, 2, 16, 16);
	ObjEffect_SetVertexXY(obj, 3, -16, 16);
	let scale = 2+rand(-1,1);
	ObjEffect_SetScale(obj, scale, scale);
	let radius = 0; let radout = rand(6,30)/8;
	let angle = rand(0,360);
	let angle2 = rand(0,360); let angle2spin = rand(2, 5)*((-1)^rand_int(0,1));
	let num = 90;
	descent(i in 0..num) {
		Obj_SetPosition(obj, nX+radius*cos(angle), nY+radius*sin(angle));
		radius+=radout;
		ascent(j in 0..4) { ObjEffect_SetVertexColor(obj, j, 255, (i)/num*255, (i)/num*255, (i)/num*255); }
		ObjEffect_SetAngle(obj, 0, 0, angle2); angle2+=angle2spin; angle2%=360;
		yield;
	}
	Obj_Delete(obj);
}