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

📄 bricksprite.java

📁 J2ME的砖块游戏!!打砖块游戏!!!开发环境用wTK
💻 JAVA
字号:
package com.yang.c10.Brick;
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;
		}
	}
}

⌨️ 快捷键说明

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