📄 mainrole.java
字号:
import java.util.*;
import javax.microedition.lcdui.*;
public class MainRole extends MySprite{
private boolean showExcalMark;
public boolean isShowExcalMark() {
return showExcalMark;
}
public void setShowExcalMark(boolean showExcalMark) {
this.showExcalMark = showExcalMark;
}
public MainRole(Image playerImg,int w,int h)
{
super(playerImg, w, h);
//System.out.println("MainRole.MainRole()");
init();
}
public void init()
{
//System.out.println("MainRole.init()");
this.setCollision(true);
currentDirect=SceneLib.scenes[SceneLib.currentSceneIndex].getRoleDir();
initDirect();
if(!SystemMenu.loading && !GameMIDlet.isOutBattle)
{
System.out.println("自动定位");
setPosition(SceneLib.scenes[SceneLib.currentSceneIndex].getRoleX(),SceneLib.scenes[SceneLib.currentSceneIndex].getRoleY());
}
else
{
System.out.println("手动定位");
}
//System.out.println("GameMIDlet.scenes["+GameMIDlet.sceneIndex+"].getRoleX()="+GameMIDlet.scenes[GameMIDlet.sceneIndex].getRoleX());
//System.out.println("GameMIDlet.scenes["+GameMIDlet.sceneIndex+"].getRoleY()="+GameMIDlet.scenes[GameMIDlet.sceneIndex].getRoleY());
//walking=false;
//haveCollision=false;
this.setName("主角");
super.isMainRole=true;
setMaxX(SceneLib.scenes[SceneLib.currentSceneIndex].getWalkMaxX()); //设置主角移动范围
setMaxY(SceneLib.scenes[SceneLib.currentSceneIndex].getWalkMaxY());
setMinX(SceneLib.scenes[SceneLib.currentSceneIndex].getWalkMinX());
setMinY(SceneLib.scenes[SceneLib.currentSceneIndex].getWalkMinY());
//System.out.println("minX="+minX);
//System.out.println("minY="+minY);
//System.out.println("maxX="+maxX);
//System.out.println("maxY="+maxY);
}
public void drawExcalMark(Graphics g,int xOffset,int yOffset)
{
Image markImg=Tools.getImage("/pic/excal.png");
Tools.drawRegion(g,markImg,0,0,8,16,this.getX()+8-xOffset,this.getY()-12-yOffset,Style.LT);
}
//获取主角接触到的对话区
public ChatArea getChatArea()
{
//Vector npcVC=npcFactory.getSpriteVC();
Vector chatVC=ChatSprites.getSprites();
for(int i=0;chatVC!=null && i<chatVC.size();i++)
{
MySprite npc=(MySprite)chatVC.elementAt(i);
if(npc.isCanChat())
{
ChatArea chatArea=npc.getChatArea();
if(chatArea!=null)
{
Box box=this.getCollisionRectangle();
Box box1=new Box();
box1.x=box.x+this.getX();
box1.y=box.y+this.getY();
box1.w=box.w;
box1.h=box.h;
Box box2=new Box();
box2.x=chatArea.x+npc.getX();
box2.y=chatArea.y+npc.getY();
box2.w=chatArea.w;
box2.h=chatArea.h;
//System.out.println(box1.x+","+box1.y+","+box2.x+","+box2.y);
if(Tools.checkBoxInter(box1,box2))
{ //System.out.println(chatArea.getParent().getName());
return chatArea;
}
}
}
}
return null;
}
public OutArea getOutArea()
{
//System.out.println("取出口");
Vector outAreaVC=SceneLib.scenes[SceneLib.currentSceneIndex].getOutArea();
Box box=this.getCollisionRectangle();
Box box1=new Box();
box1.x=box.x+this.getX();
box1.y=box.y+this.getY();
box1.w=box.w;
box1.h=box.h;
for(int i=0;outAreaVC!=null && i<outAreaVC.size();i++)
{
OutArea outArea=(OutArea)outAreaVC.elementAt(i);
if(Tools.checkBoxInter(box1,outArea))
{ //System.out.println(chatArea.getParent().getName());
return outArea;
}
}
return null;
}
public boolean checkTouchEnemy(EnemyFactory enemyFactory,RoleLayer roleLayer)
{
if(enemyFactory==null || roleLayer==null)return false;
Vector enemyVC=enemyFactory.getSpriteVC();
Box box=this.getCollisionRectangle();
Box box1=new Box();
box1.x=box.x+this.getX();
box1.y=box.y+this.getY();
box1.w=box.w;
box1.h=box.h;
for(int i=0;enemyVC!=null && i<enemyVC.size();i++)
{
EnemySprite enemySprite=(EnemySprite)enemyVC.elementAt(i);
if(Tools.checkBoxInter(box1,enemySprite.getTouchBox()))
{ //System.out.println(chatArea.getParent().getName());
roleLayer.remove(enemySprite);
GameMIDlet.midlet.enemyVC.removeElement(enemySprite);
enemyFactory.remove(i);
return true;
}
}
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -