📄 cnpc.java
字号:
import java.util.Random;
public class CNpc extends CActor {
private int up[] = { 0, 1 };
private int right[] = { 2, 3 };
private int down[] = { 4, 5 };
private int left[] = { 6, 7 };
private int npccount = 0;
private Random ran;
private int npcstatus = 0;
private final int npc_up = 0;
private final int npc_down = 1;
private final int npc_left = 2;
private final int npc_right = 3;
public CNpc(int x, int y, int frame_w, int frame_h) {
this.x = x;
this.y = y;
this.frame_w = frame_w;
this.frame_h = frame_h;
frame = up;
ran = new Random();
}
// 更新NPC状态
void updateNPC() {
if (npccount % 15 == 0) {
npcstatus = (ran.nextInt() >>> 1) % 4;
}
getColArea();
CollisionMap();
switch (npcstatus) {
case npc_up:
if (!isCollisionUp)
move(0, -1);
setFrame(up);
break;
case npc_down:
if (!isCollisionDown)
move(0, 1);
setFrame(down);
break;
case npc_left:
if (!isCollisionLeft)
move(-1, 0);
setFrame(left);
break;
case npc_right:
if (!isCollisionDown)
move(1, 0);
setFrame(right);
break;
}
if (npccount > 60)
npccount = 0;
else
npccount++;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -