#include "../Default_Functions.txt"

@Initialize {
SetDefaultBonusItemEnable(false);
}

@MainLoop {
	yield;
}

@Event {
	alternative(GetEventType())
	case(EV_GET_ITEM) {
		let itemType = GetEventArgument(0);
		alternative(itemType)
		case(1) {
		PlaySound("item",255,0);
		}
		case(2) {
		PlaySound("item",255,0);
		}
		case(3) {
		PlaySound("extend",255,0);
		Extend;
		SetPlayerLife(GetPlayerLife + 1);
		}
		case(4) {
		PlaySound("bombget",255,0);
		SetPlayerSpell(GetPlayerSpell + 1);
		}
		case(5) {
		PlaySound("item",255,0);
		}
	}
	case(EV_DELETE_SHOT_TO_ITEM){
		//BulletScore(GetEventArgument(1));
		BulletDelete(GetEventArgument(0), GetEventArgument(1));
	}
}

task BulletDelete(bullet, pos){
	if(ObjShot_GetImageID(bullet) == 0){return;} 
	let c = GetShotDataInfoA1(ObjShot_GetImageID(bullet), TARGET_ENEMY, INFO_DELAY_COLOR);

	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, GetCurrentScriptDirectory() ~ "../img/bulletbreak.png");
	ObjSprite2D_SetSourceRect(obj, 0, 0, 32, 32);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj, 1.5, 1.5, 1.5);
	ObjRender_SetColor(obj, c[0], c[1], c[2]);
	ObjRender_SetPosition(obj, pos[0], pos[1], 0);
	ObjRender_SetAngleZ(obj, rand(0, 360));
	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);

	if(c == [0, 0, 0]){ObjRender_SetBlendType(obj, BLEND_ALPHA);}

	ascent(i in 0 .. 8){
		ObjSprite2D_SetSourceRect(obj, 32*i, 0, 32*(i+1), 32);
		loop(2){yield;}
	}
	Obj_Delete(obj);
}

task BulletScore(pos){
	let obj	= CreateItemU2(5, pos[0], pos[1], pos[0], pos[1]-32, 25);
	ObjItem_SetRenderScoreEnable(obj, false);
	
	ObjItem_SetDefinedMovePatternA1(obj, ITEM_MOVE_TOPLAYER);
	
	while(!Obj_IsDeleted(obj)){
		yield;
	}
}