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

📄 bullet.java

📁 联机坦克游戏
💻 JAVA
字号:
/*
 * Created on 2005-2-6
 *
 * tank components
 */
package components;

import java.awt.Graphics2D;
import java.awt.Image;
import java.util.Vector;
import java.util.Properties;

import resource.ResourceFactory;
import shape.*;

/**
 * @author AnSen
 * 
 * Bullet
 */
public class Bullet extends GmMovComponent implements IScriptRender{

	private static String resourceID = "BULLET";

	/**
	 * @param life
	 * @param ptX
	 * @param ptY
	 * @param width
	 * @param height
	 * @param direct
	 * @param container
	 */
	public Bullet(double ptX, double ptY, int width, int height, double direct,
			Vector container) {
		super(-1, ptX, ptY, width, height, direct, container);
		initBullet();
	}

	private void initBullet() {
		this.isMoving = true;
		this.addGmListener(new GmMovCpAdapter() {
			public void hitWallProformed(double x, double y) {
				removeOject();
			}

			public void removeProformed() {
				Explode bomb = new Explode(ptX, ptY, vContainer);
				vContainer.addElement(bomb);
			}
		});
		Properties prop = ResourceFactory.getInstance().getProperties(
				resourceID);
		Polygon frame = Polygon.parsePolygon(prop.getProperty("FRAME"));
		frame.offset(ptX, ptY);
		this.ishpframe = frame;
		this.lLife = Long.parseLong(prop.getProperty("LIFE"));
		this.width = Integer.parseInt(prop.getProperty("WIDTH"));
		this.height = Integer.parseInt(prop.getProperty("HEIGHT"));
		this.iSpeed = Integer.parseInt(prop.getProperty("SPEED"));
		this.dSpeed = iSpeed;
		this.iMaxFrames = Integer.parseInt(prop.getProperty("MAXFRAMES"));
		this.images = (Image[]) prop.get("IMAGES");
	}

	public void upSpeed() {
	}//cancel acc speed

	
	/* (non-Javadoc)
	 * @see components.IScriptRender#isRenderable(int, int, int, int)
	 */
	public boolean isRenderable(int left, int top, int width, int height) {
		if (ptX > left && ptX < left + width &&
				ptY > top && ptY < top + height) {
			return true;
		}
		return false;
	}
	/* (non-Javadoc)
	 * @see components.IScriptRender#renderImage(java.awt.Graphics2D, int, int, int, int)
	 */
	public void renderImage(Graphics2D g2D, int left, int top, int width,
			int height) {
		int ptX, ptY; 
		ptX = this.getPositionX() - left 
			  -  images[iCurrFrame].getWidth(null)/2;
		ptY = this.getPositionY() - top 
			  - images[iCurrFrame].getHeight(null)/2; 
		g2D.drawImage(images[iCurrFrame], ptX, ptY, null); 
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -