let itempic="lib\Item.png";
LoadGraphic(itempic); //Declare and load the graphic used

task itemdrop(type, x, y)
{
	SetCommonData("gone", 0);
   let yacc=-5; //so that the item jumps up when spawned like in touhou games
   let collection=0; //checks if the item's moving to the player (also used it to control how fast the item's moving toward the player)
   let xpos=x;
   let ypos=y;
   let obj=Obj_Create(OBJ_EFFECT);
   ObjEffect_SetTexture(obj, itempic);
   ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
   ObjEffect_CreateVertex(obj, 4); //declare the effect object
   if(type=="POWER_S") //set UV rects... change this depending on the image you're using
   {
   ObjEffect_SetVertexUV(obj, 0, 57, 19);
   ObjEffect_SetVertexUV(obj, 1, 73, 19);
   ObjEffect_SetVertexUV(obj, 2, 73, 35);
   ObjEffect_SetVertexUV(obj, 3, 57, 35);
   }
   if(type=="POINT")
   {
   ObjEffect_SetVertexUV(obj, 0, 0, 19);
   ObjEffect_SetVertexUV(obj, 1, 16, 19);
   ObjEffect_SetVertexUV(obj, 2, 16, 35);
   ObjEffect_SetVertexUV(obj, 3, 0, 35);
   }
   if(type=="COLLECT") //Collect's just some extra item for my game :V
   {
   ObjEffect_SetVertexUV(obj, 0, 112, 0);
   ObjEffect_SetVertexUV(obj, 1, 128, 0);
   ObjEffect_SetVertexUV(obj, 2, 112, 16);
   ObjEffect_SetVertexUV(obj, 3, 128, 16);
   }
   if(type=="COLLECT_L")
   {
   ObjEffect_SetVertexUV(obj, 0, 32, 0);
   ObjEffect_SetVertexUV(obj, 1, 48, 0);
   ObjEffect_SetVertexUV(obj, 2, 32, 16);
   ObjEffect_SetVertexUV(obj, 3, 48, 16);
   }
   if(type=="POWER_L")
   {
   ObjEffect_SetVertexUV(obj, 0, 57, 0);
   ObjEffect_SetVertexUV(obj, 1, 73, 0);
   ObjEffect_SetVertexUV(obj, 2, 73, 16);
   ObjEffect_SetVertexUV(obj, 3, 57, 16);
   }
   if(type=="POWER_F")
   {
   ObjEffect_SetVertexUV(obj, 0, 96, 0);
   ObjEffect_SetVertexUV(obj, 1, 112, 0);
   ObjEffect_SetVertexUV(obj, 2, 96, 16);
   ObjEffect_SetVertexUV(obj, 3, 112, 16);
   }
   while(Obj_BeDeleted(obj)==false)
   {
   if(ypos>GetClipMaxY+50) //deletes the item if it's way below the bottom of the screen
   {
   Obj_Delete(obj);
   }
   ypos+=yacc; //controls the falling
   if(yacc<2)
   {
   yacc+=0.1;
   }
   ObjEffect_SetVertexXY(obj, 0, xpos-8, ypos-8); //sets XY rects
   ObjEffect_SetVertexXY(obj, 1, xpos+8, ypos-8);
   ObjEffect_SetVertexXY(obj, 2, xpos+8, ypos+8);
   ObjEffect_SetVertexXY(obj, 3, xpos-8, ypos+8);
   if(((xpos-GetPlayerX)^2+(ypos-GetPlayerY)^2)^0.5<=30) //if distance between item and player is less than 30, item moves to the player
   {
   collection=4;
   }
   if(((xpos-GetPlayerX)^2+(ypos-GetPlayerY)^2)^0.5<=10 && OnPlayerMissed==false) //if distance between item and player is less than 10 and player isn't dead, item is collected
   {
      if(type=="POWER_S") //if item is a small power item
      {
      SetCommonData("power", GetCommonData("power")+1);
      AddScore(10);
      }
      if(type=="POWER_L") //if item is a large power item
      {
      SetCommonData("power", GetCommonData("power")+10);
      AddScore(100);
      }
      if(type=="POWER_F") //if item is a full power item
      {
      SetCommonData("power", 128);
      AddScore(1000);
      }
      if(type=="POINT") //if item is a point item... I still have to fix this :V
      {
      if(GetPlayerY>GetClipMinY+120)
      {
      AddScore(truncate(5*(GetCommonData("GRAZE")*100)/(GetPlayerY-GetClipMinY-120))+5000);
      }else{
      AddScore(5000+GetCommonData("GRAZE")*50);
      }
      AddPoint(1);
      }
      if(type=="COLLECT") //if item is a collection item
      {
      SetCommonData("collect", GetCommonData("collect")+1);
      AddScore(50);
      }
      if(type=="COLLECT_L") //if item is a large collection item
      {
      SetCommonData("collect", GetCommonData("collect")+10);
      AddScore(500);
      }
   Obj_Delete(obj);
   }
   if(GetCommonData("power")==128) //if power is full, I turned power items to my extra special item (item_drop is a function that sets common data so that the main stage script creates the items)
   {
      if(type=="POWER_S")
      {
      CreateItem(ITEM_SCORE, Obj_GetX(obj), Obj_GetY(obj));
      Obj_Delete(obj);
      }
      if(type=="POWER_L")
      {
      CreateItem(ITEM_SCORE, Obj_GetX(obj), Obj_GetY(obj));
      Obj_Delete(obj);
      }
   }
   if(GetPlayerY<GetClipMinY+120 || OnBomb==true) //when the player is above the collection line or bombing, and isn't dead collect all the items...
   {
      if(OnPlayerMissed==false)
      {
   collection=10;
      }
   }
   if(IsBossExisting==true) //Collect items disappear when there's a boss
   {
      if(type=="COLLECT"||type=="COLLECT_L")
      {
      Obj_Delete(obj);
      }
   }
   if(collection>=1) //control movement when the item's being collected
   {
   xpos+=collection*cos(atan2(GetPlayerY-ypos, GetPlayerX-xpos));
   ypos+=collection*sin(atan2(GetPlayerY-ypos, GetPlayerX-xpos));
   }
   yield;
   }
}