using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class risutora3 : MonoBehaviour
{
 int flg=-1;int count=0;int spacewait=0;int outflg=0;
 int uriage=0;int hiyou=0;int shikin=0;int times1=0;int times2=0;int times3=0;int risukazu=0;int nowkaiko=0;
 int kakudo=0;int usakaku=-1;int usahou=1;int usayure=1;int risunum=0;
 int wx=0;int wy=0;int oldwx=0;int oldwy=0;
 int[] tj=new int[5];int[] tkaku=new int[5];int[] tkyo=new int[5];int[] tlv=new int[5];int[] texp=new int[5];
 int[] tlife=new int[5];int[] tlfs=new int[5];int[] tspeed=new int[5];int[] tfk=new int[5];int[] tkkaku=new int[5];
 int[] trnum=new int[5];int[] tw=new int[5];int[] tst=new int[5];
 int[] rj=new int[50];int[] rkaku=new int[50];int[] rkyo=new int[50];int[] rkuri=new int[50];int[] rgk=new int[50];
 int[] rlv=new int[50];int[] rexp=new int[50];int[] rlife=new int[50];int[] rlfs=new int[50];int[] rspeed=new int[50];
 int[] rkk=new int[50];int[] rmk=new int[50];int[] rgkk=new int[50];int[] rw=new int[50];
 float[] txf=new float[5];float[] tyf=new float[5];float[] rxf=new float[50];float[] ryf=new float[50];
 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 e;int e1;int a1;int a2;int moves;int mousex;int mousey;
 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 d1;string d2;string d3;string bigdata;string keyname="bignyan_risutora";string d;
 string[] datas=new string[200];string[] dts=new string[200];

 GUIStyle style1;GUIStyle style2;GUIStyle style3;
 GameObject[] obj=new GameObject[2000];
 AudioSource bgm1;AudioSource bgm2;AudioSource bgm3;
 AudioSource bgm4;AudioSource bgm5;AudioSource bgm6;

 void Start()
 {
  style1=new GUIStyle();style1.fontSize=40;
  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<=2;i++) {obj[i]=GameObject.Find("rabbit-"+i);} // 1-2  rabbit
  for (i=1;i<=10;i++) {obj[i+2]=GameObject.Find("tora-"+i);} // 3-12  tora
  for (i=1;i<=10;i++) {obj[i+12]=GameObject.Find("tora-hyo-"+i);} // 13-22  tora-hyo
  for (i=1;i<=2;i++) {obj[i+22]=GameObject.Find("kuri-"+i);} // 23-24  kuri-moto
  for (i=1;i<=4;i++) {obj[i+24]=GameObject.Find("risu-line-"+i);} // 25-28  risu-line-moto
  for (i=1;i<=2;i++) {obj[i+28]=GameObject.Find("risu-me-"+i);} // 29-30  risu-me-moto
  for (i=1;i<=20;i++) {obj[i+30]=GameObject.Find("risu-kao-"+i);} // 31-50  risu-kao-moto
  for (i=1;i<=5;i++) {obj[i+50]=GameObject.Find("ribon-"+i);} // 51-55  ribon-moto
  for (i=1;i<=2;i++) {obj[i+55]=GameObject.Find("gomi-"+i);} // 56-57  gomi
  obj[58]=GameObject.Find("risutora-ki"); // 58  ki-moto
  obj[59]=GameObject.Find("risutora-fuka"); // 59  fuka-moto
  for (i=0;i<=1;i++) {obj[i+60]=Object.Instantiate(obj[59]) as GameObject;} // 60 - 61  fuka-copy
  obj[62]=GameObject.Find("moji-tousan"); // 62  tousan
  obj[63]=GameObject.Find("risutora-title"); // 63  title
  for (i=1;i<=5;i++) {obj[i+63]=GameObject.Find("ribon-"+(i+5));} // 64-68  ribon2-moto
  obj[69]=GameObject.Find("hand"); // 69  hand
  obj[70]=GameObject.Find("moji-kiken"); // 70  kiken
  obj[71]=GameObject.Find("moji-saved"); // 71  saved
  obj[72]=GameObject.Find("risutora-savebutton"); // 72  savebutton
  obj[73]=GameObject.Find("risutora-endbutton"); // 73  endbutton
  obj[74]=GameObject.Find("risutora-deleteokng-1"); // 74  delete-okng-blue
  obj[75]=GameObject.Find("risutora-deleteokng-2"); // 75  delete-okng-pink
  obj[76]=GameObject.Find("risutora-clear-1"); // 76  clear-pink-blue
  obj[77]=GameObject.Find("risutora-clear-2"); // 77  clear-blue-orange
  for (i=1;i<=6;i++) {obj[i+77]=GameObject.Find("risutora-waku-"+i);} // 78-83  waku

  for (i=0;i<=32;i++) {obj[i+100]=Object.Instantiate(obj[58]) as GameObject;} // 100 - 132  ki-copy
  for (i=0;i<=9;i++)
  {
   obj[i+140]=GameObject.Find("num-"+i); // 140-149  nums-moto
   for (j=1;j<=25;j++) {obj[j*10+i+140]=Object.Instantiate(obj[i+140]) as GameObject;} // 150-399  nums-copy
  }
  for (i=0;i<=3;i++)
  {
   for (j=0;j<=24;j++) {obj[i*25+j+400]=Object.Instantiate(obj[i+25]) as GameObject;} // 400-499  risu-line-copy
  }
  for (i=0;i<=1;i++)
  {
   for (j=0;j<=24;j++) {obj[i*25+j+500]=Object.Instantiate(obj[i+29]) as GameObject;} // 500-549  risu-me-copy
  }
  for (i=0;i<=4;i++)
  {
   for (j=0;j<=4;j++)
   {
    obj[i*5+j+550]=Object.Instantiate(obj[j+31]) as GameObject;  // 550-574  risu-kao-typeA
    obj[i*5+j+575]=Object.Instantiate(obj[j+36]) as GameObject;  // 575-599  risu-kao-typeB
    obj[i*5+j+600]=Object.Instantiate(obj[j+41]) as GameObject;  // 600-624  risu-kao-typeA-out
    obj[i*5+j+625]=Object.Instantiate(obj[j+46]) as GameObject;  // 625-649  risu-kao-typeB-out
   }
  }
  for (i=0;i<=4;i++)
  {
   for (j=0;j<=4;j++)
   {
    obj[i*5+j+650]=Object.Instantiate(obj[i+51]) as GameObject;  // 650-674  ribon-copy
    obj[i*5+j+675]=Object.Instantiate(obj[i+51]) as GameObject;  // 675-699  ribon-copy
    obj[i*5+j+700]=Object.Instantiate(obj[i+64]) as GameObject;  // 700-724  ribon-copy
    obj[i*5+j+725]=Object.Instantiate(obj[i+64]) as GameObject;  // 725-749  ribon-copy
   }
  }
  for (i=0;i<=249;i++) {obj[i+750]=Object.Instantiate(obj[23]) as GameObject;} // 750-999  kuri-normal-copy
  for (i=0;i<=49;i++) {obj[i+1000]=Object.Instantiate(obj[24]) as GameObject;} // 1000-1049 kuri-gold-copy
  alldel();
  z=1;zx=380;zy=-240;objput();
  z=56;zx=-200;zy=-290;objput();
  for (i=0;i<=32;i++)
  {
   kakudo=290+i*10;if (kakudo>=360) {kakudo=kakudo-360;}
   xf=Mathf.Cos(kakudo*Mathf.PI/180)*320-200;yf=Mathf.Sin(kakudo*Mathf.PI/180)*320;
   z=i+100;objput2();
  }
  bgm1=obj[1].GetComponent();bgm2=obj[2].GetComponent();bgm3=obj[3].GetComponent();
  bgm4=obj[4].GetComponent();bgm5=obj[5].GetComponent();bgm6=obj[6].GetComponent();
  z=0;zx=0;zy=0;objput();
  count=500;flg=-1;
 }

 void Update()
 {
  Vector3 mpos=Input.mousePosition;
  xf=mpos.x;yf=mpos.y;mousex=(int)xf;mousey=(int)yf;
//  c1="X="+mousex.ToString()+" Y="+mousey.ToString();
  if (flg==-2)
  {
   if (spacewait>0) {spacewait=spacewait-1;}
   if (Input.GetMouseButtonDown(0) && spacewait<=0)
   {
    if (mousex>=231 && mousex<=395 && mousey>=314 && mousey<=368)
    {
     PlayerPrefs.DeleteKey(keyname);
     gamestart();
    }
    if (mousex>=703 && mousex<=867 && mousey>=314 && mousey<=368)
    {
     z=74;zx=-2000;zy=0;objput();z=80;objput();z=75;objput();z=63;zx=-200;objput();
     flg=0;spacewait=2;
    }
   }
   if (spacewait<=0)
   {
    if (Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.Keypad4)) {if (wx==1) {wx=0;} else {wx=1;}}
    if (Input.GetKeyDown(KeyCode.RightArrow) || Input.GetKeyDown(KeyCode.Keypad6)) {if (wx==1) {wx=0;} else {wx=1;}}
    if (wx!=oldwx)
    {
     if (wx==0) {z=80;zx=-389;zy=-88;objput();} else {z=80;zx=-12;zy=-88;objput();}
     oldwx=wx;
    }
    if (Input.GetKeyDown(KeyCode.Space))
    { 
     if (wx==1)
     {
      z=74;zx=-2000;zy=0;objput();z=80;objput();z=75;objput();z=63;zx=-200;objput();
      z=78;zx=6;zy=-134;objput();wx=1;wy=0;oldwx=1;oldwy=0;
      flg=0;spacewait=2;
     }
     else
     {
      PlayerPrefs.DeleteKey(keyname);
      gamestart();
     }
    }
   }
  }
  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;
   }
  }
  if (flg==0)
  {
   if (spacewait>0) {spacewait=spacewait-1;}
   if (Input.GetMouseButtonDown(0) && spacewait<=0)
   {
    if (mousex>=690 && mousex<=923 && mousey>=251 && mousey<=314) {gamestart();}
    if (mousex>=174 && mousex<=360 && mousey>=253 && mousey<=293)
    {
     z=63;zx=-2000;zy=0;objput();z=78;objput();z=79;objput();
     z=74;zx=-200;objput();z=75;objput();z=80;zx=-12;zy=-88;objput();
     flg=-2;spacewait=2;wx=1;oldwx=1;
    }
   }
   if (spacewait<=0)
   {
    if (Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.Keypad4)) {if (wx==1) {wx=0;} else {wx=1;}}
    if (Input.GetKeyDown(KeyCode.RightArrow) || Input.GetKeyDown(KeyCode.Keypad6)) {if (wx==1) {wx=0;} else {wx=1;}}
    if (wx!=oldwx)
    {
     z=78;zx=-2000;zy=0;objput();z=79;objput();
     if (wx==0) {z=79;zx=-425;zy=-143;objput();} else {z=78;zx=6;zy=-134;objput();}
     oldwx=wx;
    }
    if (Input.GetKeyDown(KeyCode.Space))
    { 
     if (wx==1) {gamestart();}
     else
     {
      z=63;zx=-2000;zy=0;objput();z=78;objput();z=79;objput();
      z=74;zx=-200;objput();z=75;objput();z=80;zx=-12;zy=-88;objput();
      flg=-2;spacewait=2;wx=1;oldwx=1;
     }
    }
   }
  }
  if (flg==1)
  {
   if (spacewait>0) {spacewait=spacewait-1;}
// rabbit-move
   usakaku=usakaku+usahou*usayure;
   if (usakaku>=30 && usahou>0) {usakaku=30;usahou=usahou*-1;}
   if (usakaku<=-30 && usahou<0) {usakaku=-30;usahou=usahou*-1;}
   obj[1].transform.rotation=Quaternion.identity;
   obj[1].transform.Rotate(0,0,usakaku);
// tora-move
   for (i=0;i<=4;i++)
   {
    tkaku[i]=tkaku[i]-1;if (tkaku[i]<0) {tkaku[i]=tkaku[i]+360;}
    if (tkaku[i]==90) {toralvup(i);}
    if (tj[i]==9)
    {
     z=56;zx=-2000;zy=0;objput();z=57;zx=-200;zy=-290;objput();
     tw[i]=tw[i]-2;
     z=i+8;zx=-198;zy=tw[i]-314;objput();
     if (tw[i]<=0)
     {
      z=i+8;zx=-2000;zy=0;objput();z=69;objput();
      z=i+13;zx=-2000;zy=0;objput();z=i+18;objput();
      z=56;zx=-200;zy=-290;objput();z=57;zx=-2000;zy=0;objput();
      tj[i]=0;nowkaiko=0;a=0;
      for (ii=0;ii<=4;ii++) {if (tj[ii]>0) {a=a+1;}}
      z=60;zx=-2000;zy=0;objput();z=61;objput();
      if (a==1) {z=61;zx=194;zy=-14;objput();}
      hiyoumake();shikin=shikin-tlv[i]*100;scoreput();bgm5.Stop();bgm5.Play();
     }
    }
    if (tj[i]==8)
    {
     axf=txf[i]+198f;ayf=tyf[i]+264f;
     if (Mathf.Sqrt(axf*axf+ayf*ayf)<=2f)
     {
      z=i+8;zx=-198;zy=-264;objput();
      z=56;zx=-2000;zy=0;objput();z=57;zx=-200;zy=-290;objput();
      tj[i]=9;tw[i]=50;
     }
     else
     {
      kakuf=Mathf.Atan2(-264f-tyf[i],-198f-txf[i]);
      txf[i]=txf[i]+(float)(Mathf.Cos(kakuf)*2f);tyf[i]=tyf[i]+(float)(Mathf.Sin(kakuf)*2f);
      xf=txf[i];yf=tyf[i];z=i+8;objput2();
      z=69;yf=yf+24f;objput2();
     }
    }
    if (tj[i]==6)
    {
     if (tkaku[i]==270) {tj[i]=1;}
    }
    if (tj[i]==5)
    {
     tkyo[i]=tkyo[i]-tspeed[i];
     if (tkyo[i]>750) {z=i+3;zx=-200;zy=tkyo[i]/-10;objput();}
     else {z=i+3;zx=-200;zy=-75;objput();tj[i]=6;}
    }
    if (tj[i]==4)
    {
     tw[i]=tw[i]-2;
     zx=-200;zy=-312+tw[i];a=trnum[i];
     z=a+450;objput();z=a+600;objput();z=a+700;objput();
     z=56;zx=-2000;zy=0;objput();z=57;zx=-200;zy=-290;objput();
     if (tw[i]<=0)
     {
      zx=-2000;zy=0;
      z=a+450;objput();z=a+600;objput();z=a+700;objput();
      obj[a+450].transform.rotation=Quaternion.identity;obj[a+600].transform.rotation=Quaternion.identity;
      obj[a+700].transform.rotation=Quaternion.identity;
      z=56;zx=-200;zy=-290;objput();z=57;zx=-2000;zy=0;objput();
      rj[a]=0;trnum[i]=-1;risucount();hiyoumake();shikin=shikin-rlv[a]*rlv[a]*10;scoreput();
      tkyo[i]=2450;tj[i]=5;bgm5.Stop();bgm5.Play();
     }
    }
    if (tj[i]==3)
    {
     axf=txf[i]+200f;ayf=tyf[i]+245f;
     if (Mathf.Sqrt(axf*axf+ayf*ayf)<=tspeed[i])
     {
      z=i+3;zx=-200;zy=-245;objput();
      zx=-200;zy=-270;a=trnum[i];
      z=a+450;objput();z=a+600;objput();z=a+700;objput();
      obj[a+450].transform.Rotate(0,0,90);obj[a+600].transform.Rotate(0,0,90);obj[a+700].transform.Rotate(0,0,90);
      z=56;zx=-2000;zy=0;objput();z=57;zx=-200;zy=-290;objput();
      tj[i]=4;tw[i]=42;
     }
     else
     {
      kakuf=Mathf.Atan2(-245f-tyf[i],-200f-txf[i]);
      txf[i]=txf[i]+(float)(Mathf.Cos(kakuf)*tspeed[i]*0.1);tyf[i]=tyf[i]+(float)(Mathf.Sin(kakuf)*tspeed[i]*0.1);
      xf=txf[i];yf=tyf[i];z=i+3;objput2();
      risuput(trnum[i]+50,xf,yf-25f,0);
     }
    }
    if (tj[i]==2)
    {
     tkyo[i]=tkyo[i]+tspeed[i];
     xf=Mathf.Cos(tkkaku[i]*Mathf.PI/180)*tkyo[i]*0.1f-200;yf=Mathf.Sin(tkkaku[i]*Mathf.PI/180)*tkyo[i]*0.1f;
     z=i+3;objput2();
     if (tkyo[i]>=rkyo[trnum[i]]-400)
     {
      risuput(trnum[i],-1000f,0f,0);rj[trnum[i]]=9;
      z=trnum[i]+1000;zx=-2000;zy=0;objput();
      for (j=0;j<=5;j++) {z=trnum[i]*5+j+750;objput();}
      xf=Mathf.Cos(tkkaku[i]*Mathf.PI/180)*tkyo[i]*0.1f-200;yf=Mathf.Sin(tkkaku[i]*Mathf.PI/180)*tkyo[i]*0.1f;
      txf[i]=xf;tyf[i]=yf;
      risuput(trnum[i]+50,xf,yf-25f,0);
      tj[i]=3;
     }
    }
    if (tj[i]==1)
    {
     xf=Mathf.Cos(tkaku[i]*Mathf.PI/180)*75-200;yf=Mathf.Sin(tkaku[i]*Mathf.PI/180)*75;
     z=i+3;objput2();findrisu(i);
     if (tj[i]==2) {tkkaku[i]=tkaku[i];tkyo[i]=750;}
    }
   }
// risu-move
   {
    for (i=0;i<=49;i++)
    {
     if (rj[i]==8)
     {
      kakuf=Mathf.Atan2(-ryf[i],-200f-rxf[i]);
      rxf[i]=rxf[i]+(float)(Mathf.Cos(kakuf)*rspeed[i]*0.1);ryf[i]=ryf[i]+(float)(Mathf.Sin(kakuf)*rspeed[i]*0.1);
      axf=rxf[i]+200f;ayf=ryf[i];
      if (Mathf.Sqrt(axf*axf+ayf*ayf)<=26) {rj[i]=4;}
      else
      {
       xf=rxf[i];yf=ryf[i];
       z=i+400;objput2();z=i+500;objput2();z=i+550;objput2();z=i+650;objput2();
      }
     }
     if (rj[i]==5)
     {
      rw[i]=rw[i]-1;
      if (rw[i]<=0)
      {
       a=0;
       if (rkuri[i]==1 && rgk[i]==1)
       {
        bgm4.Stop();bgm4.Play();
        r=Random.Range(1,4);if (r>3) {r=3;}
        a=r*100;
       }
       else
       {
        bgm3.Stop();bgm3.Play();
        r=Random.Range(5,11);a=r;
       }
       shikin=shikin+a;uriage=uriage+a;scoreput();
       rkuri[i]=rkuri[i]-1;
       zx=-2000;zy=0;z=i+1000;objput();
       for (j=0;j<=4;j++) {z=i*5+j+750;objput();}
       for (j=1;j<=rkuri[i];j++)
       {
        a=rkyo[i]+j*320+80;if (a>3250) {a=3250;}
        xf=Mathf.Cos(rkaku[i]*Mathf.PI/180)*a*0.1f-200;yf=Mathf.Sin(rkaku[i]*Mathf.PI/180)*a*0.1f;
        z=i*5+j+749;if (j==rkuri[i] && rgk[i]==1) {z=i+1000;}
        objput2();
       }
       if (rkuri[i]<1) {rj[i]=4;} else {rw[i]=10;}
      }
     }
     if (rj[i]==3)
     {
      rkyo[i]=rkyo[i]-rspeed[i];if (rkyo[i]<=260) {rkyo[i]=260;}
      xf=Mathf.Cos(rkaku[i]*Mathf.PI/180)*rkyo[i]*0.1f-200;yf=Mathf.Sin(rkaku[i]*Mathf.PI/180)*rkyo[i]*0.1f;
      risuput(i,xf,yf,0);
      for (j=1;j<=rkuri[i];j++)
      {
       a=rkyo[i]+j*320+80;if (a>3250) {a=3250;}
       xf=Mathf.Cos(rkaku[i]*Mathf.PI/180)*a*0.1f-200;yf=Mathf.Sin(rkaku[i]*Mathf.PI/180)*a*0.1f;
       z=i*5+j+749;if (j==rkuri[i] && rgk[i]==1) {z=i+1000;}
       objput2();
      }
      if (rkyo[i]<=260)
      {
       if (rkuri[i]<1) {rj[i]=4;} else {rj[i]=5;rw[i]=1;}
      }
     }
     if (rj[i]==2)
     {
      rkyo[i]=rkyo[i]+rspeed[i];if (rkyo[i]>=2750) {rkyo[i]=2750;}
      xf=Mathf.Cos(rkaku[i]*Mathf.PI/180)*rkyo[i]*0.1f-200;yf=Mathf.Sin(rkaku[i]*Mathf.PI/180)*rkyo[i]*0.1f;
      risuput(i,xf,yf,0);
      if (rkyo[i]>=2750)
      {
       rkuri[i]=0;rgk[i]=0;
       for (j=1;j<=rmk[i];j++)
       {
        r=Random.Range(0,100);
        if (r5) {rkuri[i]=5;}
       r=Random.Range(0,100);
       if (r32) {r=32;}
      rkaku[i]=290+r*10;if (rkaku[i]>=360) {rkaku[i]=rkaku[i]-360;}
      xf=Mathf.Cos(rkaku[i]*Mathf.PI/180)*rkyo[i]*0.1f-200;yf=Mathf.Sin(rkaku[i]*Mathf.PI/180)*rkyo[i]*0.1f;
      obj[i+400].transform.rotation=Quaternion.identity;obj[i+550].transform.rotation=Quaternion.identity;
      obj[i+650].transform.rotation=Quaternion.identity;obj[i+500].transform.rotation=Quaternion.identity;
      a=0;
      if (rkaku[i]<90 || rkaku[i]>=270) {a=1;}
      risuput(i,xf,yf,a);risulvup(i);
      rj[i]=2;
     }
    }
   }
// input
   if (spacewait>0) {spacewait=spacewait-1;}
   if (Input.GetMouseButtonDown(0) && spacewait<=0)
   {
    if (mousey>=536 && mousey<=568)
    {
     if (mousex>=1093 && mousex<=1155) {newrisu(1);}
     if (mousex>=1168 && mousex<=1230) {newrisu(2);}
     if (mousex>=1243 && mousex<=1305) {newrisu(3);}
     if (mousex>=1318 && mousex<=1380) {newrisu(4);}
     if (mousex>=1393 && mousex<=1455) {newrisu(5);}
    }
    if (mousey>=456 && mousey<=488)
    {
     if (mousex>=1093 && mousex<=1155) {newtora(1);}
     if (mousex>=1168 && mousex<=1230) {newtora(2);}
     if (mousex>=1243 && mousex<=1305) {newtora(3);}
     if (mousex>=1318 && mousex<=1380) {newtora(4);}
     if (mousex>=1393 && mousex<=1455) {newtora(5);}
    }
    if (mousey>=345 && mousey<=411)
    {
     if (mousex>=1093 && mousex<=1159) {torakaiko(0);}
     if (mousex>=1168 && mousex<=1234) {torakaiko(1);}
     if (mousex>=1243 && mousex<=1309) {torakaiko(2);}
     if (mousex>=1318 && mousex<=1384) {torakaiko(3);}
     if (mousex>=1393 && mousex<=1459) {torakaiko(4);}
    }
    if (mousey>=85 && mousey<=141)
    {
     if (mousex>=1386 && mousex<=1460) {datasave();}
     if (mousex>=1475 && mousex<=1549) {titleput();}
    }
   }
   if (spacewait<=0)
   {
    if (Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.Keypad8))
    {
     wy=wy-1;if (wy<0) {wy=3;}
     if (oldwy==3) {wx=0;}
     if (oldwy!=3 && wy==3) {wx=0;}
    }
    if (Input.GetKeyDown(KeyCode.DownArrow) || Input.GetKeyDown(KeyCode.Keypad2))
    {
     wy=wy+1;if (wy>3) {wy=0;}
     if (oldwy==3) {wx=0;}
     if (oldwy!=3 && wy==3) {wx=0;}
    }
    if (Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.Keypad4))
    {
     wx=wx-1;if (wx<0 && wy<3) {wx=4;}
     if (wy==3 && wx<0) {wx=1;}
    }
    if (Input.GetKeyDown(KeyCode.RightArrow) || Input.GetKeyDown(KeyCode.Keypad6))
    {
     wx=wx+1;if (wx>4) {wx=0;}
     if (wy==3 && wx==2) {wx=0;}
    }
    if (wy==3 && wx>1) {wx=1;oldwx=-1;}
    if (wx!=oldwx || wy!=oldwy)
    {
     z=81;zx=-2000;zy=0;objput();z=82;objput();z=83;objput();
     if (wy==0 || wy==1) {z=81;zx=wx*60+260;zy=81-wy*63;objput();}
     if (wy==2) {z=82;zx=wx*60+261;zy=-58;objput();}
     if (wy==3) {z=83;zx=wx*70+500;zy=-270;objput();}
     oldwx=wx;oldwy=wy;
    }
    if (Input.GetKeyDown(KeyCode.Space))
    {
     if (wy==0) {newrisu(wx+1);}
     if (wy==1) {newtora(wx+1);}
     if (wy==2) {torakaiko(wx);}
     if (wy==3)
     {
      if (wx==0) {datasave();}
      if (wx==1) {titleput();}
     }
     spacewait=2;
    }
   }
  }
  if (flg==1)
  {
// times
   ntime2f=Time.time;
   if (ntime2f-stime2f>=1f)
   {
    times3=times3+1;
    if (times3>59)
    {
     times2=times2+1;times3=0;
     hiyoumake();shikin=shikin-hiyou;scoreput();
    }
    if (times2>59) {times1=times1+1;times2=0;}
    if (times1>999) {times1=999;times2=59;times3=59;}
    timeput();stime2f=stime2f+1f;
    risustart();
   }
  }
  if (flg==1 || flg==2)
  {
// bgm-replay
   ntimef=Time.time;
   if (ntimef-stimef>=17f) {bgm1.Play();stimef=Time.time;}
  }
  if (flg==2)
  {
   count=count-1;
   if (count<=0)
   {
    z=72;zx=500;zy=-270;objput();z=73;zx=570;objput();
    z=71;zx=-2000;zy=0;objput();
    flg=1;spacewait=2;
   }
  }
  if (flg==7)
  {
   ntime2f=Time.time;
   if (ntime2f-stime2f>=0.5f)
   {
    stime2f=stime2f+0.5f;count=count+1;
    z=76;zx=-2000;zy=0;objput();z=77;objput();
    z=count%2+76;zx=-200;zy=0;objput();
    if (count>=12) {titleput();}
   }
  }
  if (flg==8)
  {
   usakaku=usakaku-4;
   if (usakaku<=-90) {usakaku=-90;}
   obj[2].transform.rotation=Quaternion.identity;
   obj[2].transform.Rotate(0,0,usakaku);
   if (usakaku<=-90) {flg=9;count=500;}
  }
  if (flg==9)
  {
   count=count-1;
   if (count<=0) {titleput();}
  }
 }

 void gamestart()
 {
  alldel();
  usakaku=0;usahou=-1;z=1;zx=380;zy=-240;objput();
  risunum=0;for (i=0;i<=-1;i++) {newrisu(1);}
  uriage=0;hiyou=200;shikin=1000;scoreput();
  times1=0;times2=0;times3=0;
  outflg=0;nowkaiko=0;
  for (i=0;i<=4;i++)
  {
   tj[i]=0;tkaku[i]=0;tkyo[i]=0;tlv[i]=0;texp[i]=0;tlife[i]=0;tlfs[i]=0;
   tspeed[i]=0;tfk[i]=0;tkkaku[i]=0;txf[i]=0f;tyf[i]=0f;trnum[i]=-1;tw[i]=0;tst[i]=0;
   tj[i]=0;tkaku[i]=i*72+90;if (tkaku[i]>=360) {tkaku[i]=tkaku[i]-360;}
  }
  for (i=0;i<=49;i++)
  {
   rj[i]=0;rkaku[i]=0;rkyo[i]=0;rkuri[i]=0;rgk[i]=0;rlv[i]=0;rexp[i]=0;rlife[i]=0;rlfs[i]=0;
   rspeed[i]=0;rkk[i]=0;rmk[i]=0;rgkk[i]=0;rxf[i]=0f;ryf[i]=0f;rw[i]=0;
  }
  dataload();
  a=0;
  for (i=0;i<=4;i++)
  {
   if (tj[i]>0)
   {
    if (tj[i]==1)
    {
     xf=Mathf.Cos(tkaku[i]*Mathf.PI/180)*75-200;yf=Mathf.Sin(tkaku[i]*Mathf.PI/180)*75;
     z=i+3;objput2();
    }
    if (tj[i]==6) {z=i+3;zx=-200;zy=-75;objput();}
    z=i+13;zx=i*60+260;zy=-58;objput();z=i+18;objput();
    a=a+1;
   }
  }
  if (a<1)
  {
   tj[0]=1;tkaku[0]=90;tkyo[0]=750;tlv[0]=1;texp[0]=0;tlife[0]=0;tlfs[0]=10;
   tspeed[0]=10;tfk[0]=10;tkkaku[0]=0;txf[0]=0f;tyf[0]=0f;trnum[0]=-1;tw[0]=0;tst[0]=1250;
   xf=Mathf.Cos(tkaku[0]*Mathf.PI/180)*75-200;yf=Mathf.Sin(tkaku[0]*Mathf.PI/180)*75;
   z=3;objput2();
   z=13;zx=260;zy=-58;objput();z=18;objput();
  }
  z=60;zx=-2000;zy=0;objput();z=61;objput();
  if (a<=1) {z=61;zx=194;zy=-14;objput();}
  if (a==5) {z=60;zx=194;zy=50;objput();}
  z=56;zx=-200;zy=-290;objput();
  z=72;zx=500;zy=-270;objput();z=73;zx=570;objput();
  hiyoumake();scoreput();timeput();risucount();
  stimef=Time.time;stime2f=Time.time;
  bgmstop();bgm1.Play();
  z=81;zx=260;zy=81;objput();wx=0;wy=0;oldwx=0;oldwy=0;
  flg=1;spacewait=4;scoreput();
 }

 void newtora(int n)
 {
  ee=-1;
  for (ii=0;ii<=4;ii++)
  {
   if (tj[ii]<1) {ee=ii;break;}
  }
  if (ee>=0 && shikin>n*100)
  {
   tj[ee]=1;tkyo[ee]=750;tlv[ee]=n;texp[ee]=0;
   tlife[ee]=0;
   for (jj=0;jj<=4;jj++)
   {
    r=Random.Range(0,10);
    if (r>=tlv[ee]*2+1) {tlife[ee]=tlife[ee]+1;}
   }
   r=Random.Range(8,13);if (r>15) {r=12;}
   tlfs[ee]=r;
   r=Random.Range(tlv[ee]*5,tlv[ee]*15+1);tspeed[ee]=r;if (tspeed[ee]>70) {tspeed[ee]=70;}
   r=Random.Range(5,16);tfk[ee]=r+tlv[ee]*10;if (tfk[ee]>99) {tfk[ee]=99;}
   r=Random.Range(0,tlv[ee]*500+1);tst[ee]=r+750;if (tst[ee]>2750) {tst[ee]=2750;}
   tkkaku[ee]=0;txf[ee]=0f;tyf[ee]=0f;trnum[ee]=-1;tw[ee]=0;
   xf=Mathf.Cos(tkaku[0]*Mathf.PI/180)*75-200;yf=Mathf.Sin(tkaku[0]*Mathf.PI/180)*75;
   z=ee+3;objput2();
   z=ee+13;zx=ee*60+260;zy=-58;objput();z=ee+18;objput();
   hiyoumake();shikin=shikin-n*100;scoreput();
  }
  a=0;
  for (ii=0;ii<=4;ii++) {if (tj[ii]>0) {a=a+1;}}
  z=60;zx=-2000;zy=0;objput();z=61;objput();
  if (a==5) {z=60;zx=194;zy=50;objput();}
 }

 void newrisu(int n)
 {
  ee=-1;
  for (ii=0;ii<=49;ii++)
  {
   a=(ii+risunum)%50;
   if (rj[a]<1) {ee=a;break;}
  }
  if (ee>=0 && shikin>n*n*10)
  {
   rkyo[ee]=260;rj[ee]=1;rlv[ee]=n;rkuri[ee]=0;rgk[ee]=0;rexp[ee]=0;
   rlife[ee]=0;
   for (jj=0;jj<=4;jj++)
   {
    r=Random.Range(0,10);
    if (r>=rlv[ee]*2+1) {rlife[ee]=rlife[ee]+1;}
   }
   r=Random.Range(3,8);if (r>7) {r=7;}
   rlfs[ee]=r;
   r=Random.Range(rlv[ee]*5,rlv[ee]*10);rspeed[ee]=r+1;if (rspeed[ee]>50) {rspeed[ee]=50;}
   r=Random.Range(rlv[ee]*5+30,rlv[ee]*10+41);rkk[ee]=r;if (rkk[ee]>99) {rkk[ee]=99;}
   r=Random.Range(rlv[ee],rlv[ee]+2);rmk[ee]=r;if (rmk[ee]>5) {rmk[ee]=5;}
   r=Random.Range(0,rlv[ee]*2+1);rgkk[ee]=r;
   rxf[ee]=0f;ryf[ee]=0f;rw[ee]=0;
   r=Random.Range(0,330);if (r>329) {r=329;}
   rkaku[ee]=290+r;if (rkaku[ee]>=360) {rkaku[ee]=rkaku[ee]-360;}
   xf=Mathf.Cos(rkaku[ee]*Mathf.PI/180)*26-200;yf=Mathf.Sin(rkaku[ee]*Mathf.PI/180)*26;
   obj[ee+400].transform.rotation=Quaternion.identity;obj[ee+550].transform.rotation=Quaternion.identity;
   obj[ee+650].transform.rotation=Quaternion.identity;obj[ee+500].transform.rotation=Quaternion.identity;
   a=0;
   if (rkaku[ee]<90 || rkaku[ee]>=270) {a=1;}
   risuput(ee,xf,yf,a);
   risunum=risunum+1;if (risunum>49) {risunum=0;}
   shikin=shikin-rlv[ee]*rlv[ee]*10;hiyoumake();risucount();
  }
 }

 void risustart()
 {
  for (ii=0;ii<=49;ii++)
  {
   if (rj[ii]==1) {rj[ii]=2;}
  }
 }

 void risuput(int n,float nxf,float nyf,int m)
 {
  xf=nxf;yf=nyf;
  z=n+400;objput2();if (n<=49) {z=n+500;objput2();}
  z=n+550;objput2();z=n+650;objput2();
  if (m==1)
  {
   obj[n+400].transform.Rotate(0,180,0);obj[n+550].transform.Rotate(0,180,0);obj[n+650].transform.Rotate(0,180,0);
   if (n<=49) {obj[n+500].transform.Rotate(0,180,0);}
  }
 }

 void findrisu(int n)
 {
  r=Random.Range(0,100);
  if (r<=tfk[n])
  {
   ee=-1;
   for (ii=0;ii<=49;ii++)
   {
    a=0;
    for (jj=0;jj<=4;jj++)
    {
     if (trnum[jj]==ii) {a=1;}
    }
    if (a==0 && rj[ii]>=2 && rj[ii]<=3)
    {
     if (tkaku[n]==rkaku[ii] && rkyo[ii]>=750 && rkyo[ii]<=tst[n])
     {
      a=rspeed[ii]*2+rmk[ii]*10+rkk[ii]+rgkk[ii]*10-30;
      if (rlife[ii]>4 && a9 && a=0)
   {
    tj[n]=2;trnum[n]=ee;
   }
  }
 }

 void torakaiko(int n)
 {
  a=0;
  for (ii=0;ii<=4;ii++) {if (tj[ii]>0) {a=a+1;}}
  if (a>1 && nowkaiko==0)
  {
   z=60;zx=-2000;zy=0;objput();z=61;objput();
   if (tj[n]>=1 && tj[n]<=6)
   {
    if (tj[n]==1)
    {
     xf=Mathf.Cos(tkaku[n]*Mathf.PI/180)*75-200;yf=Mathf.Sin(tkaku[n]*Mathf.PI/180)*75;
     txf[n]=xf;tyf[n]=yf;
    }
    if (tj[n]==2)
    {
     xf=Mathf.Cos(tkkaku[n]*Mathf.PI/180)*tkyo[n]*0.1f-200;yf=Mathf.Sin(tkkaku[n]*Mathf.PI/180)*tkyo[n]*0.1f;
     txf[n]=xf;tyf[n]=yf;
    }
    if (tj[n]==4) {txf[n]=(float)-200;tyf[n]=(float)-245;}
    if (tj[n]==5) {txf[n]=-200f;tyf[n]=tkyo[n]*-0.1f;}
    if (tj[n]==6) {txf[n]=-200f;tyf[n]=-75f;}
    z=n+3;zx=-2000;zy=0;objput();z=n+8;xf=txf[n];yf=tyf[n];objput2();
    z=69;yf=yf+24f;objput2();
    if (tj[n]==3 || tj[n]==4)
    {
     xf=txf[n];a=trnum[n];
     if (tj[n]==3) {yf=tyf[n]-25f;} else {yf=(float)(tw[n]-312);}
     obj[a+400].transform.rotation=Quaternion.identity;obj[a+550].transform.rotation=Quaternion.identity;
     obj[a+650].transform.rotation=Quaternion.identity;
     obj[a+450].transform.rotation=Quaternion.identity;obj[a+600].transform.rotation=Quaternion.identity;
     obj[a+700].transform.rotation=Quaternion.identity;
     zx=-2000;zy=0;z=a+450;objput();z=a+600;objput();z=a+700;objput();
     if (xf<-200)
     {
      obj[a+400].transform.Rotate(0,180,0);obj[a+550].transform.Rotate(0,180,0);obj[a+650].transform.Rotate(0,180,0);
      obj[a+500].transform.Rotate(0,180,0);
     }
     z=a+400;objput2();z=a+500;objput2();z=a+550;objput2();z=a+650;objput2();
     rj[a]=8;rxf[a]=xf;ryf[a]=yf;
    }
    if (tj[n]==4) {z=56;zx=-200;zy=-290;objput();z=57;zx=-2000;zy=0;objput();}
    tj[n]=8;trnum[n]=-1;nowkaiko=1;
   }
  }
 }

 void hiyoumake()
 {
  hiyou=100;
  for (ii=0;ii<=4;ii++)
  {
   if (tj[ii]>0) {hiyou=hiyou+tlv[ii]*100;}
  }
  for (ii=0;ii<=49;ii++)
  {
   if (rj[ii]>0) {hiyou=hiyou+rlv[ii]*rlv[ii]*10;}
  }
  scoreput();
 }

 void risucount()
 {
  risukazu=0;
  for (ii=0;ii<=49;ii++)
  {
   if (rj[ii]>0) {risukazu=risukazu+1;}
  }
  for (ii=370;ii<=389;ii++) {z=ii;zx=-2000;zy=0;objput();}
  zy=122;
  a=risukazu/10;if (a>0) {z=a+370;zx=376;objput();}
  a=risukazu%10;z=a+380;zx=400;objput();
  if (risukazu<50) {zx=-2000;} else {zx=194;}
  z=59;zy=114;objput();
 }

 void toralvup(int n)
 {
  texp[n]=texp[n]+1;
  if (texp[n]>=tlfs[n])
  {
   a=tlv[n];
   if (tlife[n]<=4)
   {
    r=Random.Range(a,a*5+1);if (r>a*5) {r=a*5;}
    tspeed[n]=tspeed[n]+r;if (tspeed[n]>70) {tspeed[n]=70;}
    r=Random.Range(a*5,a*10+1);if (r>a*10) {r=a*10;}
    tfk[n]=tfk[n]+r;if (tfk[n]>99) {tfk[n]=99;}
    r=Random.Range(a*10,a*50+1);if (r>a*50) {r=a*50;}
    tst[n]=tst[n]+r;if (tst[n]>2750) {tst[n]=2750;}
   }
   if (tlife[n]>=10)
   {
    r=Random.Range(1,6);if (r>5) {r=5;}
    tspeed[n]=tspeed[n]-r;if (tspeed[n]<5) {tspeed[n]=5;}
    r=Random.Range(5,11);if (r>10) {r=10;}
    tfk[n]=tfk[n]-r;if (tfk[n]<5) {tfk[n]=5;}
    r=Random.Range(10,51);if (r>50) {r=50;}
    tst[n]=tst[n]-r;if (tst[n]<1000) {tst[n]=1000;}
   }
   tlife[n]=tlife[n]+1;texp[n]=0;
  }
 }

 void risulvup(int n)
 {
  rexp[n]=rexp[n]+1;
  if (rexp[n]>=rlfs[n])
  {
   a=rlv[n];
   if (rlife[n]<=4)
   {
    r=Random.Range(a,a*5+1);if (r>a*5) {r=a*5;}
    rspeed[n]=rspeed[n]+r;if (rspeed[n]>50) {rspeed[n]=50;}
    r=Random.Range(0,10);if (r<3 && rmk[n]<5) {rmk[n]=rmk[n]+1;}
    r=Random.Range(a*5,a*10+1);if (r>a*10) {r=a*10;}
    rkk[n]=rkk[n]+r;if (rkk[n]>99) {rkk[n]=99;}
    r=Random.Range(0,a*2+1);if (r>a*2) {r=a*2;}
    rgkk[n]=rgkk[n]+r;if (rgkk[n]>20) {rgkk[n]=20;}
   }
   if (rlife[n]>=10)
   {
    r=Random.Range(2,6);if (r>5) {r=5;}
    rspeed[n]=rspeed[n]-r;if (rspeed[n]<6) {rspeed[n]=6;}
    r=Random.Range(0,10);if (r<3 && rmk[n]>1) {rmk[n]=rmk[n]-1;}
    r=Random.Range(2,11);if (r>10) {r=10;}
    rkk[n]=rkk[n]-r;if (rkk[n]<10) {rkk[n]=10;}
    r=Random.Range(0,3);if (r>2) {r=2;}
    rgkk[n]=rgkk[n]-r;if (rgkk[n]<0) {rgkk[n]=0;}
   }
   rlife[n]=rlife[n]+1;rexp[n]=0;
  }
 }

 void scoreput()
 {
  if (uriage>999999) {uriage=999999;}
  if (hiyou>99999) {hiyou=99999;}
  if (shikin>999999) {shikin=999999;}
  if (uriage<0) {uriage=0;}
  if (hiyou<0) {hiyou=0;}
  if (shikin<0) {shikin=0;}
  for (ii=140;ii<=299;ii++) {z=ii;zx=-2000;zy=0;objput();}
  zy=278;aa=0;
  a=uriage/100000;if (a>0) {aa=1;z=a+140;zx=308;objput();}
  a=(uriage%100000)/10000;if (a>0 || aa>0) {aa=1;z=a+150;zx=332;objput();}
  a=(uriage%10000)/1000;if (a>0 || aa>0) {aa=1;z=a+160;zx=356;objput();}
  a=(uriage%1000)/100;if (a>0 || aa>0) {aa=1;z=a+170;zx=380;objput();}
  a=(uriage%100)/10;if (a>0 || aa>0) {aa=1;z=a+180;zx=404;objput();}
  a=uriage%10;z=a+190;zx=428;objput();
  zy=238;aa=0;
  a=hiyou/10000;if (a>0) {aa=1;z=a+390;zx=332;objput();}
  a=(hiyou%10000)/1000;if (a>0 || aa>0) {aa=1;z=a+200;zx=356;objput();}
  a=(hiyou%1000)/100;if (a>0 || aa>0) {aa=1;z=a+210;zx=380;objput();}
  a=(hiyou%100)/10;if (a>0 || aa>0) {aa=1;z=a+220;zx=404;objput();}
  a=hiyou%10;z=a+230;zx=428;objput();
  zy=198;aa=0;
  a=shikin/100000;if (a>0) {aa=1;z=a+240;zx=308;objput();}
  a=(shikin%100000)/10000;if (a>0 || aa>0) {aa=1;z=a+250;zx=332;objput();}
  a=(shikin%10000)/1000;if (a>0 || aa>0) {aa=1;z=a+260;zx=356;objput();}
  a=(shikin%1000)/100;if (a>0 || aa>0) {aa=1;z=a+270;zx=380;objput();}
  a=(shikin%100)/10;if (a>0 || aa>0) {aa=1;z=a+280;zx=404;objput();}
  a=shikin%10;z=a+290;zx=428;objput();
  if (flg==1)
  {
   usayure=1;z=70;zx=-2000;zy=0;objput();
   if (shikin>0 && shikin=999999)
   {
    obj[1].transform.rotation=Quaternion.identity;
    z=76;zx=-200;zy=0;objput();
    z=72;zx=-2000;objput();z=73;objput();
    bgmstop();bgm6.Play();
    stime2f=Time.time;flg=7;count=0;
   }
  }
 }

 void timeput()
 {
  for (i=300;i<=369;i++) {z=i;zx=-2000;zy=0;objput();}
  if (times1>999) {times1=999;times2=59;times3=59;}
  if (times2>59) {times2=59;times3=59;}
  if (times3>59) {times3=59;}
  zy=158;aa=0;
  a=times1/100;if (a>0) {aa=1;z=a+300;zx=254;objput();}
  a=(times1%100)/10;if (a>0 || aa>0) {aa=1;z=a+310;zx=278;objput();}
  a=times1%10;z=a+320;zx=302;objput();
  a=times2/10;if (a>0) {z=a+330;zx=396;objput();}
  a=times2%10;z=a+340;zx=420;objput();
  a=times3/10;if (a>0) {z=a+350;zx=468;objput();}
  a=times3%10;z=a+360;zx=492;objput();
 }

 void gameover()
 {
  bgmstop();bgm2.Play();
  z=1;zx=-2000;zy=0;objput();z=70;objput();z=71;objput();z=72;objput();z=73;objput();
  z=62;zx=250;zy=-272;objput();
  z=2;zx=380;zy=-240;objput();
  obj[2].transform.rotation=Quaternion.identity;
  obj[2].transform.Rotate(0,0,usakaku);
  flg=8;
 }

 void titleput()
 {
  alldel();bgmstop();flg=0;spacewait=2;
  z=56;zx=-200;zy=-290;objput();z=63;zx=-200;zy=0;objput();
  z=1;zx=380;zy=-240;objput();obj[1].transform.rotation=Quaternion.identity;
  usakaku=-1;usahou=1;usayure=1;
  uriage=0;hiyou=0;shikin=0;scoreput();
  z=78;zx=6;zy=-134;objput();wx=1;wy=0;oldwx=1;oldwy=0;
  times1=0;times2=0;times3=0;timeput();risucount();
 }

 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();bgm4.Stop();bgm5.Stop();bgm6.Stop();
 }

 void alldel()
 {
  z=0;zx=-2000;zy=0;objput();
  zx=-2000;zy=0;for (i=1;i<=83;i++) {z=i;objput();}
  for (i=140;i<=399;i++) {z=i;objput();}
  for (i=400;i<=1049;i++) {z=i;objput();}
  for (i=1;i<=2;i++) {obj[i].transform.rotation=Quaternion.identity;}
  for (i=400;i<=749;i++) {obj[i].transform.rotation=Quaternion.identity;}
 }

 void datasave()
 {
  bigdata="";
  for (ii=0;ii<=4;ii++)
  {
   d=tj[ii].ToString()+" "+tkaku[ii].ToString()+" "+tkyo[ii].ToString()+" "+tlv[ii].ToString()+" ";
   d=d+texp[ii].ToString()+" "+tlife[ii].ToString()+" "+tlfs[ii].ToString()+" "+tspeed[ii].ToString()+" ";
   d=d+tfk[ii].ToString()+" "+tkkaku[ii].ToString()+" "+txf[ii].ToString()+" "+tyf[ii].ToString()+" ";
   d=d+trnum[ii].ToString()+" "+tw[ii].ToString()+" "+tst[ii].ToString();
   bigdata=bigdata+d+"/";
  }
  for (ii=0;ii<=49;ii++)
  {
   d=rj[ii].ToString()+" "+rkaku[ii].ToString()+" "+rkyo[ii].ToString()+" "+rkuri[ii].ToString()+" ";
   d=d+rgk[ii].ToString()+" "+rlv[ii].ToString()+" "+rexp[ii].ToString()+" "+rlife[ii].ToString()+" ";
   d=d+rlfs[ii].ToString()+" "+rspeed[ii].ToString()+" "+rkk[ii].ToString()+" "+rmk[ii].ToString()+" ";
   d=d+rgkk[ii].ToString()+" "+rxf[ii].ToString()+" "+ryf[ii].ToString()+" "+rw[ii].ToString();
   bigdata=bigdata+d+"/";
  }
  bigdata=bigdata+uriage.ToString()+"/"+shikin.ToString()+"/";
  bigdata=bigdata+times1.ToString()+"/"+times2.ToString()+"/";
  bigdata=bigdata+times3.ToString()+"/"+nowkaiko.ToString()+"/"+risunum.ToString();
  PlayerPrefs.SetString(keyname,bigdata);
  PlayerPrefs.Save();
  z=72;zx=-2000;zy=0;objput();z=73;objput();
  z=71;zx=510;zy=-270;objput();
  flg=2;count=50;
 }

 void dataload()
 {
  bigdata=PlayerPrefs.GetString(keyname,"nothing");
  if (bigdata!="nothing")
  {
   for (ii=0;ii<=99;ii++) {bigdata=bigdata+"/-";}
   datas=bigdata.Split('/');
   for (ii=0;ii<=4;ii++)
   {
    d="0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0";
    if (datas[ii]!=null && datas[ii]!="-")
    {
     d=datas[ii];
     for (jj=0;jj<=99;jj++) {d=d+" x";}
    }
    dts=d.Split(' ');
    if (dts[0]!=null && dts[0]!="x") {tj[ii]=int.Parse(dts[0]);} else {tj[ii]=0;}
    if (dts[1]!=null && dts[1]!="x") {tkaku[ii]=int.Parse(dts[1]);} else {tkaku[ii]=0;}
    if (dts[2]!=null && dts[2]!="x") {tkyo[ii]=int.Parse(dts[2]);} else {tkyo[ii]=0;}
    if (dts[3]!=null && dts[3]!="x") {tlv[ii]=int.Parse(dts[3]);} else {tlv[ii]=0;}
    if (dts[4]!=null && dts[4]!="x") {texp[ii]=int.Parse(dts[4]);} else {texp[ii]=0;}
    if (dts[5]!=null && dts[5]!="x") {tlife[ii]=int.Parse(dts[5]);} else {tlife[ii]=0;}
    if (dts[6]!=null && dts[6]!="x") {tlfs[ii]=int.Parse(dts[6]);} else {tlfs[ii]=0;}
    if (dts[7]!=null && dts[7]!="x") {tspeed[ii]=int.Parse(dts[7]);} else {tspeed[ii]=0;}
    if (dts[8]!=null && dts[8]!="x") {tfk[ii]=int.Parse(dts[8]);} else {tfk[ii]=0;}
    if (dts[9]!=null && dts[9]!="x") {tkkaku[ii]=int.Parse(dts[9]);} else {tkkaku[ii]=0;}
    if (dts[10]!=null && dts[10]!="x") {txf[ii]=float.Parse(dts[10]);} else {txf[ii]=0f;}
    if (dts[11]!=null && dts[11]!="x") {tyf[ii]=float.Parse(dts[11]);} else {tyf[ii]=0f;}
    if (dts[12]!=null && dts[12]!="x") {trnum[ii]=int.Parse(dts[12]);} else {trnum[ii]=-1;}
    if (dts[13]!=null && dts[13]!="x") {tw[ii]=int.Parse(dts[13]);} else {tw[ii]=0;}
    if (dts[14]!=null && dts[14]!="x") {tst[ii]=int.Parse(dts[14]);} else {tst[ii]=0;}
   }
   for (ii=0;ii<=49;ii++)
   {
    d="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0";
    if (datas[ii+5]!=null && datas[ii+5]!="-")
    {
     d=datas[ii+5];
     for (jj=0;jj<=99;jj++) {d=d+" x";}
    }
    dts=d.Split(' ');
    if (dts[0]!=null && dts[0]!="x") {rj[ii]=int.Parse(dts[0]);} else {rj[ii]=0;}
    if (dts[1]!=null && dts[1]!="x") {rkaku[ii]=int.Parse(dts[1]);} else {rkaku[ii]=0;}
    if (dts[2]!=null && dts[2]!="x") {rkyo[ii]=int.Parse(dts[2]);} else {rkyo[ii]=0;}
    if (dts[3]!=null && dts[3]!="x") {rkuri[ii]=int.Parse(dts[3]);} else {rkuri[ii]=0;}
    if (dts[4]!=null && dts[4]!="x") {rgk[ii]=int.Parse(dts[4]);} else {rgk[ii]=0;}
    if (dts[5]!=null && dts[5]!="x") {rlv[ii]=int.Parse(dts[5]);} else {rlv[ii]=0;}
    if (dts[6]!=null && dts[6]!="x") {rexp[ii]=int.Parse(dts[6]);} else {rexp[ii]=0;}
    if (dts[7]!=null && dts[7]!="x") {rlife[ii]=int.Parse(dts[7]);} else {rlife[ii]=0;}
    if (dts[8]!=null && dts[8]!="x") {rlfs[ii]=int.Parse(dts[8]);} else {rlfs[ii]=0;}
    if (dts[9]!=null && dts[9]!="x") {rspeed[ii]=int.Parse(dts[9]);} else {rspeed[ii]=0;}
    if (dts[10]!=null && dts[10]!="x") {rkk[ii]=int.Parse(dts[10]);} else {rkk[ii]=0;}
    if (dts[11]!=null && dts[11]!="x") {rmk[ii]=int.Parse(dts[11]);} else {rmk[ii]=0;}
    if (dts[12]!=null && dts[12]!="x") {rgkk[ii]=int.Parse(dts[12]);} else {rgkk[ii]=0;}
    if (dts[13]!=null && dts[13]!="x") {rxf[ii]=float.Parse(dts[13]);} else {rxf[ii]=0f;}
    if (dts[14]!=null && dts[14]!="x") {ryf[ii]=float.Parse(dts[14]);} else {ryf[ii]=0f;}
    if (dts[15]!=null && dts[15]!="x") {rw[ii]=int.Parse(dts[15]);} else {rw[ii]=0;}
    a=0;
    if ((rj[ii]==1 || rj[ii]==2) && (rkaku[ii]<90 || rkaku[ii]>=270)) {a=1;}
    if ((rj[ii]==3 || rj[ii]==5) && (rkaku[ii]>=90 || rkaku[ii]<270)) {a=1;}
    if (rj[ii]==8 && rxf[ii]<-200) {a=1;}
    if (a==1)
    {
     obj[ii+400].transform.Rotate(0,180,0);obj[ii+500].transform.Rotate(0,180,0);
     obj[ii+550].transform.Rotate(0,180,0);obj[ii+650].transform.Rotate(0,180,0);
    }
   }
   if (datas[55]!=null && datas[55]!="-") {uriage=int.Parse(datas[55]);} else {uriage=0;}
   if (datas[56]!=null && datas[56]!="-") {shikin=int.Parse(datas[56]);} else {shikin=1000;}
   if (datas[57]!=null && datas[57]!="-") {times1=int.Parse(datas[57]);} else {times1=0;}
   if (datas[58]!=null && datas[58]!="-") {times2=int.Parse(datas[58]);} else {times2=0;}
   if (datas[59]!=null && datas[59]!="-") {times3=int.Parse(datas[59]);} else {times3=0;}
   if (datas[60]!=null && datas[60]!="-") {nowkaiko=int.Parse(datas[60]);} else {nowkaiko=0;}
   if (datas[61]!=null && datas[61]!="-") {risunum=int.Parse(datas[61]);} else {risunum=0;}
  }
 }
}