?? mulittank.java
字號:
/*
* Created on 2005-2-14
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package components;
import java.awt.Graphics2D;
import java.util.Vector;
/**
* @author AnSen
*
* TODO To change the template for this generated type comment go to Window -
* Preferences - Java - Code Style - Code Templates
*/
public class MulitTank extends Tank {
private int index;
private double dTargetX = 0;
private double dTargetY = 0;
private String strUsrName=null;
private boolean isRemote = true;
/**
* @param ptX
* @param ptY
* @param container
* @param index
* @param isRemote
*/
public MulitTank(double ptX, double ptY, Vector container, int index,
boolean isRemote) {
super(ptX, ptY, container);
this.index = index;
this.isRemote = isRemote;
}
/**
* @return Returns the index.
*/
public int getIndex() {
return index;
}
public void updateTank(double direct, double x, double y) {
this.ptX = x;
this.ptY = y;
this.setDirect(direct);
this.rotateFrame(this.ishpframe);
this.moveFrame(this.ishpframe);
}
public void setTarget(double direct,double x, double y) {
dTargetX = x;
dTargetY = y;
/*double ds=Math.sqrt((dTargetX-ptX)*(dTargetX-ptX)
+(dTargetY-ptY)*(dTargetY-ptY));
if(ds>dSpeed*3){
updateTank(dDirect,x,y);
}*/
this.setDirect(direct);
}
/*
* (non-Javadoc)
*
* @see components.GmMovComponent#move()
*/
public void move() {
if (isRemote) {
if (Math.abs(dTargetX - ptX) <= 1 && Math.abs(dTargetY - ptY) <= 1) {
//updateTank(this.dInputDirect,dTargetX,dTargetY);
this.setMoving(false);
}
double ds=Math.sqrt((dTargetX-ptX)*(dTargetX-ptX)
+(dTargetY-ptY)*(dTargetY-ptY));
if(ds>dSpeed*3){
updateTank(dDirect,dTargetX,dTargetY);
}
}
super.move();
}
/**
* @param isControled The isControled to set.
*/
public void setRemote(boolean isControled) {
this.isRemote = isControled;
}
/* (non-Javadoc)
* @see components.GmComponent#renderImage(java.awt.Graphics2D, int, int, int, int)
*/
public void renderImage(Graphics2D g2D, int left, int top, int width,
int height) {
int px,py;
if(strUsrName!=null){
px=(int)Math.ceil(ptX-left-this.width/2);
py=(int)Math.ceil(ptY-top-this.height/2-10);//5=font height;
g2D.drawString(strUsrName,px,py);
}
super.renderImage(g2D, left, top, width, height);
}
/**
* @param strUsrName The strUsrName to set.
*/
public void setStrUsrName(String strUsrName) {
this.strUsrName = strUsrName;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -