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

📄 star.java

📁 JAVA GAME it include collide detection
💻 JAVA
字号:
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
import java.util.*;

public class Star extends Sprite {
	private static final String IMAGE_FILENAME = "/starsprite.png";
	private static final int IMAGE_COLUMNS = 3;
	private static final int IMAGE_ROWS = 1;

	private int m_fallY;

	private static Image m_image;
	private static final Image getImage() {
		try {
			m_image = Image.createImage(IMAGE_FILENAME);
		}
		catch (Exception e) {
			System.err.println("Error loading star image");
			return null;
		}
		return m_image;
	}

	public Star(Random rand, int screenwidth, int y) {
		super(getImage(),
			  m_image.getWidth() / IMAGE_COLUMNS,
			  m_image.getHeight() / IMAGE_ROWS);

		if (Math.abs(rand.nextInt()) % 3 == 0) {
			m_fallY = 2;
		}
		else {
			m_fallY = 1;
		}
		int x = Math.abs(rand.nextInt()) % (screenwidth - getWidth());
		setPosition(x, y);
	}

	public void fall() {
		move(0, m_fallY);
		nextFrame();
	}
}

⌨️ 快捷键说明

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