package code.kalter.longflight.space; import code.kalter.longflight.Color; import java.util.Random; import javax.microedition.lcdui.Graphics; /** * Звёзды... * * @author KalterFive */ class Star { private final int screenH; private final int COUNT; private final int[] positionX; private final int[] positionY; private final int[] color; public Star(int screenW, int screenH) { this.screenH = screenH; Random random = new Random(); COUNT = (screenH + screenW) / 3; positionX = new int[COUNT]; positionY = new int[COUNT]; color = new int[COUNT]; for (int i = 0; i < COUNT; i++) { positionX[i] = random.nextInt(screenH); positionY[i] = random.nextInt(screenW); int a = random.nextInt(256); color[i] = Color.maskRGB(a, a, a); } } public void paint(Graphics graphics) { for (int i = 0; i < COUNT; i++) { graphics.setColor(color[i]); graphics.fillRect(positionX[i], positionY[i], 1, 1); } } public void upd() { for (int i = 0; i < COUNT; i++) { if ((positionY[i] += ((color[i] & 0x0000FF) / 50)) > screenH) { positionY[i] = 0; } } } }