📄 trackrender.java
字号:
/*
* Created on 2005-3-10
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package tankgame;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.util.Vector;
import resource.ResourceFactory;
import components.*;
/**
* @author Emtry Immortal
*
* TODO To change the template for this generated type comment go to Window -
* Preferences - Java - Code Style - Code Templates
*/
public class TrackRender implements ICamera {
private Vector vContainer = null;
private BufferedImage bffImage;
private BufferedImage bffImage2;
private int width;
private int height;
private int top;
private int left;
private GmMovComponent gmcPoint=null;
private int dhWidth;
private int dhHeight;
private boolean bFlag = true;
RenderingHints renderingHints;
//Graphics2D gObj;
Graphics2D g2D1;
Graphics2D g2D2;
public TrackRender(int width, int height, GmMovComponent gmc,
Vector vContainer) {
bffImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
bffImage2 = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
this.width = width;
dhWidth = width / 2;
this.height = height;
dhHeight = height / 2;
gmcPoint = gmc;
this.vContainer = vContainer;
renderingHints=ResourceFactory.
getInstance().getRenderingHints();
g2D1=(Graphics2D)bffImage.getGraphics();
g2D1.setRenderingHints(renderingHints);
g2D2=(Graphics2D)bffImage2.getGraphics();
g2D2.setRenderingHints(renderingHints);
}
/*
* (non-Javadoc)
*
* @see tankgame.ICamera#getGmcPointX()
*/
public int getGmcPointX() {
return dhWidth;
}
/*
* (non-Javadoc)
*
* @see tankgame.ICamera#getGmcPointY()
*/
public int getGmcPointY() {
return dhHeight;
}
public void setGmcPoint(Tank tnk) {
this.gmcPoint = tnk;
}
public void setContainer(Vector vContainer) {
this.vContainer = vContainer;
}
public Image getViewImage() {
Image img;
if(bFlag){
view(g2D1);
img=bffImage;
}else{
view(g2D2);
img=bffImage2;
}
bFlag=!bFlag;
return img;
}
public void view(Graphics2D g2D) {
g2D.fillRect(0,0,width,height);
double dCenterX,dCenterY;
if(gmcPoint==null){
dCenterX=0;
dCenterY=0;
}else{
dCenterX = this.gmcPoint.getPtX();
dCenterY = this.gmcPoint.getPtY();
}
top = (int) Math.ceil(dCenterY - (dhHeight));
left = (int) Math.ceil(dCenterX - (dhWidth));
for (int i = 0; i < vContainer.size(); i++) {
IScriptRender gmcObj = ((IScriptRender) vContainer.get(i));
if(gmcObj.isRenderable(left, top, width, height)){
gmcObj.renderImage(g2D, left, top, width, height);
}
}
String str = "pos:" + (int)Math.ceil(dCenterX) +
","+ (int)Math.ceil(dCenterY);
g2D.drawString(str, 10, 10);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -