www.pudn.com > ch8-spaceshooter.rar > MyShip.java


/* 
 * MyShip.java 
 * 
 * Copyright 2001 SkyArts. All Rights Reserved. 
 */ 
import javax.microedition.lcdui.*; 
 
/** 
 * Myship类 
 * 
 * @author  Hideki Yonekawa 
 * @version 1.0 
 */ 
class MyShip extends Sprite { 
	/** 储存自机图像的变量*/ 
	private Image				shipImg; 
	/** 储存自机爆炸图像的变量 */ 
	private Image				burstImg; 
 
	/** 构造函数 */ 
	MyShip() { 
		// 取得图像 
		try { 
			shipImg = Image.createImage("/myship.png"); 
			burstImg = Image.createImage("/burst.png"); 
		}catch(Exception e) {} 
		//设定宽度与高度 
		width = shipImg.getWidth(); 
		height = shipImg.getHeight(); 
	} 
 
	/** 要移动Sprite时所调用的方法 */ 
	void doMove() { 
		tickCount++; 
		if(isHit()) { 
			if(tickCount > 4) { 
				setHit(false); 
			} 
		}else { 
			if(tickCount > 4) { 
				tickCount = 0; 
			} 
		} 
	} 
 
	/** 要描绘Sprite时所调用的方法 */ 
	void doDraw(Graphics g) { 
		if(isHit()) { 
		//Hit时描绘爆炸图像 
			g.drawImage(burstImg, x, y, Graphics.TOP|Graphics.LEFT); 
		}else { 
			g.drawImage(shipImg, x, y, Graphics.TOP|Graphics.LEFT); 
		} 
	} 
}