script_enemy_main
{    
    let imgEnemy="script\DanMUku\Stage1\Image\ParagoombaN.png";
    let count=-100;
    let a=0;
    let b=40;
    let y = 0;
    let circle = [];
    let angle=1;
    let d = 0;
    let tir ="script\DanMUku\Stage1\Son\tir.wav";
    let munch ="script\DanMUku\Stage1\Son\muncher.wav";

   @Initialize
   {
      LoadGraphic(imgEnemy);
      LoadSE(tir);
      LoadSE(munch);
            SetLife(400); 
   }
   
   @MainLoop
   {
          SetCollisionA(GetX, GetY, 32);
        SetCollisionB(GetX, GetY, 16);
if(count%10==0)
{
if(a==120)
{
a=0;
b=40;
}
else
{
a+=40;
b+=40;
}
}
if(count==50)
{
SetSpeed(0);
if(GetArgument==0)
{
loop(50)
{
PlaySE(tir);
Bullet(-sin(y*5)*30+GetX, y+GetY, angle, AQUA01, d);
y+=12;
angle=-angle;
d+=2
}
}
if(GetArgument==1)
{
loop(50)
{
PlaySE(tir);
Bullet(-sin(y*5)*30+GetX, y+GetY, angle, GREEN01, d);
y+=12;
angle=-angle;
d+=2;
}
}
}
if(count==100&&GetArgument==0)
{
    let i = 0;
while (i < length(circle))
{
   if (Obj_BeDeleted(circle[i]))
   {
      circle = erase(circle, i);
      i--;
   }
   else
   {
      let obj = circle[i];
      Obj_SetSpeed(obj, 1);
      ObjShot_SetGraphic(obj, GREEN01);
      PlaySE(munch);
   }
   i++;
}
}
if(count==100&&GetArgument==1)
{
    let i = 0;
while (i < length(circle))
{
   if (Obj_BeDeleted(circle[i]))
   {
      circle = erase(circle, i);
      i--;
   }
   else
   {
      let obj = circle[i];
      Obj_SetSpeed(obj, 1);
      ObjShot_SetGraphic(obj, AQUA01);
      PlaySE(munch);
   }
   i++;
}
}
if(count==200)
{
SetSpeed(2);
}
count++;
yield;
   }
   @Finalize
   {
CreateItem(ITEM_SCORE, rand(GetX-10, GetX+10), rand(GetY-10, GetY+10));  
CreateItem(ITEM_SCORE, rand(GetX-10, GetX+10), rand(GetY-10, GetY+10));  
CreateItem(ITEM_SCORE, rand(GetX-10, GetX+10), rand(GetY-10, GetY+10));  
CreateItem(ITEM_SCORE, rand(GetX-10, GetX+10), rand(GetY-10, GetY+10));  
	if (GetX>0&&GetY>0&&GetX<448&&GetY<480&&GetCommonData("goomba")>=0) {
		SetCommonData("goomba", GetCommonData("goomba")+1);
		if (GetCommonData("goomba")==50) {
			SetCommonData("N", true);
		}
	}
DeleteEnemyShotToItem(CHILD);
}
   
   @DrawLoop
   {
            SetColor(255,255,255);
            SetRenderState(ALPHA);
            SetTexture(imgEnemy);
            SetGraphicRect(a, 0, b, 59);
            DrawGraphic(GetX,GetY);
   }

   task Bullet(x, y, angle, graphic, delay) {
  let obj_id=Obj_Create(OBJ_SHOT);

     Obj_SetPosition(obj_id, x, y);
     Obj_SetAngle(obj_id, angle*90+90);
     Obj_SetSpeed(obj_id, 0);
     ObjShot_SetGraphic(obj_id, graphic);
     ObjShot_SetDelay  (obj_id, delay);
     circle = circle ~ [obj_id];
     while(Obj_BeDeleted(obj_id)==false) {
             yield;
      }
}
}
