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

📄 tools.java

📁 j2me的一款钓鱼的游戏
💻 JAVA
字号:
package tool;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

public class Tools {
	static public boolean isColl(int x, int y, int x1, int y1, int w, int h) {
		if (x > x1 && x <= w + x1 && y > y1 && y <= h + y1) {
			return true;
		} else {
			return false;
		}
	}

	static public boolean isCollLine(int x, int y, int l, int x1, int y1,
			int w, int h) {
		if (isColl(x, y, x1, y1, w, h) || isColl(x + l, y, x1, y1, w, h)) {
			return true;
		} else {
			return false;
		}
	}

	static public boolean isCollRect(int x, int y, int w1, int h1, int x1,
			int y1, int w, int h) {
		if (isColl(x, y, x1, y1, w, h) || isColl(x + w1, y, x1, y1, w, h)
				|| isColl(x + w1, y + h1, x1, y1, w, h)
				|| isColl(x, y + h1, x1, y1, w, h)) {
			return true;
		} else {
			return false;
		}
	}

	static public void draw_number(Image[] number, Graphics g, int num, int x,
			int y) {
		int temp = num;
		int t1 = temp;
		int i = 0;

		int lenght = 10;// 长度
		while (t1 != 0) {
			i++;
			t1 /= 10;
		}
		for (int j = 0; j < lenght - i; j++) {
			g.drawImage(number[0], j * 12 + x, y, Graphics.TOP | Graphics.LEFT);
		}
		i--;
		// =====================
		for (; i != -1;) {
			int bit = pow(10, i--);
			g.drawImage(number[temp / bit], (lenght - i - 2) * 12 + x, y,
					Graphics.TOP | Graphics.LEFT);
			temp %= bit;
		}
	}

	/**
	 * 
	 * @param resours
	 *            资源图
	 * @param x
	 *            起始X
	 * @param y
	 *            起始Y
	 * @param width
	 *            宽
	 * @param height
	 *            高
	 * @return
	 */

	static public Image getFrameIm(Image resours, int x, int y, int width,
			int height) {
		Image buffer = Image.createImage(width, height);

		Graphics g = buffer.getGraphics();
		g.setColor(0xff1155cc);
		g.fillRect(0, 0, width, height);

		g.drawImage(resours, -x, -y, Graphics.TOP | Graphics.LEFT);
		// ---------------------------------------------
		int temp[] = new int[width * height];

		buffer.getRGB(temp, 0, width, 0, 0, width, height);

		for (int i = 0; i < temp.length; i++) {
			if (temp[i] == 0xff1155cc) {
				temp[i] = 0x001155cc;
			}
		}

		return Image.createRGBImage(temp, width, height, true);

		// return buffer;
	}

	/**
	 * 得到动画祯序列
	 * 
	 * @param resours
	 * @param strax
	 * @param stray
	 * @param row
	 * @param cow
	 * @param width
	 * @param height
	 * @return
	 */
	static public Image[] getAnmi(Image resours, int strax, int stray, int row,
			int cow, int width, int height) {

		Image[] temp = new Image[row * cow];

		int count = 0;
		for (int j = 0; j < row; j++) {
			for (int i = 0; i < cow; i++) {
				temp[count++] = getFrameIm(resours, i * width + strax, j
						* height + stray, width, height);
			}
		}

		return temp;
	}

	private static int pow(int x, int n) {
		if (n == 0) {
			return 1;
		} else {
			return pow(x, n - 1) * x;
		}
	}

	/**
	 * 把指定的图片,用指定的level来进行alpha处理,并返回处理后的图片实例
	 * 
	 * @param image
	 *            图片实例
	 * @param level
	 *            alpha等级0~255
	 * @return
	 */
	static public Image getAphiImage(Image image, int level) {

		int width = image.getWidth();// 得到图象宽
		int height = image.getHeight();// 得到图象高

		int argb[] = new int[width * height];
		image.getRGB(argb, 0, width, 0, 0, width, height);
		int aphi = level;
		for (int i = 0; i < argb.length; i++) {
			argb[i] = (argb[i] & 0x00ffffff) | (aphi << 24);
		}
		image = Image.createRGBImage(argb, width, height, true);

		return image;
	}

	/**
	 * 对指定的图片,指定的颜色进行level的alpha处理,并返回该图片
	 * 
	 * @param image
	 *            图片实例
	 * @param level
	 *            alpha等级0~255
	 * @param color
	 *            进行处理的颜色值
	 * @return
	 */

	static public Image getAphiImage(Image image, int level, int color) {

		int width = image.getWidth();// 得到图象宽
		int height = image.getHeight();// 得到图象高

		int argb[] = new int[width * height];
		image.getRGB(argb, 0, width, 0, 0, width, height);
		int aphi = level;
		for (int i = 0; i < argb.length; i++) {
			if (color == argb[i]) {
				argb[i] = (argb[i] & 0x00ffffff) | (aphi << 24);
			}
		}
		image = Image.createRGBImage(argb, width, height, true);

		return image;
	}

}

⌨️ 快捷键说明

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