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

📄 sprite.java

📁 一個J2ME寫的射擊游戲,不錯不錯
💻 JAVA
字号:

import javax.microedition.lcdui.*;


abstract class Sprite {
	/** 储存了X坐标的变量 */
	protected int				x;
	/** 储存了Y坐标的变量 */
	protected int				y;
	/** 储存横宽的变量 */
	protected int				width;
	/** 储存高度的变量 */
	protected int				height;

	/** 代表是否为Alive状态的标志变量 */
	protected boolean			isAlive				= true;
	/** 代表是否为Hit状态的标志变量 */
	protected boolean			isHit				= false;
	/** 储存了TicK计数的变量 */
	protected int				tickCount			= 0;


	void setX(int x) {
		this.x = x;
	}


	int getX() {
		return x;
	}


	void setY(int y) {
		this.y = y;
	}

	int getY() {
		return y;
	}


	int getWidth() {
		return width;
	}


	int getHeight() {
		return height;
	}


	void setAlive(boolean isAlive) {
		this.isAlive = isAlive;
	}

	
	boolean isAlive() {
		return isAlive;
	}


	void setHit(boolean isHit) {
		this.isHit = isHit;
		tickCount	 = 0;
	}


	boolean isHit() {
		return isHit;
	}


	boolean isOverlaps(Sprite otherSprite) {
		if(	(otherSprite.getX() <= x && otherSprite.getX() + otherSprite.getWidth() >= x) ||	//右
			(otherSprite.getX() >= x && otherSprite.getX() <= x + width) ) {			//左
			if(	(otherSprite.getY() <= y && otherSprite.getY() + otherSprite.getHeight() >= y) ||//上 
				(otherSprite.getY() >= y && otherSprite.getY() <= y + height) ) {		//下
				return true;
			}
		}
		return false;
	}

	/** 要移动Sprite所调用的方法 */
	abstract void doMove();

	/** 要描绘Sprite所调用的方法 */
	abstract void doDraw(Graphics g);
}

⌨️ 快捷键说明

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