using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ninin_ninja : MonoBehaviour
{
int flg=-1;int count=0;int wait=0;int spacewait=0;int level=0;int score=0;int nbyou=0;int shield;
int nnwait;int ninjanum;int smwait;int shudwait;int shudcount;
int[] px=new int[2];int[] py=new int[2];int[] pym=new int[100];int[] pout=new int[2];
int[] psx=new int[20];int[] psy=new int[20];
int[] tx=new int[100];int[] ty=new int[100];int[] tyy=new int[100];int[] tj=new int[100];int[] tw=new int[100];
int[] tsx=new int[1020];int[] tsy=new int[1020];int[] tsxx=new int[1020];int[] tsyy=new int[1020];int[] tsw=new int[1020];
int[] smx=new int[20];int[] smy=new int[20];int[] smxx=new int[20];int[] smc=new int[20];int[] smw=new int[20];
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 e;int e1;int a1;int a2;int moves;int mousex;int mousey;
float stimef;float ntimef;float xf;float yf;float stime2f;float ntime2f;float af;
string c1;string c2;string c3;string c4;
GUIStyle style1;GUIStyle style2;GUIStyle style3;
GameObject[] obj=new GameObject[2000];
AudioSource bgm1;AudioSource bgm2;AudioSource bgm3;
void Start()
{
obj[0]=GameObject.Find("ng-mes"); // 0 ng-mes
for (i=1;i<=14;i++) {obj[i]=GameObject.Find("ninja-"+i);} // 1-4=ninja 5-14=ninja-moto
for (i=1;i<=7;i++) {obj[i+14]=GameObject.Find("ninja-smoke-"+i);} // 15-21 smoke-moto
for (i=1;i<=3;i++) {obj[i+21]=GameObject.Find("shuriken-"+i);} // 22-24 shurken-moto
for (i=1;i<=4;i++) {obj[i+24]=GameObject.Find("maki-"+i);} // 25-28 makis
for (i=1;i<=3;i++) {obj[i+28]=GameObject.Find("shield-"+i);} // 29-31 shields
obj[32]=GameObject.Find("ninja-title"); // 32 title
obj[33]=GameObject.Find("ninja-tt"); // 33 ninja-tt
obj[34]=GameObject.Find("shuriken-tt"); // 34 shuriken-tt
for (i=1;i<=4;i++) {obj[i+34]=GameObject.Find("ninja-endmes-"+i);} // 35-36=completed 37-38=gameover
for (i=0;i<=9;i++)
{
obj[i+40]=GameObject.Find("num-"+i); // 40-49 nums-moto
}
for (i=0;i<=5;i++)
{
for (j=0;j<=9;j++) {obj[i*10+j+50]=Object.Instantiate(obj[j+40]) as GameObject;} // 40-99 nums
}
for (i=0;i<=9;i++)
{
for (j=0;j<=19;j++) {obj[i*20+j+100]=Object.Instantiate(obj[i+5]) as GameObject;} // 100-299 e-ninja-copy
}
for (i=0;i<=6;i++)
{
for (j=0;j<=19;j++) {obj[i*20+j+300]=Object.Instantiate(obj[i+15]) as GameObject;} // 300-439 smoke-copy
}
for (i=0;i<=4;i++) {obj[i+440]=Object.Instantiate(obj[22]) as GameObject;} // 440-444 shuriken-silver-copy
for (i=0;i<=14;i++) {obj[i+445]=Object.Instantiate(obj[23]) as GameObject;} // 445-459 shuriken-pink-copy
for (i=0;i<=9;i++)
{
obj[i+460]=Object.Instantiate(obj[24]) as GameObject;
obj[i+460].transform.Rotate(0,0,90); // 460-469 shuriken-enemy-down
}
for (i=0;i<=9;i++)
{
obj[i+470]=Object.Instantiate(obj[24]) as GameObject;
obj[i+470].transform.Rotate(0,0,270); // 470-479 shuriken-enemy-up
}
for (i=0;i<=999;i++) {obj[i+480]=Object.Instantiate(obj[24]) as GameObject;} // 480-1479 shuriken-enemy-left
for (i=0;i<=9;i++)
{
obj[i+1480]=Object.Instantiate(obj[24]) as GameObject; // 1480-1489 shuriken-down
obj[i+1480].transform.rotation=Quaternion.identity;obj[i+1480].transform.Rotate(0,0,90);
obj[i+1490]=Object.Instantiate(obj[24]) as GameObject; // 1490-1499 shuriken-down
obj[i+1490].transform.rotation=Quaternion.identity;obj[i+1490].transform.Rotate(0,0,270);
}
bgm1=obj[1].GetComponent();bgm2=obj[2].GetComponent();
bgm3=obj[3].GetComponent();
style1=new GUIStyle();style1.fontSize=40;
style2=new GUIStyle();style2.fontSize=16;
style3=new GUIStyle();style3.fontSize=24;style3.normal.textColor=Color.red;
c1="";c2="";c3="";c4="";
alldel();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=mousex.ToString()+" "+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)
{
x=0;y=0;
if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.Keypad8)) {y=1;}
if (Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.Keypad2)) {y=-1;}
if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.Keypad6)) {x=1;}
if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.Keypad4)) {x=-1;}
if (x!=0 && y!=0)
{
if (x==-1 && y==1) {xx=-5;yy=6;level=0;}
if (x==1 && y==1) {xx=5;yy=6;level=1;}
if (x==-1 && y==-1) {xx=-5;yy=-2;level=2;}
if (x==1 && y==-1) {xx=5;yy=-2;level=3;}
flg=1;count=0;wait=2;
}
}
if (flg==1)
{
wait=wait-1;
if (wait<=0)
{
count=count+1;
z=34;zx=xx*count;zy=yy*count-20;objput();obj[z].transform.Rotate(0,0,9);
if (count>=20) {flg=2;count=0;} else {wait=2;}
}
}
if (flg==2)
{
count=count+1;
if (count>=50) {gamestart();}
}
if (flg==3)
{
if (spacewait>0) {spacewait=spacewait-1;}
// player move
pout[0]=0;pout[1]=0;x=0;y=0;
if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.Keypad8)) {y=1;}
if (Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.Keypad2)) {y=-1;}
if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.Keypad6)) {x=1;}
if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.Keypad4)) {x=-1;}
if (x==1) {px[0]=px[0]+2;if (px[0]>-30) {px[0]=-30;}}
if (x==-1) {px[0]=px[0]-2;if (px[0]<-300) {px[0]=-300;}}
if (y==1) {py[0]=py[0]+2;if (py[0]>124) {py[0]=124;}}
if (y==-1) {py[0]=py[0]-2;if (py[0]<-124) {py[0]=-124;}}
for (i=49;i>=0;i--) {pym[i+1]=pym[i];}
pym[0]=py[0];py[1]=pym[49];
if (Input.GetKeyDown(KeyCode.Space) && spacewait<=0)
{
e=-1;for (i=0;i<=4;i++) {if (psx[i]<-999) {e=i;break;}}
if (e>=0)
{
psx[e]=px[0]+25;psy[e]=py[0];z=e+440;zx=psx[e];zy=psy[e];objput();
obj[z].transform.rotation=Quaternion.identity;
e1=-1;for (i=0;i<=14;i++) {if (psx[i+5]<-999) {e1=i+5;break;}}
if (e1>=0)
{
psx[e1]=px[1]+25;psy[e1]=py[1];z=e1+440;zx=psx[e1];zy=psy[e1];objput();
obj[z].transform.rotation=Quaternion.identity;
}
}
}
// shield-move
e=0;for (i=0;i<=4;i++) {if (psx[i]>-999) {e=e+1;}}
if (e<=1) {shield=3;}
if (e==2) {shield=2;}
if (e==3) {shield=1;}
if (e>=4) {shield=0;}
for (i=29;i<=31;i++) {z=i;zx=-1000;zy=0;objput();}
if (shield>0) {z=shield+28;zx=px[0]+35;zy=py[0];objput();}
// enemy-ninja-move
nnwait=nnwait-1;if (nnwait<=0) {newninja();}
for (i=0;i<=99;i++)
{
if (tx[i]>-999)
{
if (tj[i]==0)
{
if (i<80) {tx[i]=tx[i]-2;aa=1;} else {tx[i]=tx[i]-4;aa=2;}
if (tx[i]<=-425) {tx[i]=-1000;ty[i]=0;}
z=i+100;zx=tx[i];zy=ty[i];objput();
ty[i]=ty[i]+tyy[i];
if (ty[i]<=-174 && tyy[i]<0) {ty[i]=-174;tyy[i]=tyy[i]*-1;}
if (ty[i]>=174 && tyy[i]>0) {ty[i]=174;tyy[i]=tyy[i]*-1;}
a1=0;
if (tyy[i]>0) {a1=1;}
if (tyy[i]<0) {a1=-1;}
tw[i]=tw[i]-1;if (tw[i]<=0) {newshuri(tx[i],ty[i],a1,aa);tw[i]=(5-level)*40+20;}
for (j=0;j<=1;j++)
{
ax=tx[i]-px[j];ay=ty[i]-py[j];af=Mathf.Sqrt(ax*ax+ay*ay);
if (af<=45) {pout[j]=1;}
}
for (j=0;j<=19;j++)
{
if (psx[j]>-999)
{
ax=tx[i]-psx[j];ay=ty[i]-psy[j];af=Mathf.Sqrt(ax*ax+ay*ay);
if (af<=35)
{
z=i+100;zx=-1000;zy=0;objput();z=i+200;zx=tx[i];zy=ty[i];objput();
z=j+440;zx=-1000;zy=0;objput();psx[j]=-1000;psy[j]=0;
tw[i]=50;tj[i]=1;score=score+1;scoreput();
}
}
}
}
else
{
tw[i]=tw[i]-1;
if (tw[i]<=0) {z=i+200;zx=-1000;zy=0;objput();tx[i]=-1000;ty[i]=0;}
}
}
}
// shuriken-enemy-move
for (i=0;i<=999;i++)
{
if (tsx[i]>-999)
{
tsy[i]=tsy[i]+tsyy[i];
if (tsy[i]<=-194 && tsyy[i]<0) {tsy[i]=-194;tsyy[i]=tsyy[i]*-1;}
if (tsy[i]>=194 && tsyy[i]>0) {tsy[i]=194;tsyy[i]=tsyy[i]*-1;}
tsx[i]=tsx[i]+tsxx[i];if (tsx[i]<=-412) {tsx[i]=-1000;tsy[i]=0;}
if (shield>0)
{
ax=Mathf.Abs((px[0]+35)-tsx[i]);ay=Mathf.Abs(py[0]-tsy[i]);
if (ax<=20 && ay<=shield*25+2) {tsx[i]=-1000;tsy[i]=0;}
}
for (j=0;j<=1;j++)
{
ax=Mathf.Abs(px[j]-tsx[i]);ay=Mathf.Abs(py[j]-tsy[i]);
if (ax<=20 && ay<=20) {pout[j]=1;}
}
z=i+480;zx=tsx[i];zy=tsy[i];objput();
}
}
// shuriken-updown-move
if (level>0) {shudwait=shudwait-1;}
if (shudwait<=0) {newshud();shudwait=(5-level)*100+100;}
for (i=1000;i<=1019;i++)
{
if (tsx[i]>-999)
{
if (tsw[i]>0) {tsw[i]=tsw[i]-1;}
if (tsw[i]<=0)
{
tsy[i]=tsy[i]+tsyy[i];if (tsy[i]<=-212 || tsy[i]>=212) {tsx[i]=-1000;tsy[i]=0;}
if (shield>0)
{
ax=Mathf.Abs((px[0]+35)-tsx[i]);ay=Mathf.Abs(py[0]-tsy[i]);
if (ax<=12 && ay<=shield*25+11) {tsx[i]=-1000;tsy[i]=0;}
}
ax=Mathf.Abs(px[0]-tsx[i]);ay=Mathf.Abs(py[0]-tsy[i]);
if (ax<=20 && ay<=20) {pout[0]=1;}
}
z=i+480;zx=tsx[i];zy=tsy[i];objput();
}
}
// smoke-move
smwait=smwait-1;
if (smwait<=0) {newsmoke();smwait=(4-level)*50+50;}
for (i=0;i<=19;i++)
{
if (smx[i]>-999)
{
if (smc[i]==99)
{
smw[i]=smw[i]-1;
if (smw[i]<=0) {z=i+340;zx=-1000;zy=0;objput();smx[i]=-1000;}
}
if (smc[i]==22)
{
smw[i]=smw[i]-1;
if (smw[i]<=0) {z=i+420;zx=-1000;zy=0;objput();smx[i]=-1000;}
}
if (smc[i]>=12 && smc[i]<=21)
{
smw[i]=smw[i]-1;
if (smw[i]<=0)
{
z=i+380;zx=-1000;zy=0;objput();z=i+400;objput();smc[i]=smc[i]+1;
if (smc[i]<=21) {z=(smc[i]%2)*20+i+380;zx=smx[i];zy=smy[i];objput();smw[i]=50;}
else {z=i+420;zx=smx[i];zy=smy[i];objput();smw[i]=50;}
}
}
if (smc[i]==11)
{
smw[i]=smw[i]-1;
if (smw[i]<=0)
{
z=i+360;zx=-1000;zy=0;objput();z=i+380;zx=smx[i];zy=smy[i];objput();
smc[i]=smc[i]+1;smw[i]=50;
}
}
if (smc[i]>=1 && smc[i]<=10)
{
smw[i]=smw[i]-1;
if (smw[i]<=0)
{
z=i+300;zx=-1000;zy=0;objput();z=i+320;objput();smc[i]=smc[i]+1;
if (smc[i]<=10) {z=(smc[i]%2)*20+i+300;zx=smx[i];zy=smy[i];objput();smw[i]=20;}
else {z=i+360;zx=smx[i];zy=smy[i];objput();smw[i]=20;}
}
}
if (smc[i]==0)
{
smx[i]=smx[i]-4;z=i+300;zx=smx[i];zy=smy[i];objput();
if (smx[i]<=smxx[i])
{
smx[i]=smxx[i];z=i+320;zx=smx[i];zy=smy[i];objput();
z=i+300;zx=-1000;zy=0;objput();
smc[i]=1;smw[i]=20;
}
}
if (smc[i]<=10)
{
for (j=0;j<=19;j++)
{
if (psx[j]>-999)
{
ax=smx[i]-psx[j];ay=smy[i]-psy[j];af=Mathf.Sqrt(ax*ax+ay*ay);
if (af<=26)
{
z=i+300;zx=-1000;zy=0;objput();z=i+320;objput();smc[i]=99;smw[i]=50;
z=i+340;zx=smx[i];zy=smy[i];objput();
z=j+440;zx=-1000;zy=0;objput();psx[j]=-1000;psy[j]=0;
score=score+1;scoreput();
}
}
}
}
}
}
// shuriken-players-move
for (i=0;i<=19;i++)
{
if (psx[i]>-999)
{
psx[i]=psx[i]+5;if (psx[i]>=412) {psx[i]=-1000;psy[i]=0;}
if (i>=5)
{
ax=psx[i]-px[0];ay=psy[i]-py[0];af=Mathf.Sqrt(ax*ax+ay*ay);
if (af<=30f) {pout[0]=1;}
}
z=i+440;zx=psx[i];zy=psy[i];objput();obj[z].transform.Rotate(0,0,-10);
}
}
for (i=1;i<=4;i++) {z=i;zx=-1000;zy=0;objput();}
z=pout[0]*2+1;zx=px[0];zy=py[0];objput();z=pout[1]*2+2;zx=px[1];zy=py[1];objput();
if (pout[0]>0 || pout[1]>0)
{
bgmstop();bgm3.Play();
flg=6;count=-1;
}
}
if (flg==3)
{
ntimef=Time.time;
if (ntimef-stimef>=35f) {bgm1.Play();stimef=Time.time;}
ntime2f=Time.time;
if (ntime2f-stime2f>=1f)
{
nbyou=nbyou-1;if (nbyou<0) {nbyou=0;}
timeput();stime2f=stime2f+1f;
if (nbyou<=0)
{
bgmstop();
zx=-1000;zy=0;
for (i=29;i<=31;i++) {z=i;objput();}
for (i=100;i<=1499;i++) {z=i;objput();}
flg=4;count=0;
}
}
}
if (flg==4)
{
for (i=0;i<=1;i++)
{
px[i]=px[i]+8;if (px[i]>=424) {px[i]=424;}
if (py[i]>0) {py[i]=py[i]-1;if (py[i]<=0) {py[i]=0;}}
if (py[i]<0) {py[i]=py[i]+1;if (py[i]>=0) {py[i]=0;}}
z=i+1;zx=px[i];zy=py[i];objput();
}
if (px[0]>=424 && px[1]>=424)
{
bgmstop();bgm2.Play();
flg=5;count=-1;
}
}
if (flg==5 || flg==6)
{
count=count+1;
if (count%30==0)
{
for (i=35;i<=38;i++) {z=i;zx=-1000;zy=0;objput();}
a=(count/30)%2;a1=(flg-5)*2;
z=35+a+a1;zx=0;zy=0;objput();
}
if (count>=300)
{
titleput();
count=0;flg=0;spacewait=2;
}
}
if (flg>=3) {if (Input.GetKeyDown(KeyCode.Escape)) {titleput();flg=0;spacewait=2;}}
}
void gamestart()
{
alldel();score=0;nbyou=120;scoreput();timeput();
px[0]=-300;py[0]=0;px[1]=-375;py[1]=0;
for (i=0;i<=49;i++) {pym[i]=py[0];}
for (i=0;i<=19;i++) {psx[i]=-1000;psy[i]=0;}
for (i=0;i<=99;i++) {tx[i]=-1000;ty[i]=0;tyy[i]=0;tj[i]=0;tw[i]=0;}
for (i=0;i<=1019;i++) {tsx[i]=-1000;tsy[i]=0;tsxx[i]=0;tsyy[i]=0;tsw[i]=0;}
for (i=0;i<=19;i++) {smx[i]=-1000;smy[i]=0;smxx[i]=0;smc[i]=0;smw[i]=0;}
z=1;zx=px[0];zy=py[0];objput();z=2;zx=px[1];zy=py[1];objput();
z=level+25;zx=-366;zy=230;objput();
nnwait=0;ninjanum=0;nnwait=(5-level)*50;newninja();smwait=(4-level)*50+25;
shudwait=(5-level)*100;shudcount=0;
stimef=Time.time;stime2f=Time.time;bgmstop();bgm1.Play();
flg=3;spacewait=2;
}
void newninja()
{
e=-1;for (i=0;i<=19;i++) {if (tx[ninjanum*20+i]<-999) {e=ninjanum*20+i;break;}}
if (e>=0)
{
tx[e]=425;ty[e]=Random.Range(-124,125);
r=Random.Range(0,2);if (r==0) {a=1;} else {a=-1;}
tyy[e]=ninjanum*a;if (ninjanum==4) {tyy[e]=0;}
tw[e]=(5-level)*20-15;tj[e]=0;
}
ninjanum=ninjanum+1;if (ninjanum>level+1) {ninjanum=0;}
nnwait=(5-level)*50+50;
}
void newshuri(int n1,int n2,int n3,int n4)
{
e=-1;for (j=0;j<=19;j++) {if (tsx[j]<-999) {e=j;break;}}
if (e>=0)
{
if (n1>-300)
{
tsx[e]=n1-20;tsy[e]=n2;tsxx[e]=-5*n4;
r=Random.Range(0,3);tsyy[e]=n3*r;tsw[e]=0;
z=e+480;zx=tsx[e];zy=tsy[e];objput();
}
}
}
void newshud()
{
if (shudcount==0)
{
e=-1;for (i=0;i<=9;i++) {if (tsx[1000+i]<-999) {e=i+1000;break;}}
if (e>=0)
{
r=Random.Range(0,10);tsx[e]=r*30-300;tsy[e]=186;tsyy[e]=-10;tsw[e]=100;
z=e+480;zx=tsx[i];zy=tsy[i];objput();shudcount=1;
}
shudwait=(4-level)*200;shudcount=1;
}
else
{
e=-1;for (i=0;i<=9;i++) {if (tsx[1010+i]<-999) {e=i+1010;break;}}
if (e>=0)
{
r=Random.Range(0,10);tsx[e]=r*30-300;tsy[e]=-186;tsyy[e]=10;tsw[e]=100;
z=e+480;zx=tsx[i];zy=tsy[i];objput();shudcount=1;
}
shudwait=(4-level)*200;shudcount=0;
}
}
void newsmoke()
{
e=-1;for (i=0;i<=19;i++) {if (smx[i]<-999) {e=i;break;}}
if (e>=0)
{
smx[e]=416;smc[e]=0;smw[e]=0;
smy[e]=Random.Range(-124,125);smxx[e]=Random.Range(-300,-31);
}
}
void scoreput()
{
if (score>999) {score=999;}
for (ii=40;ii<=69;ii++) {z=ii;zx=-1000;zy=0;objput();}
z=score/100+40;zx=362;zy=240;objput();
z=(score%100)/10+50;zx=376;zy=240;objput();
z=score%10+60;zx=390;zy=240;objput();
}
void timeput()
{
for (ii=70;ii<=99;ii++) {z=ii;zx=-1000;zy=0;objput();}
z=nbyou/100+70;zx=362;zy=215;objput();
z=(nbyou%100)/10+80;zx=376;zy=215;objput();
z=nbyou%10+90;zx=390;zy=215;objput();
}
void titleput()
{
alldel();z=32;zx=0;zy=0;objput();z=33;zx=0;zy=20;objput();
z=34;zx=0;zy=-16;objput();obj[34].transform.rotation=Quaternion.identity;
z=25;zx=-100;zy=100;objput();z=26;zx=100;zy=100;objput();
z=27;zx=-100;zy=-60;objput();z=28;zx=100;zy=-60;objput();
bgmstop();spacewait=2;flg=0;count=0;
}
void OnGUI()
{
GUI.Label (new Rect (900,200,100,30),c1,style2);
GUI.Label (new Rect (330,100,100,30),c2,style2);
GUI.Label (new Rect (330,200,100,30),c3,style1);
GUI.Label (new Rect (530,300,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 bgmstop()
{
bgm1.Stop();bgm2.Stop();bgm3.Stop();
}
void alldel()
{
z=0;zx=-2000;zy=0;objput();
zx=-1000;zy=0;for (i=1;i<=38;i++) {z=i;objput();}
for (i=40;i<=1479;i++) {z=i;objput();obj[i].transform.rotation=Quaternion.identity;}
for (i=1480;i<=1499;i++) {z=i;objput();}
obj[34].transform.rotation=Quaternion.identity;
}
}