⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mulittank.java

📁 坦克游戏
💻 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 + -