using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class screensize
{
 [RuntimeInitializeOnLoadMethod]
 static void OnRuntimeMethodLoad()
 {
  Screen.SetResolution(1280,720,false);
 }
}
public class o_kuru : MonoBehaviour
{
 int flg=-1;int count=0;int wait=0;int spacewait=0;int level=0;int score=0;int times=0;int outflg=0;
 int px;int py;int pt;int banx;int bany;int banxx;int banyy;int banw;int ttype;int tcount;int ntwait;
 int ptcount;int kingx;int kingy;int kingxx;int kingyy;int kingj;int kingw;int kingww;int kingdw;int kinghp;

 int[] pdx=new int[34];int[] pdy=new int[34];int[] pdxx=new int[34];int[] pdyy=new int[34];
 int[] tx=new int[120];int[] ty=new int[120];int[] txx=new int[120];int[] tyy=new int[120];
 int[] tt=new int[120];int[] tj=new int[120];int[] tw=new int[120];int[] thp=new int[120];
 float[] txf=new float[120];float[] tyf=new float[120];int[] tkaku=new int[120];
 float[] tdxf=new float[400];float[] tdyf=new float[400];float[] tdxxf=new float[400];float[] tdyyf=new float[400];
 string[] datas=new string[700];
 int i;int j;int k;int z;int zx;int zy;int r;int ee;int a;int aa;int aaa;int x;int y;int r1;int r2;int ax;int ay;
 int xx;int yy;int ii;int jj;int kk;int a1;int a2;int a3;int a4;
 int kakudo;
 int e;int e1;int moves;int mousex;int mousey;
 float pxf;float pxxf;float pyf;float pyyf;
 float stimef;float ntimef;float stime2f;float ntime2f;float stime3f;float ntime3f;float stime4f;float ntime4f;
 float xf;float yf;float af;float kakuf;float axf;float ayf;
 string c1;string c2;string c3;string c4;
 string d;string dd;string d1;string d2;string d3;string d4;
 GUIStyle style1;GUIStyle style2;GUIStyle style3;
 GameObject[] obj=new GameObject[2000];
 AudioSource bgm1;AudioSource bgm2;AudioSource bgm3;

 void Start()
 {
  style1=new GUIStyle();style1.fontSize=40;style1.normal.textColor=Color.red;
  style2=new GUIStyle();style2.fontSize=16;
  style3=new GUIStyle();style3.fontSize=24;style3.normal.textColor=Color.red;
  obj[0]=GameObject.Find("ng-mes"); // 0  ng-mes
  for (i=1;i<=8;i++) {obj[i]=GameObject.Find("o-kuru-"+i);} // 1-8  koma-moji-moto
  for (i=1;i<=2;i++) {obj[i+8]=GameObject.Find("o-kuru-"+(i+10));} // 9-10  koma-color-moto
  for (i=1;i<=3;i++) {obj[i+10]=GameObject.Find("o-kuru-king-"+i);} // 11-13  king
  for (i=1;i<=4;i++) {obj[i+13]=GameObject.Find("o-kuru-out-"+i);} // 14-17  koma-out-moto
  for (i=1;i<=3;i++) {obj[i+17]=GameObject.Find("dan-"+i);} // 18-20  dans-moto
  obj[21]=GameObject.Find("o-kuru-ban"); // 21  moving-board
  obj[23]=GameObject.Find("gameover-mes-1"); // 23  gameover-mes-blue
  obj[24]=GameObject.Find("gameover-mes-2"); // 24  gameover-mes-green
  obj[25]=GameObject.Find("gameclear-mes-1"); // 25  gameclear-mes-blue
  obj[26]=GameObject.Find("gameclear-mes-2"); // 26  gameclear-mes-green
  obj[27]=GameObject.Find("title-4lv"); // 27  title
  obj[28]=GameObject.Find("ya-r-32x32"); // 28  ya
  obj[29]=GameObject.Find("o-kuru-out-5"); // 29  player-out-red
  obj[30]=GameObject.Find("o-kuru-out-6"); // 30  player-out-yellow
  for (i=0;i<=19;i++)
  {
   obj[i+40]=Object.Instantiate(obj[8]) as GameObject; // 40-59  enemy-c-kao-copy
   obj[i+60]=Object.Instantiate(obj[9]) as GameObject; // 60-79  enemy-c-color1-copy
   obj[i+80]=Object.Instantiate(obj[10]) as GameObject; // 80-99  enemy-c-color2-copy
   obj[i+100]=Object.Instantiate(obj[14]) as GameObject; // 100-119  enemy-c-out-1-copy
   obj[i+120]=Object.Instantiate(obj[15]) as GameObject; // 120-139  enemy-c-out-2-copy
  }
  for (i=0;i<=99;i++)
  {
   obj[i+200]=Object.Instantiate(obj[8]) as GameObject; // 200-299  enemy-s-kao-copy
   obj[i+300]=Object.Instantiate(obj[9]) as GameObject; // 300-399  enemy-s-color1-copy
   obj[i+400]=Object.Instantiate(obj[14]) as GameObject; // 400-499  enemy-s-out-1-copy
   obj[i+500]=Object.Instantiate(obj[15]) as GameObject; // 500-599  enemy-s-out-2-copy
  }
  for (i=0;i<=3;i++)
  {
   obj[i+166]=Object.Instantiate(obj[20]) as GameObject; // 166-169  player-lasers-copy
  }
  for (i=0;i<=29;i++)
  {
   obj[i+170]=Object.Instantiate(obj[18]) as GameObject; // 170-199  player-dans-copy
  }
  for (i=0;i<=399;i++)
  {
   obj[i+600]=Object.Instantiate(obj[19]) as GameObject; // 600-999  enemy-dans-copy
  }
  for (i=0;i<=9;i++)
  {
   obj[i+1200]=GameObject.Find("num-16a-"+i); // 1200-1209  nums-moto
   for (j=1;j<=5;j++) {obj[j*10+i+1200]=Object.Instantiate(obj[i+1200]) as GameObject;} // 1210-1259  nums-copy
  }
  bgm1=obj[1].GetComponent();bgm2=obj[2].GetComponent();
  bgm3=obj[3].GetComponent();
  count=500;flg=-1;
  alldel();
  z=0;zx=0;zy=0;objput();
  count=500;flg=-1;
 }

 void Update()
 {
  Vector3 mpos=Input.mousePosition;
//  xf=mpos.x;yf=mpos.y;
//  if (flg>-9) {xf=xf*640/mfx;yf=yf*360/mfy;}
// mousex=(int)xf;mousey=(int)yf;
//  c1="X="+mousex.ToString()+" Y="+mousey.ToString();
  if (flg==-1)
  {
   count=count-1;
   if (Input.GetMouseButtonDown(0)) {count=0;}
   if (Input.GetMouseButtonDown(1)) {count=0;}
   if (Input.GetKeyDown(KeyCode.Space)) {count=0;spacewait=2;}
   if (Input.GetKeyDown(KeyCode.Return)) {count=0;}
   if (count<=0)
   {
    titleput();flg=0;spacewait=2;
   }
  }
  if (flg==0)
  {
   if (spacewait>0) {spacewait=spacewait-1;}
   if (Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.Keypad8))
   {
    level=level-1;if (level<0) {level=3;}
    z=28;zx=-94;zy=98-level*40;objput();
   }
   if (Input.GetKeyDown(KeyCode.DownArrow) || Input.GetKeyDown(KeyCode.Keypad2))
   {
    level=level+1;if (level>3) {level=0;}
    z=28;zx=-94;zy=98-level*40;objput();
   }
   if (Input.GetKeyDown(KeyCode.Space))
   {
    if (spacewait<=0) {gamestart();}
   }
  }
  if (flg==1)
  {
   if (spacewait>0) {spacewait=spacewait-1;}
// board-move
   banw=banw-1;
   if (banw<=0)
   {
    xx=1;yy=1;
    if (banxx<0) {xx=-1;}
    if (banyy<0) {yy=-1;}
    if (level==0) {banxx=0;banyy=0;}
    if (level==1) {banyy=0;}
    x=2;y=2;r1=Random.Range(0,3);if (r1>2) {r1=2;}
    if (r1==1) {x=1;}
    if (r1==2) {y=1;}
    banx=banx+banxx;bany=bany+banyy;
    if (banx>=level*50+100 && banxx>0) {banx=level*50+100;banxx=x*-1;banyy=y*yy;}
    if (banx<=level*-50-100 && banxx<0) {banx=level*-50-100;banxx=x;banyy=y*yy;}
    if (level>=2)
    {
     if (bany>=(level-1)*50 && banyy>0) {bany=(level-1)*50;banxx=x*xx;banyy=y*-1;}
     if (bany<=(level-1)*-50 && banyy<0) {bany=(level-1)*-50;banxx=x*xx;banyy=y;}
    }
    z=21;zx=banx;zy=bany;objput();
    banw=5;
   }
// player-move
   if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.Keypad4)) {px=px-6;}
   if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.Keypad6)) {px=px+6;}
   if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.Keypad8)) {py=py+6;}
   if (Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.Keypad2)) {py=py-6;}
   if (px<-376) {px=-376;}
   if (px>376) {px=376;}
   if (py<-224) {py=-224;}
   if (py>224) {py=224;}
   if (pxbanx+206) {px=banx+206;}
   if (pybany+204) {py=bany+204;}
   z=pt;zx=px;zy=py;objput();z=9;objput();
   if (Input.GetKeyDown(KeyCode.Space) && spacewait<=0) {plshot();}
// pldan-move
   for (i=0;i<=33;i++)
   {
    if (pdx[i]>-999)
    {
     pdx[i]=pdx[i]+pdxx[i];pdy[i]=pdy[i]+pdyy[i];
     if (i>=30)
     {
      if (pdx[i]<=-422 || pdx[i]>=422 || pdy[i]<=-278 || pdy[i]>=278) {pdx[i]=-1000;pdy[i]=0;}
      z=i+136;zx=pdx[i];zy=pdy[i];objput();
     }
     else
     {
      if (pdx[i]<=-408 || pdx[i]>=408 || pdy[i]<=-258 || pdy[i]>=258) {pdx[i]=-1000;pdy[i]=0;}
      z=i+170;zx=pdx[i];zy=pdy[i];objput();
     }
    }
   }
// enemy-s-move
   ntwait=ntwait-1;
   if (ntwait<=0) {newenemy();}
   for (i=0;i<=99;i++)
   {
    if (tx[i]>-999)
    {
     if (tt[i]>=1 && tt[i]<=6)
     {
      tw[i]=tw[i]+1;
      ty[i]=ty[i]+tyy[i];
      if (tw[i]%4==0 || tt[i]>=5)
      {
       tx[i]=tx[i]+txx[i];
       if (tx[i]<=-376 && txx[i]<0) {tx[i]=-376;txx[i]=txx[i]*-1;}
       if (tx[i]>=376 && txx[i]>0) {tx[i]=376;txx[i]=txx[i]*-1;}
      }
     }
     if (tt[i]>=5 && tt[i]<=6 && tw[i]%12==0)
     {
      a=tj[i];
      if (a==1)
      {
       txx[i]=txx[i]-(tt[i]-4);
       if (txx[i]<=(tt[i]-4)*-3) {tj[i]=2;}
      }
      else
      {
       txx[i]=txx[i]+(tt[i]-4);
       if (txx[i]>=(tt[i]-4)*3) {tj[i]=1;}
      }
     }
     if (ty[i]<=-276) {tx[i]=-1000;ty[i]=0;}
     a=(4-level)*120;
     if (tx[i]>-1000 && ty[i]>=-224 && tw[i]%a==0 && tt[i]<=6 && level>0) {tdset();}
     if (tt[i]>=1 && tt[i]<=6) {z=i+200;zx=tx[i];zy=ty[i];objput();z=i+300;objput();}
     if (tt[i]>=9)
     {
      tw[i]=tw[i]-1;
      if (tw[i]<=0)
      {
       z=i+400;zx=-2000;zy=0;objput();z=i+500;objput();
       tx[i]=-2000;ty[i]=0;
      }
     }
    }
   }
// king-move
   if (kingj==5)
   {
    kingww=kingww-1;
    if (kingww<=0) {kingj=2;kingww=(4-level)*200;}
   }
   if (kingj==4)
   {
    kingww=kingww-1;
    if (kingww<=0)
    {
     for (i=0;i<=19;i++)
      {
       ee=-1;
       for (j=0;j<=399;j++)
       {
        if (tdxf[j]<-999f) {ee=j;break;}
       }
       if (ee>=0)
       {
        kakudo=i*18;
        xf=Mathf.Cos(kakudo*Mathf.PI/180);yf=Mathf.Sin(kakudo*Mathf.PI/180);
        tdxf[ee]=xf*90+(float)kingx;tdyf[ee]=yf*90+(float)kingy;
        tdxxf[ee]=xf*5;tdyyf[ee]=yf*5;
        z=ee+600;xf=tdxf[ee];yf=tdyf[ee];objput2();
       }
      }
      kingj=5;kingww=(4-level)*50;
     }
    }
   if (kingj>=1 && kingj<=3)
   {
    kingw=kingw-1;
    if (kingw<=0)
    {
     if (kingj>=2 && kingj<=3)
     {
      xx=1;yy=1;
      if (kingxx<0) {xx=-1;}
      if (kingyy<0) {yy=-1;}
      x=2;y=2;a=1;if (kingj==3) {a=2;}
      r1=Random.Range(0,3);if (r1>2) {r1=2;}
      if (r1==1) {x=1;}
      if (r1==2) {y=1;}
      kingx=kingx+kingxx*a;kingy=kingy+kingyy*a;
      if (kingx>=304 && kingxx>0) {kingx=304;kingxx=x*-1;kingyy=y*yy;}
      if (kingx<=-304 && kingxx<0) {kingx=-304;kingxx=x;kingyy=y*yy;}
      if (kingy>=150 && kingyy>0) {kingy=150;kingxx=x*xx;kingyy=y*-1;}
      if (kingy<=-150 && kingyy<0) {kingy=-150;kingxx=x*xx;kingyy=y;}
      kingww=kingww-1;
      if (kingww<=0)
      {
       if (kingj==3)
       {
        if (level==0) {kingj=2;kingww=(4-level)*100;}
        else {kingj=4;kingww=(4-level)*50;}
       }
       else {kingj=3;kingww=(4-level)*50;}
      }
     }
     if (kingj==1)
     {
      kingy=kingy-1;
      if (kingy<=150)
      {
       kingy=150;kingj=2;kingww=(4-level)*100;kingdw=0;
       x=2;y=-2;a=kingj-1;r1=Random.Range(0,3);if (r1>2) {r1=2;}
       if (r1==1) {x=1;}
       if (r1==2) {y=-1;}
       r1=Random.Range(0,2);if (r1>1) {r1=1;}
       if (r1==1) {x=x*-1;}
       kingxx=x;kingyy=y;
      }
     }
     if (kingj<=1) {kingw=1;} else {kingw=2;}
    }
   }
   z=12;zx=-2000;zy=0;objput();z=13;objput();
   z=11;zx=kingx;zy=kingy;objput();
   if (kingdw>0) {z=13;kingdw=kingdw-1;} else {z=12;}
   objput();
// enemy-c-move
   for (i=40;i<=139;i++) {z=i;zx=-2000;zy=0;objput();}
   for (i=0;i<=19;i++)
   {
    a=i+100;tkaku[a]=tkaku[a]+1;
    if (tkaku[a]>=360) {tkaku[a]=tkaku[a]-360;}
    kakudo=tkaku[a];
    xf=Mathf.Cos(kakudo*Mathf.PI/180)*160+(float)kingx;yf=Mathf.Sin(kakudo*Mathf.PI/180)*160+(float)kingy;
    if (tj[a]==1)
    {
     z=i+40;objput2();obj[z].transform.rotation=Quaternion.identity;obj[z].transform.Rotate(0,0,kakudo-90);
     z=i+60;objput2();obj[z].transform.rotation=Quaternion.identity;obj[z].transform.Rotate(0,0,kakudo-90);
    }
    if (tj[a]==2)
    {
     z=i+40;objput2();obj[z].transform.rotation=Quaternion.identity;obj[z].transform.Rotate(0,0,kakudo-90);
     z=i+80;objput2();obj[z].transform.rotation=Quaternion.identity;obj[z].transform.Rotate(0,0,kakudo-90);
     tw[a]=tw[a]-1;
     if (tw[a]<=0) {tj[a]=1;}
    }
    if (tj[a]==3)
    {
     z=i+100;objput2();z=i+120;objput2();
     tw[a]=tw[a]-1;
     if (tw[a]<=0) {tj[a]=4;tw[a]=(4-level)*100;}
    }
    if (tj[a]==4)
    {
     tw[a]=tw[a]-1;
     if (tw[a]<=0) {tj[a]=1;thp[a]=(level+1)*2;}
    }
    a=i+100;txf[a]=xf;tyf[a]=yf;
   }
// enemy-dan-move
   for (i=0;i<=399;i++)
   {
    if (tdxf[i]>-999)
    {
     tdxf[i]=tdxf[i]+tdxxf[i];tdyf[i]=tdyf[i]+tdyyf[i];
     if (tdxf[i]<=-408f || tdxf[i]>=408f || tdyf[i]<=-258f || tdyf[i]>=258f) {tdxf[i]=-1000f;tdyf[i]=0f;}
     z=i+600;xf=tdxf[i];yf=tdyf[i];objput2();
    }
   }
// hithantei king - pldan
   if (kingj>=2 && kingdw<=0)
   {
    for (i=0;i<=29;i++)
    {
     ax=pdx[i]-kingx;ay=pdy[i]-kingy;
     af=Mathf.Sqrt(ax*ax+ay*ay);
     if (af<=90f)
     {
      kinghp=kinghp-1;kingdw=2;
      z=12;zx=-2000;zy=0;objput();z=13;zx=kingx;zy=kingy;objput();
      pdx[i]=-2000;pdy[i]=0;z=i+170;zx=-2000;zy=0;objput();
     }
    }
    for (i=30;i<=33;i++)
    {
     ax=pdx[i]-kingx;ay=pdy[i]-kingy;
     af=Mathf.Sqrt(ax*ax+ay*ay);
     if (af<=90f)
     {
      kinghp=kinghp-1;kingdw=6;
      z=12;zx=-2000;zy=0;objput();z=13;zx=kingx;zy=kingy;objput();
     }
    }
   }
// hithantei enemy-c - pldan
   if (kingj>=2)
   {
    for (i=0;i<=29;i++)
    {
     for (j=0;j<=19;j++)
     {
      a=j+100;
      if (txf[a]>-999f && tj[a]==1)
      {
       axf=(float)pdx[i]-txf[a];ayf=(float)pdy[i]-tyf[a];
       af=Mathf.Sqrt(axf*axf+ayf*ayf);
       if (af<=30f)
       {
        thp[a]=thp[a]-1;tj[a]=2;tw[a]=3;
        pdx[i]=-2000;pdy[i]=0;z=i+170;zx=-2000;zy=0;objput();
        if (thp[a]<=0) {tj[a]=3;tw[a]=20;score=score+1;scoreput();}
       }
      }
     }
    }
    for (i=30;i<=33;i++)
    {
     for (j=0;j<=19;j++)
     {
      a=j+100;
      if (txf[a]>-999f && tj[a]==1)
      {
       axf=(float)pdx[i]-txf[a];ayf=(float)pdy[i]-tyf[a];
       af=Mathf.Sqrt(axf*axf+ayf*ayf);
       if (af<=30f)
       {
        thp[a]=thp[a]-1;tj[a]=2;tw[a]=6;
        if (thp[a]<=0) {tj[a]=3;tw[a]=20;score=score+1;scoreput();}
       }
      }
     }
    }
   }
// hithantei enemy-s - pldan
   for (i=0;i<=29;i++)
   {
    for (j=0;j<=99;j++)
    {
     if (tx[j]>-999)
     {
      ax=pdx[i]-tx[j];ay=pdy[i]-ty[j];
      af=Mathf.Sqrt(ax*ax+ay*ay);
      if (af<=30f)
      {
       z=j+200;zx=-2000;zy=0;objput();z=j+300;objput();
       z=j+400;zx=tx[j];zy=ty[j];objput();z=500+j;objput();
       pdx[i]=-2000;pdy[i]=0;z=i+170;zx=-2000;zy=0;objput();
       tt[j]=9;tw[j]=20;
       score=score+1;scoreput();
      }
     }
    }
   }
   for (i=30;i<=33;i++)
   {
    for (j=0;j<=19;j++)
    {
     if (tx[j]>-999)
     {
      ax=pdx[i]-tx[j];ay=pdy[i]-ty[j];
      af=Mathf.Sqrt(ax*ax+ay*ay);
      if (af<=30f)
      {
       z=j+200;zx=-2000;zy=0;objput();z=j+300;objput();
       z=j+400;zx=tx[j];zy=ty[j];objput();z=500+j;objput();
       tt[j]=9;tw[j]=20;
       score=score+1;scoreput();
      }
     }
    }
   }
   outflg=0;
// outhantei pl - king
   ax=px-kingx;ay=py-kingy;
   af=Mathf.Sqrt(ax*ax+ay*ay);
   if (af<=90f) {outflg=1;}
// outhantei pl - enemy-c
   for (i=100;i<=119;i++)
   {
    if (txf[i]>-999f && tj[i]==1)
    {
     axf=(float)px-txf[i];ayf=(float)py-tyf[i];
     af=Mathf.Sqrt(axf*axf+ayf*ayf);
     if (af<=40f) {outflg=1;}
    }
   }
// outhantei pl - enemy-s
   for (i=0;i<=99;i++)
   {
    if (tx[i]>-999 && tt[i]>=1 && tt[i]<=6)
    {
     ax=px-tx[i];ay=py-ty[i];
     af=Mathf.Sqrt(ax*ax+ay*ay);
     if (af<=40f) {outflg=1;}
    }
   }
// outhantei pl - enemy-dan
   for (i=0;i<=399;i++)
   {
    if (tdxf[i]>-999f)
    {
     axf=(float)px-tdxf[i];ayf=(float)py-tdyf[i];
     af=Mathf.Sqrt(axf*axf+ayf*ayf);
     if (af<=25f) {outflg=1;}
    }
   }
   if (kinghp<=0 && outflg==0)
   {
    score=score+100;scoreput();
    for (i=11;i<=13;i++) {z=i;zx=-2000;zy=0;objput();}
    z=16;zx=kingx;zy=kingy;objput();z=17;objput();
    gameclear();
   }
   if (outflg>0)
   {
    zx=-2000;zy=0;z=9;objput();
    for (i=1;i<=7;i++) {z=i;objput();}
    z=29;zx=px;zy=py;objput();z=30;objput();
    gameover();
   }

// times & plchange & king-coming
   ntime2f=Time.time;
   if (ntime2f-stime2f>=1f)
   {
    times=times+1;
    scoreput();stime2f=stime2f+1f;
    ptcount=ptcount+1;
    if (times==65) {kingj=1;}
    if (ptcount>=10) {plchange();ptcount=0;}
   }
// if (Input.GetKeyDown(KeyCode.Return)) {plchange();}
  }
  if (flg==1)
  {
// bgm-replay
   ntimef=Time.time;
   if (ntimef-stimef>=13f) {bgm1.Play();stimef=Time.time;}
  }
  if (flg==8 || flg==9)
  {
   ntime2f=Time.time;
   if (ntime2f-stime2f>=0.5f)
   {
    stime2f=stime2f+0.5f;count=count+1;
    if (flg==8) {a=23;} else {a=25;}
    z=a;zx=-2000;zy=0;objput();z=a+1;objput();
    z=count%2+a;zx=0;zy=0;objput();
    if (count>=12) {titleput();}
   }
  }
  if (flg>0)
  {
   if (Input.GetKeyDown(KeyCode.Escape)) {titleput();}
  }
 }

 void gamestart()
 {
  alldel();
  px=0;py=-200;pt=1;ptcount=0;banx=0;bany=0;banxx=2;banyy=2;banw=5;
  kingx=0;kingy=436;kingxx=0;kingyy=0;
  kingj=0;kingw=0;kingww=0;kingdw=0;kinghp=(level+1)*10;
  z=11;zx=kingx;zy=kingy;objput();z=12;objput();
  for (i=0;i<=19;i++)
  {
   kakudo=+i*18;
   xf=Mathf.Cos(kakudo*Mathf.PI/180)*160+(float)kingx;yf=Mathf.Sin(kakudo*Mathf.PI/180)*160+(float)kingy;
   z=i+40;objput2();obj[z].transform.Rotate(0,0,kakudo-90);
   z=i+60;objput2();obj[z].transform.Rotate(0,0,kakudo-90);
   a=i+100;txf[a]=xf;tyf[a]=yf;tkaku[a]=kakudo;tj[a]=1;tw[a]=0;thp[a]=(level+1)*2;
  }
  score=0;times=0;scoreput();
  for (i=0;i<=33;i++) {pdx[i]=-1000;pdy[i]=-1000;pdxx[i]=-1000;pdyy[i]=-1000;}
  for (i=0;i<=99;i++)
  {
   tx[i]=-1000;ty[i]=0;txx[i]=0;tyy[i]=0;tt[i]=0;tj[i]=0;tw[i]=0;
  }
  for (i=0;i<=399;i++) {tdxf[i]=-1000f;tdyf[i]=0f;tdxxf[i]=0f;tdyyf[i]=0f;}
  z=pt;zx=px;zy=py;objput();z=9;objput();
  ntwait=0;tcount=0;ttype=1;newenemy();
  flg=1;spacewait=2;
  bgmstop();bgm1.Play();stimef=Time.time;
 }

 void plshot()
 {
  if (pt==2 || pt==6 || pt==7) // laser
  {
   e1=1;
   for (i=0;i<=3;i++)
   {
    if (pdx[i+30]>-999) {e1=0;break;}
   }
   if (e1==1)
   {
    for (i=0;i<=3;i++) {obj[i+166].transform.rotation=Quaternion.identity;}
    if (pt==2 || pt==7)
    {
     pdx[30]=px;pdy[30]=py+30;pdxx[30]=0;pdyy[30]=30;
    }
    if (pt==6)
    {
     obj[166].transform.Rotate(0,0,135);obj[167].transform.Rotate(0,0,45);
     obj[168].transform.Rotate(0,0,45);obj[169].transform.Rotate(0,0,135);
     pdx[30]=px+21;pdy[30]=py+21;pdxx[30]=21;pdyy[30]=21;
     pdx[31]=px-21;pdy[31]=py+21;pdxx[31]=-21;pdyy[31]=21;
     pdx[32]=px+21;pdy[32]=py-21;pdxx[32]=21;pdyy[32]=-21;
     pdx[33]=px-21;pdy[33]=py-21;pdxx[33]=-21;pdyy[33]=-21;
    }
    if (pt==7)
    {
     obj[167].transform.Rotate(0,0,90);obj[168].transform.Rotate(0,0,90);
     pdx[31]=px+30;pdy[31]=py;pdxx[31]=30;pdyy[31]=0;
     pdx[32]=px-30;pdy[32]=py;pdxx[32]=-30;pdyy[32]=0;
     pdx[33]=px;pdy[33]=py-30;pdxx[33]=0;pdyy[33]=-30;
    }
    for (i=0;i<=3;i++) {z=i+166;zx=pdx[i+30];zy=pdy[i+30];objput();}
   }
  }
  else // dan
  {
   ee=-1;
   for (i=0;i<=4;i++)
   {
    e1=1;
    for (j=0;j<=5;j++)
    {
     if (pdx[i*6+j]>-999) {e1=0;break;}
    }
    if (e1==1) {ee=i*6;break;}
   }
   if (ee>=0)
   {
    if (pt==1 || pt==4 || pt==5)
    {
     pdx[ee]=px;pdy[ee]=py+20;pdxx[ee]=0;pdyy[ee]=10;
    }
    if (pt==3)
    {
     pdx[ee]=px+8;pdy[ee]=py+16;pdxx[ee]=4;pdyy[ee]=8;
     pdx[ee+1]=px-8;pdy[ee+1]=py+16;pdxx[ee+1]=-4;pdyy[ee+1]=8;
    }
    if (pt==4)
    {
     pdx[ee+1]=px+14;pdy[ee+1]=py+14;pdxx[ee+1]=7;pdyy[ee+1]=7;
     pdx[ee+2]=px-14;pdy[ee+2]=py+14;pdxx[ee+2]=-7;pdyy[ee+2]=7;
     pdx[ee+3]=px+14;pdy[ee+3]=py-14;pdxx[ee+3]=7;pdyy[ee+3]=-7;
     pdx[ee+4]=px-14;pdy[ee+4]=py-14;pdxx[ee+4]=-7;pdyy[ee+4]=-7;
    }
    if (pt==5)
    {
     pdx[ee+1]=px+14;pdy[ee+1]=py+14;pdxx[ee+1]=7;pdyy[ee+1]=7;
     pdx[ee+2]=px-14;pdy[ee+2]=py+14;pdxx[ee+2]=-7;pdyy[ee+2]=7;
     pdx[ee+3]=px+20;pdy[ee+3]=py;pdxx[ee+3]=10;pdyy[ee+3]=0;
     pdx[ee+4]=px-20;pdy[ee+4]=py;pdxx[ee+4]=-10;pdyy[ee+4]=0;
     pdx[ee+5]=px;pdy[ee+5]=py-20;pdxx[ee+5]=0;pdyy[ee+5]=-10;
    }
    for (i=0;i<=5;i++)
    {
     z=ee+i+170;zx=pdx[ee+i];zy=pdy[ee+i];objput();
    }
   }
  }
 }

 void plchange()
 {
  for (i=1;i<=7;i++) {z=i;zx=-2000;zy=0;objput();}
  pt=pt+1;if (pt>7) {pt=1;}
  z=pt;zx=px;zy=py;objput();
 }

 void newenemy()
 {
  ee=-1;
  for (ii=0;ii<=99;ii++)
  {
   if (tx[ii]<-999) {ee=ii;break;}
  }
  if (ee>=0)
  {
   r1=Random.Range(-200,201);if (r1>200) {r1=0;}
   tx[ee]=r1;ty[ee]=276;txx[ee]=0;tyy[ee]=-1;tt[ee]=ttype;tj[ee]=1;
   r1=Random.Range(0,180);if (r1>179) {r1=0;}
   tw[ee]=r1;
   r1=Random.Range(0,2);if (r1>1) {r1=0;}
   if (r1==0) {a=1;} else {a=-1;}
   if (ttype>=2 && ttype<=4) {txx[ee]=(ttype-1)*a;}
   if (ttype>=5 && ttype<=6 && r1==1) {tj[ee]=2;}
   z=ee+200;zx=tx[ee];zy=ty[ee];objput();z=ee+300;objput();
   obj[ee+200].transform.rotation=Quaternion.identity;obj[ee+200].transform.Rotate(0,0,180);
   obj[ee+300].transform.rotation=Quaternion.identity;obj[ee+300].transform.Rotate(0,0,180);
   ntwait=(5-level)*50;
   tcount=tcount+1;
   if (tcount%4==0)
   {
    ttype=ttype+1;
    if (ttype>6) {ttype=1;}
   }
  }
 }

 void tdset()
 {
  if (level==1 || level==3)
  {
   kakuf=Mathf.Atan2(py-ty[i],px-tx[i]);tdshot();
  }
  if (level==2)
  {
   kakuf=Mathf.Atan2(py-ty[i],px-tx[i])+0.15f;tdshot();
   kakuf=Mathf.Atan2(py-ty[i],px-tx[i])-0.15f;tdshot();
  }
  if (level==3)
  {
   kakuf=Mathf.Atan2(py-ty[i],px-tx[i])+0.3f;tdshot();
   kakuf=Mathf.Atan2(py-ty[i],px-tx[i])-0.3f;tdshot();
  }
 }

 void tdshot()
 {
  ee=-1;
  for (ii=0;ii<=399;ii++)
  {
   if (tdxf[ii]<-999f) {ee=ii;break;}
  }
  if (ee>=0)
  {
   xf=Mathf.Cos(kakuf);yf=Mathf.Sin(kakuf);
   tdxf[ee]=(float)tx[i]+xf*30;tdyf[ee]=(float)ty[i]+yf*30;
   tdxxf[ee]=xf*5;tdyyf[ee]=yf*5;
   z=ee+600;xf=tdxf[ee];yf=tdyf[ee];objput2();
  }
 }

 void gameover()
 {
  z=23;zx=0;zy=40;objput();
  stime2f=Time.time;count=0;flg=8;spacewait=2;
  bgmstop();bgm2.Play();
 }

 void gameclear()
 {
  z=25;zx=0;zy=40;objput();
  stime2f=Time.time;count=0;flg=9;spacewait=2;
  bgmstop();bgm3.Play();
 }

 void scoreput()
 {
  for (i=1200;i<=1259;i++) {z=i;zx=-2000;zy=0;objput();}
  if (score<0) {score=0;}
  if (score>999) {score=999;}
  zy=275;aa=0;
  a=score/100;if (a>0) {aa=1;z=a+1200;zx=-308;objput();}
  a=(score%100)/10;if (a>0 || aa>0) {aa=1;z=a+1210;zx=-292;objput();}
  a=score%10;z=a+1220;zx=-276;objput();
  if (times<0) {times=0;}
  if (times>999) {times=999;}
  zy=275;aa=0;
  a=times/100;if (a>0) {aa=1;z=a+1230;zx=358;objput();}
  a=(times%100)/10;if (a>0 || aa>0) {aa=1;z=a+1240;zx=374;objput();}
  a=times%10;z=a+1250;zx=390;objput();
 }

 void titleput()
 {
  alldel();bgmstop();flg=0;spacewait=2;
  z=27;zx=0;zy=0;objput();z=28;zx=-94;zy=98-level*40;objput();
  stime2f=Time.time;
  bgmstop();flg=0;spacewait=2;
 }

 void OnGUI()
 {
  GUI.Label (new Rect (300,80,100,30),c1,style1);
  GUI.Label (new Rect (300,160,100,30),c2,style2);
  GUI.Label (new Rect (300,240,100,30),c3,style1);
  GUI.Label (new Rect (300,320,100,30),c4,style3);
 }

 void objput()
 {
  Vector3 pos=obj[z].transform.position;
  pos.x=zx*0.01f;pos.y=zy*0.01f;
  obj[z].transform.position=pos;
 }

 void objput2()
 {
  Vector3 pos=obj[z].transform.position;
  pos.x=xf*0.01f;pos.y=yf*0.01f;
  obj[z].transform.position=pos;
 }

 void bgmstop()
 {
  bgm1.Stop();bgm2.Stop();bgm3.Stop();
 }

 void alldel()
 {
  zx=-2000;zy=0;
  for (i=0;i<=20;i++) {z=i;objput();}
  for (i=23;i<=30;i++) {z=i;objput();}
  for (i=40;i<=139;i++) {z=i;objput();obj[i].transform.rotation=Quaternion.identity;}
  for (i=166;i<=169;i++) {z=i;objput();obj[i].transform.rotation=Quaternion.identity;}
  for (i=170;i<=999;i++) {z=i;objput();}
  for (i=1200;i<=1259;i++) {z=i;objput();}
  z=21;zx=0;zy=0;objput();
  for (i=200;i<=399;i++) {obj[i].transform.rotation=Quaternion.identity;}
 }
}