📄 npc1.java
字号:
import java.util.Random;
import javax.microedition.lcdui.Image;
public class NPC1 extends NPC
{
Random r;
int p,mx,mz;
public NPC1(Image _im, int[][] _pd, int[] _fs, MC mc,int _x,int _z)
{
super(_im, _pd, _fs);
FS = new int[][]{
{0, 0, 0, 0, 0, 1, 1, 1}, //0原地状态
{2, 2, 3, 3, 4, 4, 5, 5}, //1跑步
{13,20,27,28}, //2攻击状态
{12}, // 3后仰状态
{14,15}, // 4击飞
{16},//5倒地
{17},//6爬起
{16,29}};//7死
hp = 10;
f = true;
// x = mc.cx +150;
x = _x;
z = _z;
r = new Random();
// z = Math.abs( r.nextInt() % 80)+110;
}
public void upData(MC mc,PL pl)
{
this.nextFrame() ;
if (x > pl.x )
{
f = true;
}
else
{
f = false;
}
switch (m)
{
case 0:
this.setfs( FS[0]);
n --;
if (n <= 0)
{
p = Math.abs( r.nextInt() %100);
if (p < 30) //30%的几率进入状态 1
{
m = 1;
n = Math.abs( r.nextInt() %30)+20;
this.setfs( FS[1]);
}
else if (p < 60) // 30-60,30%几率进入状态 2
{
m = 2;
n = Math.abs( r.nextInt() %30)+20;
this.setfs( FS[1]);
}
else if (p < 75) // 60-75,15%几率进入状态 3
{
m = 3;
n = Math.abs( r.nextInt() %30)+20;
this.setfs( FS[1]);
if (x > pl.x)
{
mx = x + 100;
}
else
{
mx = x - 100;
}
}
else if (p < 90) // 75-90,15%几率进入状态 4
{
m = 4;
n = Math.abs( r.nextInt() %30)+20;
this.setfs( FS[1]);
}
else // 90-100 ,10%几率进入状态 0 待机
{
m = 0;
n = Math.abs( r.nextInt() %30)+20;
}
}
break;
case 1: //X轴接近
if (x > pl.x )
{
x -= 5;
}
else
{
x += 5;
}
// n --;
if (Math.abs( x - pl.x) < 15)
{
p = Math.abs( r.nextInt() %100);
if (p < 30) //30%的几率进入状态 1
{
m = 1;
n = Math.abs( r.nextInt() %30)+20;
this.setfs( FS[1]);
}
else if (p < 60) // 30-60,30%几率进入状态 2
{
m = 2;
n = Math.abs( r.nextInt() %30)+20;
this.setfs( FS[1]);
}
else if (p < 75) // 60-75,15%几率进入状态 3
{
m = 3;
n = Math.abs( r.nextInt() %30)+20;
this.setfs( FS[1]);
if (x > pl.x)
{
mx = x + 100;
}
else
{
mx = x - 100;
}
}
else if (p < 90) // 75-90,15%几率进入状态 4
{
m = 4;
n = Math.abs( r.nextInt() %30)+20;
this.setfs( FS[1]);
}
else // 90-100 ,10%几率进入状态 0 待机
{
m = 0;
n = Math.abs( r.nextInt() %30)+20;
}
}
if (Math.abs( x - pl.x ) < 20 && Math.abs( z - pl.z ) < 5)
{
m = 5;
n = Math.abs( r.nextInt() %5)+5;
this.setfs( FS[2]);
}
break;
case 2: //Z轴接近
if (z > pl.z )
{
z -= 3;
}
else
{
z += 3;
}
// n --;
if (Math.abs( z - pl.z) < 10)
{
p = Math.abs( r.nextInt() %100);
if (p < 30) //30%的几率进入状态 1
{
m = 1;
n = Math.abs( r.nextInt() %30)+20;
this.setfs( FS[1]);
}
else if (p < 60) // 30-60,30%几率进入状态 2
{
m = 2;
n = Math.abs( r.nextInt() %30)+20;
this.setfs( FS[1]);
}
else if (p < 75) // 60-75,15%几率进入状态 3
{
m = 3;
n = Math.abs( r.nextInt() %30)+20;
this.setfs( FS[1]);
if (x > pl.x)
{
mx = x + 100;
}
else
{
mx = x - 100;
}
}
else if (p < 90) // 75-90,15%几率进入状态 4
{
m = 4;
n = Math.abs( r.nextInt() %30)+20;
this.setfs( FS[1]);
}
else // 90-100 ,10%几率进入状态 0 待机
{
m = 0;
n = Math.abs( r.nextInt() %30)+20;
}
}
if (Math.abs( x - pl.x ) < 20 && Math.abs( z - pl.z ) < 5)
{
m = 5;
n = Math.abs( r.nextInt() %5)+5;
this.setfs( FS[2]);
}
break;
case 3: //X轴远离
if (x > pl.x )
{
if (x < mx)
{
x += 3;
}
else
{
x -= 3;
}
}
else
{
if (x > mx)
{
x -= 3;
}
else
{
x += 3;
}
}
if (Math.abs( x - mx) <20)
{
p = Math.abs( r.nextInt() %100);
if (p < 30) //30%的几率进入状态 1
{
m = 1;
n = Math.abs( r.nextInt() %30)+20;
this.setfs( FS[1]);
}
else if (p < 60) // 30-60,30%几率进入状态 2
{
m = 2;
n = Math.abs( r.nextInt() %30)+20;
this.setfs( FS[1]);
}
else if (p < 75) // 60-75,15%几率进入状态 3
{
m = 3;
n = Math.abs( r.nextInt() %30)+20;
this.setfs( FS[1]);
if (x > pl.x)
{
mx = x + 100;
}
else
{
mx = x - 100;
}
}
else if (p < 90) // 75-90,15%几率进入状态 4
{
m = 4;
n = Math.abs( r.nextInt() %30)+20;
this.setfs( FS[1]);
}
else // 90-100 ,10%几率进入状态 0 待机
{
m = 0;
n = Math.abs( r.nextInt() %30)+20;
}
}
if (Math.abs( x - pl.x ) < 20 && Math.abs( z - pl.z ) < 5)
{
m = 5;
n = Math.abs( r.nextInt() %5)+5;
this.setfs( FS[2]);
}
break;
case 4: //Z轴远离
if (z > pl.z &&z < 190)
{
z += 3;
}
if ( z > 170)
{
p = Math.abs( r.nextInt() %100);
if (p < 30) //30%的几率进入状态 1
{
m = 1;
n = Math.abs( r.nextInt() %30)+20;
this.setfs( FS[1]);
}
else if (p < 60) // 30-60,30%几率进入状态 2
{
m = 2;
n = Math.abs( r.nextInt() %30)+20;
this.setfs( FS[1]);
}
else if (p < 75) // 60-75,15%几率进入状态 3
{
m = 3;
n = Math.abs( r.nextInt() %30)+20;
this.setfs( FS[1]);
if (x > pl.x)
{
mx = x + 100;
}
else
{
mx = x - 100;
}
}
else if (p < 90) // 75-90,15%几率进入状态 4
{
m = 4;
n = Math.abs( r.nextInt() %30)+20;
this.setfs( FS[1]);
}
else // 90-100 ,10%几率进入状态 0 待机
{
m = 0;
n = Math.abs( r.nextInt() %30)+20;
}
}
if (z < pl.z &&z > 110)
{
z -= 3;
}
if (z < 130)
{
p = Math.abs( r.nextInt() %100);
if (p < 30) //30%的几率进入状态 1
{
m = 1;
n = Math.abs( r.nextInt() %30)+20;
this.setfs( FS[1]);
}
else if (p < 60) // 30-60,30%几率进入状态 2
{
m = 2;
n = Math.abs( r.nextInt() %30)+20;
this.setfs( FS[1]);
}
else if (p < 75) // 60-75,15%几率进入状态 3
{
m = 3;
n = Math.abs( r.nextInt() %30)+20;
this.setfs( FS[1]);
if (x > pl.x)
{
mx = x + 100;
}
else
{
mx = x - 100;
}
}
else if (p < 90) // 75-90,15%几率进入状态 4
{
m = 4;
n = Math.abs( r.nextInt() %30)+20;
this.setfs( FS[1]);
}
else // 90-100 ,10%几率进入状态 0 待机
{
m = 0;
n = Math.abs( r.nextInt() %30)+20;
}
}
if (Math.abs( x - pl.x ) < 20 && Math.abs( z - pl.z ) < 5)
{
m = 5;
n = Math.abs( r.nextInt() %5)+5;
this.setfs( FS[2]);
}
break;
case 5: //攻击等待
n -- ;
if (n <= 0)
{
m = 6;
n = 6;
this.setfs( FS[2]);
}
break;
case 6: //攻击
n --;
if (n <= 0)
{
p = Math.abs( r.nextInt() %100);
if (p < 80) //50几率继续攻击
{
m = 5;
n = Math.abs( r.nextInt() %5)+20;
this.setfs( FS[0]);
}
else //50几率逃离
{
if (x > pl.x)
{
mx = x + 100;
}
else
{
mx = x - 100;
}
mz = Math.abs( r.nextInt() %90)+110;
this.setfs( FS[1]);
m = 7;
}
}
break;
case 7: //逃离状态
if (x < mx)
{
x += 3;
}
else
{
x -= 3;
}
if (z < mz)
{
z += 2;
}
else
{
z -= 2;
}
if (Math.abs( x - mx) < 20 && Math.abs( z - mz) < 20)
{
m = 0;
n = Math.abs( r.nextInt() %30)+20;
this.setfs( FS[0]);
}
break;
case 8: //后仰
n--;
if (n <= 0)
{
m = 5;
n = Math.abs( r.nextInt() %5)+5;
this.setfs( FS[0]);
}
break;
case 9: //打飞
this.setfs( FS[4]);
y +=vy;
vy +=2;
if (f == false)
{
x -= 8;
}
else
{
x += 8;
}
if (y >= 0)
{
this.setfs( FS[4]);
y = 0;
m = 10;
n = 10;
}
break;
case 10: //倒地
this.setfs( FS[5]);
n--;
if (hp > 0 &&n <= 0)
{
this.setfs( FS[6]);
m = 11;
n = 10;
}
if (hp <= 0&&n <= 0)
{
this.setfs(FS[7]);
m = 12;
n =20;
}
break;
case 11: //爬起
n --;
if (n <= 0)
{
m = 0;
n = Math.abs( r.nextInt() %20)+10;
this.setfs( FS[0]);
}
break;
case 12://死亡
n --;
break;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -