📄 npc.java
字号:
import java.io.IOException;
import javax.microedition.lcdui.Image;
//Download by http://www.codefans.net
public class NPC extends sprite {
protected Main main;
static final byte Fish = 0; //鱼
static final byte conch= 1; //贝壳
static final byte crad = 2; //螃蟹
static final byte tussock = 3; //草丛
static final byte tree = 4; //树藤
static final byte fruit= 5; //果实
static final byte block = 6; //石头
static final byte mew = 7; //海鸥
static final byte drug = 8; //草药
public static byte NpcState;
private int Npc_Fish[]= {3,4};
private int Npc_conch[]= {2};
private int Npc_crad[]= {0,1};
private int Npc_tussock[]= {5};
private int Npc_tree[]= {6};
private int Npc_fruit[] = {7,8};
private int Npc_block[] = {9};
private int Npc_mew[]= {10,11};
private int Npc_drug[]= {12,13};
public Image img=null;
boolean MMchase = false;
protected int scrW,scrH;
protected int npcX,npcY;
private int SpeedX,SpeedY;
public int type;
private int W=51,H=33;//SP W,H
public int boundX,boundY;//图片大小
// public int frameSize[][] =
// {
// {14,10},{29,16},{33,29},{51,33},{17,19},{30,22},{37,20},{35,27},{15,17}
// };
private boolean availability; //可用性
public NPC(Image img,int type,int npcX,int npcY,int SpeedX,int SpeedY,Main main ){
super(img,51,33,0);
this.availability = true;
this.type = type;
this.SpeedX = SpeedX;
this.SpeedY = SpeedY;
main = main;
switch(type)
{
case Fish:
this.setFrameSequence(Npc_Fish);
boundX = 14;
boundY = 1;
break;
case conch:
this.setFrameSequence(Npc_conch);
boundX = 29;
boundY = 1;
break;
case crad:
this.setFrameSequence(Npc_crad);
boundX = 30;
boundY = 1;
break;
case tussock:
this.setFrameSequence(Npc_tussock);
boundX = 33;
boundY = 1;
break;
case tree:
this.setFrameSequence(Npc_tree);
boundX = 30;
boundY = 1;
break;
case fruit:
this.setFrameSequence(Npc_fruit);
boundX = 17;
boundY = 1;
break;
case block:
this.setFrameSequence(Npc_block);
boundX = 35;
boundY = 1;
break;
case mew:
this.setFrameSequence(Npc_mew);
boundX = 37;
boundY = 1;
break;
case drug:
this.setFrameSequence(Npc_drug);
boundX = 15;
boundY = 1;
break;
}//end switch
this.npcX = npcX;
this.npcY = npcY;
this.setPosition(npcX, npcY);
this.main = main;
scrW = main.ScrWidth;
scrH = main.ScrHeight;
}
public void move(int Speed)
{
npcY+=(Speed+SpeedY);
switch(this.type)
{
case Fish:
case fruit:
case drug:
this.nextFrame();
break;
case crad:
npcX-=SpeedX;
this.nextFrame();
break;
case mew:
this.nextFrame();
break;
}//end switch
if( npcY>main.ScrHeight+getHeight()+50 || npcX<-50 ||npcX>300)
{
remove();
}
this.setPosition(npcX, npcY);
}
public void isCollision(int excursionX,int excursionY)
{
if(main.sp_role.collidesWith(this,false,excursionX,excursionY) && availability && !main.Fly && main.RoleState != 8 && !main.Hit && !main.fall)
{
switch(type)
{
case Fish :
main.lm.remove(this);
Main.NpcState = Fish;
this.availability = false;
System.out.println("Fish");
main.Hit = true;
break;
case fruit:
Main.NpcState = fruit;
main.lm.remove(this);
this.availability = false;
System.out.println("fruit");
main.Hit = true;
break;
case crad:
if(!main.clarity)
{
Main.NpcState = crad;
this.availability = false;
System.out.println("crad");
main.Hit = true;
}
break;
case conch:
if(!main.clarity)
{
Main.NpcState = conch;
this.availability = false;
System.out.println("conch");
main.Hit = true;
}
break;
case tussock:
Main.NpcState = tussock;
NpcState = tussock;
System.out.println("tussock");
main.Hit = true;
break;
case tree:
if(!main.clarity)
{
Main.NpcState = tree;
NpcState = tree;
this.availability = false;
System.out.println("tree");
main.Hit = true;
}
break;
}
}
}
public void remove()
{
main.npcVector.removeElement(this);
main.lm.remove(this);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -