www.pudn.com > 50code.rar > BrickSprite.java, change:2007-02-26,size:1261b


package demo; 
import javax.microedition.lcdui.Image; 
import javax.microedition.lcdui.game.Sprite; 
 
 
public class BrickSprite extends Sprite{ 
	//砖块的状态值 
	public static final int BRICK_FIX 		= 0;		//固定在屏幕上方	 
	public static final int BRICK_DROP 		= 1;		//下落 
	public static final int BRICK_HIDE 		= 2;		//消失 
	public static final int BRICK_STATE_NUM 	= 3;		//状态总数 
	private int m_nState = BRICK_FIX; 
	public BrickSprite( Image image, int frameWidth, int frameHeight){ 
		super(image, frameWidth, frameHeight);		 
		defineReferencePixel(frameWidth / 2, frameHeight / 2); 
		setState(BRICK_HIDE); 
	} 
	//得到当前状态 
	public int getState(){ 
		return m_nState;  
	} 
	//设置当前状态 
	public void setState( int state ){ 
		if( state < 0 || state >= BRICK_STATE_NUM ) 
			return; 
		m_nState = state; 
		switch( m_nState ){ 
		case BRICK_FIX: 
		case BRICK_DROP: 
			setVisible(true); 
			break; 
		case BRICK_HIDE: 
			setVisible(false); 
			break; 
		} 
	} 
	//逻辑操作,处理不同状态下砖块的运动 
	public void Logic( int scrHeight ){ 
		switch( m_nState ){ 
		case BRICK_DROP: 
			int y = getRefPixelY(); 
			y +=2; 
			setRefPixelPosition(getRefPixelX(), y); 
			if( y > scrHeight ) 
				setState(BRICK_HIDE); 
			break; 
		} 
	} 
}